Home > Other External Packages > ffmpeg

ffmpeg: A Powerful Media Conversion and Processing Tool

ffmpeg is a highly powerful and versatile open-source command-line tool used for converting, streaming, recording, and editing audio and video files. It supports almost all media formats and codecs, and offers complex filtering and manipulation capabilities.

Overview

ffmpeg can perform a wide range of tasks including encoding, decoding, transcoding, multiplexing, demultiplexing, streaming, and filtering of media files. It is available on various platforms and is an essential tool for developers and advanced users.

Key Features

  • Conversion between various audio/video formats
  • Filtering such as resizing, cropping, and rotating videos
  • Audio extraction and conversion
  • Streaming media processing
  • Screen recording and webcam capture

Key Options

ffmpeg offers numerous options, but here are some of the most commonly used ones.

Input/Output Control

Video Options

Audio Options

Time Control

Generated command:

Try combining the commands.

Description:

`ffmpeg` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Examples demonstrating various uses of ffmpeg.

Convert MP4 to AVI

ffmpeg -i input.mp4 output.avi

A basic example of file format conversion.

Change Video Resolution (1280x720)

ffmpeg -i input.mp4 -vf scale=1280:720 output_hd.mp4

Changes the resolution of the video to 1280x720.

Extract Audio from Video (MP3)

ffmpeg -i input.mp4 -vn -acodec libmp3lame output.mp3

Extracts only the audio stream from a video file and saves it as an MP3 file.

Trim a Specific Segment of Video

ffmpeg -ss 00:00:10 -i input.mp4 -t 00:00:30 -c copy output_clip.mp4

Trims the video from the 10-second mark for a duration of 30 seconds.

Convert Video to GIF Animation

ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v gif output.gif

Converts a video to a low-size GIF animation. Frame rate and scale are adjusted for optimization.

Installation

ffmpeg is not included by default in most Linux distributions, so it needs to be installed via a package manager.

Debian/Ubuntu

sudo apt update
sudo apt install ffmpeg

Install using the APT package manager.

Fedora/CentOS (dnf)

sudo dnf install ffmpeg

Install using the DNF package manager. (EPEL repository may be required.)

Arch Linux

sudo pacman -S ffmpeg

Install using the Pacman package manager.

Tips & Notes

Tips and points to note for more efficient use of ffmpeg.

Performance Optimization

  • Placing the `-ss` option before `-i` can reduce input file seeking time for faster startup, but may decrease accuracy.
  • Using `-c copy` (stream copy) allows for very fast operations by directly copying streams without encoding/decoding. However, the output container must support the input streams.

Understanding Codecs

  • It is important to understand video codecs (e.g., `libx264`, `libvpx-vp9`) and audio codecs (e.g., `aac`, `libmp3lame`). Choosing the appropriate codec significantly impacts file size and quality.
  • Some codecs may not be included in the default installation and might require additional library installations.

Utilizing Filter Graphs

  • Complex media manipulations can be performed using the `-vf` (video filter) and `-af` (audio filter) options. Multiple filters can be chained together using commas (`,`) or semicolons (`;`).

Same category commands