Using FFmpeg Video Editor

What Is It?

FFmpeg is a powerful multimedia framework that can decode, encode, transcode, mux, demux, stream, filter, and play just about anything that humans and machines have created. It's the Swiss Army knife of audio and video processing.

This command-line (CLI) utility is what’s under the hood of many open-source and commercial software applications. With its extensive range of codecs and formats, ffmpeg enables developers to build robust media processing tools without having to reinvent the wheel. Whether it's for converting video formats, extracting audio, or streaming live media, ffmpeg provides the essential functionality that powers countless media workflows.

Do I Need It?

You do if you need to apply the same transformations to many files. As a CLI tool, FFmpeg is incredibly efficient and scriptable, making it perfect for batch processing. If you often find yourself converting file formats, resizing videos, extracting audio, or performing any repetitive media tasks, FFmpeg can save you a lot of time and effort. Its ability to automate these processes through scripts can streamline your workflow and increase productivity.

Sounds Complicated…

Anything worthwhile usually is, but FFmpeg's complexity comes with immense power and flexibility. Once you get the hang of the basic commands, you'll find it much easier to handle a variety of multimedia tasks. There are plenty of tutorials and resources available to help you get started, and once you've got it down, you'll wonder how you ever managed without it.

OK, What Do I Need?

First, you need to install FFmpeg on your system. It’s available for Windows, macOS, and Linux. Here’s a quick guide:

  1. Windows: Download the latest FFmpeg build from the official website. Extract the contents and add the `bin` folder to your system's PATH.
  2. macOS: You can use Homebrew by running `brew install ffmpeg` in the terminal.
  3. Linux: Most distributions have FFmpeg available in their repositories. Use your package manager (e.g., `sudo apt install ffmpeg` for Ubuntu).

Once installed, familiarize yourself with some basic commands by checking the official documentation or beginner tutorials. The more you experiment, the more comfortable you'll become with using this powerful tool.

While you can install ffmpeg on Windows directly, a better option may be installing it under the Windows Subsystem for Linux (WSL). This will allow you to take full advantage of the myriad of other CLI tools that can be used in combination with ffmpeg. You will also be able to harness the power of Bash shell scripting, which is far superior to anything Windows has to offer. Here’s a quick startup guide.

When ffmpeg is released for various operating systems, some of its features may be excluded for one reason or another. If a particular feature that you need is not available, ffmpeg can be compiled from the source code with the list of the specific features that you require. Check out these instructions for Linux.

To get some idea about how to use ffmpeg and what it can do, check out some of these examples.

Practical Examples

Let’s go over a few common use-case scenarios where ffmpeg’s batch processing capabilities are particularly handy.

Video Stabilization

Videos taken with your phone or a photo camera generally suffer from significant shake and jitter, making them look unprofessional. This is because the image stabilization technology implemented in phones and photo cameras is geared toward taking photos—not videos.

I have this video clip taken with my iPhone 14 - 2023-08-18_16-28-05_IMG_6679.MOV. The first step is to analyze the video and create a stabilization transformation file containing all the technical details about how shaky the video is:

ffmpeg -i 2023-08-18_16-28-05_IMG_6679.MOV -vf vidstabdetect=shakiness=10:accuracy=15 -f null -

The second step is to use that information to create a stabilized version of the original video:

ffmpeg -i 2023-08-18_16-28-05_IMG_6679.MOV -vf vidstabtransform=smoothing=30:input="transforms.trf" -c:v libx264 -preset veryfast -crf 12 -tune film 2023-08-18_16-28-05_IMG_6679_stabilized.MOV

Finally - and this is optional - we can create a side-by-side view that makes comparing the before and after versions easy:

ffmpeg -i 2023-08-18_16-28-05_IMG_6679.MOV -i 2023-08-18_16-28-05_IMG_6679_stabilized.MOV -vcodec libx264 -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w" 2023-08-18_16-28-05_IMG_6679_sbs.MOV

You can read more about the ffmpeg options used in this example here. Here’s a side-by-side view from the example above.

Igor Os

I’m a computer engineer, musician, cyclist dabbling in photography. I’m not trying to sell you anything. All photos are my own.

https://igoros.com