Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Videos: Official Nvidia transcoding suppport #2125

Closed
maximecurioni opened this issue Mar 5, 2022 · 24 comments
Closed

Videos: Official Nvidia transcoding suppport #2125

maximecurioni opened this issue Mar 5, 2022 · 24 comments
Assignees
Labels
idea Feedback wanted / feature request released Available in the stable release video Video Formats, Transcoding, FFmpeg, Streaming & Co

Comments

@maximecurioni
Copy link
Sponsor

maximecurioni commented Mar 5, 2022

What does not work as described in the documentation?

Up to the last 2022-01-21 release, it was possible to specify the h264_nvenc encoder to ffmpeg for GPU-based transcoding with Nvidia cards.

The latest 2022-03-02 release no longer offers a version of ffmpeg with that capability.

How can we reproduce it?

Here are the verification steps in 2022-03-02:

root@photoprism:/photoprism-storage/config# docker-compose exec photoprism bash
root@5846c5714486:/photoprism# uname -a
Linux 5846c5714486 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux
root@5846c5714486:/photoprism# cat /etc/debian_version
11.2
root@5846c5714486:/photoprism# ffmpeg -loglevel quiet -encoders | grep h264_
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V..... h264_vaapi           H.264/AVC (VAAPI) (codec h264)

Notice how h264_nvenc is not part of that list.

What behavior do you expect?

Here are the exact same steps in 2022-01-21:

root@photoprism:/photoprism-storage/config# docker-compose exec photoprism bash
root@bace6e400f6e:/photoprism# uname -a
Linux bace6e400f6e 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 x86_64 x86_64 GNU/Linux      
root@bace6e400f6e:/photoprism# cat /etc/debian_version
11.0
root@bace6e400f6e:/photoprism# ffmpeg -loglevel quiet -encoders | grep h264_
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)

What could be the cause of your problem?

The ffmpeg version packaged in the 2022-03-02 was not compiled with support for h264_nvenc encoder.

Can you provide us with example files for testing, error logs, or screenshots?

Available to provide more information if needed

Which software versions do you use?

Available to provide more information if needed

On what kind of device is PhotoPrism installed?

Available to provide more information if needed

Do you use a Reverse Proxy, Firewall, VPN, or CDN?
None

@maximecurioni maximecurioni added the bug Something isn't working label Mar 5, 2022
@maximecurioni
Copy link
Sponsor Author

maximecurioni commented Mar 5, 2022

Here is the respective version information of ffmpeg.

2022-01-21

root@db0717d57a18:/photoprism# ffmpeg -version
ffmpeg version 4.4-6ubuntu5 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-7ubuntu1)
configuration: --prefix=/usr --extra-version=6ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

2022-03-02

root@5846c5714486:/photoprism# ffmpeg -version
ffmpeg version 4.3.3-0+deb11u1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 51.100 / 56. 51.100
libavcodec     58. 91.100 / 58. 91.100
libavformat    58. 45.100 / 58. 45.100
libavdevice    58. 10.100 / 58. 10.100
libavfilter     7. 85.100 /  7. 85.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  7.100 /  5.  7.100
libswresample   3.  7.100 /  3.  7.100
libpostproc    55.  7.100 / 55.  7.100

@maximecurioni
Copy link
Sponsor Author

For anyone who wants a temporary fix, the testing version of ffmpeg works as expected.

Here is how to add it to a custom Dockerfile:

FROM photoprism/photoprism:latest

RUN echo "\ndeb http://ftp.us.debian.org/debian testing main" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -t testing ffmpeg

Here is the final result:

root@f366e79769af:/photoprism# ffmpeg -version
ffmpeg version 4.4.1-3 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Debian 11.2.0-14)
configuration: --prefix=/usr --extra-version=3 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
root@f366e79769af:/photoprism# ffmpeg -loglevel quiet -encoders | grep h264_
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)

@lastzero
Copy link
Member

lastzero commented Mar 6, 2022

Our default image now ships with the version in that comes with Debian 11: https://packages.debian.org/

However, We still provide an Ubuntu based image, check Docker Hub: https://hub.docker.com/r/photoprism/photoprism/tags?page=1&name=impish

Did you follow the instructions in our Docker Compose example?

https://dl.photoprism.app/docker/docker-compose.yml

In particular, you need to uncomment this and restart:

PHOTOPRISM_INIT: "gpu tensorflow"

Also make sure to share all necessary devices, for example:

devices:
    - "/dev/nvidia0:/dev/nvidia0"
    - "/dev/nvidiactl:/dev/nvidiactl"

You can also manually install packages in the container as needed.

@lastzero
Copy link
Member

lastzero commented Mar 6, 2022

Note we never had official Nvidia support, so I don't consider this a bug.

@lastzero lastzero changed the title ffmpeg in 2022-03-02 release no longer includes h264_nvenc encoder Videos: Official Nvidia transcoding suppport Mar 6, 2022
@lastzero lastzero added idea Feedback wanted / feature request member-feature Available to members and contributors and removed bug Something isn't working labels Mar 6, 2022
@lastzero
Copy link
Member

lastzero commented Mar 6, 2022

The nvidia-vdpau-driver for hardware video acceleration is installed here if you selected the "gpu" option in PHOTOPRISM_INIT:

https://github.com/photoprism/photoprism/blob/develop/scripts/dist/install-gpu.sh#L36

@maximecurioni
Copy link
Sponsor Author

Thank you @lastzero. Sorry for misidentifying this as a bug.

I'll give PHOTOPRISM_INIT a try. Feel free to close this issue if it's not applicable to the project.

As always, much appreciated for the quick response.

@dailow
Copy link

dailow commented Mar 23, 2022

For anyone who wants a temporary fix, the testing version of ffmpeg works as expected.

Here is how to add it to a custom Dockerfile:

FROM photoprism/photoprism:latest

RUN echo "\ndeb http://ftp.us.debian.org/debian testing main" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -t testing ffmpeg

Here is the final result:

root@f366e79769af:/photoprism# ffmpeg -version
ffmpeg version 4.4.1-3 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Debian 11.2.0-14)
configuration: --prefix=/usr --extra-version=3 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
root@f366e79769af:/photoprism# ffmpeg -loglevel quiet -encoders | grep h264_
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)

Thanks for this. Installing from the testing repo includes the required code for ffmpeg to work. I tried using gpu for PHOTOPRISM_INIT, but while that did install the nvidia libraries it did not have the version of ffmpeg with nvenc compiled.

lastzero added a commit that referenced this issue Mar 23, 2022
- successfully tested with NVIDIA Quadro P620 and driver v470.103.01
- the host Linux kernel should run the same driver version Make sure to
- driver names in PHOTOPRISM_FFMPEG_ENCODER have been simplified
- share /dev/nvidia* as shown in our new docker-compose.yml example
@lastzero lastzero self-assigned this Mar 23, 2022
@lastzero lastzero added the please-test Ready for acceptance test label Mar 23, 2022
@lastzero
Copy link
Member

Development Preview has been updated for testing:

lastzero added a commit that referenced this issue Apr 15, 2022
Adds the following video-related libs to the ARMv7 base image:
libwebm1, libmatroska7, libdvdread8, libebml5, libgav1-0, libatomic1,
libx264-163, libx265-199
lastzero added a commit that referenced this issue Apr 18, 2022
Also installs the following, additional packages:
- libcuda1
- libnvcuvid1
- mesa-va-drivers
@yuanfulou
Copy link

Development Preview has been updated for testing:

For the simplified part, I wonder how to indicate the encoder? I successfully install the testing version of FFmpeg to get the h264_nvenc encoder. I copied a sample .mov file and tested the encoder, it successfully used GPU to finish the FFmpeg command within the container. However, when I set PHOTOPRISM_FFMPEG_ENCODER: "h264_nvenc" in the docker-compose file and indexed some new files, it does not use GPU. Is there any missing part? or I misunderstand the meaning of ENCODER 😅

@yuanfulou
Copy link

root@25fad1540944:~# ffmpeg -loglevel quiet -encoders | grep 264
 V..... libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V..... libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 V..... nvenc                NVIDIA NVENC H.264 encoder (codec h264)
 V..... nvenc_h264           NVIDIA NVENC H.264 encoder (codec h264)

The ffmpeg commands I tried:

ffmpeg -y -vsync 0  -i input.mov -c:a copy -c:v h264_nvenc  output.mp4
ffmpeg -y -vsync 0  -i input.mov -c:a copy -c:v nvenc  output.mp4
ffmpeg -y -vsync 0  -i input.mov -c:a copy -c:v nvenc_h264  output.mp4

All triggered GPU to accelerate the process

ffmpeg info

root@25fad1540944:~# ffmpeg
ffmpeg version 4.4.2-1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Debian 11.2.0-20)
  configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc --enable-libsmbclient
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hyper fast Audio and Video encoder

@yuanfulou
Copy link

With the preview version of image image: photoprism/photoprism:preview, h264_nvenc installed automatically.

root@fe803b89b386:~# ffmpeg -loglevel quiet -encoders | grep 264
 V..... libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V..... libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)
 V..... h264_qsv             H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 V..... nvenc                NVIDIA NVENC H.264 encoder (codec h264)
 V..... nvenc_h264           NVIDIA NVENC H.264 encoder (codec h264)

Tho ENV looks right

root@fe803b89b386:~# echo $PHOTOPRISM_FFMPEG_ENCODER
h264_nvenc

but config looks weird. It uses libx264 instead.

❯ docker-compose exec photoprism photoprism config | grep encode
| ffmpeg-encoder         | libx264                                                |

When I tried

root@fe803b89b386:~# ffmpeg -y -vsync 0  -i input.mov -c:a copy -c:v h264_nvenc  output.mp4

it can utilize GPU without any issue.

Not sure why ffmpeg-encoder did not change to h264_nvenc

@graciousgrey
Copy link
Member

Are you a sponsor, the ffmpeg-encoder is a sponsor only config option ?

@yuanfulou
Copy link

oh wow. Did not notice the sponsor part. Let me check that up 😅

@graciousgrey
Copy link
Member

You find more information on sponsorship options here: https://photoprism.app/membership :)

@graciousgrey graciousgrey added released Available in the stable release and removed please-test Ready for acceptance test labels May 17, 2022
@ngoldack
Copy link

Is there a way to specify the NVIDIA driver version?
I'm using Unraid and it throws mismatched driver errors so it won't work.`

When I start the container I get:

Mismatching nvidia kernel module loaded

The NVIDIA driver that is being installed (version 470.103.01) does not
match the nvidia kernel module currently loaded (version 470.94).

And when I start to watch a video via the web-ui:

time="2022-05-25T10:32:15+02:00" level=info msg="convert: ffmpeg encoder h264_nvenc selected"
time="2022-05-25T10:32:15+02:00" level=info msg="h264_nvenc: transcoding 2022/03/20220311_030931_8C7AC103.mp4 to avc"
time="2022-05-25T10:32:17+02:00" level=warning msg="h264_nvenc: failed transcoding 2022/03/20220311_030931_8C7AC103.mp4 [2.254126614s]"
time="2022-05-25T10:32:17+02:00" level=info msg="libx264: transcoding 2022/03/20220311_030931_8C7AC103.mp4 to avc"
time="2022-05-25T10:33:47+02:00" level=info msg="libx264: created 20220311_030931_8C7AC103.mp4.avc [1m29.711936046s]"

It fails back to cpu transcode.

Thanks for the great work so far!

@lastzero
Copy link
Member

We'd probably have to build a special Unraid image for this as the version depends on the base image.

@lastzero lastzero added the video Video Formats, Transcoding, FFmpeg, Streaming & Co label Jul 7, 2022
@mlapaglia
Copy link

Is there currently a way to get this to work? Starting up I receive the same error

Configuring libcuda1:amd64
--------------------------

Mismatching nvidia kernel module loaded

The NVIDIA driver that is being installed (version 470.129.06) does not
match the nvidia kernel module currently loaded (version 515.57).

The X server, OpenGL, and GPGPU applications may not work properly.

@lastzero
Copy link
Member

lastzero commented Aug 11, 2022

As far as I know, NVIDIA ships a binary (proprietary) kernel module, so the versions must match exactly. However, it is impossible to know at build time which version(s) our users have (it won't be just one anyway).

The only solution I see at the moment is to open a terminal (as root via docker exec or docker-compose exec...) and install the correct module manually - from the NVIDIA server if Ubuntu/Debian don't provide it directly.

If you would like to contribute, it would be great if you improve our scripts so that the user can select the correct version via PHOTOPRISM_INIT (note that we are on vacation until the end of August):

nvidia)
echo "Installing Nvidia Drivers..."
apt-get -qq install libcuda1 libnvcuvid1 libnvidia-encode1 nvidia-opencl-icd nvidia-vdpau-driver nvidia-driver-libs nvidia-kernel-dkms libva2 vainfo libva-wayland2

@mlapaglia
Copy link

I can take a look. I am curious though could you just use Nvidia's native docker integration? I believe it can handle mounting the GPU and whatever drivers the host has inside the container for you: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html#driver-capabilities

For instance with Plex I simply put a --runtime=nvidia --NVIDIA_VISIBLE_DEVICES=all --NVIDIA_DRIVER_CAPABILITIES=all on the docker command for GPU transcoding to work. Plex doesn't have to download or install any drivers, it's provided for it.

@lastzero
Copy link
Member

Feel free to do some research on this! Does Plex use FFmpeg or does it have "native" encoders? This "Docker integration" looks like a separate Docker image to me, so we would have to change our entire build process to run PhotoPrism in it.

Note that PhotoPrism can (theoretically) use the GPU for video transcoding, Darktable, and TensorFlow. What happens if they all access the device at the same time? I have no idea, so I'd appreciate help from those who actively use this :)

@mlapaglia
Copy link

mlapaglia commented Aug 12, 2022

Ok, I removed everything from PHOTOPRISM_INIT, deleted the image and container from the host machine, then started the photoprism container using

docker run -d
-e 'NVIDIA_VISIBLE_DEVICES'='all'
-e 'NVIDIA_DRIVER_CAPABILITIES'='all'
-e 'PHOTOPRISM_FFMPEG_ENCODER'='nvidia'
--runtime=nvidia 
'photoprism/photoprism'

(non-relevant arguments removed for brevity)

After starting I was able to get ffmpeg to run inside the container without having to install any extra packages.

image
Notice the driver being used is 515.65.01, this driver and the nvidia libraries get passed in from what is installed on the host.

the transcode running inside the container:
command ffmpeg -y -hwaccel auto -i 20220527_171543_385F694A.mp4 -c:a copy -c:v hevc_nvenc output.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20220527_171543_385F694A.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 131072
    compatible_brands: isomiso2mp41
    creation_time   : 2022-05-27T17:15:43.000000Z
    com.android.capture.fps: 60.000000
  Duration: 00:00:09.12, start: 0.000000, bitrate: 72459 kb/s
  Stream #0:0[0x1](eng): Data: none (mett / 0x7474656D), 31 kb/s (default)
    Metadata:
      creation_time   : 2022-05-27T17:15:43.000000Z
      handler_name    : MetaHandle
  Stream #0:1[0x2](eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2022-05-27T17:15:43.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 3840x2160, 72359 kb/s, SAR 1:1 DAR 16:9, 59.77 fps, 59.94 tbr, 90k tbn (default)
    Metadata:
      creation_time   : 2022-05-27T17:15:43.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
    Side data:
      displaymatrix: rotation of -90.00 degrees
[h264 @ 0x55bfe56fcc80] Using auto hwaccel type cuda with new default device.
Stream mapping:
  Stream #0:2 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x55bfe5710480] track 1: codec frame size is not set
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 131072
    compatible_brands: isomiso2mp41
    com.android.capture.fps: 60.000000
    encoder         : Lavf59.16.100
  Stream #0:0(eng): Video: hevc (Main) (hev1 / 0x31766568), nv12(pc, bt470bg/bt470bg/smpte170m, progressive), 2160x3840 [SAR 1:1 DAR 9:16], q=2-31, 2000 kb/s, 59.94 fps, 60k tbn (default)
    Metadata:
      creation_time   : 2022-05-27T17:15:43.000000Z
      handler_name    : VideoHandle
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.18.100 hevc_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: N/A
      displaymatrix: rotation of -0.00 degrees
  Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2022-05-27T17:15:43.000000Z
      handler_name    : SoundHandle
      vendor_id       : [0][0][0][0]
frame=  331 fps=101 q=49.0 Lsize=    2033kB time=00:00:05.50 bitrate=3025.0kbits/s speed=1.68x

Also, I found some of my videos failing to transcode:

/usr/bin/ffmpeg -i /photoprism/originals/2022/04/20220410_005134_05813BF6.mp4 -pix_fmt yuv420p -c:v hevc_nvenc -c:a aac -preset 15 -pixel_format yuv420p -gpu any -vf format=yuv420p -rc:v constqp -cq 0 -tune 2 -r 30 -b:v 50M -profile:v 1 -coder:v 1 -f mp4 -y /photoprism/storage/sidecar/2022/04/20220410_005134_05813BF6.mp4.avc

resulted in

InitializeEncoder failed: invalid param (8): Invalid Level.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Once I remove the level argument it works. I found it still uses a LOT of CPU, when I add -hwaccel auto to the argument then it uses 100% of the GPU and transcodes over twice as fast.

@lastzero
Copy link
Member

From the NVIDIA documentation:

The toolkit includes a container runtime library and utilities to automatically configure containers to leverage NVIDIA GPUs.

So it seems that they have added a Docker "plugin" that automatically configures container images as needed. This is a (much) more advanced approach than the existing init script, e.g. they automatically detect the version, while our init script installs the default drivers. However, the toolkit must be installed and configured on the host (which maybe not everyone has?):

👉 https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html#adding-the-nvidia-runtime

@lastzero
Copy link
Member

If the CPU load is still very high, maybe something is missing....

  • are you sure you don't need to share your host's GPU device(s)?
  • or maybe there are permissions issues so that the device is visible but can't be used?
  • or FFmpeg needs additional libraries to work correctly with the GPU?

There's a reason we only offer hardware transcoding to our sponsors, because it eats up time like nothing else. That being said, make sure you enable sponsor features for it to work! 👍

@lastzero
Copy link
Member

I have added a follow up issue and hope someone can take care of it as our time will still be very limited over the next few months:

@lastzero lastzero added plus-feature Available to PhotoPrism+ Members and removed member-feature Available to members and contributors labels Feb 1, 2023
@graciousgrey graciousgrey removed the plus-feature Available to PhotoPrism+ Members label Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Feedback wanted / feature request released Available in the stable release video Video Formats, Transcoding, FFmpeg, Streaming & Co
Projects
Status: Release 🌈
Development

No branches or pull requests

7 participants