A powerful command-line tool for all your multimedia conversion needs
Recently, I needed to create a .FLV file in Ubuntu from a .MOV for the Jungle Jim’s video. During this process, I discovered FFmpeg—an incredibly versatile command-line tool that makes converting between media formats remarkably simple.
FFmpeg is a powerful, open-source multimedia framework that can decode, encode, transcode, mux, demux, stream, filter, and play nearly any type of media. It’s the Swiss Army knife of multimedia processing, relied upon by countless applications, websites, and services worldwide.
In this guide, I’ll walk you through installing FFmpeg on Ubuntu, explain the most useful conversion commands, and break down the parameters so you understand exactly what’s happening when you run these commands.
Installing FFmpeg on Ubuntu
Before diving into conversion commands, let’s make sure FFmpeg is properly installed on your system. Ubuntu users have several options for installation:
Method 1: Install from Ubuntu Repositories (Simplest)
Open a terminal and enter the following commands:
sudo apt update sudo apt install ffmpeg
Verify the installation by checking the version:
ffmpeg -version
Note: The version in the standard repositories may not be the most recent. As of early 2025, Ubuntu repositories typically provide FFmpeg version 6.1, while the latest stable release is 7.1.
Method 2: Install Latest Version via PPA (Recommended)
For the latest features and improvements, you can install FFmpeg from a PPA:
sudo add-apt-repository ppa:ubuntuhandbook1/ffmpeg7 sudo apt update sudo apt install ffmpeg
This will install the latest FFmpeg 7.x version with additional features and improvements.
Understanding FFmpeg Command Structure
Before diving into specific commands, it’s helpful to understand the basic structure of FFmpeg commands:
ffmpeg [global_options] -i input_file [output_options] output_file
- global_options: Apply to the entire process
- -i input_file: Specifies the input file to process
- output_options: Apply to the output file (codecs, bitrates, etc.)
- output_file: The destination file name/path
Pro Tip: FFmpeg will automatically determine which encoders and formats to use based on file extensions, but you can specify them explicitly for more control.
Common FFmpeg Conversion Commands
Here are some of the most useful FFmpeg commands for various conversion tasks. Simply open your terminal, navigate to the directory containing your media files, and run these commands (replacing the filenames with your own).
Converting Video Formats
Convert a FLV file to MPG:
ffmpeg -i original_file.flv new_file.mpg
Convert a MPG file to FLV:
ffmpeg -i original_file.mpg new_file.flv
Convert a MOV file to MP4:
ffmpeg -i original_file.mov -c:v libx264 -c:a aac new_file.mp4
What this does: Converts a MOV file to MP4 using the H.264 video codec and AAC audio codec, which offer excellent quality and compatibility.
Working with Audio
Extract audio from a video file as MP3:
ffmpeg -i input_video.mp4 -vn -ar 44100 -ac 2 -ab 192k -f mp3 output_audio.mp3
What this does:
- -vn: Disables video recording (extracts audio only)
- -ar 44100: Sets audio sampling rate to 44.1 kHz (CD quality)
- -ac 2: Sets 2 audio channels (stereo)
- -ab 192k: Sets audio bitrate to 192 kbps
- -f mp3: Forces the output format to MP3
Convert WAV to MP3:
ffmpeg -i input.wav -vn -ar 44100 -ac 2 -ab 192k -f mp3 output.mp3
Extract audio from a video file (simplified command):
ffmpeg -i video.mp4 -vn audio_only.mp3
This simpler command works in many cases, as FFmpeg will automatically select reasonable defaults based on the output file extension.
Pro Tip: If you’re unsure about which audio formats your FFmpeg supports, run ffmpeg -encoders | grep audio
to see a list of available audio encoders.
Advanced FFmpeg Commands
Once you’re comfortable with basic conversions, you can explore more advanced FFmpeg capabilities:
Video Resizing and Quality Control
Convert and resize a video:
ffmpeg -i input.mp4 -vf "scale=1280:720" -c:a copy output_720p.mp4
What this does: Resizes the video to 1280×720 pixels (720p) while keeping the original audio.
Create a high-quality MP4 with specific encoding settings:
ffmpeg -i input.mov -c:v libx264 -preset slow -crf 18 -c:a aac -b:a 192k output.mp4
What this does:
- -c:v libx264: Uses H.264 video codec
- -preset slow: Uses slower encoding for better compression
- -crf 18: Sets Constant Rate Factor to 18 (high quality, lower = better)
- -c:a aac: Uses AAC audio codec
- -b:a 192k: Sets audio bitrate to 192 kbps
Trimming and Combining
Trim a video to a specific duration:
ffmpeg -i input.mp4 -ss 00:00:30 -to 00:02:00 -c copy trimmed_output.mp4
What this does: Extracts a clip starting at 30 seconds and ending at 2 minutes from the original video.
Concatenate multiple videos:
First, create a file list (videos.txt):
file 'video1.mp4' file 'video2.mp4' file 'video3.mp4'
Then concatenate them:
ffmpeg -f concat -safe 0 -i videos.txt -c copy combined_video.mp4
Important: For concatenation to work properly, all videos should have the same codec, resolution, and frame rate. If they differ, you might need to re-encode them first.
Troubleshooting Common Issues
Missing Codecs
If you encounter errors about missing encoders, you may need to install additional codec packages:
sudo apt install ubuntu-restricted-extras
Permission Denied
If you see “permission denied” errors:
- Check that you have read permissions for input files
- Ensure you have write permissions for the output directory
- Use sudo if necessary (though this is rarely needed for FFmpeg)
Unknown Encoder
If FFmpeg reports an “Unknown encoder” error, it means your installation was not compiled with support for that codec. You can check available encoders with:
ffmpeg -encoders
Consider installing FFmpeg from a PPA (as described in the installation section) for a version with more codecs.
Conclusion
FFmpeg is an incredibly powerful tool that can handle virtually any multimedia conversion task you throw at it. While it may seem intimidating at first with its command-line interface, the basic commands are straightforward, and the flexibility it offers is unmatched by graphical alternatives.
As you become more comfortable with FFmpeg, you’ll discover even more advanced features like filters, multi-stream processing, and complex encoding parameters. The official FFmpeg documentation is an excellent resource for exploring these capabilities further.
Whether you’re a content creator, developer, or just someone who occasionally needs to convert media files, FFmpeg is an essential tool to have in your Linux toolkit.
Share Your Experience
Do you have a favorite FFmpeg command or trick? Share it in the comments below to help fellow Ubuntu users!
pony says:
Here is an example – http://www.youtube.com/watch?v=A5ppNyTrf5k