I'm working on FFMPEG with Jetson nano and PC.
I want to know the ordering element of FFMPEG can be effect in the result? Is it necessory to observe the ordering of elements?
In the concept of decoding and encoding streams:
ffmpeg -hwaccel cuvid -c:v h264_nvdec -c:v h264_cuvid -i input -c:v
h264_nvenc output
If I replace the -hwaccel cuvid with -c:v h264_nvdec, such as:
ffmpeg -c:v h264_nvdec -c:v h264_cuvid -hwaccel cuvid -i input -c:v
h264_nvenc output
Q1- May be these two above commands corecttly run, but in the backgrand these two commands have same operations and results?
Q2 -Or if I want to put -hwaccel cuvid after -i input, are these two commands have same operations and results?
Related
I am working on concatenating multiple videos and use another video and image as an overlay on the concatenated video.
I am trying below command to concatenate two videos, one audio merge , a video and an image as overlay using gpu
ffmpeg -re -hwaccel cuda -hwaccel_output_format cuda -i inputone.mp4 -re -hwaccel cuda -hwaccel_output_format cuda -i inputthree.mp4 -ss 00:01:00 -to 00:02:00 -re -hwaccel cuda -hwaccel_output_format cuda -i output5.mp4 -i abc.png -hwaccel cuda -hwaccel_output_format cuda -i audio.mp3 -filter_complex "[0]scale_npp=720:576:force_original_aspect_ratio=decrease:format=yuv420p,hwdownload,pad=720:576:(ow-iw)/2:(oh-ih)/2,setsar=1,setpts=1.0*PTS[v0];[1]scale_npp=720:576:force_original_aspect_ratio=decrease:format=yuv420p,hwdownload,pad=720:576:(ow-iw)/2:(oh-ih)/2,setsar=1,setpts=1.0*PTS[v1];[2]scale=iw/4:-2,hwupload_cuda,setpts=PTS-STARTPTS,scale_npp=format=nv12[fg];[3]crop=2000:2000,scale=-1:50:force_original_aspect_ratio=decrease[ig];[4]volume=1.0[au];[v0][v1]concat=n=2:v=1:a=0,hwupload_cuda,scale_npp=720:576:format=nv12[bg];[bg][fg]overlay_cuda=eof_action=pass:x=main_w - overlay_w:y=main_h - overlay_h,format=nv12[vt];[vt][ig]overlay_cuda=10:100,format=yuv420p[v]" -map "[v]" -map "[au]" -preset fast -crf 51 -c:v h264_nvenc -b:v 500k -c:a aac -g 30 -r 30 -f flv -flvflags no_duration_filesize rtmp://localhost/show/stream40x
Error
Impossible to convert between the formats supported by the filter 'Parsed_overlay_cuda_20' 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 #4:0
Where as without GPU command is working fine for me
ffmpeg -re -i inputone.mp4 -re -i inputthree.mp4 -ss 00:01:00 -to 00:02:00 -re -i output5.mp4 -i abc.png -i audio.mp3 -filter_complex "[0]scale=720:576:force_original_aspect_ratio=decrease,pad=720:576:(ow-iw)/2:(oh-ih)/2,setsar=1,setpts=1.0*PTS[v0];[1]scale=720:576:force_original_aspect_ratio=decrease,pad=720:576:(ow-iw)/2:(oh-ih)/2,setsar=1,setpts=1.0*PTS[v1];[2]scale=iw/4:-2, setpts=PTS-STARTPTS[fg];[3]crop=2000:2000,scale=-1:50:force_original_aspect_ratio=decrease[ig];[4]volume=1.0[au];[v0][v1]concat=n=2:v=1:a=0[bg];[bg][fg]overlay=eof_action=pass:x=main_w - overlay_w:y=main_h - overlay_h[vt];[vt][ig]overlay=10:100,format=yuv420p[v]" -map "[v]" -map "[au]" -preset fast -crf 51 -c:v h264_nvenc -b:v 500k -c:a aac -g 30 -r 30 -f flv -flvflags no_duration_filesize rtmp://localhost/show/stream40x
I have an mp4 and I am trying to merge multiple audio files into it. The command is generated dynamically given the number of audio and their offset. Everything works when I have multiple audios to merge but doesn't when I have one audio file to merge.
Here is the command to merge single audio into the mp4
ffmpeg -y -i ./video.mp4 -itsoffset 00:00:1.753 -i ./audio0.mp3 -filter_complex amix -map 0:v -map 1:a -c:v copy -async 1 -c:a aac -strict experimental -t 10 ./finalVideo.mp4
Here is the command to merge multiple audio files which works
ffmpeg -y -i ./video.mp4 -itsoffset 00:00:1.753 -i ./audio0.mp3 -itsoffset 00:00:0.113 -i ./audio/audio1.mp3 -filter_complex amix -map 0:v -map 1:a -map 2:a -c:v copy -async 1 -c:a aac -strict experimental -t 10 ./finalVideo.mp4
Option: -psnr as H264 parameter
ffmpeg -i input.mp4 -vf -codec:v libx264 -psnr -f mp4 -b:v 100k -pass 1 output.mp4
Option : Comparing input and output with the psnr filter.
ffmpeg -i input.mp4 -vf -codec:v libx264 -f mp4 -b:v 100k -pass 1 output.mp4
ffmpeg -i output.mp4 -i input.mp4 -filter_complex psnr -f null –
The CLI switch -psnr instructs the encoder to calculate PSNR, so it is useful to get PSNR for the current encoding session and only the current encoding session.
The psnr filter is used to calculate the value between two pre-encoded streams, and cannot be used to calculate for encoding happening in the same command.
I'm using ffmpeg from the command line on Windows 10 and I wanted to gave GPU acceleration a try to improve execution times. A simple cut command like this works fine and its execution time is reduced by 60-70%. Awesome.
ffmpeg -hwaccel cuvid -c:v h264_cuvid -ss 00:00:10 -i in.mp4 -c:v h264_nvenc out.mp4
Now I tried to use the -filter_complex flag to overlay, fade and translate a png image over a video. The working non-GPU enhanced command is this one:
ffmpeg -i in.mp4 -loop 1 -t 75 -i overlay.png -filter_complex "[1:v]fade=t=in:st=30:d=0.3:alpha=1,fade=t=out:st=35.7:d=0.3:alpha=1[png1];[0:v][png1]overlay=x='if(gte(t,30), (t-30)*10, NAN)'" -movflags +faststart out.mp4
Then, I added the GPU-related flags to the command like this.
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i in.mp4 -loop 1 -t 75 -i overlay.png -filter_complex "[1:v]fade=t=in:st=30:d=0.3:alpha=1,fade=t=out:st=35.7:d=0.3:alpha=1[png1];[0:v][png1]overlay=x='if(gte(t,30), 60-tanh((t-30)*30/5)*60, NAN)'" -movflags +faststart -c:v h264_nvenc out.mp4
But it won't work. I get 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 #0:0
I don't even know what it means. Can I actually run ANY ffmpeg command on the GPU with GPU acceleration? I've found some information about the hwupload_cuda flag but I'm not sure if I should use it and how. My attempts have failed so far.
Any advice on how I should modify the command to make it work on the GPU?
Just add
hwdownload,YOUR_FILTER,hwupload
like this:
ffmpeg.exe
-y
-hwaccel_device 2
-hwaccel cuvid
-c:v h264_cuvid
-i input.mp4
-vfhwdownload,format=nv12,drawtext=textfile=file.txt:x=0:y=0:fontfile='c\:\/windows\/fonts\/arial.ttf',hwupload
-c:v h264_nvenc
-f mp4 output.mp4"
I am trying to use -rc_override option for FFMPEG. However, i do not see any change in the frame
I have tried 2 command mentioned below
ffmpeg -i abp1.mp4 -b:v 154k -rc_override:v 6336,6436,-48 -vstats_file stats.txt -c:v libx265 -c:a copy abp1_compress_154.mp4
ffmpeg -i abp1.mp4 -b:v 154k -rc_override:v 6336,6436,1 -vstats_file stats.txt -c:v libx265 -c:a copy abp1_compress_154.mp4
Please let me know if there is any issue with this command
-rc_override is an old option confined to the internal MPEG-1/2 encoders.
For x265, use zones.
ffmpeg -i abp1.mp4 -c:v libx265 -b:v 154k -x265-params "zones=6336,6436,b=1.5"
-vstats_file stats.txt -c:a copy abp1_compress_154.mp4
b here indicates the bitrate multiplier.