datarhei / restreamer

The Restreamer is a complete streaming server solution for self-hosting. It has a visually appealing user interface and no ongoing license costs. Upload your live stream to YouTube, Twitch, Facebook, Vimeo, or other streaming solutions like Wowza. Receive video data from OBS and publish it with the RTMP and SRT server.
https://docs.datarhei.com/restreamer/
Apache License 2.0
3.78k stars 438 forks source link

CUDA Support for encoding rtsp stream and reduce buffering time #503

Open cruzcat01 opened 1 year ago

cruzcat01 commented 1 year ago

Hello, Firstly, I really appreciate all the work done to provide the restreamer service. I am running the latest cuda version of the restreamer docker container in Ubuntu 20.04 LTS I have an nvidia 1080Ti with cuda 11.7 and can confirm that the GPU is available within docker. sudo docker run -t --rm --gpus all ubuntu nvidia-smi returns a valid response and reports CUDA version 11.7.

However, I cannot get a valid stream with hardware encoding and using NVENC is always returning an error. I can only get a valid stream if I use passthrough. Here is the output from the log regarding the error;

@1674939332 ffmpeg version 5.1.2-datahrei Copyright (c) 2000-2022 the FFmpeg developers @1674939332 built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1) @1674939332 configuration: --extra-version=datahrei --prefix=/usr/local --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --enable-nonfree --enable-gpl --enable-version3 --enable-postproc --enable-static --enable-openssl --enable-libxml2 --enable-cuda --enable-cuvid --enable-nvenc --enable-libnpp --enable-libv4l2 --enable-libfreetype --enable-libsrt --enable-libx264 --enable-libx265 --enable-libvpx --enable-libmp3lame --enable-libopus --enable-libvorbis --disable-ffplay --disable-ffprobe --disable-debug --disable-doc @1674939332 libavutil 57. 28.100 / 57. 28.100 @1674939332 libavcodec 59. 37.100 / 59. 37.100 @1674939332 libavformat 59. 27.100 / 59. 27.100 @1674939332 libavdevice 59. 7.100 / 59. 7.100 @1674939332 libavfilter 8. 44.100 / 8. 44.100 @1674939332 libswscale 6. 7.100 / 6. 7.100 @1674939332 libswresample 4. 7.100 / 4. 7.100 @1674939332 libpostproc 56. 6.100 / 56. 6.100 @1674939335 Input #0, rtsp, from 'rtsp://192.168.1.199:554/stream1': @1674939335 Metadata: @1674939335 title : Session streamed by "nessyMediaServer" @1674939335 comment : h264 @1674939335 Duration: N/A, start: 0.000000, bitrate: N/A @1674939335 Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 2688x1944 [SAR 1:1 DAR 112:81], 10 fps, 25 tbr, 90k tbn @1674939335 Stream #0:1: Data: none @1674939335 Stream mapping: @1674939335 Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc)) @1674939335 Press [q] to stop, [?] for help @1674939338 [swscaler ] [swscaler @ 0x56353bbf5280] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c911a80] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c96c740] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c9c9ec0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353ca27640] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353bbf5280] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c90fb80] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353ca24800] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c96c5c0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c9c9d40] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c90 [restreamer-cuda-error.txt](https://github.com/datarhei/restreamer/files/10528359/restreamer-cuda-error.txt) 9fc0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353bb9b2c0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353ca24800] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c96c5c0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c9c9d40] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c909fc0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353bb9b2c0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353ca24800] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c96c5c0] deprecated pixel format used, make sure you did set range correctly @1674939338 [swscaler ] [swscaler @ 0x56353c9c9d40] deprecated pixel format used, make sure you did set range correctly @1674939338 [h264_nvenc @ 0x56353bb7f200] Cannot load libcuda.so.1 @1674939338 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 @1674939338 Conversion failed!

Are there any other settings that I need to enable to get GPU encoding with restreamer.

Tks for the help.

restreamer-cuda-error.txt

cruzcat01 commented 1 year ago

Hello, I managed to resolve the issue. The --runtime=nvidia as mentioned in the github instructions is deprecated. I updated the docker run command to use --gpus=all and and I am able to use NVENC as the decoder successfully.

One question I have is how to reduce the latency between liveview from RTSP stream and livestream from Restreamer. Are there any options that can be passed from the API for the POST /api/v3/process to reduce the buffering.

Tks.