ffmpeg: add -apad option which injects a apad filter only in the presence of video streams

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-05-08 23:43:19 +02:00
parent 410905f7fd
commit 33ff943f70
4 changed files with 25 additions and 0 deletions

View File

@ -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);

View File

@ -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 {
@ -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;

View File

@ -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];
@ -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;

View File

@ -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);
@ -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 },