Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#4450 closed defect (fixed)

Copying subtitle streams aborts w/non monotonically increasing dts

Reported by: Hans Carlson Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: av_interleaved_write_frame mpegps dvdsub
Cc: gajjanagadde@gmail.com Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:
Copying the subtitle streams from some mpeg files causes ffmpeg to abort with the following message (example 1 below):

[vob @ 0x9aa6860] Application provided invalid, non monotonically increasing dts to muxer in stream 2: 307990683 >= 0
av_interleaved_write_frame(): Invalid argument

If only video and audio streams are copied, then a similar message is displayed for the audio streams, but ffmpeg does NOT abort (example 2 below):

[vob @ 0x8526700] Non-monotonous DTS in output stream 0:1; previous: 331320960, current: 331319487; changing to 331320961. This may result in incorrect timestamps in the output file.

If ffmpeg.c line 679 is modified to include AVMEDIA_TYPE_SUBTITLE or line 679 is removed, then example 1 will complete the copy. ffmpeg generates the same warning as example 2 for each subtitle stream, but the resulting file appears to be fine with all subtitles intact.

This issue does not happen with ALL mpeg files and it may not be restricted to mpeg files. I've noticed it on several mpeg files where the duration is incorrectly detected. In the 2 examples below ffmpeg indicates the duration is 01:14:31.97, but the actual length is 02:15:53.30. This is confirmed by looking at the output from the successful example 2 below:

$ ffmpeg -i mpeg-COPY-VA.vob 2>&1 | grep Duration
  Duration: 02:15:53.30, start: 0.533367, bitrate: 5677 kb/s

Example 1 - copy 1 video, audio and subtitle stream - aborts:

$ ffmpeg -i mpeg.vob -map 0:0 -map 0:13 -map 0:8 -codec copy -f vob mpeg-COPY-VAS.vob
ffmpeg version N-71325-g9c37c81 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.5.1 (GCC) 20100924 (Red Hat 4.5.1-4)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-x11grab
  libavutil      54. 22.101 / 54. 22.101
  libavcodec     56. 34.100 / 56. 34.100
  libavformat    56. 30.100 / 56. 30.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpeg, from 'mpeg.vob':
  Duration: 01:14:31.97, start: 0.207756, bitrate: 12204 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, smpte170m), 720x480 [SAR 32:27 DAR 16:9], max. 9800 kb/s, 31.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x20]: Subtitle: dvd_subtitle
    Stream #0:2[0x21]: Subtitle: dvd_subtitle
    Stream #0:3[0x22]: Subtitle: dvd_subtitle
    Stream #0:4[0x23]: Subtitle: dvd_subtitle
    Stream #0:5[0x24]: Subtitle: dvd_subtitle
    Stream #0:6[0x25]: Subtitle: dvd_subtitle
    Stream #0:7[0x26]: Subtitle: dvd_subtitle
    Stream #0:8[0x27]: Subtitle: dvd_subtitle
    Stream #0:9[0x28]: Subtitle: dvd_subtitle
    Stream #0:10[0x29]: Subtitle: dvd_subtitle
    Stream #0:11[0x2a]: Subtitle: dvd_subtitle
    Stream #0:12[0x2b]: Subtitle: dvd_subtitle
    Stream #0:13[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:14[0x81]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:15[0x82]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:16[0x83]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Output #0, vob, to 'mpeg-COPY-VAS.vob':
  Metadata:
    encoder         : Lavf56.30.100
    Stream #0:0: Video: mpeg2video, yuv420p, 720x480 [SAR 32:27 DAR 16:9], q=2-31, max. 9800 kb/s, 31.97 fps, 59.94 tbr, 90k tbn, 29.97 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), 448 kb/s
    Stream #0:2: Subtitle: dvd_subtitle
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:13 -> #0:1 (copy)
  Stream #0:8 -> #0:2 (copy)
Press [q] to stop, [?] for help
[vob @ 0x9aa6860] Application provided invalid, non monotonically increasing dts to muxer in stream 2: 307990683 >= 0
av_interleaved_write_frame(): Invalid argument
frame=88264 fps=548 q=-1.0 Lsize= 2547730kB time=01:01:21.37 bitrate=5669.3kbits/s
video:2314651kB audio:201325kB subtitle:24kB other streams:0kB global headers:0kB muxing overhead: 1.261121%
Conversion failed!

Example 2 - copy 1 video and audio stream - finishes:

$ ffmpeg -i mpeg.vob -map 0:0 -map 0:13 -codec copy -f vob mpeg-COPY-VA.vob
ffmpeg version N-71325-g9c37c81 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.5.1 (GCC) 20100924 (Red Hat 4.5.1-4)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-x11grab
  libavutil      54. 22.101 / 54. 22.101
  libavcodec     56. 34.100 / 56. 34.100
  libavformat    56. 30.100 / 56. 30.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpeg, from 'mpeg.vob':
  Duration: 01:14:31.97, start: 0.207756, bitrate: 12204 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, smpte170m), 720x480 [SAR 32:27 DAR 16:9], max. 9800 kb/s, 31.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x20]: Subtitle: dvd_subtitle
    Stream #0:2[0x21]: Subtitle: dvd_subtitle
    Stream #0:3[0x22]: Subtitle: dvd_subtitle
    Stream #0:4[0x23]: Subtitle: dvd_subtitle
    Stream #0:5[0x24]: Subtitle: dvd_subtitle
    Stream #0:6[0x25]: Subtitle: dvd_subtitle
    Stream #0:7[0x26]: Subtitle: dvd_subtitle
    Stream #0:8[0x27]: Subtitle: dvd_subtitle
    Stream #0:9[0x28]: Subtitle: dvd_subtitle
    Stream #0:10[0x29]: Subtitle: dvd_subtitle
    Stream #0:11[0x2a]: Subtitle: dvd_subtitle
    Stream #0:12[0x2b]: Subtitle: dvd_subtitle
    Stream #0:13[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:14[0x81]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:15[0x82]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:16[0x83]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Output #0, vob, to 'mpeg-COPY-VA.vob':
  Metadata:
    encoder         : Lavf56.30.100
    Stream #0:0: Video: mpeg2video, yuv420p, 720x480 [SAR 32:27 DAR 16:9], q=2-31, max. 9800 kb/s, 31.97 fps, 59.94 tbr, 90k tbn, 29.97 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), 448 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:13 -> #0:1 (copy)
Press [q] to stop, [?] for help
[vob @ 0x8526700] Non-monotonous DTS in output stream 0:1; previous: 331320960, current: 331319487; changing to 331320961. This may result in incorrect timestamps in the output file.
frame=195485 fps=458 q=-1.0 Lsize= 5651160kB time=02:15:53.29 bitrate=5678.0kbits/s
video:5135016kB audio:445886kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.258899%

Here's complete debug output for the input file used in the above examples:

$ ffmpeg -v 9 -loglevel 99 -i mpeg.vob
ffmpeg version N-71325-g9c37c81 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.5.1 (GCC) 20100924 (Red Hat 4.5.1-4)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-x11grab
  libavutil      54. 22.101 / 54. 22.101
  libavcodec     56. 34.100 / 56. 34.100
  libavformat    56. 30.100 / 56. 30.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input file with argument 'mpeg.vob'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input file mpeg.vob.
Successfully parsed a group of options.
Opening an input file: mpeg.vob.
[mpeg @ 0x825d2c0] Format mpeg probed with size=8192 and score=52
[mpeg @ 0x825d2c0] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0
[mpeg @ 0x825d2c0] probing stream 0 pp:2500
[mpeg @ 0x825d2c0] Probe with size=2012, packets=1 detected mpegvideo with score=25
[mpeg @ 0x825d2c0] probed stream 0
[mpeg @ 0x825d2c0] max_analyze_duration 5000000 reached at 5004667 microseconds
rfps: 23.916667 0.017421
rfps: 24.000000 0.011237
rfps: 60.000000 0.007633
rfps: 23.976024 0.009996
    Last message repeated 1 times
rfps: 59.940060 0.000000
    Last message repeated 1 times
[mpeg @ 0x825d2c0] After avformat_find_stream_info() pos: 0 bytes read:2871440 seeks:2 frames:750
Input #0, mpeg, from 'mpeg.vob':
  Duration: 01:14:31.97, start: 0.207756, bitrate: 12204 kb/s
    Stream #0:0[0x1e0], 122, 1/90000: Video: mpeg2video (Main), 1 reference frame, yuv420p(tv, smpte170m, left), 720x480 [SAR 32:27 DAR 16:9], 1001/60000, max. 9800 kb/s, 31.97 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x20], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:2[0x21], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:3[0x22], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:4[0x23], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:5[0x24], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:6[0x25], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:7[0x26], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:8[0x27], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:9[0x28], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:10[0x29], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:11[0x2a], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:12[0x2b], 1, 1/90000: Subtitle: dvd_subtitle
    Stream #0:13[0x80], 154, 1/90000: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:14[0x81], 154, 1/90000: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:15[0x82], 154, 1/90000: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:16[0x83], 154, 1/90000: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Successfully opened the file.
At least one output file must be specified
[AVIOContext @ 0x825cae0] Statistics: 2871440 bytes read, 2 seek

Change History (8)

comment:1 by Ganesh Ajjanagadde, 9 years ago

Cc: gajjanagadde@gmail.com added

Please upload sample file so that we may reproduce this.

comment:2 by Carl Eugen Hoyos, 9 years ago

Keywords: av_interleaved_write_frame added

comment:3 by Hans Carlson, 9 years ago

I've uploaded an 8Mb sample vob file to the FTP server listed on the ffmpeg Bug Report page (ftp://upload.ffmpeg.org/incoming). The filename is non-monotonically.increasing.dts.vob and there is also a non-monotonically.increasing.dts.txt file with a reference to this ticket.

In order to create the sample file I needed to use dd and skip to the point in the video (about 1 hour in) where the problem occurs. Because of this, the file doesn't contain any initial header information. Also, when running the copy test (below) a lot of "buffer underflow" errors are generated. The original file does NOT generate "buffer underflow" errors, so I assume this is a result of the way the sample was generated (via dd).

Using the sample file and ffmpeg (N-74266-ge322b70) I get the following:

$ ffmpeg-dev -i non-monotonically.increasing.dts.vob -map 0 -codec copy -f vob non-monotonically.increasing.dts-COPY.vob
...
[vob @ 0xa0642c0] Application provided invalid, non monotonically increasing dts to muxer in stream 5: 8217903303 >= 797166
av_interleaved_write_frame(): Invalid argument
...
frame=  181 fps=0.0 q=-1.0 Lsize=    7116kB time=25:21:50.03 bitrate=   0.6kbits/s
video:5282kB audio:1699kB subtitle:12kB other streams:0kB global headers:0kB muxing overhead: 1.747478%
Conversion failed!

I can provide the complete ffmpeg output if necessary.

comment:4 by Carl Eugen Hoyos, 9 years ago

Keywords: mpegps dvdsub added
Reproduced by developer: set
Status: newopen

comment:5 by Evren Yurtesen, 7 years ago

I am sorry to dig up such an old problem, but I am having exactly the same issue. I tried copyts and it still give error. The OP seems to have posted the fix also, why the fix is not included in ffmpeg.c ?

comment:6 by Hans Carlson, 7 years ago

I retested the original "fix" with the latest ffmpeg (N-84804-g247d033) and it still works.

The same change also appears to fix https://trac.ffmpeg.org/ticket/6248

Here's a diff of the single line change:

diff -u ffmpeg-master/ffmpeg.c ffmpeg-master-dts/ffmpeg.c
--- ffmpeg-master/ffmpeg.c	2017-03-29 12:33:47.038626570 -0700
+++ ffmpeg-master-dts/ffmpeg.c	2017-03-29 15:02:33.732864853 -0700
@@ -751,7 +751,7 @@
                      - FFMIN3(pkt->pts, pkt->dts, ost->last_mux_dts + 1)
                      - FFMAX3(pkt->pts, pkt->dts, ost->last_mux_dts + 1);
         }
-        if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
+        if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) &&
             pkt->dts != AV_NOPTS_VALUE &&
             !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) &&
             ost->last_mux_dts != AV_NOPTS_VALUE) {

comment:7 by Carl Eugen Hoyos, 6 years ago

Resolution: fixed
Status: openclosed

The patch was applied as a790813739a880a0a86084ec8c4e2d5a6a79c11d
Thank you for the report, the fix and a lot of patience!
Thanks to Markus Kohm for reminding us of the issue.

comment:8 by Carl Eugen Hoyos, 6 years ago

Component: undeterminedffmpeg
Note: See TracTickets for help on using tickets.