This page shows some examples on how to use FFmpeg command line tool which is a complete, cross-platform solution to record, convert, capture, decode, encode, modify, combine, stream audio and video.
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.
-preset picture : Optimizes for still‑image quality (other presets are photo, drawing, icon, text).
-compression_level 6 : Controls how hard the encoder works (0‑6). Higher values give smaller files but take longer; 6 is the maximum for loss‑less.
output.webp : Resulting loss‑less WebP file.
🛈 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.
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:
-i input.mp3: The first input, the file to convert.
-i cover.jpg: The second input, the album art you want to add.
-map 0:a: From the input 0 (aka input.mp3), select the audio (a).
-map 1:0: From the input 1 (aka cover.png), selects the first stream (0).
output.mp3: The converted file.
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:
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:
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.
-ss 00:00:00: the start of the section that you want to trim.
-to 00:10:00: the end of the section that you want to trim.
-c copy: this option means trimming video via stream copy, which is fast and will not re-encode video.
output.mp4: the path for the output file.
-t 10: the duration of the section to trim, rather than the end time.
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:
Create a command.bat file in the same directory as the media files you want to join, comand.bat contains the command for ffmpeg.exe, in this format:
In the same directory as above, save the code below into a command.bat file, then run it.
ffmpeg -f concat -safe 0 -i list.txt output.mp4
-f concat: this forces ffmpeg to use concat mode for the output file.
-safe 0: this is needed if absolute paths are provided as the input.
-i list.txt: the path to the list of input files, if your current working directory is where this file is you can supply the file name only.
output.mp4: the path for the output file.
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:
Resize to specific width and height (may stretch video): ffmpeg -i input.mp4 -vf "scale=1280:720" output.mp4
Resize by width, preserve aspect ratio (height auto-calculated and even): ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
Scale to a percentage of original size (e.g., 50%): ffmpeg -i input.mp4 -vf "scale=iw*0.5:ih*0.5" output.mp4
Fit within a resolution without stretching (add black bars if needed): ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Batch resize all MP4s in a folder to 720p (Linux): for f in *.mp4; do ffmpeg -i "$f" -vf "scale=1280:-2" -c:a copy "resized_$f"; done
Batch resize all MP4s in a folder to 720p (Windows cmd): for %f in (*.mp4) do ffmpeg -i "%f" -vf "scale=1280:-2" -c:a copy "resized_%f"
Batch resize all MP4s in a folder to 720p (Windows .bat): for %%f in (*.mp4) do ffmpeg -i "%%f" -vf "scale=1280:-2" -c:a copy "resized_%%f"
Rotate a Video
To rotate a video using FFmpeg, use the -vf (video filter) option with specific filters:
Rotate 180°: ffmpeg -i input.mp4 -vf "transpose=2,transpose=2" output.mp4 Alternatively, use hflip,vflip for a 180° rotation.
Rotate by any angle (e.g., 45°): Use the rotate filter with radians: ffmpeg -i input.mp4 -vf "rotate=45*PI/180" output.mp4 For 180°, use rotate=PI.
Rotate without re-encoding (metadata only): This preserves quality but may not work on all players: ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4 To copy all metadata: ffmpeg -i input.mp4 -map_metadata 0 -metadata:s:v:0 rotate=90 -codec copy output.mp4
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
Install FFmpeg: Run sudo pacman -S ffmpeg (Arch based distros), sudo apt install ffmpeg (Debian/Ubuntu/Mint) or sudo dnf install ffmpeg (Fedora).
Save: Save the code as script.sh.
Run: Open a terminal in that folder and run: chmod +x script.sh && ./script.sh
Convert multi files to another formatDownloadRemove and clean meta data of multi filesDownload
Windows BAT (.bat) Scripts
How to Use on Windows
Install FFmpeg: Ensure ffmpeg.exe is installed and added to your Windows PATH, or place ffmpeg.exe in the same folder as this script.
Save: Copy the code, paste it into Notepad, and save it as script.bat.
Run: Double-click script.bat in the folder containing your media files.
Convert multi files to another formatDownloadRemove and clean meta data of multi filesDownload
Frame : Frame is a native Rust desktop utility with a GPUI-CE interface for FFmpeg video, audio, image, subtitle, and metadata workflows.
ffmpeg.wasm : ffmpeg.wasm is a pure WebAssembly / JavaScript port of FFmpeg enabling video & audio record, convert and stream right inside browsers!
FFmpeg Online : Run ffmpeg directly in your browser with a terminal-like interface. No installations needed. Convert, edit, and process multimedia files with this powerful web-based tool.