DEV Community

Picoable
Picoable

Posted on • Originally published at bashlinux.picoable.com

Awesome FFmpeg Tricks for Video and Audio Manipulation

FFmpeg is the swiss army knife of multimedia processing. It’s a free and open-source command-line tool that can handle virtually any video or audio format. Whether you're a developer, a content creator, or just someone who wants to have more control over their media files, FFmpeg is an essential tool to have in your arsenal. Here are some awesome tricks to get you started.

Get Media File Information

Before you start manipulating a file, you can get detailed information about it, including its codecs, resolution, and duration.

ffmpeg -i input.mp4
Enter fullscreen mode Exit fullscreen mode

Convert Video and Audio Formats

One of the most basic and useful features of FFmpeg is format conversion.

To convert a video from .mov to .mp4:

ffmpeg -i input.mov output.mp4
Enter fullscreen mode Exit fullscreen mode

To extract the audio from a video and save it as an MP3:

ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 192k -f mp3 output.mp3
Enter fullscreen mode Exit fullscreen mode

Trim and Cut Videos

Easily cut a video to a specific length by providing a start time and an end time.

ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:40 -c copy output.mp4
Enter fullscreen mode Exit fullscreen mode

Using -c copy is a great trick because it avoids re-encoding the video, which is much faster and preserves the original quality.

Create a GIF from a Video

Animated GIFs are a great way to share short video clips. FFmpeg makes creating them a breeze.

ffmpeg -i input.mp4 -ss 00:00:10 -t 5 -vf "fps=10,scale=320:-1:flags=lanczos" output.gif
Enter fullscreen mode Exit fullscreen mode

This command creates a 5-second GIF starting at the 10-second mark, with a frame rate of 10 fps and a width of 320 pixels.

Extract Images from a Video

Need to grab some frames from a video? FFmpeg can do that too.

ffmpeg -i input.mp4 -r 1 -f image2 image-%3d.png
Enter fullscreen mode Exit fullscreen mode

This command will extract one frame every second and save it as a PNG image with a numbered sequence (image-001.png, image-002.png, etc.).

Conclusion

These are just a handful of the many tricks you can perform with FFmpeg. It’s a deep and powerful tool, and the best way to learn is to experiment. For more information, you can always consult the extensive official documentation. Happy encoding!

Top comments (0)