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

Nvidia GPU features not working #79

Open
izevar opened this issue Oct 31, 2020 · 59 comments
Open

Nvidia GPU features not working #79

izevar opened this issue Oct 31, 2020 · 59 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@izevar
Copy link

izevar commented Oct 31, 2020

Hello
Seem that all GPU related features are not working:
GPU decoding
GPU encoding
Object detection

There is any extra step needed to enable it ?

@ispysoftware
Copy link
Collaborator

you might need to get an ffmpeg build with GPU enabled or install a video codec SDK. The GPU stuff is only tested on Windows.
Something like:
https://hub.docker.com/r/willprice/nvidia-ffmpeg/
Note that RAW recording will always be faster than GPU encode if you are using IP cameras as there is basically no encode step.

@doitandbedone
Copy link
Owner

@izevar did you try the above steps? Did they work? Could you please give us an update? Thank you!

@doitandbedone doitandbedone added bug Something isn't working help wanted Extra attention is needed labels Nov 4, 2020
@stripeyhorse
Copy link

im not having any performance issues , but is intel quicksync supported under docker.

btw im using raw and having no issues at all. just trying to make sure it uses as little resources as possible.

@ispysoftware
Copy link
Collaborator

ispysoftware commented Nov 10, 2020 via email

@ispysoftware
Copy link
Collaborator

@doitandbedone test version here for linux h264 support
https://ispyrtcdata.blob.core.windows.net/downloads/Agent_Linux64_H264.zip
see server settings and you can set the Codec to H264 on the General tab. Then set the encoder on the recording tab on the camera to use quicksync and if the drivers are installed properly it should use them. See the logs for messages. Specifically on Agent startup if quicksync is going to work there should be a message about it under
"Hardware Support"

@doitandbedone
Copy link
Owner

doitandbedone commented Nov 13, 2020 via email

Repository owner deleted a comment from izevar Nov 13, 2020
@doitandbedone
Copy link
Owner

Sorry for the delay, been having issues lately with the sever, spent the last few days to put it back up and not lose any of my data phew. So back to almost normal but still need to do a few other things. If everything goes well I should be able to run a test tomorrow. I really appreciate all the help and effort you're putting into this!

@oriol73
Copy link

oriol73 commented Nov 17, 2020

Hi there,
I'm running a server with Ubuntu 20.04, Docker 19.03.13, with your AgentDVR container. I've been trying to enable GPU decoding/encoding as well to reduce CPU workload. 5x IP cameras (four RSTP streams at 1080p, one at 720p bring my cpu above 60%). I have one Nvidia Geforce GT710 with nvidia-driver-455.38 installed, nvidia-docker2, docker nvidia/cuda 11.1 , nvtop. All up and running.

If I log into the container via shell and retry dotnet /agent/Agent.dll, I get an ffmpeg output like this:

Init FFmpeg
ffmpeg path: /usr/lib/x86_64-linux-gnu
Error: Unable to load DLL 'avutil.56': The specified module could not be found.
Error: at FFmpeg.AutoGen.ffmpeg.LoadLibrary(String libraryName, Boolean throwException)
at FFmpeg.AutoGen.ffmpeg.<>c.<.cctor>b__6_0(String libraryName)
at FFmpeg.AutoGen.ffmpeg.<>c.<.cctor>b__6_604(Int32 level)
at FFmpeg.AutoGen.ffmpeg.av_log_set_level(Int32 level)
at CoreLogic.FFmpeg.SetFfmpegLogging(Int32 loglevel)
at CoreLogic.FFmpeg.Init()
at CoreLogic.Threads.StartUp()
Unable to load DLL 'avutil.56': The specified module could not be found.
Install FFMPEG (v4) using the terminal. See the download page on ispyconnect.com for instructions.
Killed

I can run some tests for you on my server if this helps us speed up the resolution.

Best regards,
oriol

@ispysoftware
Copy link
Collaborator

ispysoftware commented Nov 18, 2020

you need to use a build of ffmpeg that has the libraries instead of the static binaries - agent uses the libraries like avutil.56 not the ffmpeg binary file.

also to decode using the gpu you need to select GPU on the decoder options under the video source settings.. and you'd need to use the build of agent that i uploaded up there ^^ somewhere

@doitandbedone
Copy link
Owner

doitandbedone commented Nov 18, 2020

Yes, that's where I left off as well. Seems the recommended ffmpeg repo has other libraries included. I was using the logs to try and install all the ones it complained about and use the compilation flags for it too. Still a work in progress though. The build is posted in an earlier comment, you will have to modify the current Dockerfile to make use of the new build however. Once the version is ready I'll make it available more publicly.

@ispysoftware
Copy link
Collaborator

ispysoftware commented Nov 18, 2020

Do you have it working? It works fine on Windows so in theory should be OK on Docker. As long as the ffmpeg parts are there

@doitandbedone
Copy link
Owner

Not yet, ffmpeg is proving to be the most challenging part so far, but then again, haven't been able to get back to it, there's two branches I created if you want to take a look.

@ispysoftware
Copy link
Collaborator

I'm not 100% certain you need to rebuild it. If it can save to mp4 using the h264 codec then it should be able to use the gpu if the codecs are available

@doitandbedone
Copy link
Owner

So I finally had to time to run it, ran into a few issues (dirvers/cuda version) but all resolved, however, it still prefers software. I do see a warning:
�[37m�[40mWarning: h264 compatible version of ffmpeg must be installed to use H264 encoding
Do I need another version, or is this just a friendly warning?

And a few errors/warnings:

�[37m�[40mParking: Failed to create specified HW device.

�[32m�[40m[h264 @ 0x14c03403ba40] A hardware frames or device context is required for hardware accelerated decoding.
�[32m�[40m[h264 @ 0x14c03403ba40] Failed setup for format vaapi_vld: hwaccel initialisation returned error.

�[37m�[40mParking: Failed to create specified HW device.

�[32m�[40m[h264 @ 0x14c03403ba40] A hardware frames or device context is required for hardware accelerated decoding.
�[32m�[40m[h264 @ 0x14c03403ba40] Failed setup for format vaapi_vld: hwaccel initialisation returned error.

I followed setup as instructed:

  • Set server settings to Codec H264/MP4/MP3
    Screen Shot 2020-11-22 at 9 50 03 PM
  • Set Recording to quicksync
    Screen Shot 2020-11-22 at 9 50 21 PM
    Additionally, I tried going into Video Source (camera settings) and change Decoder to GPU (used FFMPEG as well), but no luck on either.
    Screen Shot 2020-11-22 at 9 51 25 PM
    Screen Shot 2020-11-22 at 9 51 32 PM

Full logs:
nvidia-docker-ispy-error.zip

@ispysoftware
Copy link
Collaborator

ispysoftware commented Nov 23, 2020 via email

@doitandbedone
Copy link
Owner

Woah, after enabling more logs it goes haywire, it gets so overwhelming it starts to freeze the server...

Anyhow, had to kill the container and collect logs afterwards. The container also seems to stay fine, so got the logs from it as well. They seem to be truncated given the huge amount of data.
Hope it helps:
ffmpeg-loglevel-48.zip

@ispysoftware
Copy link
Collaborator

It's missing the connection logs where it complains about creating the hardware context. Stop the camera, make sure its all set up to use the gpu, start it and stop it and then save off the logs.

@ispysoftware
Copy link
Collaborator

ispysoftware commented Nov 25, 2020

GPU support isn't available on docker on windows, which is my dev environment :(
https://www.edureka.co/community/19378/is-gpu-pass-through-possible-with-docker-for-windows

With docker on linux it seems you have to forward the device to the container for it to be able to access it like:
jellyfin/jellyfin#2281 (comment)
specifically calling docker with:
--device /dev/dri:/dev/dri \

also
https://stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 3, 2020

Yes, I'm using the special nvidia cuda container:
https://github.com/NVIDIA/nvidia-docker
And I am passing the GPU over, I can actually see it in the container when running nvidia-smi:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.59 Driver Version: 440.59 CUDA Version: 10.2
| 0 GeForce GTX 750 Ti
+-------------------------------+----------------------+----------------------+

One thing I noticed however, seems the ffmpeg does not have cuda enabled:
Hardware acceleration methods: vdpau vaapi drm opencl

I noticed since I tried using the available libx264:
#> ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i 11_TimeLapse_2020-12-03_07-04-43.mp4 -c:a copy -c:v libx264 -b:v 5M output.mp4 Device creation failed: -12. [h264 @ 0x5636e258bd80] No device available for decoder: device type cuda needed for codec h264.

Output:
Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Device setup failed for decoder on input stream #0:0 : Cannot allocate memory

Perhaps ffmpeg needs to be rebuild to enable cuda acceleration?

@ispysoftware
Copy link
Collaborator

ispysoftware commented Dec 4, 2020 via email

@ispysoftware
Copy link
Collaborator

here's an updated version - use this and set the recorder mode to GPU and the codec in settings to h264
https://ispyrtcdata.blob.core.windows.net/downloads/Agent_Linux64.zip
Should have hardware decode and encode using vaapi. Any probs check the logs.

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 4, 2020

Wow, you beat me to it.. I'll try it, give me a few mins.
I did managed to recompile ffmpeg but with minimal codecs. I tried using Jonathon's PPA as a base for all the libraries it installs. I then tried to get ffmpeg 4.3.1 source and recompile with old + new config flags but ffmpeg configure cannot find the reference to the libraries it had installed even though they are there. Anyhow, let me see...

@doitandbedone
Copy link
Owner

Did you take any extra steps to get it working? Seems it's not using the GPU, however, I turn everything off and rebooted to see starting logs, I see this:

[37m�[40mffmpeg path: /usr/lib/x86_64-linux-gnu
�[37m�[40mInitializing devices
�[37m�[40mHardware Decoders:
�[37m�[40mvdpau
�[37m�[40mvaapi
�[37m�[40mdrm
�[37m�[40mopencl
�[37m�[40mCUDA not available
�[37m�[40mcall ffplay -nodisp -f v4l2 -list_formats all /dev/video0
�[37m�[40m[video4linux2,v4l2 @ 0x14d760000b80] cannot open video device /dev/video0: no such file or directory

I tried a standalone command:
ffmpeg -hwaccel vdpau -i /agent/Media/WebServerRoot/Media/video/Mazda\ Parking/13_2020-11-22_21-08-50_542.mp4 /agent/Media/WebServerRoot/Media/output.mp4

Output:

[AVHWDeviceContext @ 0x5594cf789880] Cannot open the X11 display .
Device creation failed: -1313558101.
[h264 @ 0x5594cf6942c0] No device available for decoder: device type vdpau needed for codec h264.
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Device setup failed for decoder on input stream #0:0 : Unknown error occurred

I'm thinking compatibility issues with the card? Or somehow missing something that is not letting the card be seen? I do get a good output with nvidia-smi thoug,h as shown before.

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 4, 2020

So I went back to your comment earlier on passing the devices. I guess internally it's looking for
/dev/video0 ... /dev/video<n>
So then I found this:
https://stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container
Recommends to use the following to get your device list:
ls -la /dev | grep nvidia
Then forward it:
--device /dev/<host-device>:/dev/<container-device>
Mine spits out:

crw-rw-rw- 1 root root 195, 254 Dec 2 12:05 nvidia-modeset
crw-rw-rw- 1 root root 244, 0 Dec 2 12:05 nvidia-uvm
crw-rw-rw- 1 root root 244, 1 Dec 2 12:05 nvidia-uvm-tools
crw-rw-rw- 1 root root 195, 0 Dec 2 11:37 nvidia0
crw-rw-rw- 1 root root 195, 255 Dec 2 11:37 nvidiactl

I then tried --device /dev/nvidia0:/dev/video0
And the logs now don't spit out the error:

�[37m�[40mcall ffplay -nodisp -f v4l2 -list_formats all /dev/video0
�[37m�[40m[video4linux2,v4l2 @ 0x14fb88000b80] ioctl(vidioc_querycap): invalid argument
�[37m�[40mcall ffplay -nodisp -f v4l2 -list_formats all /dev/video1
�[37m�[40m[video4linux2,v4l2 @ 0x14ce40000b80] cannot open video device /dev/video1: no such file or directory

But as you may have noticed, it then goes onto /dev/video1. Not too sure about that "invalid argument" though.
How should devices be forwarded? Not too sure how to correlate them, what do you recommend?

P.S.: Do note that the devices are being forwarded by nvidia onto the container without the need of --device, the print was in fact from inside the container (and it prints the same on the host machine), they are just referenced differently within agent's commands/libs.

@doitandbedone doitandbedone changed the title GPU features not working Nvidia GPU features not working Dec 4, 2020
@ispysoftware
Copy link
Collaborator

i've been concentrating on getting it working on linux, should work on docker as long as the devices are forwarded into the container.

maybe this will help:
#100 (comment)

@doitandbedone
Copy link
Owner

Right, I mean at the end of the day docker container is running ubuntu 18.04. The question again is what the devices ffplay is expecting in what order. The nvidia runtime forwards with the naming printed above. But ffplay seems to be using /dev0, /dev1 not too sure what those are supposed to be mapped to. nvidia-uvm, nvidia-actl, nvidia-0, etc

@ispysoftware
Copy link
Collaborator

@rb2k would you be able to help us out here how you got the gpu working under docker?

@rb2k
Copy link

rb2k commented Dec 6, 2020

The mesa-va-drivers will just help with open source drivers (intel, amd).
I don't have any Nvidia cards myself, but I've seen other containers having to do a whole song and dance:

https://github.com/blakeblackshear/frigate/blob/master/docker/Dockerfile.amd64nvidia#L17-L47

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 6, 2020

Oh yup... I know all about it. But it essentially comes down to installing drivers on your host machine and either using the nvidia runtime for any base image or the cuda base image that comes with the included runtime. From there there's the --runtime nvidia flag and the environment variables to expose the GPU and its capabilities. All done and check working.
In fact I have this working on other containers. As a side note, you can only pass the GPU to one container or VM otherwise you get into funky town. But for this case I stopped other constiners VMs before trying.
In ispy's case, we are not using CUDA which is what usually the environment is installed. Since we are using VAAPI I'm not too sure but from the website it states that either generic drivers must be installed or the ones from nvidia. Just hit a roadblock...

@ispysoftware
Copy link
Collaborator

Vaapi is a wrapper.. It should work with cuda. The message about cuda not available in the logs is from opencv saying it wasn't built with cuda support (because that adds about 300mb to the size of it).

@doitandbedone
Copy link
Owner

Right, that's why I was looking on the ffmpeg side but needs to be rebuilt to add support for it. Vaapi still uses Cuda under the hood? I thought it was just an alternative and cuda wasn't needed.

@ispysoftware
Copy link
Collaborator

I'm not sure about that, I guess so, when I run it on windows it lists CUDA as an option but that is using a different build of ffmpeg.
I don't think the build of ffmpeg is the issue though as it's (vaapi) working fine on my linux box for decode and encode (not under docker but with all the same libraries)

Screenshot from 2020-12-07 06-13-31

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 6, 2020 via email

@ispysoftware
Copy link
Collaborator

ispysoftware commented Dec 6, 2020 via email

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 7, 2020 via email

@ispysoftware
Copy link
Collaborator

whats the console output from start to decode/ encode with GPU enabled?

@ispysoftware
Copy link
Collaborator

apt install mesa-va-drivers
should be added to the docker file though right for it to work with gpu under other devices

@doitandbedone
Copy link
Owner

doitandbedone commented Dec 7, 2020 via email

@oriol73
Copy link

oriol73 commented Jan 10, 2021

Hey guys, happy New Year! any update on this? Thanks

@doitandbedone
Copy link
Owner

@oriol73 Sorry for the late reply and Happy New Year as well! Unfortunately, no advances have been done on this. But will post any developments in this topic as soon as we find them. For the time being, we still recommend using raw for fastest results.

@thomasleitner
Copy link

Hi guys, I’m also wondering if there’s any update on this ?
Thanks!

@ispysoftware
Copy link
Collaborator

@doitandbedone bearing in mind i know next to nothing about docker, there's a deploy command in this example that seems to give deepstack access to the gpu, is this something that could be used to open up the gpu to agent in docker?

#197

@doitandbedone
Copy link
Owner

doitandbedone commented Mar 25, 2021 via email

@ispysoftware
Copy link
Collaborator

there is this
https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/
just need to get it building in shared library mode instead

@oriol73
Copy link

oriol73 commented Mar 29, 2021

@doitandbedone there's a docker container with ffmpeg already compiled with nvidia libraries here:

example:
docker run --runtime=nvidia jrottenberg/ffmpeg:4.1-nvidia -hwaccel cuvid -c:v h264_cuvid -i INPUT -vf scale_npp=-1:720 -c:v h264_nvenc -preset slow OUTPUT

You can leave this container up and running with:
docker run --runtime=nvidia -it --entrypoint='bash' jrottenberg/ffmpeg:4.1-nvidia

and then ffmpeg binaries/libraries could be shared/cloned from ffmpeg container to agentdvr container....then adding the right PATH env, and start using them.

Would this help?

@doitandbedone
Copy link
Owner

doitandbedone commented Mar 29, 2021 via email

@oriol73
Copy link

oriol73 commented Apr 4, 2021

@doitandbedone I've read on iSpy release notes that for Linux installation it's required an ffmeg distribution, required from specific PPAs: jonathonf/ffmpeg-4 or savoury1/ffmpeg4 .

Checking savoury1/ffmpeg4 PPA description here https://launchpad.net/~savoury1/+archive/ubuntu/ffmpeg4 , seems that this is already compiled with nvidia hardware support:

* nVidia display hardware: FFmpeg at this PPA is built with nv-codec-headers allowing hardware-accelerated video encoding and decoding using recent enough nVidia GPUs. The version of nv-codec-headers used (9.1.23) requires at least version 435.21 or newer of the nVidia proprietary display drivers. For newer nVidia drivers than official Ubuntu repos see the Ubuntu "Graphics Drivers" team PPA here: https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
*

Have you considered to configure your dockerfile with savoury1/ffmpeg4 PPA instead of jonathonf/ffmpeg-4 ? Furthermore, if this works well, you won't need a different tag for nvidia setup, having one single version of the container as this PPA seems verified by iSPY.

@doitandbedone
Copy link
Owner

@oriol73 I had actually already looked into this. There's a branch called feature/simple-ffmpeg-nvidia. Back then it still didn't work, but there's been multiple updates. You can check it out. At the moment I'm swamped but as soon as I get a chance I can revisit it.

@theaccountforjake
Copy link

theaccountforjake commented Apr 15, 2021

I think I was able to get a container that uses hardware accelerated video decoding. I'll paste my Dockerfile below, but the highlights are:

  1. Built from a a .net docker image based on Debian 10 instead of Ubuntu 18.04, because this allows
  2. Installation of ffmpeg from the deb-multimedia repository

The deb-multimedia version of ffmpeg seems to fit the bill. It has various Nvidia hardware acceleration features enabled, and it's not built statically so it contains the required libraries.

Now when I run my custom Docker container, I see in the log:

Using hardware decoder: AV_HWDEVICE_TYPE_CUDA

And I also see an entry in nvidia-smi, showing that dotnet is using 67MiB on the GPU. However, CPU usage still seems to be higher than I would've thought, so I'm not sure everything is working correctly.

Anyway, the Dockerfile I used is:

# Use MS maintained .net docker image wuith aspnet and core runtimes.
FROM mcr.microsoft.com/dotnet/aspnet:3.1

#Define download location variables
ARG FILE_LOCATION="https://ispyfiles.azureedge.net/downloads/Agent_Linux64_3_2_7_0.zip"
ENV FILE_LOCATION_SET=${FILE_LOCATION:+true}
ENV DEFAULT_FILE_LOCATION="https://www.ispyconnect.com/api/Agent/DownloadLocation2?productID=24&is64=true&platform=Linux"
ARG DEBIAN_FRONTEND=noninteractive 
ARG TZ=America/Los_Angeles
    

# Download and install dependencies
RUN apt-get update \
    && apt-get install -y wget libtbb-dev libc6-dev unzip multiarch-support gss-ntlmssp software-properties-common \
    && wget http://security.ubuntu.com/ubuntu/pool/main/libj/libjpeg-turbo/libjpeg-turbo8_1.5.2-0ubuntu5.18.04.4_amd64.deb \
    && wget http://fr.archive.ubuntu.com/ubuntu/pool/main/libj/libjpeg8-empty/libjpeg8_8c-2ubuntu8_amd64.deb \
    && dpkg -i libjpeg-turbo8_1.5.2-0ubuntu5.18.04.4_amd64.deb \
    && dpkg -i libjpeg8_8c-2ubuntu8_amd64.deb \
    && rm libjpeg8_8c-2ubuntu8_amd64.deb \
    && rm libjpeg-turbo8_1.5.2-0ubuntu5.18.04.4_amd64.deb

# Install deb-multimedia ffmpeg
RUN apt-get update
RUN echo "deb http://www.deb-multimedia.org buster main non-free" >> /etc/apt/sources.list
RUN apt-get update -oAcquire::AllowInsecureRepositories=true -y --force-yes
RUN apt-get install deb-multimedia-keyring -y --force-yes
RUN apt-get update
RUN apt-get install ffmpeg -y --force-yes

# Download/Install iSpy Agent DVR: 
# Check if we were given a specific version
RUN if [ "${FILE_LOCATION_SET}" = "true" ]; then \
    echo "Downloading from specific location: ${FILE_LOCATION}" && \
    wget -c ${FILE_LOCATION} -O agent.zip; \
    else \
    #Get latest instead
    echo "Downloading latest" && \
    wget -c $(wget -qO- "https://www.ispyconnect.com/api/Agent/DownloadLocation2?productID=24&is64=true&platform=Linux" | tr -d '"') -O agent.zip; \
    fi && \
    unzip agent.zip -d /agent && \
    rm agent.zip
    
# Install libgdiplus, used for smart detection
RUN apt-get install -y libgdiplus
    
# Install Time Zone
RUN apt-get install -y tzdata

# Clean up
RUN apt-get -y --purge remove unzip wget \ 
    && apt autoremove -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Docker needs to run a TURN server to get webrtc traffic to and from it over forwarded ports from the host
# These are the default ports. If the ports below are modified here you'll also need to set the ports in XML/Config.xml
# for example <TurnServerPort>3478</TurnServerPort><TurnServerMinPort>50000</TurnServerMinPort><TurnServerMaxPort>50010</TurnServerMaxPort>
# The main server port is overridden by creating a text file called port.txt in the root directory containing the port number, eg: 8090
# To access the UI you must use the local IP address of the host, NOT localhost - for example http://192.168.1.12:8090/

# Define default environment variables
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Main UI port
EXPOSE 8090

# TURN server port
EXPOSE 3478/udp

# TURN server UDP port range
EXPOSE 50000-50010/udp

# Data volumes
VOLUME ["/agent/Media/XML", "/agent/Media/WebServerRoot/Media", "/agent/Commands"]

# Define service entrypoint
CMD ["dotnet", "/agent/Agent.dll"]

@doitandbedone
Copy link
Owner

@theaccountforjake Do appreciate all the work, however, I'm afraid I can't use a non-free and also experimental/unofficial repo. Will keep looking for alternatives however.

@theaccountforjake
Copy link

@doitandbedone That's a good point. Does usage of CUDA or other HW acceleration require the --enable-nonfree option in ffmpeg? I honestly don't know if it does, but I think suspect it does, and I think, in general, ffmpeg binaries built with the option aren't redistributable.

Nvidia's instructions for building (https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/) use the non-free option, unfortunately.

@doitandbedone
Copy link
Owner

Still a little bit of a grey area for me as well, since this is for ffmpeg. The repo didn't have much details to be honest. As for nvidia, last I found out was that it's open source (free) vs closed source (nvivida nonfree). These are available for everyone but not sure if there's any other licensing caveats in there, didn't find any. Once you get to the codecs there's some very tricky licensing schemes. This is why I went to use their CUDA images and that makes it work, but then ffmpeg became the issue.

@autumnwalker
Copy link

Check in on this - any update? I'm super interested in GPU support in the Docker, but unclear how I can assist.

@doitandbedone doitandbedone added enhancement New feature or request and removed bug Something isn't working labels Sep 12, 2022
@scornflake
Copy link

For those interested, here's a Dockerfile I put together for Ubuntu 22.04.
I've commented it where I made changes. It was based upon the Dockerfile of this repo (doitandbedone)

You need to have your docker setup for nvidia as per: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

# Use Ubuntu LTS
#FROM ubuntu:22.04

# NOTE: Using a dev image containing all the required cuda stuff.
# IMPORTANT: The version (in this case 12.0.0) must be compatible with what's loaded on the bare metal.
FROM nvidia/cuda:12.0.0-devel-ubuntu22.04

# Define download location variables

ARG FILE_LOCATION="https://ispyfiles.azureedge.net/downloads/Agent_Linux64_4_9_6_0.zip"


ENV FILE_LOCATION_SET=${FILE_LOCATION:+true}
ENV DEFAULT_FILE_LOCATION="https://www.ispyconnect.com/api/Agent/DownloadLocation4?platform=Linux64&fromVersion=0"
ARG DEBIAN_FRONTEND=noninteractive 
ARG TZ=America/Los_Angeles
ARG name
    

# Download and install dependencies
RUN apt-get update \
    && apt-get install -y wget unzip software-properties-common alsa-utils

# Note: to install ffmpeg; you need the nv-codec-headers
# ffnvcodec
RUN apt-get install -y git make
RUN git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
RUN cd nv-codec-headers && make install && cd ..

# Download/Install iSpy Agent DVR: 
# Check if we were given a specific version
RUN if [ "${FILE_LOCATION_SET}" = "true" ]; then \
    echo "Downloading from specific location: ${FILE_LOCATION}" && \
    wget -c ${FILE_LOCATION} -O agent.zip; \
    else \
    #Get latest instead
    echo "Downloading latest" && \
    wget -c $(wget -qO- "https://www.ispyconnect.com/api/Agent/DownloadLocation4?platform=Linux64&fromVersion=0" | tr -d '"') -O agent.zip; \
    fi && \
    unzip agent.zip -d /agent && \
    rm agent.zip
    
# Install libgdiplus, used for smart detection
RUN apt-get install -y libgdiplus 

# Install ffmpeg
# NOTE: Added unzip wget libnuma1 libnuma-dev as per https://docs.nvidia.com/video-technologies/video-codec-sdk/11.1/ffmpeg-with-nvidia-gpu/index.html
RUN apt-get install -y build-essential xz-utils yasm cmake libtool libc6 libc6-dev \
 pkg-config libx264-dev libx265-dev libmp3lame-dev libopus-dev \
 libvorbis-dev libfdk-aac-dev libvpx-dev libva-dev \
 unzip wget libnuma1 libnuma-dev

# NOTE: Use the 'wget' method if you want a specific version of ffmpeg.
#RUN wget https://ffmpeg.org/releases/ffmpeg-6.0.tar.gz &&\
#tar xf ffmpeg-6.0.tar.gz &&\
#cd ffmpeg-6.0 && \

# NOTE: Using a git clone here; because v6.0 of ffmpeg is broken with respect to  --enable-hardcoded-tables
# Does that matter? Dunno 
RUN git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ &&\
cd ffmpeg && \
./configure --disable-debug \
 --disable-doc \
 --enable-shared \
 --enable-pthreads \
 --enable-hwaccels \
 # Broken in ffmpeg6.0 (works ok if pulling current from git direct)
 --enable-hardcoded-tables \   
 --enable-vaapi \
 --enable-nonfree \
 --enable-cuda-nvcc \
 --enable-libnpp \
 --disable-static \
 --enable-gpl \
 --enable-libx264 \
 --enable-libmp3lame \
 --enable-libopus \
 --enable-libvorbis \
 --enable-libfdk-aac \
 --enable-libx265 \
 --enable-libvpx \
 --extra-cflags=-I/usr/local/cuda/include \
 --extra-ldflags=-L/usr/local/cuda/lib64 && \
 make -j 8 && \
 make install && \
 cd ..
    
# Install Time Zone
RUN apt-get install -y tzdata

# Install curl, used for calling external webservices in Commands
RUN apt-get install -y curl

# Clean up
RUN apt-get -y --purge remove unzip wget build-essential \ 
    && apt autoremove -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Docker needs to run a TURN server to get webrtc traffic to and from it over forwarded ports from the host
# These are the default ports. If the ports below are modified here you'll also need to set the ports in XML/Config.xml
# for example <TurnServerPort>3478</TurnServerPort><TurnServerMinPort>50000</TurnServerMinPort><TurnServerMaxPort>50010</TurnServerMaxPort>
# The main server port is overridden by creating a text file called port.txt in the root directory containing the port number, eg: 8090
# To access the UI you must use the local IP address of the host, NOT localhost - for example http://192.168.1.12:8090/

# Modify permission for execution
RUN echo "Adding executable permissions" && \
    chmod +x /agent/Agent && \
    chmod +x /agent/agent-register.sh && \
    chmod +x /agent/agent-reset.sh && \
    chmod +x /agent/agent-reset-local-login.sh

# Define default environment variables
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Fix a memory leak on encoded recording
ENV MALLOC_TRIM_THRESHOLD_=100000

# Make sure that all libraries are loaded into the container
ENV NVIDIA_DRIVER_CAPABILITIES=all

# Main UI port
EXPOSE 8090

# STUN server port
EXPOSE 3478/udp

# TURN server UDP port range
EXPOSE 50000-50010/udp

# Data volumes
VOLUME ["/agent/Media/XML", "/agent/Media/WebServerRoot/Media", "/agent/Commands"]

# Define service entrypoint
CMD ["/agent/Agent"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

10 participants