FFmpeg is a powerful libre / free software tool that I use frequently to edit or manipulate videos individually or in bulk. It supports a very wide range of codecs and formats, making it an essential tool for any video hobbyist or professional.

This article aims to provide you with a list of 15 short and handy FFmpeg commands to help you get started with this versatile tool.

The history of FFmpeg dates back to 2000, when Fabrice Bellard, a French programmer, developed it as a collection of libraries and tools for handling multimedia data.

Over the years, FFmpeg has become a widely used and respected tool for video and audio manipulation, thanks to its active community of developers and users.

FFMPEG Basic Commands

Basic conversion

ffmpeg -i INPUT_VIDEO.mov OUTPUT_VIDEO.mp4
  • i Input or stream input. In this case the original video, in .mov format, as an example.
  • The last parameter corresponds to the output. In this case, the converted video.

Extracting audio from a video

ffmpeg -i INPUT_VIDEO.mp4 -vn -c:a mp3 -b:a 128k -ac 2 -ar 44100 YOUR_AUDIO.mp3
    • vn No video.
    • c:a Audio codec.
  • b:a Biterate
  • ac Audio channels
  • ar Audio rate kHz

Extract video without audio

ffmpeg -i YOUR_VIDEO -an -c:v copy OUTPUT
  • an No audio.
  • c:v Video codec. In this case, no codec, just copy.

Extract a part of a video

ffmpeg -ss 00:01:00.000 -i YOUR_VIDEO.mp4 -t 00:00:10.000 -c copy VIDEO_SEGMENT.mp4
  • ss Since it is before the -i option, it will place the start of the stream here. In this case, the start of the cut, in this example right at minute 1, format HH:MM:SS:ms.
  • t The stream duration time. In this case, the duration of the cut, 10 seconds in HH:MM:SS:ms format.

Change the size or resolution of a video.

ffmpeg -i YOUR_INPUT.mov -s 1280x720 YOUR_OUTPUT.mp4
  • s Is the desired output resolution.

Get the length of a video:

fprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal YOUR_INPUT.mp4

This command displays the duration of the video or stream in hours:minutes:seconds:milliseconds format. The ffprobe command is used to get information about the input file.

The -select_streams, -show_entries and -of parameters are used to specify the information to be obtained and the output format.

Adding a logo to a video

ffmpeg -i INPUT VIDEO.mp4 -i LOGO.png -filter_complex "overlay=100:100" -codec:a copy OUTPUT_VIDEO_WITH_LOGO.mp4

This command adds a logo to an existing video.

  • The -i parameter is used to specify both the input video and the logo file.
  • The -filter_complex parameter is used to specify the filter to apply, in this case the overlay filter to add the logo to the video.
  • The numeric parameters (100:100) are used to specify the position of the logo in the video.
  • The -codec:a copy parameter is used to copy the original audio codec without performing any conversion.

Converting a video to an animated GIF

This command converts a video into an animated gif in three steps:

1. Resize the video

ffmpeg -i output.mp4 -vf scale=640x360 -c:v h264 -crf 18 -c:aac OUTPUT_1.mp4

2. Generate the frames in PNG format

ffmpeg -i OUTPUT_1.mp4 framed.png

3. Generate the gif from the frames:

For high quality:

gifski -o GIF_OUTPUT.gif frame*.png

Low quality

ffmpeg -i OUTPUT_1.mp4 GIF_OUTPUT.gif

Create a video from a group of images

ffmpeg -framerate 1 -i imgd.png -r 25 -pix_fmt yuv420p output.mp4

This command creates a video from a series of images.

  • The -framerate parameter is used to specify the desired frame rate
  • The -i parameter is used to specify the filename pattern of the images.
  • The -r parameter is used to specify the desired playback speed (in this case 25 frames per second).
  • The -pix_fmt parameter is used to specify the desired pixel format (in this case, yuv420p).

Generate audio waveforms

ffmpeg -i INPUT_AUDIO.AAC -filter_complex "[0:a]showwaves=mode=cline:s=192020x1080:colors=white[v]" -map '[v]' -map '0:a' -c:a copy -pix_fmt yuv420p OUTPUT_VIDEO.mp4

This command generates a video showing the audio waveforms of an audio file.

  • The -filter_complex parameter is used to specify the filter to apply, in this case the showwaves filter to display the audio waves.
  • The numeric and color parameters are used to specify the size and colors of the video.
  • The -map parameter is used to specify which streams should be included in the output.
  • The -c:a copy parameter is used to copy the original audio codec without performing any conversion.

Change subtitle format

ffmpeg -i YOUTUBE_SUBTITLES.vtt YOUR_SUB.ass

This command converts a subtitle file from VTT format to ASS format.

  • The -i parameter is used to specify the input file
  • The last parameter is used to specify the output file.

Replacing the audio track of a video

ffmpeg -i INPUT_VIDEO.mp4 -i NEW_AUDIO.mp3 -map 0:v -map 1:a -c copy OUTPUT_VIDEO.mp4

This command replaces the audio track of an existing video with a new audio track.

  • The -i parameters are used to specify both the input video and the input audio file.
  • The -map parameters are used to specify which streams should be included in the output (in this case, the video from the first file and the audio from the second file).
  • The -c copy parameter is used to copy the original video and audio codec without performing any conversion.

Extracting metadata from a media file

ffmpeg -i INPUT_FILE -f ffmetadata metadata.txt

This command extracts the metadata from an input file and saves it to a text file.

  • The -f parameter is used to specify the desired output format (in this case, ffmetadata).

Adjusting the volume of an audio

ffmpeg -i INPUT_AUDIO.mp3 -vol 200 OUTPUT_AUDIO.mp3
  • vol 200: sets the volume of the output file. In this case, it is set to 200, which means that the volume will be doubled with respect to the original. Higher values increase the volume, while lower values decrease it.

Extracting images from a video

ffmpeg -i INPUT -f image2 -bt 20M -vf fps=1/1 d.png
  • f image2 It is the filter in charge of creating the image from the video.
  • vf fps=1/2 Frames per second. In this case, the number of images to obtain every second. In the example, 1 image every 2 seconds.

Conclusion

FFmpeg is an incredibly powerful and versatile tool for manipulating and editing videos. The commands we have presented in this article are just a small sample of what you can do with FFmpeg. With a little practice, you can make FFmpeg an indispensable tool in your video editing workflow.

A few years ago, editing or manipulating videos without a user interface was hard for me to imagine. However, once I got used to using it, the efficiency and flexibility FFmpeg offers makes me wonder why I didn’t start using it sooner.