[FFmpeg-devel] [PATCH 2/4] concatdec: factorize duration calculating code to get_duration function

Marton Balint cus at passwd.hu
Mon Nov 2 00:15:56 CET 2015


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/concatdec.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0180a7e..15094bf 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -285,6 +285,16 @@ static int match_streams(AVFormatContext *avf)
     return 0;
 }
 
+static int64_t get_duration(ConcatFile *file, AVFormatContext *avf)
+{
+    int64_t duration = avf->duration;
+    if (file->inpoint != AV_NOPTS_VALUE)
+        duration -= (file->inpoint - file->file_start_time);
+    if (file->outpoint != AV_NOPTS_VALUE)
+        duration -= avf->duration - (file->outpoint - file->file_start_time);
+    return duration;
+}
+
 static int open_file(AVFormatContext *avf, unsigned fileno)
 {
     ConcatContext *cat = avf->priv_data;
@@ -469,13 +479,8 @@ 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) {
-        cat->cur_file->duration = cat->avf->duration;
-        if (cat->cur_file->inpoint != AV_NOPTS_VALUE)
-            cat->cur_file->duration -= (cat->cur_file->inpoint - cat->cur_file->file_start_time);
-        if (cat->cur_file->outpoint != AV_NOPTS_VALUE)
-            cat->cur_file->duration -= cat->avf->duration - (cat->cur_file->outpoint - cat->cur_file->file_start_time);
-    }
+    if (cat->cur_file->duration == AV_NOPTS_VALUE)
+        cat->cur_file->duration = get_duration(cat->cur_file, cat->avf);
 
     if (++fileno >= cat->nb_files) {
         cat->eof = 1;
-- 
2.1.4



More information about the ffmpeg-devel mailing list