How to Install and Use FFmpeg on Ubuntu 24.04
Complete guide to install and use FFmpeg on Ubuntu 24.04 LTS: video transcoding, audio extraction, hardware acceleration, and CLI examples.

6 min read
Complete guide to install and use FFmpeg on Ubuntu 24.04 LTS: video transcoding, audio extraction, hardware acceleration, and CLI examples.
- Prerequisites and Supported Releases
- Step 1: Installing FFmpeg via the Official Ubuntu Repositories
- Step 2: Verifying FFmpeg Installation and Supported Encoders
Digital media workflows, automated web processing pipelines, and video streaming architectures require robust tooling capable of handling hundreds of legacy and modern multimedia container formats. When you install and use ffmpeg on ubuntu 24.04, you deploy an open-source multimedia powerhouse capable of decoding, encoding, muxing, demuxing, streaming, filtering, and playing virtually any format ever created.
Ubuntu 24.04 LTS includes FFmpeg 6.1 (codenamed 'Heaviside') in its official universe repository, providing out-of-the-box support for AV1, HEVC/H.265, H.264/AVC, VP9, Opus, and modern hardware acceleration interfaces. This comprehensive guide details installation methods, fundamental conversion syntax, practical video optimization recipes, and production troubleshooting.
FFmpeg is the industry-standard multimedia framework for recording, transcoding, streaming, and editing audio and video files. This tutorial guides you through how to install and use FFmpeg on Ubuntu 24.04 LTS, with verified examples for video format conversion, audio extraction, video compression, thumbnail generation, and GPU hardware acceleration.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- An active installation of Ubuntu 24.04 LTS running on a desktop or server.
- A user account with sudo administrative privileges.
- Terminal access and basic familiarity with executing Linux command-line operations.
- At least 2 GB of free disk storage for media processing buffers.
Step 1: Installing FFmpeg via the Official Ubuntu Repositories
Installing libavcodec-extra ensures that extra restricted codecs and patent-encumbered algorithms (such as certain proprietary AAC and MP3 encoding profiles) are available for encoding pipelines.
# Update local package index
sudo apt update
# Install FFmpeg and auxiliary codec packages
sudo apt install -y ffmpeg libavcodec-extra
Step 2: Verifying FFmpeg Installation and Supported Encoders
Verify the installed build version and confirm that the FFmpeg executable is accessible in your system's PATH.
Run the ffmpeg -version command to display configuration flags and library build details.
# Check the installed FFmpeg version
ffmpeg -version
# Sample output excerpt:
# ffmpeg version 6.1.1-3ubuntu1 Copyright (c) 2000-2023 the FFmpeg developers
# built with gcc 13 (Ubuntu 13.2.0-23ubuntu4)
# configuration: --prefix=/usr --enable-gpl --enable-gnutls --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
Listing Available Audio and Video Codecs
FFmpeg supports hundreds of encoders and decoders. You can inspect all compiled video and audio encoders to ensure your required format is supported.
# List all compiled video encoders
ffmpeg -encoders | grep -E '^[ V]' | head -n 15
# Search specifically for modern H.264, HEVC, and AV1 encoders
ffmpeg -encoders | grep -E '(x264|x265|av1|libaom)'
Step 3: Basic Video Conversion and Format Transcoding
The fundamental syntax of FFmpeg follows a clean structure: ffmpeg [input_options] -i input_file [output_options] output_file.
To convert a high-bitrate AVI or MKV video into an MP4 file using the universally compatible H.264 video codec and AAC audio codec, execute the following command:
# Convert MKV video to universally compatible MP4 (H.264 + AAC)
ffmpeg -i video_input.mkv -c:v libx264 -c:a aac output_web.mp4
Fast Transcoding with Stream Copying (-c copy)
If your source video already contains H.264 video streams but resides inside an MKV or WebM container, you do not need to re-encode the pixels. Re-muxing the container takes only seconds and preserves 100% of the original video quality.
# Remux MKV container to MP4 container without re-encoding video frames
ffmpeg -i input_capture.mkv -c copy output_packaged.mp4
Step 4: Compressing Videos and Controlling Quality with CRF
Video compression requires balancing visual fidelity against final file size. FFmpeg's libx264 and libx265 encoders utilize Constant Rate Factor (CRF) rate control for predictable visual quality.
The CRF scale for libx264 ranges from 0 (lossless) to 51 (worst quality), with 23 as the default. A value between 18 and 24 yields visually indistinguishable quality from the source with massive size reductions.
# Compress video with CRF 22 and the 'slow' compression preset
ffmpeg -i raw_screen_recording.mov -c:v libx264 -crf 22 -preset slow -c:a aac -b:a 192k compressed_video.mp4
| Preset Name | Encoding Speed | Compression Efficiency | Best Use Case |
|---|---|---|---|
| ultrafast | Instantaneous | Lowest (larger file) | Live capture, test pipelines |
| veryfast | Fast | Moderate | Rapid preview generation |
| medium | Balanced | Standard (Default) | General ad-hoc conversions |
| slow | Deliberate | High (smaller file) | Production web asset publishing |
| veryslow | Intensive | Maximum compression | Archival storage |
Step 5: Extracting and Converting Audio Streams
FFmpeg makes it trivial to strip video streams entirely and save the audio track as an MP3, AAC, or Opus file.
Use the -vn flag (video none) to disable video processing and output pristine audio.
# Extract audio track from an MP4 video and convert to high-quality MP3 (192 kbps)
ffmpeg -i interview_recording.mp4 -vn -c:a libmp3lame -b:a 192k audio_track.mp3
# Extract pristine, uncompressed WAV audio for sound engineering
ffmpeg -i lecture.mp4 -vn -c:a pcm_s16le output_audio.wav
Step 6: Resizing Videos and Generating Thumbnails
Video scaling is executed through FFmpeg's video filter graph using the -vf flag. To resize a 4K or 1080p video down to 720p while preserving aspect ratio, scale the horizontal width and set the height to -2 (ensuring the dimension is an even number required by H.264).
# Scale video to 720p (1280px width, proportional height divisible by 2)
ffmpeg -i 4k_source.mp4 -vf "scale=1280:-2" -c:v libx264 -crf 23 -c:a copy video_720p.mp4
# Extract a single representative thumbnail frame at the 15-second mark
ffmpeg -ss 00:00:15 -i video_input.mp4 -vframes 1 -q:v 2 thumbnail.jpg
Step 7: Trimming and Slicing Media Clips
To extract a specific segment of a video file without re-encoding the entire duration, specify the start timestamp with -ss and the duration with -t.
Placing -ss before -i utilizes keyframe seeking, enabling instantaneous seeking through multi-gigabyte media files.
# Extract a 30-second clip starting at minute 2 (00:02:00) using stream copy
ffmpeg -ss 00:02:00 -i full_webinar.mp4 -t 00:00:30 -c copy highlight_clip.mp4
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Unknown encoder 'libx264' or 'libmp3lame'.
Cause: FFmpeg was compiled without external codec support or restricted package dependencies are missing.
Resolution: Ensure the universe repository is active and install libavcodec-extra: sudo add-apt-repository universe && sudo apt install -y libavcodec-extra ffmpeg.
sudo apt install --reinstall libavcodec-extra
Width or height not divisible by 2 error during H.264 encoding.
Cause: The H.264 codec requires macroblock dimensions that are divisible by 2.
Resolution: Use the pad or scale filter to guarantee even pixel boundaries: -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2".
ffmpeg -i input.mp4 -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' output.mp4
Audio and video are out of sync after trimming.
Cause: Seeking directly to a keyframe (-ss before -i) without decoding audio timestamps can misalign audio stream headers.
Resolution: Re-encode streams or add -avoid_negative_ts make_zero when slicing: ffmpeg -ss 00:01:00 -i in.mp4 -t 30 -avoid_negative_ts make_zero out.mp4.
ffmpeg -ss 00:01:00 -i in.mp4 -t 30 -avoid_negative_ts make_zero out.mp4
Security Best Practices and Hardening
When running FFmpeg on servers processing untrusted user-uploaded media files, enforce strict container and protocol whitelisting (-protocol_whitelist file,crypto,data) to guard against Server-Side Request Forgery (SSRF) vulnerabilities in HLS/m3u8 playlists.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install Python and Pip on Ubuntu 24.04 LTS — Build automated Python scripting pipelines using the ffmpeg-python wrapper.
- How to Uninstall Software Packages on Ubuntu — Safely remove media codecs and obsolete software packages from Ubuntu.
- How to Check Your Ubuntu Version — Verify your Ubuntu 24.04 architecture and kernel specifications before building media pipelines.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
-c:v h264_nvenc or -c:v hevc_nvenc.-c copy flag demuxes the input container and remuxes streams directly into the target container without decoding and re-compressing frames. It completes almost instantly without CPU load and suffers zero generation loss.for f in *.mkv; do ffmpeg -i "$f" -c:v libx264 -c:a aac "${f%.mkv}.mp4"; done.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!