Practical examples of FFmpeg commands for converting formats on Linux

Last update: 09/05/2025
Author Isaac
  • Master video and audio conversion and editing in Linux with FFmpeg from the terminal using commands clear and personalized.
  • Discover comprehensive examples for changing formats, adjusting quality, extracting tracks, or working with images and subtitles.
  • Learn how to automate repetitive multimedia conversion and processing tasks, optimizing your workflow on Linux.

ffmpeg

FFmpeg is considered one of the most robust and versatile pillars of multimedia processing on Linux, making it a must-have for those seeking flexibility and absolute control from the terminal. Despite the existence of graphical programs, the console offers precision, speed, and the ability to automate all types of audiovisual tasks. FFmpeg can convert formats, adapt files for devices, extract tracks, trim fragments, modify quality, manage subtitles and much more, handling both audio and video. and even images, all with a few well-structured commands.

In this extensive article, we have compiled and rewritten in detail the most comprehensive and advanced information from the best ranking articles in Google to convert formats and manipulate files with FFmpeg on Linux. Here you will not only find the basic commands, but also the Tricks, parameters and practical examples that cover everything from installation, mass file conversion, metadata editing, and quality optimization, to troubleshooting common issues and advanced cases such as automation, working with subtitles, TV compatibility, and audio and video synchronization.

What is FFmpeg and why use it on Linux?

FFmpeg is a set of programs and libraries developed for the management, conversion, transmission and analysis of multimedia files. Born under the umbrella of free software, it stands out for its compatibility with an immense amount of codecs and containers. Although it exists for Windows y Mac, its integration into the Linux world is legendary: many graphical applications use FFmpeg as an internal engine, and in servers or scripts, it is unrivaled.

The main advantage of FFmpeg is the power of the terminal: You can manipulate large volumes of data, automate workflows, and customize every technical aspect of your media file. Its flexibility makes it useful for both novice users, simply looking to change formats, and experts who need to adjust specific parameters for each file or perform advanced post-processing.

Installing FFmpeg on Linux

Installing FFmpeg is straightforward on most Linux distributions. It is usually found in the official repositories:

  • Debian, Ubuntu and derivatives: sudo apt install ffmpeg
  • Arch, Manjaro: sudo pacman -S ffmpeg
  • Fedora, CentOS, openSUSE: sudo dnf install ffmpeg

Check that FFmpeg is correctly installed by running ffmpeg -version o which ffmpegIf the route appears, you can start working.

Key concepts: codecs, formats and containers

ffmpeg

Before diving into the commands, it's a good idea to understand a few concepts:

  • Codec: Algorithm that compresses and decompresses audio or video. Examples: h264, xvid, mp3, aac.
  • Format or container: A file that groups video, audio, subtitle, and metadata tracks. Examples: mp4, mkv, avi, mov, webm.
  • Parameters: Specific options to adjust bitrate, resolution, fps, audio channels, etc.

FFmpeg supports a multitude of combinations, but the result depends on compatibility between codecs and containers. Not all formats support all track types, nor are all configurations equally compatible on all devices.

Basic FFmpeg syntax and command structure

The general structure of any FFmpeg command is:

ffmpeg -i archivo_entrada archivo_salida

Some important points:

  • Options apply to the input or output file that follows. The order matters.
  • You can have multiple input and output files, manipulating each with indexes.
  • If no output file is specified, FFmpeg will only display the information in the console, it will not generate a new file.
  • Global options (e.g. verbosity level) go at the beginning.
  How do I set up Google Translate to work with my microphone? Improving its performance

For example, to convert an AVI file to MP4:

ffmpeg -i video.avi video.mp4

And if you want to set a specific parameter, such as video bitrate at 2500 kb/s and audio bitrate at 192 kb/s:

ffmpeg -i video.avi -b:v 2500k -b:a 192k video_final.mp4

Essential commands for format conversion

Change the format of a video or audio

  • From MP4 to AVI:
    ffmpeg -i entrada.mp4 salida.avi
  • From MKV to MP4:
    ffmpeg -i original.mkv convertida.mp4
  • From AVI to MPG (MPEG):
    ffmpeg -i video.avi video.mpg
  • From FLV to MPEG:
    ffmpeg -i video.flv video.mpeg
  • From MOV to MP4:
    ffmpeg -i archivo.mov resultado.mp4

The output format is defined only by changing the extension, but if you want to force a codec or certain features, add the necessary parameters:

ffmpeg -i entrada.mov -c:v libx264 -c:a aac salida.mp4

Convert audio between formats

  • From WAV to MP3:
    ffmpeg -i cancion.wav nueva.mp3
  • From WMA to MP3:
    ffmpeg -i audio.wma -f mp3 -ab 192 audio.mp3
  • From FLAC to OGG:
    ffmpeg -i original.flac destino.ogg

You can also change parameters such as codec, bit rate, channels, or sampling:

ffmpeg -i sonido.flac -acodec libmp3lame -ab 128k -ar 44100 nuevo.mp3

Practical example: converting multiple files

To batch convert files in a folder, use a loop in bash:


for archivo in *.avi; do
ffmpeg -i "$archivo" "${archivo%.avi}.mp4"
done

This will convert all the AVI files in the folder into MP4 files.

Quality control and adjustment of key parameters

Video and audio bitrate

  • Videographer: -b:v 3000k (3000 kbps)
  • Audio: -b:a 192k (192 kbps)

You can adjust the quality depending on the use. For example, for mobile devices You can reduce the resolution and bitrate:

ffmpeg -i entrada.mkv -vf scale=1280:720 -b:v 1500k salida.mp4

And for lighter audios:

ffmpeg -i cancion.wav -b:a 96k cancion_compacta.mp3

Change the resolution and aspect ratio

  • To force a specific output resolution:
    ffmpeg -i entrada.mp4 -s 1280x720 salida_720p.mp4
  • To change the aspect ratio:
    ffmpeg -i entrada.mp4 -aspect 16:9 salida_16_9.mp4

Sometimes certain devices require specific pixel formats, such as LG TVs that need -pix_fmt yuv420p: more about pixel compatibility.

Change the frame rate per second (FPS)

To change or force an FPS number:

ffmpeg -i original.mp4 -r 30 salida_30fps.mp4

Remember that changing the resolution or frame rate does not improve the original quality, although it may be necessary for compatibility.

Information extraction and file analysis

Before converting, it is essential to know the file characteristics:

ffmpeg -i archivo.ext

This will display the codec, duration, quality, channels and metadata in the console.

If you want the output to be cleaner, add -hide_banner: More about analytics and metadata.

ffmpeg -hide_banner -i archivo.ext

For comprehensive and customizable analysis, use ffprobe: More about ffprobe and advanced analysis.

ffprobe -i archivo.ext -print_format json -show_format -show_streams

This way you get all the information structured in JSON.

Advanced editing and manipulation of multimedia files

Edit metadata

  • Export metadata from an MP3 file:
    ffmpeg -i cancion.mp3 -f ffmetadata metadata.txt
  • Modify and import metadata:
    ffmpeg -i original.mp3 -metadata artist='Nuevo Artista' -acodec copy salida.mp3

You can edit information such as artist, album, genre, year, track, etc. Ideal for organizing your music or adapting it to demanding players (for example, Apple).

Extract audio tracks or remove audio/video

  • Extract audio only without re-encoding:
    ffmpeg -i original.avi -vn -acodec copy solo_audio.mp3
  • Extract converted audio to another format (e.g. from a video):
    ffmpeg -i video.mp4 -q:a 0 -map a solo_audio.mp3
  • Remove all audio tracks from a video:
    ffmpeg -i original.avi -map 0 -map -0:a -c copy sin_audio.avi
  • Delete all audio streams except specific ones:
    ffmpeg -i original.avi -map 0 -map -0:a:3 -map -0:a:6 -c copy con_dos_streams.avi
  • Extract only a specific audio track:
    ffmpeg -i original.avi -map 0:a:2 -c copy solo_pista2.avi

Extract images or create videos from images

  • Extract all frames as images:
    ffmpeg -i video.mp4 imagen%d.jpg
  • Extract one frame every second:
    ffmpeg -i video.mp4 -vf fps=1 imagen%d.jpg
  • Extract only the keyframes:
    ffmpeg -i video.avi -vf "select=eq(pict_type\,I)" -vsync vfr imagen%d.jpg
  • Create a video from a sequence of images:
    ffmpeg -i imagen%d.jpg video.avi
  • Create a video with a custom framerate:
    ffmpeg -framerate 1 -i img%03d.png -r 25 -pix_fmt yuv420p salida.mp4

Convert video to animated GIF

FFmpeg lets you transform a video clip into an animated GIF, useful for memes and social media:

  Keys to choosing the best font for Windows 11

ffmpeg -i original.mp4 -vf "scale=320:-1" animado.gif

For higher quality, extract the frames first and use a tool like gifski:

ffmpeg -i original.mp4 frame%04d.png
gifski -o salida.gif frame*.png

Convert between 4K, FullHD, HD resolutions…

  • From 4K to FullHD (changing container):
    ffmpeg -i 4k.mkv -vf scale=1920:1080 -q:a 0 -q:v 0 1080p.avi
  • From FullHD to HD:
    ffmpeg -i fullhd.mkv -vf scale=1280:720 -b:v 2000k hd.mp4
  • From FullHD to 4K:
    ffmpeg -i 1080p.mkv -vf scale=3840:-1 4k.mkv

Editing fragments: cutting, joining, trimming, and combining files

Cut a video or audio fragment

To extract a specific chunk of a file:

ffmpeg -ss 00:00:30 -t 00:00:15 -i original.mp4 -c copy fragmento.mp4

This cuts from second 30, with a duration of 15 seconds. If you want to define the end instead of the duration, use -to:

ffmpeg -ss 00:00:35 -to 00:01:05 -i original.mp4 -c copy fragmento.mp4

You can also cut from the beginning to a point:

ffmpeg -t 00:01:36 -i original.mp4 -c copy recortado.mp4

Merge multiple videos into one

The most reliable method is through file lists and filtering concat: More about joining files with FFmpeg

  1. Create a text file (for example, lista.txt) with the names of the videos:
file 'part1.mp4' file 'part2.mp4'
  1. Run:

ffmpeg -f concat -safe 0 -i lista.txt -c copy resultado.mp4

This method is fast and does not recompress, but the videos must have identical codecs.

Combine audio and video from different files

You can merge an audio file with a video file:

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental final.mp4

To replace the audio track of a video:

ffmpeg -i video.mp4 -i nuevo_audio.mp3 -map 0:v -map 1:a -c copy video_con_nuevo_audio.mp4

Automation: Batch Conversion and Scripting

One of FFmpeg's strengths is automating processes using bash scripts. You can change the format of hundreds of files with just a few lines:


IFS=$'\n'
for i in *.webm; do ffmpeg -i "$i" "${i/%.webm/.mp3}"; done; unset IFS

With similar loops you can convert .flv to .ogg, or any other combination. Remember that in names with spaces, the use of IFS is fundamental.

Bug fixes and compatibility

Repair problematic files

Some videos may not perform well on devices such as Smart TVs. This can be resolved by generating an unencoded copy in FFmpeg:

ffmpeg -i video_orig.avi -c:v copy -c:a copy reparado.avi

If there are problems with the resolution, you can force -vf "setdar=16:9,setsar=1:1" to set the appropriate aspect ratio. More information on compatibility with different formats and devices is available at tools to convert virtual disks.

Optimize for maximum compatibility

If you need an MKV file to work on almost all TVs, use:

ffmpeg -i original.mkv -c:a libmp3lame -pix_fmt yuv420p compatible.mkv

Sometimes audio codecs can cause problems, so choose MP3 or AAC for maximum compatibility.

Other advanced tasks and operations

Extract and add subtitles

  • Convert subtitles from .vtt to .ass:
    ffmpeg -i subtitulos.vtt salida.ass
  • Add subtitles to a video:
    ffmpeg -i video.mp4 -i subtitulos.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast salida.mkv

Remove subtitles and other streams

ffmpeg -i entrada.mkv -map 0:v -map 0:a -c copy solo_video_audio.mkv

Add watermarks or logos

You can add an image (PNG with transparency, for example) in any corner:

  16 pregnancy gifts for first-time mothers

ffmpeg -i video.mp4 -i logo.png -filter_complex "overlay=10:10" salida.mp4

To place the logo in the lower right corner:

ffmpeg -i video.mp4 -i logo.png -filter_complex "overlay=W-w-10:H-h-10" salida.mp4

Adjust volume or clear audio

  • Increase volume by multiplying x3.5:
    ffmpeg -i entrada.mkv -filter:a "volume=3.5" -c:v copy -acodec mp3 salida.mkv
  • Remove background noise (requires sox):
    Extract the noise fragment first
    ffmpeg -i entrada.mp3 -ss 00:00:00 -t 1 ruido.mp3
    After:
    sox entrada.mp3 limpio.mp3 noisered noise.prof 0.21

Synchronize audio and video

If you detect desynchronization, delay the audio or video with -itsoffset o -af adelay:

ffmpeg -itsoffset 1.7 -i video.mkv -i video.mkv -map 0:0 -map 1:1 -acodec copy -vcodec copy sincronizado.mkv

In simpler cases to delay the audio by 1.7 seconds:

ffmpeg -i video1.webm -af "adelay=1700|1700" -vcodec copy video_sincronizado.webm

Concatenate videos with different codecs or formats

When the files do not have the same codec and parameters, it is best to recode them first or use concat with transcoding. You can also check out .

ffmpeg -f concat -i lista.txt -c:v libx264 -c:a aac -strict experimental salida.mp4

Rotate Videos

To rotate a video 90 degrees to the right:

ffmpeg -i original.mov -vf "transpose=1" -c:a copy rotado.mov

For 180 degrees:

ffmpeg -i original.mov -vf "transpose=2,transpose=2" -c:a copy rotado.mov

Loop a video

ffmpeg -stream_loop 2 -i original.mp4 -c copy loop.mp4

The number indicates the repetitions; use -1 for infinity.

Stabilize shaky videos

For unstable videos:

  1. Detects motion:
    ffmpeg -i tembloroso.avi -vf vidstabdetect=stepsize=6:shakiness=3:accuracy=9:result=vectors.trf -f null -
  2. Correct the video:
    ffmpeg -i tembloroso.avi -vf vidstabtransform=input=vectors.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy corregido.avi

Playback speed

To speed up or slow down a video:

  • Accelerate x2:
    ffmpeg -i video.mpg -vf "setpts=0.5*PTS" rapido.mpg
  • Slow down x4:
    ffmpeg -i video.mpg -vf "setpts=4.0*PTS" lento.mpg

Record video from your desktop or streaming

  • Record desktop (FullHD) and audio:
    ffmpeg -f alsa -i default -f x11grab -s 1920x1080 -r 30 -i :0.0 -preset ultrafast -vcodec libx264 -tune zerolatency -f mpegts tcp://IP_DESTINO:4444
  • Record from webcam:
    ffmpeg -f v4l2 -i /dev/video0 -preset ultrafast salida.webm

Automate mass editing and repetitive tasks

Combine FFmpeg into bash scripts, python or any language that handles processes for converting, renaming, and processing hundreds of files at once. Example of automatic slicing using a file with a task list and a script that will traverse the entire directory and execute the appropriate commands for each file as needed.

Automatically change multiple file formats

Use custom loops or scripts. For example, to convert all the .wav files on a CD to MP3 and save them in a folder:


cd /ruta/al/cd
mkdir ~/MP3s
IFS=$'\n'
for i in *.wav; do ffmpeg -i "$i" ~/MP3s/"${i/%.wav/.mp3}"; done; unset IFS

Advanced case: converting DVD, Blu-ray or ISO content

  1. Mount the ISO image on your system.
  2. Identifies video fragments (usually .VOB for DVD, .m2ts for BluRay).
  3. Concatenate large files to get the full movie:
    cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB > pelicula.vob
  4. Check the streams:
    ffmpeg -probesize 4G -analyzeduration 4G -i pelicula.vob
  5. Select only the necessary streams (video and audio in Spanish, for example):
    ffmpeg -i pelicula.vob -q:a 0 -q:v 0 -map 0:1 -map 0:2 pelicula_es.mkv

The whole process is adaptable to needs, and you can include subtitles or alternative tracks using the appropriate parameters. -map.