Why this ffmpeg mp4/mkv/wmv/flv/avi to webm command line with cuda is as slow as with CPU? - ffmpeg

im playing with my video files, I want to convert them from mp4, mkv, wmv, avi, flv, mov... to webm.
So I have written this:
for file in *
do
if [ -f "$file" ]
then filename="${file%.*}"
../ffmpeg -hwaccel nvdec -hwaccel_device 0 -hwaccel_output_format cuda -i "$file" -c:v vp9 -b:v 0 -crf 31 -c:a libvorbis "$filename".webm
fi
done
As shown, I have compiler my own ffmpeg binary, with those options:
./configure --enable-gpl --enable-libx264 --enable-nonfree --enable-cuda-nvcc --enable-libvpx --enable-vaapi --enable-libvorbis --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
It works, but, with CPU I got speed 0,1x and with cuda... almost the same.
My CPU? 11th Gen Intel(R) Core(TM) i7-11800H
My GPU? GeForce RTX™ 3060 mobile
Filesize? 300-3000mb (same speed with any)
Is there anything I could do? (I also tried vp9_vaapi, getting
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Any clue? Or do I have to give up?
Thanks

Well, after some tests, the bests results were obtained using
-c:v libvpx-vp9 -cpu-used 8 -deadline realtime
speed increased from 0,05x to 1,12x slow, but, good enough.
Quality is good for me.

Related

How to use the hardware acceleration for ffmepg on m1-max?

Since there aren't m1 builds available from ffmpeg.org, I had to compile my own. Obviously, I'd like to get the best possible performance.
Does ffmpeg use the "Hardware-accelerated H.264" on the m1 max?
Is there anything I need to do, like compiler flags, to get it?
Any switch at run time?
How can I verify that it's being used?
To compile ffmpeg, I just did the basics:
./configure --prefix=/tmp/ff --enable-gpl --enable-nonfree --enable-libx264
make
make install
For x264, I just did
./configure --prefix=/tmp/ff
make
make install
to run:
ffmpeg -i random.wmv -c:v libx264 -preset ultrafast -c:a aac output-ultra.mp4
Anything else I should be doing?
It looks like what I wanted was videotoolbox
Usage is documented here, basically
To use H.264/HEVC hardware encoding in macOS, just use the encoder -c:v h264_videotoolbox
Example:
ffmpeg -i random.wmv -c:v h264_videotoolbox -c:a aac junk-vt.mp4
Seems to be slightly faster than "ultrafast" with software, and much smaller files.
H264_videotoolbox is useless on M1 Pro. I don't see that the GPU is working. I use the same file to transcode h264_videotoolbox can only play to a 6.x magnification and -vcodec h264 Use CPU magnification to reach 12.x
Ffmpeg 5.1.2 macos 13.1

ffmpeg hwaccel no decoder surfaces left

Recently I compiled natively the latest version of ffmpeg 4.3 on Windows 10 amd64.
Evironment:CUDA11.0, NASM, VS2019, MYSY2 with mingw64.
I also used the patch https://trac.ffmpeg.org/attachment/ticket/9019/0001-Patch-for-ticket-9019-CUDA-Compile-Broken-Using-MSVC.patch
Compile featrues were:
--enable-nonfree --enable-cuda-nvcc --enable-libnpp --enable-gpl --enable-libx264 --enable-cuda-llvm --enable-nvenc
--toolchain=msvc --extra-cflags=-I../nv_sdk --extra-ldflags=-libpath:../nv_sdk
I tested ffmpeg for cuda acceleration. the CPU is an AMD 3500x. the GPU is an RTX 2060Ultra.
Issuing this command:
.\ffmpeg -hwaccel cuvid -i .\a.wmv -c:v hevc_nvenc -bf 4 -preset slow -c:a aac -b:a 256k myvideo.mp4
But recieved this error:
[wmv3 # 000002632DFC5180] No decoder surfaces left
Error while decoding stream #0:0: Cannot allocate memory
[hevc_nvenc # 00000263300B1740] Failed locking bitstream buffer: out of memory (10):
video encoding failed: Cannot allocate memory
I'm not sure where I've gone wrong here.
Try adding -extra_hw_frames N to your input and increase N until the error ceases. I just needed 8 myself.
I encountered this same problem on version 4.4 as well. This was reported against 4.1 but only on some cases. Someone suggested the -extra_hw_frames N workaround on https://trac.ffmpeg.org/ticket/7562 and it worked for me.
I also had the same problem as OP and followed the user's "Moby Disk" advice to use "-extra_hw_frames N"
Here is what I used which worked for me:
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -extra_hw_frames 8 -i video_sample.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4
The GPU I have is:
MSI Nvidia GeForce GT 710 2GB 2GD3
setting the output format to auto working for me. the -extra_hw_frames cause a initialisation error (but do convert the video)
ffmpeg -hwaccel cuda -hwaccel_output_format auto

NVIDIA accelerated ffmpeg (nvenc_h264 ) is dead slow on Amazon G2 instance

FFMPEG when compiled with following options give abysmal performance on Amazon G2 instance( g2.2xlarge, GRID K520) when compared with standalone Dell-Precision-T1700 (Quadro-k620)
"--enable-nonfree --enable-gpl --enable-version3 --enable-shared --enable pthreads [b]--enable-nvenc[/b] --enable-runtime-cpudetect --disable-doc --enable-libmp3lame"
Above ffmpeg binary took 66 seconds to transcode 5.22 mins BVE_Localize.mp4 file with following command.
time ffmpeg -y -i BVE_Localize.mp4 -strict -2 -vcodec nvenc_h264 -b 5000k -acodec aac -ab 256k -f mpegts BVELocalize.ts ( took 1m6.990s on G2)
When same ffmpeg command is executed on Dell-Precision-T1700 (Xeon Dual core, Quadro K620) based workstation takes 0m41.572s.
I would like ffmpeg to perform better on Amazon G2 instance. What do you think I might be missing? My Amazon G2 instance configuration is Ubuntu 14.04 64 bit, Cuda 7.0 , 352.55 drivers, MSI disabled,NVIDIA SDK 5.0.1

transcode and segment with ffmpeg

It appears that ffmpeg now has a segmenter in it, or at least there is a command line option
-f segment
in the documentation.
Does this mean I can use ffmpeg to realtime-transcode a video into h.264 and deliver segmented IOS compatible .m3u8 streams using ffmpeg alone? if so, what would a command to transcode an arbitrary video file to a segmented h.264 aac 640 x 480 stream ios compatible stream?
Absolutely - you can use -f segment to chop video into pieces and serve it to iOS devices. ffmpeg will create segment files .ts and you can serve those with any web server.
Working example (with disabled sound) - ffmpeg version N-39494-g41a097a:
./ffmpeg -v 9 -loglevel 99 -re -i sourcefile.avi -an \
-c:v libx264 -b:v 128k -vpre ipod320 \
-flags -global_header -map 0 -f segment -segment_time 4 \
-segment_list test.m3u8 -segment_format mpegts stream%05d.ts
Tips:
make sure you compile ffmpeg from most recent git repository
compile with libx264 codec
-map 0 is needed
How I compiled FFMPEG - with extra rtmp support to get feeds from flash-media-server
export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:../rtmpdump-2.3/librtmp"
./configure --enable-librtmp --enable-libx264 \
--libdir='../x264/:/usr/local/lib:../rtmpdump-2.3' \
--enable-gpl --enable-pthreads --enable-libvpx \
--disable-ffplay --disable-ffserver --disable-shared --enable-debug
This is found in the ffmpeg documentation: https://ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment

ffmpeg rtmp streaming issue

I am trying to stream my webcam video using the ffmpeg to wowza media server on linux..
ffmpeg -re -f video4linux2 -i /dev/video0 -acodec libfacc -vcodec libx264 -f h264 rtmp://localhost:1935/live/test
This is the command I used for some reason it doesn't seem to work as I am not able to run the example that came with wowza. I tried using flash media live encoder to send a rtmp to my wowza server and it works.
Any pointers on how to solve this problem.
I build ffmpeg from their git repo with the following config
--enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
ffmpeg -protocols says it has rtmp input/output support
With these build options my FFMPEG build does receive and decode rtsp streams
--enable-network --enable-protocol=tcp --enable-demuxer=rtsp --enable-decoder=h264
I have answered a similar question here FFMPEG API: How to connect to RTSP stream using av_open_input_file?
Your second -f switch, for the container format, should be mp4 not h264. H264 is a codec not a container format
In order to stream to rtmp, one should select 'flv' output format like this:
ffmpeg -re -f video4linux2 -i /dev/video0 -acodec libfacc -vcodec
libx264 -f flv rtmp://localhost:1935/live/test

Resources