erikkaashoek / Comskip

A free commercial detector
GNU General Public License v2.0
598 stars 80 forks source link

qsv on Ubuntu 22.04 crash - core dump #167

Closed viotemp1 closed 9 months ago

viotemp1 commented 10 months ago

Hello,

Good news about qsv, the speed(fps) is good (3x times better than dxva2.

When I run comskip with --hwassist --dxva2 everything is fine, commercials are found, but when I run with --hwassist --qsv I have the following error close to the end:

comskip: /opt/src/msdk/_studio/shared/umc/core/vm_plus/src/mfx_vm++_pthread_unix.cpp:52: virtual MfxMutex::~MfxMutex(): Assertion '!res' failed.

I compiled comskip on my PC from source.

Regards, V

jmarcet commented 10 months ago

Hi,

I contributed the qsv patch. The only way I could get qsv to work fine was using jellyfin-ffmpeg. I tried building ffmpeg myself, alpine, debian & ubuntu's versions.

None of them worked well with qsv. Hence I settled for installing the one from jellyfin, with it both ffmpeg & comskip work well with qsv. Arch also has a working ffmpeg, but it is not ideal to dockerize.

Here you can see how I have it dockerized.

jmarcet commented 10 months ago

About the speed, with ffmpeg-6, comskipping SD content is impressive, 1h in 30s. HD content takes ~2-4 mins.

viotemp1 commented 10 months ago

Thanks I'll give a try to jellyfin-ffmpeg. Thanks for your answer!

viotemp1 commented 9 months ago

I compiled again after installing from source oneVPL-intel-gpu and now is working (no core dump).

Now I have one error at the end of mpeg2dec.c main function:

Enabling use_qsv
Using Codec: h264_qsv instead of h264
Using Codec: h264_qsv instead of h2641.15 fps), 1.00 sec(518.00 fps), 17%
 0:14:32 - 26007 frames in 46.58 sec(558.33 fps), 1.00 sec(523.00 fps), 97%
26443 frames decoded in 47.40 seconds (557.87 fps)
Commercials were found.
comskip_qsv: /opt/src/msdk/_studio/shared/umc/core/vm_plus/src/mfx_vm++_pthread_unix.cpp:52: virtual MfxMutex::~MfxMutex(): Assertion `!res' failed.
Aborted

Commercials are detected, no problem with this. Exit code is affected only (127)

Any ideea how to gracefully release the gpu thread/resources or whatever is causing this?

Regards,

jmarcet commented 9 months ago

@viotemp1 Are you compiling comskip with the jellyfin-ffmpeg headers like I am?

I never encountered that issue, I use it very often and it works very well. I have no idea what might be causing that.

viotemp1 commented 9 months ago

I really have no idea which headers are used because I installed so many packages related to ffmpeg lately. If there is any way to find out from compiling stage which headers I'm using please let me know and I'll test.

I have installed: jellyfin-ffmpeg6/unknown,now 6.0.1-1-jammy ffmpeg/jammy-updates,jammy-security,now 7:4.4.2-0ubuntu0.22.04.1 libmfx-dev/focal,now 22.5.0+i419~u20.04 libmfx1/focal,now 22.5.0+i419~u20.04 libmfxgen1/focal,now 22.5.0+i419~u20.04 libavcodec-dev/jammy-updates,jammy-security,now 7:4.4.2-0ubuntu0.22.04.1 libavdevice58/jammy-updates,jammy-security,now 7:4.4.2-0ubuntu0.22.04.1 libavformat-dev/jammy-updates,jammy-security,now 7:4.4.2-0ubuntu0.22.04.1 libavutil-dev/jammy-updates,jammy-security,now 7:4.4.2-0ubuntu0.22.04.1 onevpl-gpu from git

I dropped the Docker way because it was taking too much time to change, compile, test.

Anyhow, I got rid of the above assert error adding file_close() in main function before exit:

//
// Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
//
    file_close(); // -> here
#if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410)
jmarcet commented 9 months ago

This is how I'm building comskip and making jellyfin-ffmpeg available system-wide within a debian container, although the same steps should work on Ubuntu

export COMSKIP_BRANCH=master
export JELLYFIN_FFMPEG_BRANCH=jellyfin

export ffmpeg_CFLAGS="-I/usr/lib/jellyfin-ffmpeg/include"
export ffmpeg_LIBS="-L/usr/lib/jellyfin-ffmpeg/lib -lavcodec -lavformat -lavutil -lswscale"

echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/$( awk -F'=' '/^ID=/{ print $NF }' /etc/os-release ) $( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release ) main" | tee /etc/apt/sources.list.d/jellyfin.list \
&& VER=$( wget -q -O- https://repo.jellyfin.org/releases/server/debian/versions/jellyfin-ffmpeg/ | tac | grep -m 1 'href="6' | cut -d'"' -f2 ) \
&& FFMPEG=$( wget -q -O- https://repo.jellyfin.org/releases/server/debian/versions/jellyfin-ffmpeg/${VER} | grep -m 1 "bookworm_${TARGETARCH}\(hf\)\?.deb" | cut -d'"' -f2 ) \
&& wget https://repo.jellyfin.org/releases/server/debian/versions/jellyfin-ffmpeg/${VER}${FFMPEG} \
&& apt-get install --no-install-recommends --no-install-suggests -y gnupg \
&& wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | apt-key add - \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
   jellyfin-ffmpeg5 \
   mesa-va-drivers \
&& apt-get purge -y gnupg jellyfin-ffmpeg5 \
&& dpkg -i ${FFMPEG} \
&& rm -f ${FFMPEG} \
&& apt-get install --no-install-recommends --no-install-suggests -y \
   autoconf \
   automake \
   libargtable2-dev \
   libtool \
   pkg-config \
&& git clone -b ${JELLYFIN_FFMPEG_BRANCH} https://github.com/jellyfin/jellyfin-ffmpeg \
&& cd jellyfin-ffmpeg \
&& ./configure --prefix=/usr/lib/jellyfin-ffmpeg --disable-x86asm \
&& make -j$(nproc) install-headers \
&& cd .. \
&& rm -fr jellyfin-ffmpeg \
&& git clone -b ${COMSKIP_BRANCH} https://github.com/erikkaashoek/Comskip \
&& cd Comskip \
&& ./autogen.sh \
&& ./configure \
&& make -j$(nproc) \
&& make -j$(nproc) install \
&& cd .. \
&& rm -fr Comskip \
&& rm -fr /usr/lib/jellyfin-ffmpeg/include \
&& apt-get purge -y \
   autoconf \
   automake \
   libargtable2-dev \
   libtool \
   pkg-config \
&& apt-get install --no-install-recommends --no-install-suggests -y libargtable2.0 \
&& ln -s /usr/lib/jellyfin-ffmpeg/ff* /usr/local/bin/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/lib/libavcodec.so.* /usr/local/lib/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/lib/libavformat.so.* /usr/local/lib/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/lib/libavutil.so.* /usr/local/lib/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/lib/libswscale.so.* /usr/local/lib/
viotemp1 commented 9 months ago

Hello,

I tried adding these to a Dockerfile (with some changes) and I've got this error:

gcc -g -O2    -o comskip comskip-comskip.o comskip-mpeg2dec.o comskip-platform.o comskip-video_out_dx.o ccextratorwin/comskip-608.o ccextratorwin/comskip-ccextractor.o ccextratorwin/comskip-encoding.o ccextratorwin/comskip-general_loop.o ccextratorwin/comskip-myth.o -largtable2 -L/usr/lib/jellyfin-ffmpeg/lib -lavcodec -lavformat -lavutil -lswscale  -lpthread -lm
13.41 /usr/bin/ld: cannot find -lavcodec: No such file or directory
13.41 /usr/bin/ld: cannot find -lavformat: No such file or directory
13.41 /usr/bin/ld: cannot find -lavutil: No such file or directory
13.41 /usr/bin/ld: cannot find -lswscale: No such file or directory
13.42 collect2: error: ld returned 1 exit status
jmarcet commented 9 months ago

@viotemp1 See the updated instructions above, you're missing the jellyfin-ffmpeg5 or jellyfin-ffmpeg6 package.

The instructions above first install jellyfin-ffmpeg5 which is available on jellyfin's repo, so it correctly installs all the required deps, then uninstall it and install jellyfin-ffmpeg6 instead. When installing jellyfin-ffmpeg6 directly there are dependency problems.

viotemp1 commented 9 months ago

Hi jmarcet, All good now, thanks for help. It's working now in docker with qsv. Anyhow the speed it's a bit lower than running native on Ubuntu (471.19 fps vs 548.38 fps). Regards