[FFmpeg-devel] [PATCH] ffmpeg: Do not fill gap before the first decodable frame on single stream input files in CFR mode.

Michael Niedermayer michaelni at gmx.at
Thu Nov 14 02:04:45 CET 2013


Fixes different behavior to JM and probably several if not all
reference decoders.

We cannot just do this unconditionally as it would ruin AV sync in
some use cases.

Bug-Found-by: BugMaster
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 ffmpeg.c     |   10 ++++++++++
 ffmpeg.h     |    1 +
 ffmpeg_opt.c |    1 +
 3 files changed, 12 insertions(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index 2a88535..be3513e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -824,6 +824,16 @@ static void do_video_out(AVFormatContext *s,
         } else
             format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? ((s->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR;
     }
+    if (   ist
+        && format_video_sync == VSYNC_CFR
+        && input_files[ist->file_index]->ctx->nb_streams == 1
+        && input_files[ist->file_index]->input_ts_offset == 0
+        && ost->frame_number == 0
+        && delta - duration >= 0.5) {
+        av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta - duration));
+        delta = duration;
+        ost->sync_opts = lrint(sync_ipts);
+    }
 
     switch (format_video_sync) {
     case VSYNC_CFR:
diff --git a/ffmpeg.h b/ffmpeg.h
index 409525c..8e42e26 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -281,6 +281,7 @@ typedef struct InputFile {
     int eof_reached;      /* true if eof reached */
     int eagain;           /* true if last read attempt returned EAGAIN */
     int ist_index;        /* index of first stream in input_streams */
+    int64_t input_ts_offset;
     int64_t ts_offset;
     int64_t last_ts;
     int64_t start_time;   /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 23e1c40..8da1ce4 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -852,6 +852,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
     f->ist_index  = nb_input_streams - ic->nb_streams;
     f->start_time = o->start_time;
     f->recording_time = o->recording_time;
+    f->input_ts_offset = o->input_ts_offset;
     f->ts_offset  = o->input_ts_offset - (copy_ts ? 0 : timestamp);
     f->nb_streams = ic->nb_streams;
     f->rate_emu   = o->rate_emu;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list