Opened 11 years ago
Last modified 10 years ago
#4855 new enhancement
Support subtitles in (most likely) broken old vdr recordings
| Reported by: | Carl Eugen Hoyos | Owned by: | |
|---|---|---|---|
| Priority: | wish | Component: | avformat |
| Version: | git-master | Keywords: | mpegps dvbsub dvdsub |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description (last modified by )
https://ffmpeg.org/pipermail/ffmpeg-user/2015-September/028406.html
A user uploaded a vdr recording that contains a digital television stream within a mpeg program stream. The recording is supposed to contain subtitles, possibly dvbsub, FFmpeg detects dvdsub but does not decode anything, just like vlc and MPlayer.
$ ffmpeg -i 002.vdr -filter_complex [0:0][0:3]overlay -qscale 2 -t 60 out.avi
ffmpeg version N-75300-g4a38078 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.7 (SUSE Linux)
configuration: --enable-gpl
libavutil 55. 2.100 / 55. 2.100
libavcodec 57. 2.100 / 57. 2.100
libavformat 57. 2.100 / 57. 2.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 4.100 / 6. 4.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
[mpeg @ 0x2d034e0] Format mpeg detected only with low score of 25, misdetection possible!
[NULL @ 0x2d899e0] start time for stream 3 is not set in estimate_timings_from_pts
Input #0, mpeg, from '002.vdr':
Duration: 00:01:03.96, start: 47298.333311, bitrate: 2244 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 704x576 [SAR 12:11 DAR 4:3], max. 15000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 192 kb/s
Stream #0:2[0x1c1]: Audio: mp2, 48000 Hz, mono, s16p, 64 kb/s
Stream #0:3[0x20]: Subtitle: dvd_subtitle
Please use -q:a or -q:v, -qscale is ambiguous
[mpeg @ 0x2d034e0] sub2video: using 704x576 canvas
Output #0, avi, to 'out.avi':
Metadata:
ISFT : Lavf57.2.100
Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 704x576 [SAR 12:11 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
Metadata:
encoder : Lavc57.2.100 mpeg4
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s
Metadata:
encoder : Lavc57.2.100 ac3
Stream mapping:
Stream #0:0 (mpeg2video) -> overlay:main (graph 0)
Stream #0:3 (dvdsub) -> overlay:overlay (graph 0)
overlay (graph 0) -> Stream #0:0 (mpeg4)
Stream #0:1 -> #0:1 (mp2 (native) -> ac3 (native))
Press [q] to stop, [?] for help
[mpeg2video @ 0x2d055e0] 00 motion_type at 36 29
[mpeg2video @ 0x2d055e0] Warning MVs not available
[mpeg2video @ 0x2d055e0] concealing 88 DC, 88 AC, 88 MV errors in P frame
[mpeg2video @ 0x2d055e0] ac-tex damaged at 13 180:00:07.16 bitrate=2335.5kbits/s
[mpeg2video @ 0x2d055e0] Warning MVs not available
[mpeg2video @ 0x2d055e0] concealing 44 DC, 44 AC, 44 MV errors in I frame
[mpeg2video @ 0x2d055e0] ac-tex damaged at 11 900:00:13.96 bitrate=2466.3kbits/s
[mpeg2video @ 0x2d055e0] Warning MVs not available
[mpeg2video @ 0x2d055e0] concealing 44 DC, 44 AC, 44 MV errors in I frame
[mpeg2video @ 0x2d055e0] ac-tex damaged at 2 2300:00:20.68 bitrate=2433.5kbits/s
[mpeg2video @ 0x2d055e0] Warning MVs not available
[mpeg2video @ 0x2d055e0] concealing 44 DC, 44 AC, 44 MV errors in P frame
[mpeg2video @ 0x2d055e0] mb incr damagedB time=00:00:54.16 bitrate=2345.7kbits/s
[mpeg2video @ 0x2d055e0] 00 motion_type at 13 35
[mpeg2video @ 0x2d055e0] Warning MVs not available
[mpeg2video @ 0x2d055e0] concealing 88 DC, 88 AC, 88 MV errors in P frame
frame= 1477 fps=321 q=2.0 Lsize= 17600kB time=00:01:00.00 bitrate=2403.0kbits/s
video:16107kB audio:1404kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.511689%
No subtitles are visible in the output stream, ProjectX is able to export some data.
Note:
See TracTickets
for help on using tickets.



I got to the bottom of this
Old VDR (1.x) adds a 4 byte "subheader" 0x20, 0x01, 0x00, 0x00 ahead of the subtitle data to indicate beginning of subtitle page. Subsequent fragments have 0x20, 0x01, 0x00, 0x01 headers. It is necessary to decode the packets containing fragments of segments, which may be spread over multiple packets (VDR limits packet size to 2048 bytes by default), so a number of packets may be needed to get a complete PES packet with a complete set of segments describing a single subtitle. VDR puts the PTS for the subtitle in the first packet only.
Once the various fragments are assembled into a set of segments, the subtitles conform to standard EN 300 743 dvbsub segments, and ffmpeg can recognise them.
However ffmpeg often probes them as "bin_data" not "dvbsub" due to broadcasters regularly sending what I call "cleardown" PES packets containing just page and region composition segments, these look like this in dvbsnoop. IMHO dvbsub.c is a bit too simplistic in its stream scoring, and should really recognise these as valid, or at least probe further for "real" subtitle data. Using -analyzeduration and -probesize switches don't usually help much, if at all, in this respect.
VDR contains a subtitle assembler in dvbsubtitle.c that shows how reassembly can be done, though my reading of ffmpeg code is that it only wants complete PES packets, so some pre-assembly of fragments may be required