Tutorial on FFMPEG (Draft)
Bensuperpc February 16, 2025 #Features #FFMPEG #AV1 #x265 #x264 #SVT-AV1 #Rav1e #Audio #Video #Image #MetadataAbout FFMPEG
Convert video to AV1 CRF (SVT-AV1)
Option | default | Example | Description |
---|---|---|---|
-vf | - | -vf scale=1920:-1 | Downscale the video to 1080p |
-g | ? | -g 60 | Set the keyframe interval of x frames, lower value increase quality but increase file size |
-pix_fmt | Depends on source | -pix_fmt yuv420p | Set the pixel format, yuv420p for 8-bit, yuv420p10le for 10-bit ect... |
-crf | - | - | Constant Rate Factor, options depend on the encoder |
-preset | - | - | Set the encoding speed, options depend on the encoder |
-tune | - | - | Set the encoding tune, options depend on the encoder |
-c:v | - | -c:v libx265 | Set the video codec, options depend on installed codecs |
-c:a | - | -c:a copy | Set the audio codec, options depend on installed codecs |
-c:s | - | -c:s copy | Set the subtitle codec, options depend on installed codecs |
-map | - | -map 0 | Map the input stream to the output |
-map_metadata | - | -map_metadata 0 | Map the metadata to the output |
-map_chapters | - | -map_chapters 0 | Map the chapters to the output |
-fps_mode | auto | -fps_mode passthrough | Set the frame rate mode, passthrough, cfr, vfr, auto |
-loglevel | - | -loglevel error | Set the log level, error, warning, info, verbose, debug, trace |
-hide_banner | - | -hide_banner | Hide the banner |
-y | - | -y | Overwrite output files without asking |
This table shows the most common options for SVT-AV1, like the preset, crf, and svtav1-params.
For svtav1-params each option is separated by a colon :
, option and value are separated by =
, like tune=0:enable-qm=1:qm-min=0
.
Option | default | Min/Max | Example | Description |
---|---|---|---|---|
-preset | 4 | -preset 4 | 0-12 | 0 for slowest, 12 for fastest encoding |
-crf | 18 | -crf 30 | 0-63 | Constant Rate Factor, lower value increase quality |
-svtav1-params | - | - | -svtav1-params tune=0:enable-qm=1 | SVT-AV1 specific options |
tune | 1 | 0-1 | -svtav1-params tune=0 | 0 for subjective quality, 1 for objective quality (PSNR) |
enable-qm | 0 | 0-1 | -svtav1-params enable-qm=1 | Enable quantization matrices |
qm-min | 8 | 0-15 | -svtav1-params qm-min=0 | Minimum quantization matrix |
qm-max | 15 | 0-15 | -svtav1-params qm-max=10 | Maximum quantization matrix |
aq-mode | 2 | 0-2 | -svtav1-params aq-mode=2 | Adaptive quantization mode |
enable-overlays | 0 | 0-1 | -svtav1-params enable-overlays=1 | Enable overlays |
film-grain | 0 | 0-12 | -svtav1-params film-grain=8 | Add film grain to the video |
More information about the options can be found in the SVT-AV1 documentation
Example of encoding CRF for very high quality (Maybe little overkill, preset 4 and crf 20 is a good start for 1080p).
- -preset 1: i recommend to use 4-6 for good quality and speed, 3 or lower for better quality but it really slow (~2x slower per lower step, for minimal gain).
- -crf 14: CRF 20-24 is a good start, 14 for very high quality bit bigger file size.
- tune=0: Enable subjective quality, 1 for objective quality (PSNR).
- enable-qm=1: Enable quantization matrices.
- qm-min=0: Minimum quantization matrix, reduce it for lower compression in certain zones, the 8 default is little too high, 0-4 is a good start.
- qm-max=8: Maximum quantization matrix, increase it for higher compression in certain zones, the 15 default is little too high, 8-12 is a good start.
With AV1AN, it usefull if you have move than 16 threads, SVT-AV1 is not well optimized for over 16 threads, AV11AN encode the video in parallel per scene.
Copy metadata and chapters:
Optional for AV1AN:
- Add
--video-filter "scale=1920:-1"
to downscale the video to 1080p - Add
--keyint 60
in video-params to set the keyframe interval to 60 frames (every 1 seconds at 60fps), lower value increase quality but increase file size
Convert video to AV1 CRF(AOM)
Convert video to AV1 CRF (Rav1e)
Convert video to h265 CRF (x265)
Convert video to h265 ABR 2 pass and scale to 720p (x265)
&&
Convert video to h264 CRF (x264)
Get SSIM
SSIM Y: For luma (Y) channel, 0-1, 1 is perfect match SSIM U: For chrominance (U) channel, 0-1, 1 is perfect match SSIM V: For chrominance (V) channel, 0-1, 1 is perfect match SSIM All: Average of YUV, 0-1, 1 is perfect match
Get PSNR
PSNR Y: For luma (Y) channel, in dB higher is better PSNR U: For chrominance (U) channel, in dB higher is better PSNR V: For chrominance (V) channel, in dB higher is better PSNR All: Average of YUV, in dB higher is better
Get VMAF
VMAF score, higher is better
Output into a json file
Cut video without re-encoding
Extract from 125s to 200s
Extract from 125s to 150s
Import watermark
Import watermark at 10:10 from the top left corner
Change video speed
Speed up the video by 2x
Change the video frame rate to 30fps (2x slower if the original is 60fps)
Convert video to gif
Add vintage look effect to video and play it with ffplay
- curves=vintage: Add a vintage look
- noise=alls=30:allf=t+u: Add noise
- hue=s=0.7: Reduces saturation
- eq=contrast=0.85:brightness=-0.01:saturation=0.7: Adjust contrast, brightness and saturation
- gblur=sigma=1.5: Add a gaussian blur
- colorbalance=rm=0.2:gm=0.1:bm=-0.2: Adjust color balance to sepia tone
- vignette: Add a vignette
Image commands examples
Convert images png to webp (lossless)
| &&
Get difference between two images
Or with ImageMagick
| |
Audio commands examples
Generate audio spectrogram with sox
You can generate a spectrogram with sox, for example with a flac file to detect "fake" flac files.
Add -t flac
if the input file is not recognized as flac.
Increase audio volume without re-encoding
Convert audio
Audio lib | Max bitrate | Extension |
---|---|---|
libmp3lame | 320kbps | mp3 |
aac | 250kbps | m4a |
libopus | 250kbps | opus |
flac | lossless | flac |
Convert audio to mp3
Convert audio to lossy or "fake" flac
Remove noise from audio
Metadata commands examples
Get metadata from audio or video file
Youtube-dlp
Download audio from youtube video without re-encoding:
Download video from youtube video without re-encoding:
Useful links
- FFMPEG
- ImageMagick
- Simple SVT-AV1 Beginner Guide
- CommonQuestions SVT-AV1
- Vintage look with ffmpeg
- FFMPEG filters
- FFMPEG Lame
- Encoding Animation with SVT-AV1: A Deep Dive