Skip to content

Commit 62903e9

Browse files
author
Rodger Combs
committed
ffmpeg: use lavf API for applying bitstream filters
1 parent 8daa336 commit 62903e9

File tree

3 files changed

+9
-44
lines changed

3 files changed

+9
-44
lines changed

ffmpeg.c

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -676,47 +676,10 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
676676
if (bsfc)
677677
av_packet_split_side_data(pkt);
678678

679-
while (bsfc) {
680-
AVPacket new_pkt = *pkt;
681-
AVDictionaryEntry *bsf_arg = av_dict_get(ost->bsf_args,
682-
bsfc->filter->name,
683-
NULL, 0);
684-
int a = av_bitstream_filter_filter(bsfc, avctx,
685-
bsf_arg ? bsf_arg->value : NULL,
686-
&new_pkt.data, &new_pkt.size,
687-
pkt->data, pkt->size,
688-
pkt->flags & AV_PKT_FLAG_KEY);
689-
if(a == 0 && new_pkt.data != pkt->data) {
690-
uint8_t *t = av_malloc(new_pkt.size + AV_INPUT_BUFFER_PADDING_SIZE); //the new should be a subset of the old so cannot overflow
691-
if(t) {
692-
memcpy(t, new_pkt.data, new_pkt.size);
693-
memset(t + new_pkt.size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
694-
new_pkt.data = t;
695-
new_pkt.buf = NULL;
696-
a = 1;
697-
} else
698-
a = AVERROR(ENOMEM);
699-
}
700-
if (a > 0) {
701-
pkt->side_data = NULL;
702-
pkt->side_data_elems = 0;
703-
av_packet_unref(pkt);
704-
new_pkt.buf = av_buffer_create(new_pkt.data, new_pkt.size,
705-
av_buffer_default_free, NULL, 0);
706-
if (!new_pkt.buf)
707-
exit_program(1);
708-
} else if (a < 0) {
709-
new_pkt = *pkt;
710-
av_log(NULL, AV_LOG_ERROR, "Failed to open bitstream filter %s for stream %d with codec %s",
711-
bsfc->filter->name, pkt->stream_index,
712-
avctx->codec ? avctx->codec->name : "copy");
713-
print_error("", a);
714-
if (exit_on_error)
715-
exit_program(1);
716-
}
717-
*pkt = new_pkt;
718-
719-
bsfc = bsfc->next;
679+
if ((ret = av_apply_bitstream_filters(s, pkt, bsfc)) < 0) {
680+
print_error("", ret);
681+
if (exit_on_error)
682+
exit_program(1);
720683
}
721684

722685
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
@@ -4176,7 +4139,6 @@ static int transcode(void)
41764139
av_dict_free(&ost->sws_dict);
41774140
av_dict_free(&ost->swr_opts);
41784141
av_dict_free(&ost->resample_opts);
4179-
av_dict_free(&ost->bsf_args);
41804142
}
41814143
}
41824144
}

ffmpeg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ typedef struct OutputStream {
451451
AVDictionary *sws_dict;
452452
AVDictionary *swr_opts;
453453
AVDictionary *resample_opts;
454-
AVDictionary *bsf_args;
455454
char *apad;
456455
OSTFinished finished; /* no more packets should be written for this stream */
457456
int unavailable; /* true if the steram is unavailable (possibly temporarily) */

ffmpeg_opt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,11 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
12551255
bsfc_prev->next = bsfc;
12561256
else
12571257
ost->bitstream_filters = bsfc;
1258-
av_dict_set(&ost->bsf_args, bsfc->filter->name, arg, 0);
1258+
if (arg)
1259+
if (!(bsfc->args = av_strdup(arg))) {
1260+
av_log(NULL, AV_LOG_FATAL, "Bitstream filter memory allocation failed\n");
1261+
exit_program(1);
1262+
}
12591263

12601264
bsfc_prev = bsfc;
12611265
bsf = next;

0 commit comments

Comments
 (0)