cea-sec / sanzu

Graphical remote desktop solution
GNU General Public License v3.0
179 stars 27 forks source link

CodecNotFound: libx264 Centos 7, ffmpeg 4 #132

Closed mcff2 closed 1 year ago

mcff2 commented 1 year ago

Hi,

I got a weird error : "[2023-01-25T07:01:46.989148100Z ERROR sanzu_server] Server error [2023-01-25T07:01:46.989242403Z ERROR sanzu_server] - due to Error in init video encoder [2023-01-25T07:01:46.989264520Z ERROR sanzu_server] - due to Error in EncoderBuilder [2023-01-25T07:01:46.989279303Z ERROR sanzu_server] - due to Error in new AVCodec [2023-01-25T07:01:46.989302310Z ERROR sanzu_server] - due to CodecNotFound: libx264"

But sanzu_server is dynamicaly linked to the correct libs :

    linux-vdso.so.1 =>  (0x00007ffee02c2000)
    libopus.so.0 => /lib64/libopus.so.0 (0x00007f706c8c4000)
    libasound.so.2 => /lib64/libasound.so.2 (0x00007f706c5c4000)
    libavutil.so.55 => /lib64/libavutil.so.55 (0x00007f706c33f000)
    libavcodec.so.57 => /lib64/libavcodec.so.57 (0x00007f706ae0f000)
    libX11.so.6 => /lib64/libX11.so.6 (0x00007f706aad1000)
    libpam.so.0 => /lib64/libpam.so.0 (0x00007f706a8c2000)
    libpam_misc.so.0 => /lib64/libpam_misc.so.0 (0x00007f706a6be000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f706a471000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f706a25b000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f706a053000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7069e37000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f7069b35000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f7069931000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f7069563000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f706d220000)
    libdrm.so.2 => /lib64/libdrm.so.2 (0x00007f7069352000)
    libmfx.so.0 => /lib64/libmfx.so.0 (0x00007f706913e000)
    libva-drm.so.1 => /lib64/libva-drm.so.1 (0x00007f7068f3b000)
    libva-x11.so.1 => /lib64/libva-x11.so.1 (0x00007f7068d35000)
    libva.so.1 => /lib64/libva.so.1 (0x00007f7068b15000)
    libvdpau.so.1 => /lib64/libvdpau.so.1 (0x00007f7068911000)
    libOpenCL.so.1 => /lib64/libOpenCL.so.1 (0x00007f70686f2000)
    libswresample.so.2 => /lib64/libswresample.so.2 (0x00007f70684d5000)
    libzvbi.so.0 => /lib64/libzvbi.so.0 (0x00007f7068246000)
    libxvidcore.so.4 => /lib64/libxvidcore.so.4 (0x00007f7067f32000)
    libx265.so.165 => /lib64/libx265.so.165 (0x00007f70678aa000)
    libx264.so.148 => /lib64/libx264.so.148 (0x00007f706754e000)
    libvpx.so.1 => /lib64/libvpx.so.1 (0x00007f70671c6000)
    libvorbisenc.so.2 => /lib64/libvorbisenc.so.2 (0x00007f7066cf7000)
    libvorbis.so.0 => /lib64/libvorbis.so.0 (0x00007f7066aca000)
    libvo-amrwbenc.so.0 => /lib64/libvo-amrwbenc.so.0 (0x00007f70668b0000)
    libtheoraenc.so.1 => /lib64/libtheoraenc.so.1 (0x00007f7066683000)
    libtheoradec.so.1 => /lib64/libtheoradec.so.1 (0x00007f7066473000)
    libspeex.so.1 => /lib64/libspeex.so.1 (0x00007f706625a000)
    librsvg-2.so.2 => /lib64/librsvg-2.so.2 (0x00007f7066024000)
    libcairo.so.2 => /lib64/libcairo.so.2 (0x00007f7065ced000)
    libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f7065a9c000)
    libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f7065786000)
    libopenjp2.so.7 => /lib64/libopenjp2.so.7 (0x00007f7065533000)
    libopencore-amrwb.so.0 => /lib64/libopencore-amrwb.so.0 (0x00007f706531f000)
    libopencore-amrnb.so.0 => /lib64/libopencore-amrnb.so.0 (0x00007f70650f4000)
    libmp3lame.so.0 => /lib64/libmp3lame.so.0 (0x00007f7064e7b000)
    libgsm.so.1 => /lib64/libgsm.so.1 (0x00007f7064c6f000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f7064a59000)
    libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f7064831000)
    libaudit.so.1 => /lib64/libaudit.so.1 (0x00007f7064608000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f706431f000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f70640ec000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f7063ee8000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f7063cd8000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f7063ad4000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f70638ba000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f70635b2000)
    libXext.so.6 => /lib64/libXext.so.6 (0x00007f70633a0000)
    libXfixes.so.3 => /lib64/libXfixes.so.3 (0x00007f706319a000)
    libsoxr.so.0 => /lib64/libsoxr.so.0 (0x00007f7062f37000)
    libpng15.so.15 => /lib64/libpng15.so.15 (0x00007f7062d0c000)
    libnuma.so.1 => /lib64/libnuma.so.1 (0x00007f7062b00000)
    libogg.so.0 => /usr/lib64/libogg.so.0 (0x00007f70628f9000)
    libgdk_pixbuf-2.0.so.0 => /lib64/libgdk_pixbuf-2.0.so.0 (0x00007f70626d1000)
    libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x00007f7062331000)
    libpangocairo-1.0.so.0 => /lib64/libpangocairo-1.0.so.0 (0x00007f7062123000)
    libpangoft2-1.0.so.0 => /lib64/libpangoft2-1.0.so.0 (0x00007f7061f0d000)
    libpango-1.0.so.0 => /lib64/libpango-1.0.so.0 (0x00007f7061cc7000)
    libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f7061a85000)
    libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007f70617c6000)
    libcroco-0.6.so.3 => /lib64/libcroco-0.6.so.3 (0x00007f706158b000)
    libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f7061221000)
    libpixman-1.so.0 => /lib64/libpixman-1.so.0 (0x00007f7060f78000)
    libEGL.so.1 => /lib64/libEGL.so.1 (0x00007f7060d64000)
    libxcb-shm.so.0 => /lib64/libxcb-shm.so.0 (0x00007f7060b60000)
    libxcb-render.so.0 => /lib64/libxcb-render.so.0 (0x00007f7060952000)
    libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f7060747000)
    libGL.so.1 => /lib64/libGL.so.1 (0x00007f70604bb000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f7060259000)
    libffi.so.6 => /lib64/libffi.so.6 (0x00007f7060051000)
    libXau.so.6 => /lib64/libXau.so.6 (0x00007f705fe4d000)
    libcap-ng.so.0 => /lib64/libcap-ng.so.0 (0x00007f705fc47000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f705fa20000)
    libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f705f7fa000)
    libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f705f5f6000)
    libmount.so.1 => /lib64/libmount.so.1 (0x00007f705f3b3000)
    libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x00007f705f116000)
    libthai.so.0 => /lib64/libthai.so.0 (0x00007f705ef0a000)
    libfribidi.so.0 => /lib64/libfribidi.so.0 (0x00007f705ecee000)
    libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f705eac4000)
    libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f705e8bf000)
    libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f705e6af000)
    liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f705e489000)
    libGLdispatch.so.0 => /lib64/libGLdispatch.so.0 (0x00007f705e1d3000)
    libGLX.so.0 => /lib64/libGLX.so.0 (0x00007f705dfa1000)
    libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f705dd61000)
    libgraphite2.so.3 => /lib64/libgraphite2.so.3 (0x00007f705db33000)

I know that it's not easy to investigate with those limited infos. But based on your experience with sanzu_server, do you have any clue?

serpilliere commented 1 year ago

Hi @mcff2 !

You can try to investigate the problem using ffmpeg cmdline:

First, you can retrieve the ffmpeg supported encoders in your configuration:

$ ffmpeg -encoders
...
 V..... h263                 H.263 / H.263-1996
 V..... h263_v4l2m2m         V4L2 mem2mem H.263 encoder wrapper (codec h263)
 V.S... h263p                H.263+ / H.263-1998 / H.263 version 2
 V....D libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V....D libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V....D h264_amf             AMD AMF H.264 Encoder (codec h264)
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
...

Check if your ffmpeg installation supports the libx264 (maybe you didn't install the right package, or if you have compiled ffmpeg yourself, maybe you miss the lixb264 configuration

Once it's done, you can also get informations on a specific codec (for example here h264_qsv):

$ ffmpeg -h encoder=h264_qsv
...
Encoder h264_qsv [H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration)]:
    General capabilities: delay hybrid 
    Threading capabilities: none
    Supported hardware devices: qsv qsv qsv 
    Supported pixel formats: nv12 p010le qsv
h264_qsv encoder AVOptions:
  -async_depth       <int>        E..V....... Maximum processing parallelism (from 1 to INT_MAX) (default 4)
  -avbr_accuracy     <int>        E..V....... Accuracy of the AVBR ratecontrol (unit of tenth of percent) (from 1 to 65535) (default 1)
  -avbr_convergence  <int>        E..V....... Convergence of the AVBR ratecontrol (unit of 100 frames) (from 1 to 65535) (default 1)
  -preset            <int>        E..V....... (from 1 to 7) (default medium)
     veryfast        7            E..V.......
     faster          6            E..V.......
     fast            5            E..V.......
     medium          4            E..V.......
     slow            3            E..V.......
     slower          2            E..V.......
     veryslow        1            E..V.......
  -forced_idr        <boolean>    E..V....... Forcing I frames as IDR frames (default false)
...

If you decide to compile your ffmpeg, here is an example of a configuration for the "./configuration" run:

ffmpeg-5.1.1]$ head config.h
/* Automatically generated by configure - do not modify! */
#ifndef FFMPEG_CONFIG_H
#define FFMPEG_CONFIG_H
#define FFMPEG_CONFIGURATION "--enable-gpl --enable-libx264 --enable-libx265 --enable-vaapi --enable-vdpau --enable-libmfx --enable-librav1e --enable-libaom --enable-libvpx --enable-libv4l2 --enable-libopus --enable-libmp3lame --enable-libfreetype --prefix=/usr --enable-shared"
...

So you may download ffmpeg 5.1.1 and do:

./configure --enable-gpl --enable-libx264 --enable-libx265 --enable-vaapi --enable-vdpau --enable-libmfx --enable-librav1e --enable-libaom --enable-libvpx --enable-libv4l2 --enable-libopus --enable-libmp3lame --enable-libfreetype --prefix=/usr --enable-shared
make
sudo make install

it enables libx264, qsv hardware compression (for intel cpu) If you have an nvidia, you may also add the h264_nvenc

serpilliere commented 1 year ago

Oh, another solution: Maybe you simply didn't install the x264 package on your distrib?

serpilliere commented 1 year ago

May I close this issue @mcff2 ?

serpilliere commented 1 year ago

Hi @mcff2 I have something for this one. On old ffmpeg version, for example on CentOS 7 distribution, ffmpeg needs to call a function to register all codecs. This function has been deprecated in new ffmpeg version, and we remove it's call in Sanzu some monthes ago. If you build sanzu on such systems, you have to apply the following patch which call the function in the encoder side and in the decoder side:

diff --git a/sanzu/src/video_decoder.rs b/sanzu/src/video_decoder.rs
index 76f146e..c715248 100644
--- a/sanzu/src/video_decoder.rs
+++ b/sanzu/src/video_decoder.rs
@@ -33,6 +33,10 @@ pub fn init_video_codec<'a>(
         ffmpeg::av_log_set_level(ffmpeg::AV_LOG_FATAL);
     }

+    unsafe {
+        ffmpeg::av_register_all();
+    }
+
     let decoder: Box<dyn Decoder> = match name {
         "null" => Box::new(DecoderNull {
             data_rgb: None,
diff --git a/sanzu/src/video_encoder.rs b/sanzu/src/video_encoder.rs
index 5692b45..b341c3d 100644
--- a/sanzu/src/video_encoder.rs
+++ b/sanzu/src/video_encoder.rs
@@ -610,6 +610,11 @@ pub fn init_video_encoder<'a>(
     unsafe {
         ffmpeg::av_log_set_level(ffmpeg::AV_LOG_FATAL);
     }
+
+    unsafe {
+        ffmpeg::av_register_all();
+    }
+
     let encoder: Box<dyn Encoder> = match name {
         "null" => Box::new(EncoderNull::new()),
         name => {
mcff2 commented 1 year ago

I confirm that your guess was the good one. After adding those lines, it works.

Thanks !

serpilliere commented 1 year ago

Thank you for your feedback. We may not add a branch to support this old version of ffmpeg, as it is a deprecated API. Moreover, we approche the centos 7 eol.

mcff2 commented 1 year ago

No pb, and thanks for the support. Once it's identified, it's rather easy to add those two lines.