[FFmpeg-devel] [PATCH 1/2] lavf/concatdec: detect duration inconsistencies.

Nicolas George nicolas.george at normalesup.org
Tue Mar 5 17:17:08 CET 2013


Print a warning if the duration read from the file is
different from the actual duration of the packets by
more than 0.1s.

Address trac ticket #2319.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavformat/concatdec.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)


I am not sure whether such a trivial warning deserves so much added code,
but it was requested on trac.

Another possibility is to just document it (cf. the next patch).


diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index a9fcc76..6187cf4 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -244,10 +244,22 @@ fail:
 static int open_next_file(AVFormatContext *avf)
 {
     ConcatContext *cat = avf->priv_data;
-    unsigned fileno = cat->cur_file - cat->files;
-
-    if (cat->cur_file->duration == AV_NOPTS_VALUE)
+    unsigned i, fileno = cat->cur_file - cat->files;
+
+    if (cat->cur_file->duration == AV_NOPTS_VALUE) {
+        int64_t dts = AV_NOPTS_VALUE;
+        for (i = 0; i < cat->avf->nb_streams; i++)
+            dts = FFMAX(dts, av_rescale_q(cat->avf->streams[i]->cur_dts,
+                                          cat->avf->streams[i]->time_base,
+                                          AV_TIME_BASE_Q));
+        if (dts != AV_NOPTS_VALUE &&
+            FFABS(dts - cat->avf->duration) > AV_TIME_BASE / 10)
+            av_log(avf, AV_LOG_WARNING, "Inconsistent duration in file %s: "
+                   "%.2fs instead of %.2fs\n", cat->cur_file->url,
+                   cat->avf->duration / (double)AV_TIME_BASE,
+                   dts                / (double)AV_TIME_BASE);
         cat->cur_file->duration = cat->avf->duration;
+    }
 
     if (++fileno >= cat->nb_files)
         return AVERROR_EOF;
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list