Skip to content

Commit

Permalink
ffmpeg: add -apad option which injects a apad filter only in the pres…
Browse files Browse the repository at this point in the history
…ence of video streams

Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed May 8, 2013
1 parent 410905f commit 33ff943
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,7 @@ static int transcode(void)
}
av_freep(&ost->st->codec->subtitle_header);
av_freep(&ost->forced_kf_pts);
av_freep(&ost->apad);
av_dict_free(&ost->opts);
av_dict_free(&ost->swr_opts);
av_dict_free(&ost->resample_opts);
Expand Down
3 changes: 3 additions & 0 deletions ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ typedef struct OptionsContext {
int nb_passlogfiles;
SpecifierOpt *guess_layout_max;
int nb_guess_layout_max;
SpecifierOpt *apad;
int nb_apad;
} OptionsContext;

typedef struct InputFilter {
Expand Down Expand Up @@ -356,6 +358,7 @@ typedef struct OutputStream {
AVDictionary *opts;
AVDictionary *swr_opts;
AVDictionary *resample_opts;
char *apad;
int finished; /* no more packets should be written for this stream */
int unavailable; /* true if the steram is unavailable (possibly temporarily) */
int stream_copy;
Expand Down
15 changes: 15 additions & 0 deletions ffmpeg_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
OutputStream *ost = ofilter->ost;
AVCodecContext *codec = ost->st->codec;
AVFilterContext *last_filter = out->filter_ctx;
OutputFile *of = output_files[ost->file_index];
int pad_idx = out->pad_idx;
char *sample_fmts, *sample_rates, *channel_layouts;
char name[255];
Expand Down Expand Up @@ -519,6 +520,20 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
AUTO_INSERT_FILTER("-vol", "volume", args);
}

if (ost->apad && of->shortest) {
char args[256];
int i;

for (i=0; i<of->ctx->nb_streams; i++)
if (of->ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
break;

if (i<of->ctx->nb_streams) {
snprintf(args, sizeof(args), "%s", ost->apad);
AUTO_INSERT_FILTER("-apad", "apad", args);
}
}

ret = insert_trim(ost, &last_filter, &pad_idx);
if (ret < 0)
return ret;
Expand Down
6 changes: 6 additions & 0 deletions ffmpeg_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in

MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);

MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
ost->apad = av_strdup(ost->apad);

ost->avfilter = get_ost_filters(o, oc, ost);
if (!ost->avfilter)
exit(1);
Expand Down Expand Up @@ -2642,6 +2645,9 @@ const OptionDef options[] = {
{ "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
OPT_OUTPUT, { .off = OFFSET(shortest) },
"finish encoding within shortest input" },
{ "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
OPT_OUTPUT, { .off = OFFSET(apad) },
"audio pad", "" },
{ "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
"timestamp discontinuity delta threshold", "threshold" },
{ "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
Expand Down

0 comments on commit 33ff943

Please sign in to comment.