[FFmpeg-user] Using FFMpeg with Nvidia CUDA to crop and scale videos
SMF Forum 1
smf.forum1 at ntlworld.com
Wed Sep 11 13:49:40 EEST 2024
On Tue, 2024-09-10 at 18:21 +0200, Ferdi Scholten wrote:
> > My NVIDIA and FFMPEG configuration is as follows:
> > > > Linux TestBox1 6.8.0-41-generic #41-Ubuntu SMP PREEMPT_DYNAMIC
> > > > Fri
> > > > Aug
> > > > 2 20:41:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
> > > >
> > > > NVIDIA-Linux-x86_64-560.31.02
> > > >
> > > > ffmpeg version git-2024-08-19-507c2a577
> > > > encoders:
> > > > V....D av1_nvenc NVIDIA NVENC av1 encoder (codec
> > > > av1)
> > > > V....D h264_nvenc NVIDIA NVENC H.264 encoder (codec
> > > > h264)
> > > > V....D hevc_nvenc NVIDIA NVENC hevc encoder (codec
> > > > hevc)
> > > > decoders:
> > > > V..... av1_cuvid Nvidia CUVID AV1 decoder (codec
> > > > av1)
> > > > V..... h264_cuvid Nvidia CUVID H264 decoder (codec
> > > > h264)
> > > > V..... hevc_cuvid Nvidia CUVID HEVC decoder (codec
> > > > hevc)
> > > > V..... mjpeg_cuvid Nvidia CUVID MJPEG decoder (codec
> > > > mjpeg)
> > > > V..... mpeg1_cuvid Nvidia CUVID MPEG1VIDEO decoder
> > > > (codec
> > > > mpeg1video)
> > > > V..... mpeg2_cuvid Nvidia CUVID MPEG2VIDEO decoder
> > > > (codec
> > > > mpeg2video)
> > > > V..... mpeg4_cuvid Nvidia CUVID MPEG4 decoder (codec
> > > > mpeg4)
> > > > V..... vc1_cuvid Nvidia CUVID VC1 decoder (codec
> > > > vc1)
> > > > V..... vp8_cuvid Nvidia CUVID VP8 decoder (codec
> > > > vp8)
> > > > V..... vp9_cuvid Nvidia CUVID VP9 decoder (codec
> > > > vp9)
> > > > filters:
> > > > ... bilateral_cuda V->V GPU accelerated bilateral
> > > > filter
> > > > T.. bwdif_cuda V->V Deinterlace CUDA frames
> > > > ... chromakey_cuda V->V GPU accelerated chromakey
> > > > filter
> > > > ... colorspace_cuda V->V CUDA accelerated video color
> > > > converter
> > > > ..C crop V->V Crop the input video.
> > > > T.C cropdetect V->V Auto-detect crop size.
> > > > ... hwupload_cuda V->V Upload a system memory frame
> > > > to
> > > > a
> > > > CUDA device.
> > > > ... overlay_cuda VV->V Overlay one video on top of
> > > > another
> > > > using CUDA
> > > > ... scale_cuda V->V GPU accelerated video
> > > > resizer
> > > > ... scale_npp V->V NVIDIA Performance
> > > > Primitives
> > > > video
> > > > scaling and format conversion
> > > > ... scale2ref_npp VV->VV NVIDIA Performance
> > > > Primitives
> > > > video
> > > > scaling and format conversion to the given reference.
> > > > ... sharpen_npp V->V NVIDIA Performance
> > > > Primitives
> > > > video
> > > > sharpening filter.
> > > > ... thumbnail_cuda V->V Select the most
> > > > representative
> > > > frame
> > > > in a given sequence of consecutive frames.
> > > > ... transpose_npp V->V NVIDIA Performance
> > > > Primitives
> > > > video
> > > > transpose
> > > > T.. yadif_cuda V->V Deinterlace CUDA frames
> > > >
> > > > I would like to be able to use CUDA to crop and scale videos
> > > > but I
> > > > cannot find the correct syntax.
> > > > My efforts usually work in terms of the scale but not the crop,
> > > > here is
> > > > an example of the type of problems I have been having:
> > > >
> > > > The source file in this example is a short mpeg2 video (960x540
> > > > with
> > > > black bars top and bottom). The command is currently run from a
> > > > bash
> > > > script.
> > > >
> > > > ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -c:v
> > > > mpeg2_cuvid -
> > > > crop 960x408x0x66 -i $1 -vf scale_npp=1280x544 -c:a copy -c:v
> > > > h264_nvenc -b:v 2M -preset slow $2
> > > >
> > > > This is throwing the following error:
> > > >
> > > > [mpeg2_cuvid @ 0x5e6d9deb56c0] cuvid decode callback error
> > > > [vist#0:0/mpeg2video @ 0x5e6d9de85b40] [dec:mpeg2_cuvid @
> > > > 0x5e6d9de7b7c0] Decoding error: Generic error in an
> > > > external
> > > > library
> > > >
> > > > I have looked around the web but none of the solutions offered
> > > > have
> > > > worked for me.
> > > >
> > > > Do I have a problem with my ffmpeg build, should the list of
> > > > filters
> > > > include something like crop_cuda or crop_npp or have I just got
> > > > the
> > > > wrong syntax to perform everything on the GPU (is it even
> > > > possible).
> > > >
> > > > Thanks for any suggestions.
> > > >
> > Some suggestions
> >
> > -Specify exact type of your Nvidia card, support for cuda and/or
> > encode/decode is different or even absent, depending on card type
> > (even
> > within the same product range using the same GPU). For example, my
> > Pascal based Quadro P500 has no video encode/decode support at all.
> > -Check if you have "NVIDIA compute utilities" installed with the
> > same
> > version as your driver, as the error seems to suggest this is
> > missing
> > or
> > incomplete.
> > -We also need your full ffmpeg commandline and full uncut output of
> > that
> > commandline.
> > _______________________________________________
> > ffmpeg-user mailing list
> > ffmpeg-user at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
Thanks for the reply, herewith the information you requested:-
The Nvidia card.
NVIDIA GPU NVIDIA GeForce RTX 4060 (AD107-A) at PCI:11:0:0
NVIDIA compute utilities.
This was missing and I was using Driver Version 560.31.02 but this
currently does not have a supporting "NVIDIA compute utilities" from
ubuntu.
So I have downgraded to Driver Version: 550.107.02 CUDA Version: 12.4
and installed nvidia-compute-utils-550-server 550.90.07-
0ubuntu0.24.04.1.
This also resulted in a kernel update as a by product.
Linux TestBox1 6.8.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Tue Aug
13 13:35:26 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
I have also changed the test video clip for a more representative
sample of what I wish to do.
My test still fails to crop the video but the failure is less dramatic
with the "NVIDIA compute utilities" added :
ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -crop
1280x720x0x120 -i Trial.mov -vf scale_npp=1920:1080 -c:a copy -c:v
h264_nvenc -b:v 2M -preset slow /tmp/x.mkv
ffmpeg version git-2024-08-19-507c2a577 Copyright (c) 2000-2024 the
FFmpeg developers
built with gcc 13 (Ubuntu 13.2.0-23ubuntu4)
configuration: --prefix=/usr --enable-shared --enable-pthreads --
enable-gpl --enable-version3 --enable-postproc --enable-libxcb --
enable-nonfree --enable-libx264 --enable-libxvid --enable-libmp3lame --
enable-vdpau --enable-libfdk_aac --enable-libbluray --enable-libvpx --
enable-vaapi --enable-libass --enable-libtesseract --enable-libx265 --
disable-static --enable-opengl --enable-openssl --disable-debug --
enable-libvorbis --enable-libopus --enable-libtheora --enable-
libfreetype --enable-lto --enable-libdav1d --enable-cuda-nvcc --enable-
libnpp --enable-cuvid --enable-nvenc --enable-cuda --enable-nvdec --
enable-nonfree --enable-cuda-llvm --enable-ffplay --nvcc=nvcc
libavutil 59. 34.100 / 59. 34.100
libavcodec 61. 11.100 / 61. 11.100
libavformat 61. 5.101 / 61. 5.101
libavdevice 61. 2.100 / 61. 2.100
libavfilter 10. 2.102 / 10. 2.102
libswscale 8. 2.100 / 8. 2.100
libswresample 5. 2.100 / 5. 2.100
libpostproc 58. 2.100 / 58. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Trial.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
title : Trial
encoder : Lavf60.10.100
Duration: 00:01:00.00, start: 0.000000, bitrate: 2162 kb/s
Stream #0:0[0x1]: Video: mpeg2video (Main) (m2v1 / 0x3176326D),
yuv420p(tv, bt709, progressive), 1280x960 [SAR 1:1 DAR 4:3], 2027 kb/s,
30 fps, 30 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : FFMP
encoder : Lavc60.23.100 mpeg2video
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 573440 vbv_delay:
N/A
Stream #0:1[0x2]: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x5e39fa809580] Codec AVOption crop
(Crop (top)x(bottom)x(left)x(right)) 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.
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, matroska, to '/tmp/x.mkv':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
title : Trial
encoder : Lavf61.5.101
Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), cuda(tv, bt709,
progressive), 1920x1080 [SAR 3:4 DAR 4:3], q=2-31, 2000 kb/s, 30 fps,
1k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : FFMP
encoder : Lavc61.11.100 h264_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000
vbv_delay: N/A
Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz,
stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
[out#0/matroska @ 0x5e39fa810580] video:14761KiB audio:938KiB
subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead:
0.201574%
frame= 1800 fps=248 q=21.0 Lsize= 15730KiB time=00:00:59.90
bitrate=2151.3kbits/s speed=8.25x
More information about the ffmpeg-user
mailing list