ffmpeg: add -apad option which injects a apad filter only in the presence of video...
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 8 May 2013 21:43:19 +0000 (23:43 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 8 May 2013 21:55:06 +0000 (23:55 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
ffmpeg.c
ffmpeg.h
ffmpeg_filter.c
ffmpeg_opt.c

index 1f61d29..15c2a29 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -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);
index 558c996..24e6d47 100644 (file)
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -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;
index 58581c2..4b5c676 100644 (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;
index c87bf01..2aff601 100644 (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 },