FFMpeg
Free, open source software for transcoding
TOC
- Filters
- Libx264
- x265
- NvEnc
- Sequence to video
- Getting info and help
- Colorspace conversion
- FFprobe
- Progress
- Frameserver
Filters
filters in a chain are separated by commas ","
chains by a semicolon ";"
if an input or output is not specified it is assumed to come from the preceding or sent to the following item in the chain.
"filter1=setting1=value1:setting2=value2,filter2=setting1=value1:setting2=value2"
Scale
The FFmpeg rescaler provides a high-level interface to the libswscale library image conversion utilities. In particular it allows one to perform image rescaling and pixel format conversion.
https://trac.ffmpeg.org/wiki/Scaling https://ffmpeg.org/ffmpeg-scaler.html
iw
is input width
-1
and -2
to preserve ratio
ffmpeg -i input -vf "scale=iw/2:-1" output
Libx264
https://trac.ffmpeg.org/wiki/Encode/H.264
To list all possible internal presets and tunes:
@echo off
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -f lavfi -i nullsrc "-c:v libx264" -preset help -f mp4 NUL
Rate control
There are two rate control modes that are usually suggested for general use:
CRF
The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless.
The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate.
Will two-pass provide a better quality than CRF?
No, though it does allow you to target a file size more accurately.
Two-pass ABR
For two-pass, you need to run ffmpeg
twice, with almost the same settings, except for:
- In pass 1 and 2, use the
-pass 1
and-pass 2
options, respectively. - In pass 1, output to a null file descriptor, not an actual file. (This will generate a logfile that ffmpeg needs for the second pass.)
- In pass 1, you may leave audio out by specifying
-an
When using option
-an
, you may eventually get a segfault or a broken file. If so, remove option-an
and replace by-vsync cfr
to the first pass.
Presets
To see a list of current presets with -preset help
If you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.
Libx265
H.265/HEVC
NvEnc
Source
[[Using_FFmpeg_with_NVIDIA_GPU_Hardware_Acceleration.pdf]]
FFmpeg wiki
@REM h264_nvenc help
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=h264_nvenc
Sequence to video
Many high-end video pipelines work with DPX, EXR or TIFF sequences. To transform these sequences into video files, the easiest way is to specify the first file in the sequence as the input and then use -framerate
to set the input frame rate and -r
to set the output frame rate:
@echo off
ffmpeg -i input_0001.dpx -framerate 59.94 -c:v libx264 -b:v 30M -r 29.97 -an output.mp4
Palettegen
and Paletteuse, dithering options
https://ffmpeg.org/ffmpeg-filters.html#palettegen-1
Getting info and help
For filters, codecs, muxers, etc
@echo off
rem Get encoder help
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=exr
@echo off
rem Get encoder help
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=aac
@echo off
rem Get all pixel formats
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -pix_fmts
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=libx264 | findstr "pixel"
@echo off
rem Get pixel muxer's private options
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h muxer=apng
@echo off
rem Get pixel muxer's private options
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h muxer=mjpeg
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=h264_nvenc
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=hevc_nvenc
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=libvpx-vp9
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=mjpeg
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=png
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=libx264
@echo off
rem Get pixel formats for encoder
"C:\Program Files\ffmpeg\bin\ffmpeg" -hide_banner -h encoder=libx265
Colorspace conversion
https://trac.ffmpeg.org/wiki/colorspace
FFprobe
Count keyframes
@set "file=D:\Keerah\Projects1\stf tests\thecolour05.mov"
@"C:\Program Files\ffmpeg\bin\ffprobe.exe" -hide_banner -of compact=p=0:nk=1 -select_streams "v:0" -count_frames -show_entries stream=nb_read_frames -skip_frame nokey -v 0 -i "%file%"
Show streams
set "file=D:\Keerah\Projects1\stf tests\Blossom1.0001.puzzleMatte\Blossom1.0001.puzzleMatte_jpeg40.jpg"
@"C:\Program Files\ffmpeg\bin\ffprobe.exe" -v error -hide_banner -show_streams -show_format -sexagesimal -i "%file%"
Format name
set "file=D:\Keerah\Projects1\stf tests\thecolour05.mov"
@"C:\Program Files\ffmpeg\bin\ffprobe.exe" -v error -hide_banner -show_entries "format=format_name" -of "default=noprint_wrappers=1:nokey=1" -sexagesimal -i "%file%"
Get particular stream data
@set "file=D:\Keerah\Projects1\stf tests\thecolour05.mov"
@"C:\Program Files\ffmpeg\bin\ffprobe.exe" -v error -hide_banner -show_entries "stream=width,height,duration,codec_name,pix_fmt,color_space,color_primaries,color_transfer,color_range,avg_frame_rate" -of "default=noprint_wrappers=1" -select_streams "v:0" -sexagesimal -i "%file%"
Progress
Move ffmpeg execution into a separate process? run and fetch progress?
-progress %TEMP%\progr.txt
https://blog.programster.org/ffmpeg-output-progress-to-file
Frameserver
https://www.debugmode.com/frameserver/