Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#1277 closed defect (fixed)

Subtitle (hdmv_pgs_subtitle) conversion fails

Reported by: Hamed Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: dvdsub
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description (last modified by Clément Bœsch)

I need to convert the format of the subtitle stream of a movie so my device can play it.
Here is the list of all existing streams :

    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x816 [SAR 1:1 DAR 40:17], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
    Metadata:
      title           : 3/2+1
    Stream #0:2(eng): Subtitle: hdmv_pgs_subtitle (default)
    Stream #0:3(ger): Subtitle: hdmv_pgs_subtitle
    Stream #0:4(ger): Subtitle: hdmv_pgs_subtitle
    Stream #0:5(ger): Subtitle: hdmv_pgs_subtitle
    Stream #0:6(ger): Subtitle: hdmv_pgs_subtitle

I want to keep only the English subtitle and convert it too. The available codecs are :

> ffmpeg -codecs | grep sub
 DES    ass             Advanced SubStation Alpha subtitle
 DES    dvbsub          DVB subtitles
 DES    dvdsub          DVD subtitles
 D S    pgssub          HDMV Presentation Graphic Stream subtitles
 DES    srt             SubRip subtitle
 DES    xsub            DivX subtitles (XSUB)

I choose dvdsub as the new format and try to run ffmpeg command with the following arguments :

ffmpeg -i in.mkv -scodec dvdsub -vcodec copy -acodec copy out.mkv

It starts running, but after a while ( I think when it reaches the first frame with subtitle ) crashes. Here you can see the messages :

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (pgssub -> dvdsub)
Press [q] to stop, [?] for help
Subtitle encoding failed1.0 size=  182919kB time=00:00:00.00 bitrate=   0.0kbits/s 

The interesting point is that ffplay and mplayer both can play the input file and they show the subtitle properly.

Here is the output of ffmpeg -version command :

ffmpeg version 0.10.2-4:0.10.2-0ubuntu0jon1~oneiric1
built on Mar 18 2012 11:07:55 with gcc 4.6.1
configuration: --extra-version='4:0.10.2-0ubuntu0jon1~oneiric1' --arch=amd64 --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-stripping --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-libfreetype --enable-vaapi --enable-frei0r --enable-gpl --enable-postproc --enable-x11grab --enable-librtmp --enable-libvo-aacenc --enable-version3 --enable-libvo-amrwbenc --enable-version3 --enable-libdc1394 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
libavutil      51. 35.100 / 51. 35.100
libavcodec     53. 61.100 / 53. 61.100
libavformat    53. 32.100 / 53. 32.100
libavdevice    53.  4.100 / 53.  4.100
libavfilter     2. 61.100 /  2. 61.100
libswscale      2.  1.100 /  2.  1.100
libswresample   0.  6.100 /  0.  6.100
libpostproc    52.  0.100 / 52.  0.100

Attachments (6)

ffmpeg-20120505-192526.log (2.0 MB ) - added by Hamed 13 years ago.
the report created by ffmpeg
sub_bad_colors_ffplay.png (64.8 KB ) - added by Cigaes 12 years ago.
Screenshot of ffplay after encoding with the "ffmpeg: add an option to fix subtitles durations" patch
sub_bad_colors_mplayer.png (93.3 KB ) - added by Cigaes 12 years ago.
Screenshot of mplayer after encoding with the "ffmpeg: add an option to fix subtitles durations" patch
sub_good_colors_huge_ffplay.png (60.5 KB ) - added by Cigaes 12 years ago.
Screenshot of ffplay after encoding with the "dvdsubenc: make it usable for transcoding" patch
sub_good_colors_huge_mplayer.png (129.7 KB ) - added by Cigaes 12 years ago.
Screenshot of mplayer after encoding with the "dvdsubenc: make it usable for transcoding" patch
sub_fixed_mplayer.png (110.1 KB ) - added by Cigaes 12 years ago.
Screenshot of mplayer after encoding with the patch series suggested in comment #15

Change History (34)

comment:1 by Carl Eugen Hoyos, 13 years ago

Please provide backtrace etc. for crashes, as explained on http://ffmpeg.org/bugreports.html

by Hamed, 13 years ago

Attachment: ffmpeg-20120505-192526.log added

the report created by ffmpeg

in reply to:  1 comment:2 by Hamed, 13 years ago

Replying to cehoyos:

Please provide backtrace etc. for crashes, as explained on http://ffmpeg.org/bugreports.html

I attached the report file to the ticket. Would you please let me know if it is enough or something else is needed ?

comment:3 by Carl Eugen Hoyos, 13 years ago

In your original report you describe a "crash", the report you provided does not show any indication for a crash. Please clarify.

in reply to:  3 ; comment:4 by Hamed, 13 years ago

Replying to cehoyos:

In your original report you describe a "crash", the report you provided does not show any indication for a crash. Please clarify.

It exits after an error occurs. It prints the error message : Subtitle encoding failed. As you can see in the attached log file, it happens while converting the 4308 frame of the movie and the conversion fails. I am not sure if I can call it a crash or not.

in reply to:  4 ; comment:5 by Carl Eugen Hoyos, 13 years ago

Keywords: pgssub -> removed
Priority: importantnormal

Replying to bakhshian:

It exits after an error occurs. It prints the error message : Subtitle encoding failed. As you can see in the attached log file, it happens while converting the 4308 frame of the movie and the conversion fails. I am not sure if I can call it a crash or not.

It is not a crash.

Is the problem also reproducible if you cut the sample with dd (to make it short enough to attach / upload)?

in reply to:  5 ; comment:6 by Hamed, 13 years ago

Replying to cehoyos:

Replying to bakhshian:

It exits after an error occurs. It prints the error message : Subtitle encoding failed. As you can see in the attached log file, it happens while converting the 4308 frame of the movie and the conversion fails. I am not sure if I can call it a crash or not.

It is not a crash.

Is the problem also reproducible if you cut the sample with dd (to make it short enough to attach / upload)?

I cut 3minutes of the movie and converted its video and audio formats to make it small enough to upload. The same error occurs while trying to convert the subtitle codec. The file can be found under ftp://upload.ffmpeg.org/incoming/. Its name is SCodecConversionFailsSample.mkv. There is another txt file with the same name describing the problem.

in reply to:  6 comment:7 by Hamed, 13 years ago

hi again,

was my problem re-producible by the given file ? or is it just a problem from my side ?

please help

comment:8 by Carl Eugen Hoyos, 13 years ago

Component: FFmpegundetermined
Reproduced by developer: set
Status: newopen
Version: 0.10.2git-master

Sorry for the delay, the issue is reproducible: encode_dvd_subtitles() is called with h->num_rects == 0

comment:9 by Carl Eugen Hoyos, 13 years ago

A possibly related bug is the null-pointer dereference in line 136 of xsubenc.c in xsub_encode():
$ ffmpeg -i SCodecConversionFailsSample.mkv -scodec xsub -f null -

in reply to:  9 comment:10 by Hamed, 13 years ago

Replying to cehoyos:

A possibly related bug is the null-pointer dereference in line 136 of xsubenc.c in xsub_encode():
$ ffmpeg -i SCodecConversionFailsSample.mkv -scodec xsub -f null -

Converting to xsub using '-f null' option, I get a more descriptive message :

[xsub @ 0x2026680] No more than 4 subtitle colors supported (256 found.)
[xsub @ 0x2026680] Only single rects supported (0 in subtitle.)

comment:11 by Michael Niedermayer, 12 years ago

Summary: Subtitle conversion failsSubtitle (hdmv_pgs_subtitle) conversion fails

comment:12 by Cigaes, 12 years ago

I would like to access the sample, to see if my recent patches in that area are enough to solve the problem.

comment:13 by Carl Eugen Hoyos, 12 years ago

Sample uploaded to samples/ffmpeg-bugs/trac/ticket1277

comment:14 by Cigaes, 12 years ago

Thanks Carl Eugen.

This patch fixes the failure:
http://ffmpeg.org/pipermail/ffmpeg-devel/2012-August/129069.html

The resulting encoded subtile has completely wrong colors, but the following patch fixes it, and gives IMHO a very decent result given the limitations of the dvdsub format:
http://ffmpeg.org/pipermail/ffmpeg-devel/2012-August/129070.html

The resulting subtitle is still huge, though, and slightly differently so between MPlayer and ffplay, but that is definitely an improvement. See the attached screenshots.

I'll try to look into the size matter.

by Cigaes, 12 years ago

Attachment: sub_bad_colors_ffplay.png added

Screenshot of ffplay after encoding with the "ffmpeg: add an option to fix subtitles durations" patch

by Cigaes, 12 years ago

Attachment: sub_bad_colors_mplayer.png added

Screenshot of mplayer after encoding with the "ffmpeg: add an option to fix subtitles durations" patch

by Cigaes, 12 years ago

Screenshot of ffplay after encoding with the "dvdsubenc: make it usable for transcoding" patch

by Cigaes, 12 years ago

Screenshot of mplayer after encoding with the "dvdsubenc: make it usable for transcoding" patch

comment:15 by Cigaes, 12 years ago

I believe the following patch series:
http://ffmpeg.org/pipermail/ffmpeg-devel/2012-August/129111.html
fixes all the issues. You need to add -fix_sub_duration to the input and either -analyzeduration 20E6 to the input or -s:s 1920x1080 to the output.
The subtitles will stay huge in certain players, but it works at least in MPlayer.

by Cigaes, 12 years ago

Attachment: sub_fixed_mplayer.png added

Screenshot of mplayer after encoding with the patch series suggested in comment #15

comment:16 by Hamed, 12 years ago

Thank you so much. Would you please let me know how can I apply this patch or when the new official release including these changes will be available ?

comment:17 by Carl Eugen Hoyos, 12 years ago

If you cannot apply the latest series of this patch - http://ffmpeg.org/pipermail/ffmpeg-devel/2012-August/129212.html - please wait until the patch is applied and the ticket closed.

comment:18 by Cigaes, 12 years ago

The patch series was just pushed to the current Git head. Please close the bug if it fixes things for you.

comment:19 by Sharkhunter, 12 years ago

Does these patches fix srt -> dvdsub as well? Previous adding srt -> dvdsub worked but crashed the video during playback (crash on first subtitle frame) now (at least Zeranoes win build" carshes completly without a trace...

comment:20 by Cigaes, 12 years ago

No, it does not. srt is text, dvdsub is bitmap: converting one to the other would require rendering the text, using fonts and layout engine.

comment:21 by Sharkhunter, 12 years ago

So burning srt to dvdsub will simply never work?

comment:22 by Cigaes, 12 years ago

Not never, but nobody is currently working on it, and it will certainly have to wait for a proper API for decoded text subtitles.

Note that spumux can do it.

comment:23 by Sharkhunter, 12 years ago

Mencoder can as well but it has other issues. It would just be nice to avoid using 3 or 4 programs just to get it working...

comment:24 by Cigaes, 12 years ago

AFAIK, no, mencoder can not, unless you expressed your problem incorrectly. Also, remember this is an issue tracker, and this issue is, I hope, fixed.

comment:25 by Sharkhunter, 12 years ago

Sure I just asked.

in reply to:  19 comment:26 by Carl Eugen Hoyos, 12 years ago

Resolution: fixed
Status: openclosed

Replying to Sharkhunter:

Previous adding srt -> dvdsub worked but crashed the video during playback (crash on first subtitle frame) now (at least Zeranoes win build" carshes completly without a trace...

Did you report this?
Even if no backtrace is possible, complete, uncut console output missing.

comment:28 by Clément Bœsch, 12 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.