Codec / Libraries

The following formats use these codecs/libraries.

Audio

flac

-c:a flac

mp3

-c:a libmp3lame

mp3

-c:a aac

ogg

-c:a libvorbis

opus

-c:a libopus


Image

avif

-c:v libaom-av1 or -c:v libxav1

jxl

-c:v libjxl

png

-c:v png

webp

-c:v libwebp


Video

mkv APV (Advanced Professional Video)

-c:v libopenapv

mkv AV1 libaom‑av1 (reference encoder, highest quality, slower)

-c:v libaom-av1

mkv AV1 (Rust‑based encoder, good quality, fast)

--c:v librav1e

mkv AV1 SVT‑AV1 (Intel‑backed, very fast at high quality)

--c:v libsvtav1

mkv FFV1 (lossless)

-c:v ffv1

mp4 H264

-c:v libx264

webm VP9

-c:a libvpx-vp9

Convert Audio, Video, Image

Simple file convertion with the command lines below. The rule is the same with audio, video and images. Specifiy the codecs are optional for a simple format convertion unless you need more control on the output.

Syntax: ffmpeg -i input (c:v codec-video) (c:a codec-audio) output

Convert an audio file

ffmpeg -i input.wav output.opus

Convert an image file

ffmpeg -i input.bmp output.webp

Convert a video file

ffmpeg -i input.avi output.webm

Examples

Audio .wav to .flac

ffmpeg -i input.wav output.flac

Audio .flac to .mp3

ffmpeg -i input.flac output.mp3

Audio .mp3 to .opus

ffmpeg -i input.mp3 output.opus

Image .bmp to .png (lossless max compression 0-9)

ffmpeg -i input.bmp -c:v png -compression_level 9 output.png

Image .bmp to .webp

ffmpeg -i input.bmp output.webp

Image .png to .jxl

ffmpeg -i input.png output.jxl

Animation .gif to .avif

ffmpeg -i input.gif output.avif

Animation .gif to .apng +loop

ffmpeg -i input.gif -plays 0 output.apng

Animation .gif to .webp +quality 50 (0-100 higher value is better, default is 75)

ffmpeg -i input.gif -q.:v 50 output.webp

Animation .gif to .webp +loop +lossless

ffmpeg -i input.gif -lossless 1 -loop 0 output.webp

Animation .png sequance to .apng animation (lossless max compression 0-9, infinite loop)

ffmpeg -framerate 30 -i image_%03d.png -c:v png -compression_level 9 -pred mixed -plays 0 output.apng

Video .avi to .mkv (AV1 video + Opus audio)

ffmpeg -i input.avi -c:v libaom-av1 -c:a libopus output.mkv

Video .avi to .mp4 (H264 video + AAC audio)

ffmpeg -i input.avi -c:v libx264 -c:a aac output.mp4

Video .avi to .webm (VP9 video + OPUS audio)

ffmpeg -i input.avi -c:v libvpx-vp9 -c:a libopus output.webm

Video .avi to .webm lossless (VP9 video, no audio)

ffmpeg -i input.avi -c:v libvpx-vp9 -lossless 1 -an output.webm

Video .avi to .webm (AV1 video + OPUS audio)

ffmpeg -i input.avi -c:v libaom-av1 -c:a libopus output.webm

Video .mp4 to .apng animation (lossless max compression 0-9, infinite loop)

ffmpeg -i input.mp4 -c:v png -compression_level 9 -pred mixed -plays 0 output.apng

Good WebM Video + Audio .mkv (SVTAV1 + Opus)

ffmpeg -i input -c:v libsvtav1 -c:a libopus output.webm

True lossless Video + Audio .mkv (FFV1 + FLAC)

ffmpeg -i input -c:v ffv1 -c:a flac output.mkv

Convert a PNG image to a loss‑less AVIF file

ffmpeg -i input.png -c:v libaom-av1 -crf 0 -b:v 0 output.avif

🛈 Actually only libaom-av1 encoder support lossless mode.

Convert a PNG image to a loss‑less WebP file

ffmpeg -i input.png -c:v libwebp -lossless 1 -preset picture -compression_level 6 output.webp

🛈 If you want the absolute smallest loss‑less file, you can bump -compression_level to 6 (the max). For most everyday use, the default 6 already gives a good size‑vs‑speed trade‑off.

Test & Comparison

The original source file lossless.mkv, is a 1920x1080, 60 sec, 60 fps, 2.4 GB lossless .mkv video, encoded with FFV1 for video stream and FLAC audio stream.

All options and encoding parameters are default, as ffmpeg manage them.

CONTAINER VIDEO AUDIO OUTPUT SIZE TIME ELAPSED COMMAND .mkv ffv1 (lossless) flac (lossless) 48000Hz 2.4 GB 0:00:18.62 ffmpeg -i lossless.mkv -c:v ffv1 -c:a flac lossless2.mkv .mkv h264 (high) (libx264) vorbis (libvorbis) 48000Hz 27.6 MB 0:00:23.85 ffmpeg -i lossless.mkv video.mkv .mp4 h264 (high) (libx264) aac (LC) (mp4a) 48000Hz 27.8 MB 0:00:22.08 ffmpeg -i lossless.mkv video.mp4 .webm vp9 (libvpx-vp9) opus (libopus) 48000Hz 34.6 MB 0:05:41.99 ffmpeg -i lossless.mkv video.webm .webm av1 (libsvtav1) Opus (libopus) 48000Hz 30.0 MB 0:00:23.12 ffmpeg -i lossless.mkv -c:v libsvtav1 -c:a libopus video.webm

We like and support WebM. By defaut, FFmpeg encodes WebM video with VP9 (libvpx-vp9) and audio with Opus (libopus), which is probably the best lossy audio codec actually (2025), but in our test, VP9 is slow compared to AV1 (libsvtav1), so to have a good compromise between compression and time, we strongly suggest to use AV1 (libsvtav1) instead of VP9 (libvpx-vp9) to make WebM.

Why WebM is good

WebM is a modern, open-source video format designed for efficient web streaming and playback, offering several key advantages. It is royalty-free, meaning it can be used by anyone without licensing fees, which makes it a cost-effective choice for developers and content creators. WebM is particularly effective for online video delivery because it provides high video quality while achieving smaller file sizes compared to formats like MP4, often reducing file size by 20-30% without sacrificing visual quality. This efficient compression is due to its use of advanced codecs like VP9 and AV1 for video, and Opus for audio, which deliver excellent quality at lower bitrates.

The format is well-suited for websites and online platforms, where faster load times and optimized user experience are crucial. Its compatibility with modern web browsers, including recent versions of Safari, Chrome, Firefox, and Opera, ensures seamless playback for users with up-to-date devices. WebM is also ideal for live streaming and video conferencing due to its low latency, especially when using the Opus audio codec. Furthermore, WebM is widely supported by major video platforms like YouTube and Vimeo, and it integrates well with HTML5, making it a preferred choice for web-based video content.

REMINDER: A simple command to make a good webm video:
ffmpeg -i input.video.mkv -c:v libsvtav1 -c:a libopus output.video.webm

Insert subtitles SRT file in a video

To embed an SRT file into a video using FFmpeg, you have several options depending on whether you want to include subtitles as a separate, selectable track (soft subtitles) or burn them directly into the video (hard subtitles).

Method 1: Embed subtitles as a separate track (Recommended for MP4)

To add the SRT file as a soft subtitle track (so viewers can enable/disable them), use this command for MP4 output:

ffmpeg -i input.mp4 -f srt -i subtitles.srt -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s mov_text output.mp4

NOTE: MP4 only supports mov_text subtitles. If your SRT contains special formatting, ensure compatibility.

Method 2: Embed subtitles in MKV (Supports native SRT)

For MKV files, which support SRT subtitles natively, use:

ffmpeg -i video.mkv -f srt -i subtitles.srt -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt output.mkv

This creates a new MKV file with the subtitles as a separate selectable track, preserving the original video and audio quality.

Method 3: Burn subtitles into the video (Hardcoded subtitles)

To permanently burn subtitles into the video frames (visible to all viewers):

ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4

Customize subtitle appearance:

You can style the burned-in subtitles:

ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='FontName=Arial, FontSize=24, PrimaryColour=&H00FFFF&, Alignment=2'" output.mp4

This sets:

Summary

Method Command Use Case Soft subtitles (MP4)-c:s mov_text Soft subtitles (MKV)-c:s srt Hardcoded subtitles-vf "subtitles=..."

Choose the method based on your needs: flexibility (soft subtitles) or guaranteed visibility (hardcoded).

Add a Cover Image to an Audio File

The following command will add an album art cover.jpg to an mp3 file input.mp3 without re-encoding by copying the streams.

ffmpeg -i input.mp3 -i cover.jpg -c copy -map 0:a -map 1:0 output.mp3

Cropdetect and Crop Filters (Remove Black Borders)

Simple file convertion with the command lines below. The rule is the same with audio, video and images. Specifiy the codecs are optional for a simple format convertion unless you need more control on the output.

1. Get crop parameters

cropdetect can be used to provide the parameters for the crop filter.

In this example the first 90 seconds is skipped and 10 frames are processed:

ffmpeg -ss 90 -i input.mp4 -vframes 10 -vf cropdetect -f null -

...
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:215 t:0.215000 crop=1280:720:0:0
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:257 t:0.257000 crop=1280:720:0:0
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:299 t:0.299000 crop=1280:720:0:0


At the end of each line, you can see it says crop=1280:720:0:0. So according to cropdetect we can use crop=1280:720:0:0.

2. Preview with ffplay

ffplay -vf crop=1280:720:0:0 input.mp4

3. Re-encode using the crop filter

ffmpeg -i input.mp4 -vf crop=1280:720:0:0 -c:a copy output.mp4

source: llogan @ superuser.com

Extract Audio From Video

To keep only the audio stream from a video file using FFmpeg, you can use the -map option to select the audio stream and discard all others. The following command will extract the audio from the input file and save it as a new audio file:

ffmpeg -i input.mp4 -map 0:a -c:a copy output.aac

This command maps only the audio stream (0:a) from the first input file (0) and copies the audio codec without re-encoding (-c:a copy). The output file will contain only the audio track.

If the input file contains multiple audio tracks and you want to keep only a specific one, such as the first audio track, you can specify it by index:

ffmpeg -i input.mkv -map 0:a:0 -c:a copy output.aac

This selects the first audio stream (0:a:0).

Extract or Trim a Video Part

The following command lines are used to trim video in FFmpeg, the stream copy (-c copy) enables to trim video without re-encoding and keeps original quality for the output video.

Method 1: Using start time -ss and end time -to

ffmpeg -i input.mp4 -ss 00:00:00 -to 00:10:00 -c copy output.mp4

Method 2 : Using start time -ss and duration time -t

ffmpeg -i input.mp4 -ss 00 -t 10 -c copy output.mp4

NOTE: You can use -t durationTime instead of -to endTime.

Join Multiple Audio or Video Files Together

1. Create the list file

Create a list.txt file in the same directory as the media files you want to join, list.txt contains the list of media input files you will concatenate, in this format:

list.txt contains the lines below:
file 'media1.mp4'
file 'media2.mp4'
file 'media3.mp4'

2. Run the command

ffmpeg -f concat -safe 0 -i list.txt output.mp4

Resize a Video

The primary method uses the -vf scale filter, allowing you to resize to exact dimensions, maintain aspect ratios, or scale by percentages. Use -2 instead of -1 for automatic dimension calculation to ensure compatibility with H.264/H.265 encoders, which require even pixel values.

Use one of the following commands based on your resizing needs:

Rotate a Video

To rotate a video using FFmpeg, use the -vf (video filter) option with specific filters:

NOTE: The transpose filter re-encodes the video. For lossless rotation, use metadata-only methods when supported. Always test playback on target devices.

Scripts

Below are some useful scripts for you to use, for mass file manipulation with FFmepg, for Linux and Windoes. Modifiy them to your needs!

Linux Bash (.sh) Scripts

How to Use on Linux

  1. Install FFmpeg: Run sudo pacman -S ffmpeg (Arch based distros), sudo apt install ffmpeg (Debian/Ubuntu/Mint) or sudo dnf install ffmpeg (Fedora).
  2. Save: Save the code as script.sh.
  3. Run: Open a terminal in that folder and run: chmod +x script.sh && ./script.sh
Convert multi files to another format
Download
Remove and clean meta data of multi files
Download

Windows BAT (.bat) Scripts

How to Use on Windows

  1. Install FFmpeg: Ensure ffmpeg.exe is installed and added to your Windows PATH, or place ffmpeg.exe in the same folder as this script.
  2. Save: Copy the code, paste it into Notepad, and save it as script.bat.
  3. Run: Double-click script.bat in the folder containing your media files.
Convert multi files to another format
Download
Remove and clean meta data of multi files
Download

Official

Application / GUI