FFMPEG Notes¶
- Render only a part of the video:
-ss 10:20 -to 10:30-ss and -to arguments must be entered first
ffmpeg -i input.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p,scale=1920:-1,subtitles=subs.srt -c:a libfdk_aac -b:a 128k -ac 2 -c:v h264_nvenc -pixel_format yuv420p -cq:v 25 -b:v 0 -movflags +faststart output.mp4
-vf: Video filter, list, separated by,- Convert HDR to SDR:
zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p(from https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/) - Resize:
scale=1920:-1(-1 means based on aspect ratio) - Burn in subtitles:
subtitles=subs.srt
- Convert HDR to SDR:
- Use H.264 encoding with nvenc:
-c:v h264_nvenc - H.264 quality (lower the better quality):
-cq:v 25 -b:v 0(don't change-b:v 0) - Convert audio to AAC format:
-c:a libfdk_aac -b:a 128k - Convert to stereo sound:
-ac 2 - Optimise for playing on the web:
-movflags +faststart
ffmpeg -i input.mkv -map 0:3 subs.srt
- Extract subs from the video to a srt file.
- Select stream
0:3to convert:-map 0:3(get stream name fromffmpeg -i <file>)
ffmpeg -y -hwaccel_device 0 -hwaccel cuda -init_hw_device opencl=gpu:0.0 -filter_hw_device gpu -vsync 0 -i input.mkv -vf scale=1920:-1,subtitles=hp3.srt,format=yuv420p,hwupload,nlmeans_opencl=p=5:r=11,hwdownload,format=yuv420p -pixel_format yuv420p -c:a libfdk_aac -ac 2 -c:v h264_nvenc -cq:v 22 -b:v 0 -movflags +faststart ./hp3-v3.mp4
- A bunch of flags that I don't understand to enable the use of GPU in filters:
-hwaccel_device 0 -hwaccel cuda -init_hw_device opencl=gpu:0.0 -filter_hw_device gpu - Video filters
- Denoise:
nlmeans_opencl=p=5:r=11 - Upload/download frames to GPU for opencl filters:
hwuploadhwdownload- Put a format filter right after
hwdownloadto change downloaded format
- Put a format filter right after
- Denoise:
Notes on use subtitle filter with -ss¶
Trim the srt file before use it in the filter:
ffmpeg -ss 0:10 -i input.srt output.srt
Denoise¶
ffmpeg -i input.mp4 -af "highpass=f=200, lowpass=f=2000" out.mp4
Crop Video¶
ffmpeg -i input.mp4 -filter:v "crop=80:60:200:100" -c:a copy out.mp4
out_wis the width of the output rectangleout_his the height of the output rectanglexandyspecify the top left corner of the output rectangle
Get First Frame¶
ffmpeg -i input.mp4 -vframes 1 -f image2 ./first_frame.jpg
Last update:
November 21, 2021
Created: April 14, 2021
Created: April 14, 2021