FFmpeg is a powerful and versatile command-line tool for handling multimedia data. Whether you're a casual user or a seasoned pro, FFmpeg offers a treasure trove of tricks for video and audio editing on Linux. The benefit of using this command line tool is that you can do a mass edit and by combining it with a shell script to many advanced tricks that save many hours of hard work. Here are ten tips and tricks to help you get the most out of this amazing tool.
1. Trim a Video Without Re-encoding
Need to cut out a portion of a video quickly? Use FFmpeg to trim videos without losing quality:
ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:30 -c copy output.mp4
- -ss: Start time.
- -to: End time.
- -c copy: Avoids re-encoding for faster processing.
2. Extract Audio from Video
Want just the audio from a video file? This command extracts it in its original format:
ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
- -q:a 0: Ensures the best audio quality.
- -map a: Maps only the audio stream.
3. Convert Video to GIF
Create an animated GIF from a video file effortlessly:
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" output.gif
- fps=10: Sets the frame rate to 10 frames per second.
- scale=320:-1: Resizes the width to 320 while maintaining the aspect ratio.
4. Merge Videos Together
Combine multiple video files into one seamlessly:
Create a text file (file_list.txt) with the paths of the files to merge:
file 'part1.mp4' file 'part2.mp4'
Run the command:
ffmpeg -f concat -safe 0 -i file_list.txt -c copy output.mp4
5. Add Subtitles to a Video
Hardcode subtitles into a video using FFmpeg:
ffmpeg -i video.mp4 -vf subtitles=subtitles.srt output.mp4
- Replace subtitles.srt with your subtitle file.
6. Compress Video Files
Reduce the size of a video file while maintaining decent quality:
ffmpeg -i input.mp4 -vcodec libx264 -crf 28 output.mp4
- libx264: Uses the H.264 codec for compression.
- -crf: Lower values mean better quality; 28 is a good balance for small size.
7. Speed Up or Slow Down Video
Adjust playback speed by modifying the frame rate:
- Speed up by 2x:
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4
- Slow down by 2x:
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" output.mp4
8. Extract Frames from a Video
Save individual frames as images:
ffmpeg -i video.mp4 -vf fps=1 frame_%03d.png
- fps=1: Saves one frame per second.
- frame_%03d.png: Generates filenames like frame_001.png.
9. Normalize Audio Levels
Ensure consistent audio volume across files:
ffmpeg -i input.mp4 -af loudnorm output.mp4
- loudnorm: Applies EBU R128 loudness normalization.
10. Overlay a Logo or Watermark
Add a watermark to your video:
ffmpeg -i video.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4
- overlay=10:10: Positions the logo 10 pixels from the top-left corner.
Conclusion
FFmpeg is a Swiss Army knife for multimedia editing, offering endless
possibilities for video and audio manipulation. Whether you’re
extracting, converting, or enhancing media files, these tricks will help
you work smarter and faster. Got more FFmpeg tips? Share them in the
comments below!