wader / static-ffmpeg

Multi-arch docker image with ffmpeg/ffprobe binaries built as hardened static PIE binaries with no external dependencies
https://hub.docker.com/r/mwader/static-ffmpeg/
MIT License
258 stars 62 forks source link

Error encoding to libx265 #528

Open GHLuckM4n opened 3 days ago

GHLuckM4n commented 3 days ago

/sample # ffmpeg -hide_banner -y -i Sample.mp4 -preset faster -c:v libx265 -crf 24 -map 0:v -map 0:a -c:a aac -b:a 192k OUT.mkv Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Sample.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 1970-01-01T00:00:00.000000Z encoder : Lavf53.24.2 Duration: 00:00:29.57, start: 0.000000, bitrate: 1421 kb/s Stream #0:00x1: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1032 kb/s, 25 fps, 25 tbr, 12800 tbn (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:10x2: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : SoundHandler vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help x265 [info]: HEVC encoder version 4.0+1-6318f22 x265 [info]: build info [Linux][GCC 13.2.1][64 bit] 8bit+10bit+12bit x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 x265 [info]: Main profile, Level-3.1 (Main tier) x265 [warning]: No thread pool allocated, --wpp disabled x265 [warning]: No thread pool allocated, --lookahead-slices disabled x265 [info]: Slices : 1 x265 [info]: frame threads / pool features : 3 / none x265 [info]: Coding QT: max CU size, min CU size : 64 / 8 x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra x265 [info]: ME / range / subpel / merge : hex / 57 / 2 / 2 x265 [info]: Keyframe min / max / scenecut / bias : 25 / 250 / 40 / 5.00 x265 [info]: Lookahead / bframes / badapt : 15 / 4 / 0 x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0 x265 [info]: References / ref-limit cu / depth : 2 / on / on x265 [info]: AQ: mode / str / qg-size / cu-tree : 2 / 1.0 / 32 / 1 x265 [info]: Rate Control / qCompress : CRF-24.0 / 0.60 x265 [info]: tools: rd=2 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp x265 [info]: tools: fast-intra strong-intra-smoothing deblock sao Output #0, matroska, to 'OUT.mkv': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf61.1.100 Stream #0:0(und): Video: hevc, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 1k tbn (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc61.3.100 libx265 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A Stream #0:1(und): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, 5.1, fltp, 192 kb/s (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : SoundHandler vendor_id : [0][0][0][0] encoder : Lavc61.3.100 aac [libx265 @ 0x7f1d0197cc00] Unknown picture type encountered.N/A speed=N/A [vost#0:0/libx265 @ 0x7f1d01cda040] Error submitting video frame to the encoder [vost#0:0/libx265 @ 0x7f1d01cda040] Error encoding a frame: Generic error in an external library [vost#0:0/libx265 @ 0x7f1d01cda040] Task finished with error code: -542398533 (Generic error in an external library) [vost#0:0/libx265 @ 0x7f1d01cda040] Terminating thread with return code -542398533 (Generic error in an external library) [out#0/matroska @ 0x7f1d01cf01c0] video:0KiB audio:247KiB subtitle:0KiB other streams:0KiB global headers:2KiB muxing overhead: 2.717726% frame= 0 fps=0.0 q=0.0 Lsize= 254KiB time=N/A bitrate=N/A speed=N/A x265 [info]: frame I: 1, Avg QP:21.36 kb/s: 21621.80

encoded 1 frames in 1.46s (0.69 fps), 21621.80 kb/s, Avg QP:21.36 [aac @ 0x7f1d01993000] Qavg: 602.711 Conversion failed!

Im on latest 7.0.2

wader commented 3 days ago

Hey, can you reproduce the error with some other ffmpeg build? and does ffmpeg -i file -f null - also produce an error? if so i would say there is something fishy with the input file or some decoder/demux bug in ffmpeg

GHLuckM4n commented 3 days ago

Hey, can you reproduce the error with some other ffmpeg build? and does ffmpeg -i file -f null - also produce an error? if so i would say there is something fishy with the input file or some decoder/demux bug in ffmpeg

/sample # ffmpeg -i Sample.mp4 -c:v libx265 -f null - ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers built with gcc 13.2.1 (Alpine 13.2.1_git20240309) 20240309 configuration: --pkg-config-flags=--static --extra-cflags=-fopenmp --extra-ldflags='-fopenmp -Wl,--allow-multiple-definition -Wl,-z,stack-size=2097152' --toolchain=hardened --disable-debug --disable-shared --disable-ffplay --enable-static --enable-gpl --enable-version3 --enable-fontconfig --enable-gray --enable-iconv --enable-lcms2 --enable-libaom --enable-libaribb24 --enable-libass --enable-libbluray --enable-libdav1d --enable-libdavs2 --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libkvazaar --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librabbitmq --enable-librav1e --enable-librsvg --enable-librtmp --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libuavs3d --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxevd --enable-libxeve --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-openssl --enable-libjxl libavutil 59. 8.100 / 59. 8.100 libavcodec 61. 3.100 / 61. 3.100 libavformat 61. 1.100 / 61. 1.100 libavdevice 61. 1.100 / 61. 1.100 libavfilter 10. 1.100 / 10. 1.100 libswscale 8. 1.100 / 8. 1.100 libswresample 5. 1.100 / 5. 1.100 libpostproc 58. 1.100 / 58. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Sample.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 1970-01-01T00:00:00.000000Z encoder : Lavf53.24.2 Duration: 00:00:29.57, start: 0.000000, bitrate: 1421 kb/s Stream #0:00x1: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1032 kb/s, 25 fps, 25 tbr, 12800 tbn (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:10x2: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : SoundHandler vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265)) Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native)) Press [q] to stop, [?] for help x265 [info]: HEVC encoder version 4.0+1-6318f22 x265 [info]: build info [Linux][GCC 13.2.1][64 bit] 8bit+10bit+12bit x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 x265 [info]: Main profile, Level-3.1 (Main tier) x265 [warning]: No thread pool allocated, --wpp disabled x265 [warning]: No thread pool allocated, --lookahead-slices disabled x265 [info]: Slices : 1 x265 [info]: frame threads / pool features : 3 / none x265 [info]: Coding QT: max CU size, min CU size : 64 / 8 x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra x265 [info]: ME / range / subpel / merge : hex / 57 / 2 / 3 x265 [info]: Keyframe min / max / scenecut / bias : 25 / 250 / 40 / 5.00 x265 [info]: Lookahead / bframes / badapt : 20 / 4 / 2 x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0 x265 [info]: References / ref-limit cu / depth : 3 / off / on x265 [info]: AQ: mode / str / qg-size / cu-tree : 2 / 1.0 / 32 / 1 x265 [info]: Rate Control / qCompress : CRF-28.0 / 0.60 x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp x265 [info]: tools: b-intra strong-intra-smoothing deblock sao Output #0, null, to 'pipe:': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf61.1.100 Stream #0:0(und): Video: hevc, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25 tbn (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc61.3.100 libx265 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, 5.1, s16, 4608 kb/s (default) Metadata: creation_time : 1970-01-01T00:00:00.000000Z handler_name : SoundHandler vendor_id : [0][0][0][0] encoder : Lavc61.3.100 pcm_s16le [libx265 @ 0x7f3895479c00] Unknown picture type encountered.d=N/A [vost#0:0/libx265 @ 0x7f38957d8040] Error submitting video frame to the encoder [vost#0:0/libx265 @ 0x7f38957d8040] Error encoding a frame: Generic error in an external library [vost#0:0/libx265 @ 0x7f38957d8040] Task finished with error code: -542398533 (Generic error in an external library) [vost#0:0/libx265 @ 0x7f38957d8040] Terminating thread with return code -542398533 (Generic error in an external library) [out#0/null @ 0x7f38957ed1c0] video:0KiB audio:16632KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown frame= 0 fps=0.0 q=0.0 Lsize=N/A time=N/A bitrate=N/A speed=N/A x265 [info]: frame I: 1, Avg QP:25.01 kb/s: 15357.20

encoded 1 frames in 1.38s (0.73 fps), 15357.20 kb/s, Avg QP:25.01 Conversion failed!

Got same error Yeah, i have try ffmpeg 7.0.1 and 6.1.1 is working fine

wader commented 3 days ago

Even without -c:v libx265? but i think this might be a ffmpeg problem/regression. Maybe should report it to the upstream trac? no sure i can help much without access to the source input file

GHLuckM4n commented 3 days ago

Working without -c:v libx265 because input file is x264 https://sample-videos.com/ this is the source file

wader commented 3 days ago

Tried to reproduce with https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4 but it seems to work fine. Tried both the amd64 and arm64 image.

$ curl -OLJ https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4
...
$ docker run -i --rm -u $UID:$GROUPS -v "$PWD:$PWD" --platform linux/amd64 -w "$PWD" mwader/static-ffmpeg:7.0.2 -i big_buck_bunny_720p_1mb.mp4 -c:v libx265 -f null -
ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 13.2.1 (Alpine 13.2.1_git20240309) 20240309
  configuration: --pkg-config-flags=--static --extra-cflags=-fopenmp --extra-ldflags='-fopenmp -Wl,--allow-multiple-definition -Wl,-z,stack-size=2097152' --toolchain=hardened --disable-debug --disable-shared --disable-ffplay --enable-static --enable-gpl --enable-version3 --enable-fontconfig --enable-gray --enable-iconv --enable-lcms2 --enable-libaom --enable-libaribb24 --enable-libass --enable-libbluray --enable-libdav1d --enable-libdavs2 --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libkvazaar --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librabbitmq --enable-librav1e --enable-librsvg --enable-librtmp --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libuavs3d --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxevd --enable-libxeve --enable-libxml2 --enable-libxvid --enable-libzimg --enable-openssl --enable-libjxl
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'big_buck_bunny_720p_1mb.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01T00:00:00.000000Z
    encoder         : Lavf53.24.2
  Duration: 00:00:05.31, start: 0.000000, bitrate: 1589 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1205 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
      Metadata:
        creation_time   : 1970-01-01T00:00:00.000000Z
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 384 kb/s (default)
      Metadata:
        creation_time   : 1970-01-01T00:00:00.000000Z
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.6+1-aa7f602f7
x265 [info]: build info [Linux][GCC 13.2.1][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
x265 [info]: Main profile, Level-3.1 (Main tier)
x265 [warning]: No thread pool allocated, --wpp disabled
x265 [warning]: No thread pool allocated, --lookahead-slices disabled
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 4 / none
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing deblock sao
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.1.100
  Stream #0:0(und): Video: hevc, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25 tbn (default)
      Metadata:
        creation_time   : 1970-01-01T00:00:00.000000Z
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.3.100 libx265
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, 5.1, s16, 4608 kb/s (default)
      Metadata:
        creation_time   : 1970-01-01T00:00:00.000000Z
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.3.100 pcm_s16le
[out#0/null @ 0x7ffff60cf1c0] video:461KiB audio:2988KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=  132 fps= 14 q=34.6 Lsize=N/A time=00:00:05.20 bitrate=N/A speed=0.57x
x265 [info]: frame I:      1, Avg QP:25.01  kb/s: 15357.20
x265 [info]: frame P:     35, Avg QP:26.17  kb/s: 1924.92
x265 [info]: frame B:     96, Avg QP:34.33  kb/s: 116.00
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%

encoded 132 frames in 9.06s (14.57 fps), 711.10 kb/s, Avg QP:32.10
GHLuckM4n commented 3 days ago

Sorry, i do on mwader/static-ffmpeg:latest tag build

wader commented 3 days ago

So 7.0.2 works? i get same error with latest tag. Hmm ok then i would guess it's some recent change in x265 that makes things break :( also seems like they have started doing stable versioned releases again so maybe i should switch to to that instead of building with latest master

GHLuckM4n commented 3 days ago

Yep on 7.0.2 is working fine. Thanks for fast reply

wader commented 3 days ago

👍 i guess it would be good to try x265 4.0 and see if it has the same problem and if so report it somewhere

GHLuckM4n commented 3 days ago

Sound good, i'm waiting for...

wader commented 3 days ago

Ok seems i can reproduce with x265 4.0 but not 3.6 with ffmpeg 7.0.2

wader commented 3 days ago

On possibility is that the API has changed with 4.0 so that the ffmpeg binding needs to be updated

GHLuckM4n commented 3 days ago

Ok wafting for new update

wader commented 3 days ago

Seems to be very broken, even this fails docker run -i --rm -u $UID:$GROUPS -v "$PWD:$PWD" -w "$PWD" x265-master -f lavfi -i testsrc -c:v libx265 -f null -

wader commented 3 days ago

https://bitbucket.org/multicoreware/x265_git/issues/955/conversion-failed-with-x265-40-and-ffmpeg

GHLuckM4n commented 3 days ago

Hmm, i have no idea

wader commented 3 days ago

(it's my bug report to x265)