When it comes to audio and video processing, FFmpeg is the ultimate open-source tool. I’ve been using it for a while, but my notes were scattered. Since I’m using it more frequently now, I decided to compile my most-used commands here (and add a few missing ones).
Convert Video Format
| |
Extract Audio from Video
| |
-vn: Disables video recording in the output file.
Re-encode Video
Sometimes a video file has a corrupted encoding or lags on certain devices. Re-encoding usually fixes this.
| |
This re-encodes the video using x264 and the audio using AAC.
Convert to Silent WebM
| |
Parameters:
-an: Removes audio.-c:v libvpx-vp9: Specifies the video codec (VP9 is widely supported; uselibvpxfor faster conversion).-crf 30: Controls quality (0-63). Lower numbers mean better quality and larger files.-b:v 0: When using VP9, it’s common to set bitrate to 0 and let the-crfparameter determine quality.
Convert to GIF
Use the -loop 0 parameter for infinite looping.
| |
If you need a transparent background, there are two scenarios:
1. The source video already has an alpha channel (e.g., ProRes 4444 .mov). Direct conversion often results in noise. Use a palette filter to ensure transparency is mapped correctly:
| |
Parameters:
fps=15: Sets the frame rate.split[s0][s1]: Splits the video into two streams.s0generates the palette,s1is the output image.[s0]palettegen[p]: Generates a specialized 256-color palette namedp. It preserves transparency by default.[s1][p]paletteuse: Applies palettepto the video streams1.
2. The source video has a solid background color. Use the colorkey filter to remove it:
| |
For colorkey=0x00FF00:0.1:0.1:
0x00FF00: The color to remove (Pure Green here; Black is0x000000).- First
0.1: Similarity. Ranges 0.01-1.0. Usually set between 0.1 and 0.3. - Second
0.1: Blend. Softens the edges.
Merge Audio and Video
First, check if the audio codec is compatible (like AAC).
| |
If compatible, use stream copy:
| |
If the audio is incompatible, re-encode it during the merge:
| |
Image Formats
FFmpeg can even convert image formats. For a basic conversion:
| |
Very handy for quick format swaps.