The ffmpeg command in Linux: converting and processing audio and video

Introduction

FFmpeg is a cross‑platform command‑line tool that allows you to convert, compress, filter, and stream virtually any audio and video format. On Linux it has become the de facto standard for multimedia tasks thanks to its large number of built‑in codecs and its ability to work via scripts. This post shows the most useful commands for beginners and advanced users, explaining the basic syntax, quality parameters, and some practical examples you can adapt to your workflow.

Installing ffmpeg

In most Linux distributions ffmpeg is available in the official repositories. On Ubuntu or Debian simply run sudo apt update && sudo apt install ffmpeg. On Fedora use sudo dnf install ffmpeg and on Arch Linux sudo pacman -S ffmpeg. If you need the latest version with all codecs, you can compile from source or use snap/flatpak packages. Verify the installation with ffmpeg -version.

Basic format conversion

Converting a video file to another format is as simple as specifying the input and output files. For example, to go from MKV to MP4 without re‑encoding the video and only copying the streams, use:

  • ffmpeg -i input.mkv -c copy output.mp4
  • ffmpeg -i input.wav -ar 44100 -ac 2 output.mp3 to convert WAV audio to MP3 with a 44.1 kHz rate and stereo.

The -c copy parameter tells FFmpeg to copy the stream without re‑compression, saving time and avoiding quality loss. When you need to change resolution or bitrate, add options such as -vf scale=1280:720 or -b:v 2M.

Audio processing

FFmpeg lets you extract, mix, and apply effects to audio tracks. To extract the audio track from a video and save it as AAC, run:

  • ffmpeg -i video.mov -vn -c:a aac -b:a 192k audio.aac

The -vn flag discards the video. To normalize volume you can use the loudnorm filter:

  • ffmpeg -i input.wav -af loudnorm=I=-16:TP=-1.5:LRA=11 output.wav

In addition, you can concatenate several audio files with the concat demuxer or create a fade‑in/fade‑out using afade.

Video processing

In the video domain, video filters (-vf) allow scaling, cropping, changing speed, and applying color effects. A typical example is reducing resolution to 720p and limiting the bitrate to 2 Mbps:

  • ffmpeg -i input.mkv -vf scale=1280:720 -b:v 2M -c:a aac -b:a 128k output.mp4

To create a timelapse you can speed up the video with setpts:

  • ffmpeg -i input.mkv -vf 'setpts=0.5*PTS' output.mp4

If you need to burn in subtitles, use -c:s mov_text for MP4 or -c:s srt for MKV.

Advanced examples: filters and concatenation

FFmpeg chains multiple filters separated by commas. For example, apply a Gaussian blur and then adjust brightness:

  • ffmpeg -i input.mp4 -vf 'gblur=sigma=2,eq=brightness=0.06:saturation=1.2' output.mp4

Concatenating several clips is done by creating a list file (mylist.txt

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .