diff --git a/ffmpeg.c b/ffmpeg.c
index a19f2077ba0522b75a90bab38b81393b401ffac3..1119fdf0132a25ef5e1742ffe1e1a46c9ca1970f 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
@@ -1787,6 +1789,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
@@ -2242,13 +2247,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;
 }
 
@@ -2265,6 +2263,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 19674270a497550a5d1d07637587c0321a0deadd..f59823cea17d75a01a6a039a8b984e8d5be3d2b3 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 bfffb090c243307d40bbec8b36baa5aa117bedfa..24f3f0d8238096531d682ebab9c2dbc7bc581e55 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 2a228b20b941e3f09ebbc0c30e2de7511e08c4f4..e8720afc5482ac6ed80958f3189b35b270370d68 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 63101b89ed518e13adcc989650c386bce373b27e..f70b6d9c0548ceea6004e8748577e388dd368616 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 cf0a5831ef0b2e66ac868d5a5f07e4058f7fd21d..08d5552c9ed9d93df8b5da339f266f2ea8f82a7e 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 b23b75dbb60b0f1529bcd206c28a7b177279ce8d..ca697751ba5b4ae6326402e1bdac6727f95610be 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 8d2f862afc92545b7a8c8d0cff1afb1de7b10e06..8b3ca5ab0e1b4d2eadf367ca8e34f32d3c4eabc7 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 51a488e6c7d23afcdc9e5b3d4a4123d83d9620e8..7e48d50973b35f0b4f42325af20960ff19232325 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 bfc62de0c89a1b0b0bfca3e9bf217640bc4ef91e..584e09bfbb44eb5631d12998e0d43f2e997a94ce 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