[FFmpeg-devel] [PATCH 2/4] ffmpeg: use filter time base as codec time base.

Nicolas George nicolas.george at normalesup.org
Thu May 24 00:46:28 CEST 2012

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
 ffmpeg.c |    2 ++
 1 file changed, 2 insertions(+)

I have some doubts about that. Here is the problem:

Currently, the time base of an output encoder, if not set on the command
line, is copied from the frame rate of the corresponding input decoder.

Without filters, it makes reasonable sense, although it does not work well
with variable frame rate inputs.

With simple filters, the frame rate can change randomly, but it will still
work in the simple cases.

With complex filters, there is no "corresponding input".

The current code, with complex filters, finds the first input that has the
same media type as the output. That is IMHO completely nonsensical, and
patch #3 removes it.

The obvious solution would be to use the time base of the output link as the
time base for the encoder. Unfortunately, that will not work if the result
goes into a format that does not support variable frame rate: some filters,
and even a few input formats, select a time base with a frequency much
higher than the frame rate.

For that reason, this patch takes the output link time base only if the time
base is not set yet. With the current code, it happens with trans-media
filters; with patch #3, it will happen for all complex filters.

If someone has a better suggestion... Maybe have the filters compute and
forward an estimated frame rate during their config_props?


  Nicolas George

diff --git a/ffmpeg.c b/ffmpeg.c
index 79835a2..4e3b46a 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3178,6 +3178,8 @@ static int transcode_init(void)
             case AVMEDIA_TYPE_VIDEO:
                 codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
+                if (ost->filter && !(codec->time_base.num && codec->time_base.den))
+                    codec->time_base = ost->filter->filter->inputs[0]->time_base;
                 if (   av_q2d(codec->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH
                    && (video_sync_method == VSYNC_CFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){
                     av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n"

More information about the ffmpeg-devel mailing list