[FFmpeg-devel] [PATCH] ffmpeg: rework checks for the -t option.

Nicolas George nicolas.george at normalesup.org
Tue Jul 3 21:15:26 CEST 2012


This commit is based on libav's implementation and
makes sure to compare output timestamps together.
It also reduces the differences with avconv.

The changes to the test reference files are caused
by an additional packet at the end, the timestamp
of the frame encoded by this packet is always
strictly below the limit stated by the -t option.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 ffmpeg.c                          |   22 +++++++++++++---------
 tests/ref/fate/bethsoft-vid       |    1 -
 tests/ref/fate/idroq-video-encode |    2 +-
 tests/ref/lavf/dv_fmt             |    6 +++---
 tests/ref/lavf/gxf                |    6 +++---
 tests/ref/lavf/ismv               |    6 +++---
 tests/ref/lavf/mov                |    6 +++---
 tests/ref/lavf/mpg                |    6 +++---
 tests/ref/lavf/mxf                |    6 +++---
 tests/ref/lavf/ogg                |    6 +++---
 10 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 25112d3..88fe1b3 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1570,10 +1570,10 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
     av_init_packet(&pkt);
     pkt.data = NULL;
     pkt.size = 0;
-#if 0
+
     if (!check_recording_time(ost))
         return;
-#endif
+
     if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
         frame->pts = ost->sync_opts;
     ost->sync_opts = frame->pts + frame->nb_samples;
@@ -1681,6 +1681,8 @@ static void do_subtitle_out(AVFormatContext *s,
 
     for (i = 0; i < nb; i++) {
         ost->sync_opts = av_rescale_q(pts, ist->st->time_base, enc->time_base);
+        if (!check_recording_time(ost))
+            return;
 
         sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q);
         // start_display_time is required to be 0
@@ -1782,6 +1784,9 @@ duplicate_frame:
 
     in_picture->pts = ost->sync_opts;
 
+    if (!check_recording_time(ost))
+        return;
+
     if (s->oformat->flags & AVFMT_RAWPICTURE &&
         enc->codec->id == CODEC_ID_RAWVIDEO) {
         /* raw pictures are written as AVPicture structure to
@@ -2237,13 +2242,6 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
     if (of->start_time && ist->pts < of->start_time)
         return 0;
 
-    if (of->recording_time != INT64_MAX &&
-        av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time,
-                      (AVRational){ 1, 1000000 }) >= 0) {
-        ost->is_past_recording_time = 1;
-        return 0;
-    }
-
     return 1;
 }
 
@@ -2260,6 +2258,12 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         !ost->copy_initial_nonkeyframes)
         return;
 
+    if (of->recording_time != INT64_MAX &&
+        ist->pts >= of->recording_time + of->start_time) {
+        ost->is_past_recording_time = 1;
+        return;
+    }
+
     /* force the input stream PTS */
     if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
         audio_size += pkt->size;
diff --git a/tests/ref/fate/bethsoft-vid b/tests/ref/fate/bethsoft-vid
index 1967427..f59823c 100644
--- a/tests/ref/fate/bethsoft-vid
+++ b/tests/ref/fate/bethsoft-vid
@@ -141,4 +141,3 @@
 1,      54760,      54760,      537,     1074, 0x142ce7ba
 0,         69,         69,        1,   192000, 0x159313a8
 1,      55297,      55297,      925,     1850, 0x7ff682f7
-0,         70,         70,        1,   192000, 0x8e685d68
diff --git a/tests/ref/fate/idroq-video-encode b/tests/ref/fate/idroq-video-encode
index bfffb09..24f3f0d 100644
--- a/tests/ref/fate/idroq-video-encode
+++ b/tests/ref/fate/idroq-video-encode
@@ -1 +1 @@
-736168b00f6b79f472a57bf47b587c8c
+2be5ade557acab688d58f1c5ec0773f4
diff --git a/tests/ref/lavf/dv_fmt b/tests/ref/lavf/dv_fmt
index 2a228b2..e8720af 100644
--- a/tests/ref/lavf/dv_fmt
+++ b/tests/ref/lavf/dv_fmt
@@ -1,9 +1,9 @@
 6f9cfff48f536fa727696f2f9fb3ac08 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x5ce4e5e4
-cc33ae4f9e6828914dea0f09d1241b7e *./tests/data/lavf/lavf.dv
-3480000 ./tests/data/lavf/lavf.dv
-./tests/data/lavf/lavf.dv CRC=0x8d5e9e8f
+2e8989478f05f6d4eaf1921fdfac4799 *./tests/data/lavf/lavf.dv
+3600000 ./tests/data/lavf/lavf.dv
+./tests/data/lavf/lavf.dv CRC=0x747caf33
 87d3b20f656235671383a7eaa2f66330 *./tests/data/lavf/lavf.dv
 3600000 ./tests/data/lavf/lavf.dv
 ./tests/data/lavf/lavf.dv CRC=0x0e868a82
diff --git a/tests/ref/lavf/gxf b/tests/ref/lavf/gxf
index 63101b8..f70b6d9 100644
--- a/tests/ref/lavf/gxf
+++ b/tests/ref/lavf/gxf
@@ -1,9 +1,9 @@
 befc1a39c37a4ecd9264942a3e34b3f6 *./tests/data/lavf/lavf.gxf
 796392 ./tests/data/lavf/lavf.gxf
 ./tests/data/lavf/lavf.gxf CRC=0x102918fd
-267d2b2b6e357209d76c366302cf35c3 *./tests/data/lavf/lavf.gxf
-794572 ./tests/data/lavf/lavf.gxf
-./tests/data/lavf/lavf.gxf CRC=0xab47d02d
+474c4dd8b124790b395b435ac95a6d14 *./tests/data/lavf/lavf.gxf
+816772 ./tests/data/lavf/lavf.gxf
+./tests/data/lavf/lavf.gxf CRC=0xc7d66595
 0a1a37fa79b62435545271b4e8e882f5 *./tests/data/lavf/lavf.gxf
 796392 ./tests/data/lavf/lavf.gxf
 ./tests/data/lavf/lavf.gxf CRC=0x3b1a8e91
diff --git a/tests/ref/lavf/ismv b/tests/ref/lavf/ismv
index cf0a583..08d5552 100644
--- a/tests/ref/lavf/ismv
+++ b/tests/ref/lavf/ismv
@@ -1,9 +1,9 @@
 eb116b60befadfd5c9118635d81c5a6e *./tests/data/lavf/lavf.ismv
 312271 ./tests/data/lavf/lavf.ismv
 ./tests/data/lavf/lavf.ismv CRC=0xbcc963fc
-90db70a6f33cf22db9ce242087b5870b *./tests/data/lavf/lavf.ismv
-321545 ./tests/data/lavf/lavf.ismv
-./tests/data/lavf/lavf.ismv CRC=0x3998478f
+456b04d243a2c45f820ee3cd6ed3ae3b *./tests/data/lavf/lavf.ismv
+331249 ./tests/data/lavf/lavf.ismv
+./tests/data/lavf/lavf.ismv CRC=0x5c2fddcd
 eb116b60befadfd5c9118635d81c5a6e *./tests/data/lavf/lavf.ismv
 312271 ./tests/data/lavf/lavf.ismv
 ./tests/data/lavf/lavf.ismv CRC=0xbcc963fc
diff --git a/tests/ref/lavf/mov b/tests/ref/lavf/mov
index b23b75d..ca69775 100644
--- a/tests/ref/lavf/mov
+++ b/tests/ref/lavf/mov
@@ -4,9 +4,9 @@
 21b992f6a677f971dfd685cc055a2b0a *./tests/data/lavf/lavf.mov
 358463 ./tests/data/lavf/lavf.mov
 ./tests/data/lavf/lavf.mov CRC=0x2f6a9b26
-f1e80a52983775ea27dda0590b46e17a *./tests/data/lavf/lavf.mov
-367893 ./tests/data/lavf/lavf.mov
-./tests/data/lavf/lavf.mov CRC=0xab307eb9
+f607c5ac4f2668149c064d75a4ddd0dd *./tests/data/lavf/lavf.mov
+377609 ./tests/data/lavf/lavf.mov
+./tests/data/lavf/lavf.mov CRC=0x4e671506
 305a68397e3cdb505704841fedcdc352 *./tests/data/lavf/lavf.mov
 357845 ./tests/data/lavf/lavf.mov
 ./tests/data/lavf/lavf.mov CRC=0x2f6a9b26
diff --git a/tests/ref/lavf/mpg b/tests/ref/lavf/mpg
index 8d2f862..8b3ca5a 100644
--- a/tests/ref/lavf/mpg
+++ b/tests/ref/lavf/mpg
@@ -1,9 +1,9 @@
 8d47f1d92230442d475477ed4ec0c778 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
 ./tests/data/lavf/lavf.mpg CRC=0x88f58ba1
-ac56ba7cec2d2be0a1ca17473e5b152c *./tests/data/lavf/lavf.mpg
-387072 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0xe8637d83
+a0510a6f6ad056882827a2d2a92fd537 *./tests/data/lavf/lavf.mpg
+399360 ./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0x93df648f
 af32acbc73ee486b05a37d53e516d5e7 *./tests/data/lavf/lavf.mpg
 372736 ./tests/data/lavf/lavf.mpg
 ./tests/data/lavf/lavf.mpg CRC=0x88f58ba1
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index 51a488e..7e48d50 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,9 +1,9 @@
 4cc269e1d2066fac03a3d7466f011c8e *./tests/data/lavf/lavf.mxf
 525881 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x4ace0849
-87eb6e0e51d31c8ffa414d02672edfa0 *./tests/data/lavf/lavf.mxf
-537657 ./tests/data/lavf/lavf.mxf
-./tests/data/lavf/lavf.mxf CRC=0x9b928d6b
+88ab06201db1953329bfb4aa04a4fe05 *./tests/data/lavf/lavf.mxf
+553529 ./tests/data/lavf/lavf.mxf
+./tests/data/lavf/lavf.mxf CRC=0x86fddf92
 52c5b74ecfdc48bd77d79a6bbe62d2de *./tests/data/lavf/lavf.mxf
 525881 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x4ace0849
diff --git a/tests/ref/lavf/ogg b/tests/ref/lavf/ogg
index bfc62de..584e09b 100644
--- a/tests/ref/lavf/ogg
+++ b/tests/ref/lavf/ogg
@@ -1,3 +1,3 @@
-810fbac66c4c65fd155b3c7f27ce69c5 *./tests/data/lavf/lavf.ogg
-12610 ./tests/data/lavf/lavf.ogg
-./tests/data/lavf/lavf.ogg CRC=0xf651632a
+ce1734741fa50c6c85f9cc8f410a720c *./tests/data/lavf/lavf.ogg
+13985 ./tests/data/lavf/lavf.ogg
+./tests/data/lavf/lavf.ogg CRC=0x37a143ea
-- 
1.7.10



More information about the ffmpeg-devel mailing list