Watermark video by ffmpeg and hardware accelerator - ffmpeg

I use a p4000 card and ffmpeg with all requirements (driver , toolkit , cuda compile)
I want to put watermark on the video by this command
./bin/ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -i input.png -filter_complex "overlay=10:10" -c:v h264_nvenc output.mp4
but I encounter this error
Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0: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 #1:0
Thanks for the advice

-hwaccel cuvid
Mean that decoded frame will go to hw encoder directly (not copy in system memory), so at this time it's impossible to add filters to decoded frame. Try remove -hwaccel cuvid, but speed will be slow.
https://trac.ffmpeg.org/wiki/HWAccelIntro#CUDACUVIDNVDEC

Related

ffmpeg refuses to encode video

The command:
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -resize 1920x1080 -i "Infinity.mkv" -vf "ass=Infinity.ass" -c:v h264_nvenc -preset slowest -crf 18 -c:a flac -af aformat=s32:48000 -compression_level 5 -strict -2 Infinity.mp4
results in:
Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0:0' and the filter 'auto_scale_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
Conversion failed!
I tried adding hwupload and hwdownload to the vf filters. The result was the same.

ffmpeg h264_nvenc force level=41

I have some videos at 1080p 60fps.
These videos are with level=50 and my TV plays only videos up to level=41, so I want to convert my videos using ffmpeg and hardware acceleration.
I have a Windows 10 machine with ffmpeg and Geforce 2060, so I try run below command:
ffmpeg -i video.mp4 -vcodec h264_nvenc -preset slow -level 4.1 output.mp4
but I get this error:
[h264_nvenc # 000001dd43cd07c0] InitializeEncoder failed: invalid param (8): Invalid Level.
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
When I try to run the same command above using "-level 4.2" or above, the encode process works! But it is useless for me, because I really need "-level 4.1".
I noticed that if use libx264 instead of h264_nvenc, the encode process accepts "-level 4.1", but it take too long to complete (I want to enjoy hardware acceleration instead of CPU).
How can I force h264_nvenc to accept "level=4.1" ?

ffmpeg filter_complex trim out-sync

command line:
ffmpeg -i <INPUT> -filter-complex "<FILTER_COMPLEX>" -map "[ofa]" -map "[ofv]" -acodec aac -vcodec libx264 test.mp4
FILTER_COMPLEX content:
[0:v]split=3[sv1][sv2][sv3];
[0:a]asplit=3[sa1][sa2][sa3];
[sv1]trim=start=200:duration=5,setpts=PTS-STARTPTS[ov1];[sa1]atrim=start=200:duration=5[oa1];
[sv2]trim=start=300:duration=5,setpts=PTS-STARTPTS[ov2];[sa2]atrim=start=300:duration=5[oa2];
[sv3]trim=start=400:duration=5,setpts=PTS-STARTPTS[ov3];[sa3]atrim=start=400:duration=5[oa3];
[ov1][ov2][ov3]concat=n=3:v=1:a=0[ofv];
[oa1][oa2][oa3]concat=n=3:v=0:a=1[ofa]
As a result, the output video sounds are out of sync, and the video is redirected to 00:00:00, but the sound remains at the original time position.
Therefore, how to use ffmpeg to intercept several clips from a video, recombine them into a new video file, and keep the sound and picture synchronized.
I tried with [sa1]atrim=start=200:duration=5,setpts=PTS-STARTPTS[oa1] but an error:
Media type mismatch between the 'Parsed_atrim_4' filter output pad 0 (audio) and the 'Parsed_setpts_5' filter input pad 0 (video)
Cannot create the link atrim:0 -> setpts:0
Error initializing complex filters.
Invalid argument

FFMPEG Transcode H265 video from 10-bit to 8-bit

I'm trying to convert my library from various formats into HEVC 8-bit mainly to shrink my library down. This is generally working but I've run into an issue when trying to convert an existing file from 10-bit H.265 to 8-bit H.265.
My processor, an Intel Celeron J3455, supports hardware decoding/encoding H.265 at 8-bit but only hardware decoding for 10-bit.
It seems that ffmpeg is attempting to keep the video as 10-bit to match the source rather than allowing me to convert to 8-bit and this is creating an error.
Here is a sample command that I'm using:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.10bit.x265.mkv -map 0:0 -c:v:0 hevc_vaapi -vf "scale_vaapi=w=-1:h=1080" -b:v 4027047 -map 0:1 -c:a:0 aac -b:a 384000 -ac 6 -map 0:s -scodec copy -map_metadata:g -1 -metadata JBDONEVERSION=1 -metadata JBDONEDATE=2020-06-06T20:52:36.072Z -map_chapters 0 output.8bit.x265.mkv
The error I get is:
[hevc_vaapi # 0x5568b27fb1c0] No usable encoding entrypoint found for profile VAProfileHEVCMain10 (18).
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
From what I can tell ffmpeg looks at the source and selectes VAProfileHEVCMain10 instead of VAProfileHEVCMain. I'd like to force it to output 8-bit.
I've tried adding -pix_fmt yuv420p but that gives me this error:
Incompatible pixel format 'yuv420p' for codec 'hevc_vaapi', auto-selecting format 'vaapi_vld'
I've also tried making this change to the command: "scale_vaapi=w=-1:h=1080,format=yuv420p"
However that gives me the error:
Impossible to convert between the formats supported by the filter 'Parsed_scale_vaapi_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Any suggestions?
I've just been figuring this out as well. Your problem is (most likely) with -hwaccel_output_format vaapi. It's outputting frames in VAAPI format and not the format you need (read more here, also quoted a section at the end of this comment). So you need to adjust for 8-bit there: -hwaccel_output_format yuv420p.
In my case I'm also using -filter_hw_device vaapi0 -vf format=nv12|vaapi,hwupload (specified before -c:v hevc_vaapi). The vaapi0 here is a named device I've initialised with init_hw_device. You're directly using a path with -hwaccel_device so I'm not sure what the name of your device is, but you may not need these extra arguments.
The hardware codecs used by VAAPI are not able to access frame data in arbitrary memory. Therefore, all frame data needs to be uploaded to hardware surfaces connected to the appropriate device before being used. All VAAPI hardware surfaces in ffmpeg are represented by the vaapi pixfmt (the internal layout is not visible here, though).
The hwaccel decoders normally output frames in the associated hardware format, but by default the ffmpeg utility download the output frames to normal memory before passing them to the next component. This allows the decoder to work standlone to make decoding faster without any additional options:
ffmpeg -hwaccel vaapi ... -i input.mp4 -c:v libx264 ... output.mp4
For other outputs, the option -hwaccel_output_format can be used to specify the format to be used. This can be a software format (which formats are usable depends on the driver), or it can be the vaapi hardware format to indicate that the surface should not be downloaded.

FFMPEG hwaccel complex filters

I know this can be done by simply removing -hwaccel cuvid BUT I was wondering how this hwuplaod / hwdownload complex filtering stuff actually works with ffmpeg.
T:\ffmpeg\bin\20181015-c27c7b4-win64-static\ffmpeg.exe -y -loglevel 48 -hwaccel_device 0 -hwaccel cuvid -c:v h264_cuvid -i "input.mp4" -i "watermark.png" -filter_complex "format=nv12,hwupload,overlay=0:0" -b:v 24000k -c:v h264_nvenc -c:a copy "output.mp4"
Parsed_format_0 # 00000250b79758c0] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and the filter 'Parsed_format_0'
Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0: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 #1:0
This results in the errors above, however removing the -hwaccel_device 0 and -hwaccel cuvid allows ffmpeg to run and export as expected, however GPU (gtx1080ti) usage is only at about 25% and my cpu (i9-7900x sits around 80%). There is obviously a better way to work this.

Resources