Project

General

Profile

Nvidia Scale using spawn profile

Added by Jack Jordan over 3 years ago

Hello,

I am using spawn profile with ffmpeg command line to decode and encode channel stream input using nvidia card, my feed is MPEG 1080P is there anyway to reduce video resolution to 720P or 540P, i am using h264_nvenc encoder and mpeg2_cuvid decoder in spawn profile, ffmpeg is configured with cuda and cuvid enabled along with libnpp but i am still unable to use -vf scale_npp or -vf scale_cuda to reduce video resolution. i also used resize command with no success

Any help please, i followed link https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/ to compile ffmpeg with requird libraries and codecs

ffmpeg version N-103078-gbc5faacc3f Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --enable-cuda --enable-cuvid --enable-nvdec --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 57. 2.100 / 57. 2.100
libavcodec 59. 3.102 / 59. 3.102
libavformat 59. 4.101 / 59. 4.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 1.103 / 8. 1.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
Hyper fast Audio and Video encoder


Replies (12)

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

Thank you for sharing the document, really nice presentation, i followed the steps in the scale_cuda and scale_npp but unfortunately did not work for me, attached is tvheadend log for both attempts

i used below ffmpeg lines (tried to keep it simple for testing scaling function)

/usr/bin/ffmpeg -y -vsync 0 -loglevel debug -hwaccel cuvid -c:v mpeg2_cuvid -i pipe:0 -vf scale_cuda=1280:720 -c:a copy -vcodec h264_nvenc -b:v 5M -f mpegts pipe:1

/usr/bin/ffmpeg -y -vsync 0 -loglevel debug -hwaccel cuvid -c:v mpeg2_cuvid -i pipe:0 -vf scale_npp=1280:720 -c:a copy -vcodec h264_nvenc -b:v 5M -f mpegts pipe:1

appreciate if you can check the logs and guide me where is my mistake,thanks in advance

RE: Nvidia Scale using spawn profile - Added by saen acro over 3 years ago

Get url of some channel with pass profile, and test in command line with input url from tvh and output

 -f mpegts udp://239.5.5.5:5555?pkt_size=188&localaddr=192.168.0.20

ip 192.168.0.20 is interface with client see streamer

use vlc to watch results

https://www.red5pro.com/docs/plugins/restreamer/mpeg-ts-ingest-plugin/

or test
this scenario
https://superuser.com/questions/1614417/how-to-split-and-scale-streams-in-ffmpeg-with-cuda

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

Thank you for your reply, i tried testing the output with the command you provided and was able to see the stream in vlc but unable to correlate this with the down scale using nvenc encoder with -vf scale_cuda or -vf scale_npp

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

I also noticed that adding -vf scale_cuda =1280:720 to ffmpeg in command line gives below error (no such filter invalid argument)

[aac 0x556b1236dc40] Using a PCE to encode channel layout "5.1(side)"
[AVFilterGraph
0x556b123cb100] No such filter: 'scale_cuda'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[aac 0x556b1236dc40] Qavg: 116.596
[aac
0x556b1236dc40] 2 frames left in the queue on closing
Conversion failed!

while using -vf scale_npp=1280:720 only sound is coming and video output gives green screen (attached for your reference)

scale_npp.png (836 KB) scale_npp.png -vf scale_npp vlc output

RE: Nvidia Scale using spawn profile - Added by saen acro over 3 years ago

what say

ffmpeg -h encoder=h264_nvenc

Ffmpeg -hwaccel cuvid -resize 1280x720 -i INPUT -c:a copy -c:v h264_nvenc -b:v 5M OUTPUT

https://github.com/philipl/nv-video-info

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

Dear, please find attached the output of encoder h264_nvenc and the error log when using -resize parameter with cuvid decoder, seems that - resize is not recognized and also i have some error related to memory allocation

encoder h264_nvenc output is attached for your reference
- resize error log is also attached

thanks a lot for all your help

(Resize (width)x(height)) specified for input file #0 has not been used
for any stream. The most likely reason is either wrong type (e.g. a video option
with no video streams) or that it is a private option of some decoder which was
not actually used for any stream.

[mpeg2video  0x561e5ba64cc0] No decoder surfaces left
Error while decoding stream #0:0: Cannot allocate memory
[mpeg2video
0x561e5ba64cc0] No decoder surfaces left
Error while decoding stream #0:0: Cannot allocate memory
[mpeg2video 0x561e5ba64cc0] No decoder surfaces left
Error while decoding stream #0:0: Cannot allocate memory
Impossible to convert between the formats supported by the filter 'Parsed_null_0
and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[aac
0x561e5bab3b40] Qavg: 114.072
[aac @ 0x561e5bab3b40] 2 frames left in the queue on closing
Conversion failed!

RE: Nvidia Scale using spawn profile - Added by saen acro over 3 years ago

No decoder surfaces left
reduce surfaces in all transcoding to 8 by default is 20
/read again https://tvheadend.org/boards/5/topics/45187/

Guessing problem is with poor options enabled in your ffmpeg binary

  --extra-cflags="-I/usr/local/cuda/include/" \
  --extra-ldflags="-L/usr/local/cuda/lib64/" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-shared  \
  --enable-nonfree \
  --enable-cuda \
  --enable-nvenc \
  --enable-opengl \
  --enable-libnpp \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265


https://superuser.com/questions/1444978/using-ffmpeg-with-nvidia-gpu/1456114

it's time to attach second GPU ;) Quadro K420 have boundaries.

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

Thank you for all your help, people like you make this domain even more interesting ,thanks

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

following your provided presentation file, I think somehow i manage to do GPU scale using below ffmpeg in command line

ffmpeg -vsync 0 -c:v mpeg2_cuvid -i http://addre -vf "hwupload_cuda,scale_npp=640:480,hwdownload,format=nv12" -c:a aac -b:a 160k -ar 44100 -c:v h264_nvenc -b:v 1M -f mpegts udp://addre

it works!!

however tvheadend stream profile did not work when adding the same

/usr/bin/ffmpeg -vsync 0 -loglevel debug -c:v mpeg2_cuvid -i pipe:0 -vf "hwupload_cuda,scale_npp=640:480,hwdownload,format=nv12" -c:a aac -b:a 160k -ar 44100 -c:v h264_nvenc -b:v 1M -f mpegts pipe:1

I am getting below same error message :-( in tvheadend stream profile

spawn: Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0

I started thinking the issue could be in tvheadend build (my version is HTS Tvheadend 4.3-1967~geb59284b8)

Thank you

RE: Nvidia Scale using spawn profile - Added by Jack Jordan over 3 years ago

Finally, i reconfigured ffmpeg with the libraries you provided and it works with below command in tvheadend

/usr/bin/ffmpeg -y -hwaccel cuvid -c:v mpeg2_cuvid -resize 640x480 -i pipe:0 -c:a aac -ac 2 -ar 44100 -b:a 128k -c:v h264_nvenc -b:v 700k -f mpegts pipe:1

still -vf sacle_npp and scale_cuda are not working in tvheadend, but i do not care at least it is now working with mpeg2_cuvid decoder BIG THANK YOU

RE: Nvidia Scale using spawn profile - Added by saen acro over 3 years ago

Install Cuda it include also video driver, maby some libraries missing
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu

With this command line expect some artifacts on output when there is more motion.
always set framerate and surfaces

lot of time ago there was so many web sites with with can generate command line for FFPEG now thera are few of them but limited
http://www.mackinger.at/ffmpeg/

ffmpeg -i INPUT -c:v libx264 -b:v 4M -minrate 2M -preset ultrafast -vf scale=640:-1 -c:a aac -b:a 64K _converted.mp4

now no one work on them :(

p.s.
try now in place of FFMPEG to use GStreamer commandline is different but who knows
https://developer.download.nvidia.com/embedded/L4T/r32_Release_v1.0/Docs/Accelerated_GStreamer_User_Guide.pdf
http://lifestyletransfer.com/how-to-install-nvidia-gstreamer-plugins-nvenc-nvdec-on-ubuntu/

next
https://github.com/rigaya/NVEnc


https://github.com/markus-perl/ffmpeg-build-script
ffmpeg build script with all extras :) , without AMF :(

    (1-12/12)