Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#11594 closed defect (invalid)

Hardcoding subtitles broken with libx265 since 20241205

Reported by: SubJunk Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

This commit http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=17e4746687abc53f0a042620a7af6dd6cea44b80 broke hardcoding of subtitles when encoding with libx265.

Verified it is still broken with the latest Gyan build 2025-05-15-git-12b853530a

How to reproduce:

% ffmpeg -i input -filter_complex [0:v][0:s:0]overlay -maxrate 89000k -crf 16 -c:a copy -c:v libx265 -preset superfast -f mpegts file.ts
ffmpeg version 2025-05-15-git-12b853530a
built on 2025-05-15

I also have an automated test on GitHub for periodically checking whether this is fixed.
You can see the failing build when FFmpeg is updated to latest:
https://github.com/UniversalMediaServer/UniversalMediaServer/pull/5537/commits/bdcca6b4f2e06784a3de2f6cb3bd39ab47a69c08

And the succeeding build when the older 7.1 release is used:
https://github.com/UniversalMediaServer/UniversalMediaServer/pull/5537/commits/7065d765dac8acdc57d13a5628d15b891b3b1fdf

Change History (9)

comment:1 by Gyan, 14 months ago

Cannot repro here.

Share full logs, and link to input if possible.

comment:2 by SubJunk, 14 months ago

Hi Gyan, thanks for the quick response.

The input file it uses is https://github.com/UniversalMediaServer/UniversalMediaServer/blob/7065d765dac8acdc57d13a5628d15b891b3b1fdf/src/test/resources/net/pms/parsers/video-h265_dolbyvision_p08.06-eac3_dolby_surround_ex-srt.mkv

The output is:

Input #0, matroska,webm, from 'D:\a\UniversalMediaServer\UniversalMediaServer\target\test-classes\net\pms\parsers\video-h265_dolbyvision_p08.06-eac3_dolby_surround_ex-srt.mkv':
Metadata:
encoder         : libebml v1.4.5 + libmatroska v1.7.1
creation_time   : 2025-05-17T05:48:07.000000Z
Duration: 00:02:12.90, start: 0.000000, bitrate: 1151 kb/s
Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1608, SAR 1:1 DAR 160:67, 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS             : 12605646
DURATION        : 00:00:10.427000000
NUMBER_OF_FRAMES: 250
NUMBER_OF_BYTES : 16429884
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-17 05:48:07
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Side data:
DOVI configuration record: version: 1.0, profile: 8, level: 6, rpu flag: 1, el flag: 0, bl flag: 1, compatibility id: 1, compression: 0
Stream #0:1(eng): Audio: eac3, 48000 Hz, 7.1, fltp, 1536 kb/s (default)
Metadata:
title           : DDP 7.1
BPS             : 1536000
DURATION        : 00:00:10.432000000
NUMBER_OF_FRAMES: 326
NUMBER_OF_BYTES : 2002944
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-17 05:48:07
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(eng): Subtitle: subrip (srt) (default)
Metadata:
BPS             : 85
DURATION        : 00:02:10.794000000
NUMBER_OF_FRAMES: 44
NUMBER_OF_BYTES : 1406
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-17 05:48:07
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:3: Video: png, rgb24(pc, gbr/unknown/unknown), 608x759 [SAR 3780:3780 DAR 608:759], 90k tbr, 90k tbn (attached pic)
Metadata:
filename        : Knock at the Cabin 2023 4K DV BiTOR.PNG
mimetype        : image/png
Stream mapping:
Stream #0:0 (hevc) -> overlay
Stream #0:2 (srt) -> overlay
overlay:default -> Stream #0:0 (libx265)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx265 @ 000001d173492880] Loaded libx265 does not support alpha layer encoding.
[vost#0:0/libx265 @ 000001d173492640] [enc:libx265 @ 000001d1733b97c0] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[fc#0 @ 000001d1731e5840] Error sending frames to consumers: Error number -129 occurred
[fc#0 @ 000001d1731e5840] Task finished with error code: -129 (Error number -129 occurred)
[fc#0 @ 000001d1731e5840] Terminating thread with return code -129 (Error number -129 occurred)
[vost#0:0/libx265 @ 000001d173492640] [enc:libx265 @ 000001d1733b97c0] Could not open encoder before EOF
[vost#0:0/libx265 @ 000001d173492640] Task finished with error code: -22 (Invalid argument)
[vost#0:0/libx265 @ 000001d173492640] Terminating thread with return code -22 (Invalid argument)
[out#0/mpegts @ 000001d1732aef00] Nothing was written into output file, because at least one of its streams received no packets.
frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A elapsed=0:00:00.52
Conversion failed!

That file is just one I muxed together to demonstrate the problem, but this happens on a lot of real world files too

The test runs on GitHub Actions so the output for your latest build is here https://github.com/UniversalMediaServer/UniversalMediaServer/actions/runs/15091954469/job/42421723488#step:5:7501

comment:3 by Gyan, 14 months ago

Resolution: invalid
Status: newclosed

The sample input has a text-based sub stream (SRT) which can be burnt using the subtitles filter. overlay filter can only burn image-based subtitle formats such as HDMV.

I can confirm that the following filter works with my latest build.

-filter_complex [0:v]subtitles=f=input.mkv

And I've checked that image-based subs continue to work with the overlay filter.

comment:4 by SubJunk, 14 months ago

Thanks again for the response, but I get the same error with HDMV subtitles.

The input file can be downloaded here https://github.com/UniversalMediaServer/UniversalMediaServer/blob/b0709d67fc7761cc719744461bfbbb9ca2422e90/src/test/resources/net/pms/parsers/video-h265_dolbyvision_p08.06-eac3_dolby_surround_ex-hdmv_pgs.mkv

The command:

ffmpeg.exe -y -loglevel info -i input.mkv -filter_complex [0:v][0:s:0]overlay -maxrate 89000k -crf 16 -c:a copy -c:v libx265 -preset superfast -f mpegts output.ts

Output:

ffmpeg version 2025-05-15-git-12b853530a-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 15.1.0 (Rev4, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      60.  2.100 / 60.  2.100
  libavcodec     62.  3.101 / 62.  3.101
  libavformat    62.  0.102 / 62.  0.102
  libavdevice    62.  0.100 / 62.  0.100
  libavfilter    11.  0.100 / 11.  0.100
  libswscale      9.  0.100 /  9.  0.100
  libswresample   6.  0.100 /  6.  0.100
[matroska,webm @ 0000023384427a00] Could not find codec parameters for stream 2 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'input.mkv':
  Metadata:
    encoder         : libebml v1.4.2 + libmatroska v1.6.4
    creation_time   : 2022-12-17T02:31:50.000000Z
  Duration: 01:09:15.17, start: 0.000000, bitrate: 3425 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 605.939000
      Metadata:
        title           : 00:00:00.000
    Chapter #0:1: start 605.939000, end 820.695000
      Metadata:
        title           : 00:10:05.939
    Chapter #0:2: start 820.695000, end 1088.462000
      Metadata:
        title           : 00:13:40.695
    Chapter #0:3: start 1088.462000, end 1559.641000
      Metadata:
        title           : 00:18:08.462
    Chapter #0:4: start 1559.641000, end 1812.561000
      Metadata:
        title           : 00:25:59.641
    Chapter #0:5: start 1812.561000, end 2018.850000
      Metadata:
        title           : 00:30:12.561
    Chapter #0:6: start 2018.850000, end 2397.186000
      Metadata:
        title           : 00:33:38.850
    Chapter #0:7: start 2397.186000, end 2622.703000
      Metadata:
        title           : 00:39:57.186
    Chapter #0:8: start 2622.703000, end 2990.196000
      Metadata:
        title           : 00:43:42.703
    Chapter #0:9: start 2990.196000, end 3447.444000
      Metadata:
        title           : 00:49:50.196
    Chapter #0:10: start 3447.444000, end 3841.046000
      Metadata:
        title           : 00:57:27.444
    Chapter #0:11: start 3841.046000, end 4155.168000
      Metadata:
        title           : 01:04:01.046
  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv), 1920x1080, SAR 1:1 DAR 16:9, 23.81 fps, 23.81 tbr, 1k tbn (default)
  Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
  Stream #0:2(eng): Subtitle: hdmv_pgs_subtitle (pgssub) (default)
    Metadata:
      title           : 
Stream mapping:
  Stream #0:0 (hevc) -> overlay
  Stream #0:2 (pgssub) -> overlay
  overlay:default -> Stream #0:0 (libx265)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx265 @ 0000023384706740] Loaded libx265 does not support alpha layer encoding.
[vost#0:0/libx265 @ 0000023384706040] [enc:libx265 @ 0000023384645dc0] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[fc#0 @ 0000023384423400] Error sending frames to consumers: Error number -129 occurred
[fc#0 @ 0000023384423400] Task finished with error code: -129 (Error number -129 occurred)
[fc#0 @ 0000023384423400] Terminating thread with return code -129 (Error number -129 occurred)
[vost#0:0/libx265 @ 0000023384706040] [enc:libx265 @ 0000023384645dc0] Could not open encoder before EOF
[vost#0:0/libx265 @ 0000023384706040] Task finished with error code: -22 (Invalid argument)
[vost#0:0/libx265 @ 0000023384706040] Terminating thread with return code -22 (Invalid argument)
[out#0/mpegts @ 00000233845ebb80] Nothing was written into output file, because at least one of its streams received no packets.
frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A elapsed=0:00:00.18    
Conversion failed!

comment:5 by Gyan, 14 months ago

See this line:

Could not find codec parameters for stream 2 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size

This is an input error.

Try again with

-analyzeduration 100M -probesize 100M -i input.mkv

or find an input without that error.

comment:7 by SubJunk, 14 months ago

I forgot to add the output after those flags were added:

ffmpeg version 2025-05-15-git-12b853530a-essentials_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers
built with gcc 15.1.0 (Rev4, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil      60.  2.100 / 60.  2.100
libavcodec     62.  3.101 / 62.  3.101
libavformat    62.  0.102 / 62.  0.102
libavdevice    62.  0.100 / 62.  0.100
libavfilter    11.  0.100 / 11.  0.100
libswscale      9.  0.100 /  9.  0.100
libswresample   6.  0.100 /  6.  0.100
Input #0, matroska,webm, from 'D:\a\UniversalMediaServer\UniversalMediaServer\target\test-classes\net\pms\parsers\video-h265_dolbyvision_p08.06-eac3_dolby_surround_ex-hdmv_pgs.mkv':
Metadata:
encoder         : libebml v1.4.5 + libmatroska v1.7.1
creation_time   : 2025-05-18T08:48:33.000000Z
Duration: 01:05:40.40, start: 0.000000, bitrate: 52 kb/s
Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1608, SAR 1:1 DAR 160:67, 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS             : 12605646
DURATION        : 00:00:10.427000000
NUMBER_OF_FRAMES: 250
NUMBER_OF_BYTES : 16429884
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-18 08:48:33
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Side data:
DOVI configuration record: version: 1.0, profile: 8, level: 6, rpu flag: 1, el flag: 0, bl flag: 1, compatibility id: 1, compression: 0
Stream #0:1(eng): Audio: eac3, 48000 Hz, 7.1, fltp, 1536 kb/s (default)
Metadata:
title           : DDP 7.1
BPS             : 1536000
DURATION        : 00:00:10.432000000
NUMBER_OF_FRAMES: 326
NUMBER_OF_BYTES : 2002944
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-18 08:48:33
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(eng): Subtitle: hdmv_pgs_subtitle (pgssub), 1920x1080, Start 11.929000 (default)
Metadata:
BPS             : 32813
DURATION        : 01:05:28.466000000
NUMBER_OF_FRAMES: 1442
NUMBER_OF_BYTES : 16113414
_STATISTICS_WRITING_APP: mkvmerge v92.0 ('Everglow') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2025-05-18 08:48:33
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:3: Video: png, rgb24(pc, gbr/unknown/unknown), 608x759 [SAR 3780:3780 DAR 608:759], 90k tbr, 90k tbn (attached pic)
Metadata:
filename        : file.PNG
mimetype        : image/png
Stream mapping:
Stream #0:0 (hevc) -> overlay
Stream #0:2 (pgssub) -> overlay
overlay:default -> Stream #0:0 (libx265)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx265 @ 0000011a46bdebc0] Loaded libx265 does not support alpha layer encoding.
[vost#0:0/libx265 @ 0000011a46dd37c0] [enc:libx265 @ 0000011a4782d240] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[fc#0 @ 0000011a46b15a80] Error sending frames to consumers: Error number -129 occurred
[fc#0 @ 0000011a46b15a80] Task finished with error code: -129 (Error number -129 occurred)
[fc#0 @ 0000011a46b15a80] Terminating thread with return code -129 (Error number -129 occurred)
[vost#0:0/libx265 @ 0000011a46dd37c0] [enc:libx265 @ 0000011a4782d240] Could not open encoder before EOF
[vost#0:0/libx265 @ 0000011a46dd37c0] Task finished with error code: -22 (Invalid argument)
[vost#0:0/libx265 @ 0000011a46dd37c0] Terminating thread with return code -22 (Invalid argument)
[out#0/mpegts @ 0000011a46b15200] Nothing was written into output file, because at least one of its streams received no packets.
frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A elapsed=0:00:00.25
Conversion failed!

and that error "Loaded libx265 does not support alpha layer encoding." matches the commit from December

comment:8 by Gyan, 14 months ago

Since x265 now supports alpha layer, it advertises yuva420p as a supported pixel format, and the overlay filter will select that automatically.

So, when either input to overlay has alpha, add format=yuv420p after overlay when using libx265

-filter_complex [0:v][0:s:0]overlay,format=yuv420p

comment:9 by SubJunk, 14 months ago

That's a great outcome, thanks for your help. This means we can update FFmpeg in Universal Media Server.

I wonder if you could please have a quick look at my other recent ticket too, to see if you know of any commands that could make it work? That would make a lot of our users happy too https://trac.ffmpeg.org/ticket/11193

Note: See TracTickets for help on using tickets.