[FFmpeg-trac] #3621(avformat:new): "pts < dts" causing crash in av_interleaved_write_frame(): Invalid argument

FFmpeg trac at avcodec.org
Wed May 7 10:22:33 CEST 2014


#3621: "pts < dts" causing crash in av_interleaved_write_frame(): Invalid argument
----------------------------------+--------------------------------------
             Reporter:  tmm1      |                     Type:  defect
               Status:  new       |                 Priority:  normal
            Component:  avformat  |                  Version:  git-master
             Keywords:            |               Blocked By:
             Blocking:            |  Reproduced by developer:  0
Analyzed by developer:  0         |
----------------------------------+--------------------------------------
 I have some h264/mkv files that ffmpeg blows up on while remuxing, due to
 non-monotonic pts timestamps.

 {{{
 $ ffmpeg -nostats -i test.mkv -c:v copy -c:a copy out.mkv
 ffmpeg version 2.2.1 Copyright (c) 2000-2014 the FFmpeg developers
   built on May  7 2014 00:59:53 with Apple LLVM version 5.1
 (clang-503.0.40) (based on LLVM 3.4svn)
   configuration: --enable-shared --enable-pthreads --enable-gpl --enable-
 version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample
 --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264
 --enable-libfaac --enable-libmp3lame --enable-libxvid
   libavutil      52. 66.100 / 52. 66.100
   libavcodec     55. 52.102 / 55. 52.102
   libavformat    55. 33.100 / 55. 33.100
   libavdevice    55. 10.100 / 55. 10.100
   libavfilter     4.  2.100 /  4.  2.100
   libavresample   1.  2.  0 /  1.  2.  0
   libswscale      2.  5.102 /  2.  5.102
   libswresample   0. 18.100 /  0. 18.100
   libpostproc    52.  3.100 / 52.  3.100
 Input #0, matroska,webm, from 'test.mkv':
   Metadata:
     encoder         : libebml v1.3.0 + libmatroska v1.4.0
     creation_time   : 2014-05-06 09:28:53
   Duration: 00:44:21.01, start: 0.000000, bitrate: 0 kb/s
     Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709), 1280x720
 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 2k tbc (default)
     Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
 (default)
     Stream #0:2(eng): Subtitle: subrip (default)
 Output #0, matroska, to 'out.mkv':
   Metadata:
     encoder         : Lavf55.33.100
     Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p, 1280x720
 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 1k tbn, 1k tbc (default)
     Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz,
 5.1(side), 384 kb/s (default)
     Stream #0:2(eng): Subtitle: ssa (default)
 Stream mapping:
   Stream #0:0 -> #0:0 (copy)
   Stream #0:1 -> #0:1 (copy)
   Stream #0:2 -> #0:2 (subrip -> ssa)
 Press [q] to stop, [?] for help
 [matroska @ 0x7f9c6283de00] pts (375) < dts (418) in stream 0
 av_interleaved_write_frame(): Invalid argument
 frame=   11 fps=0.0 q=-1.0 Lsize=     217kB time=00:00:00.59
 bitrate=2983.2kbits/s
 video:189kB audio:27kB subtitle:0 data:0 global headers:0kB muxing
 overhead 0.492406%
 }}}

 Here are the video packets from -debug_ts on one of the files:

 {{{
 muxer <- type:video pkt_pts:0 pkt_pts_time:0 pkt_dts:0 pkt_dts_time:0
 size:32998
 muxer <- type:video pkt_pts:42 pkt_pts_time:0.042 pkt_dts:42
 pkt_dts_time:0.042 size:31878
 muxer <- type:video pkt_pts:83 pkt_pts_time:0.083 pkt_dts:83
 pkt_dts_time:0.083 size:34437
 muxer <- type:video pkt_pts:125 pkt_pts_time:0.125 pkt_dts:125
 pkt_dts_time:0.125 size:26936
 muxer <- type:video pkt_pts:167 pkt_pts_time:0.167 pkt_dts:167
 pkt_dts_time:0.167 size:22856
 muxer <- type:video pkt_pts:209 pkt_pts_time:0.209 pkt_dts:209
 pkt_dts_time:0.209 size:22355
 muxer <- type:video pkt_pts:250 pkt_pts_time:0.25 pkt_dts:250
 pkt_dts_time:0.25 size:14882
 muxer <- type:video pkt_pts:292 pkt_pts_time:0.292 pkt_dts:292
 pkt_dts_time:0.292 size:3548
 muxer <- type:video pkt_pts:334 pkt_pts_time:0.334 pkt_dts:334
 pkt_dts_time:0.334 size:2954
 muxer <- type:video pkt_pts:417 pkt_pts_time:0.417 pkt_dts:417
 pkt_dts_time:0.417 size:138
 muxer <- type:video pkt_pts:375 pkt_pts_time:0.375 pkt_dts:418
 pkt_dts_time:0.418 size:140
 [matroska @ 0x7fb88c0eaa00] pts (375) < dts (418) in stream 0
 av_interleaved_write_frame(): Invalid argument
 }}}

 I believe the error can be ignored, as ffmpeg will attempt to fix
 timestamps in the output file.

 {{{
 --- a/libavformat/mux.c
 +++ b/libavformat/mux.c
 @@ -486,7 +486,6 @@ static int compute_pkt_fields2(AVFormatContext *s,
 AVStream *st, AVPacket *pkt)
      if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE &&
 pkt->pts < pkt->dts) {
          av_log(s, AV_LOG_ERROR, "pts (%s) < dts (%s) in stream %d\n",
                 av_ts2str(pkt->pts), av_ts2str(pkt->dts), st->index);
 -        return AVERROR(EINVAL);
      }

      av_dlog(s, "av_write_frame: pts2:%s dts2:%s\n",
 }}}

 With the change above, ffmpeg on master warns me but is able to process my
 entire input file without crashing:

 {{{
 [matroska @ 0x7fabdc034600] pts (375) < dts (418) in stream 0
 [matroska @ 0x7fabdc034600] Non-monotonous DTS in output stream 0:0;
 previous: 418, current: 375; changing to 418. This may result in incorrect
 timestamps in the output file.
 frame=  152 fps=0.0 q=-1.0 Lsize=    4475kB time=00:00:06.48
 bitrate=5654.2kbits/s
 video:4168kB audio:303kB subtitle:0kB other streams:0kB global headers:0kB
 muxing overhead: 0.089263%
 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/3621>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list