FFmpeg on Linux: Discover 10 Secrets! 💻🔍
Want to get more out of the Linux terminal? You might not instinctively associate videos with the command line, but with FFmpeg, you can do a lot with a video file just by typing a simple command in your terminal! 🎥💻
If you didn't know him, FFmpeg is a command-line tool that handles everything media-related. It's available in the repositories of most Linux distributions, so you just have to search for and install the package to start using it. 🛠️👨💻
Whether you want to play a video quickly, get information or perform tricks For great video editing tools, FFmpeg has you covered. Here are some useful things you can do with FFmpeg on your Linux machine. 🔍✨
1 . Play a Video
You may already have a favorite video player, and that's great. But sometimes, you just need a quick and easy way to watch something without opening a full graphical application. You can do this using FFmpeg's built-in player. ffplay
.
For example, to play a video, open your terminal and run:
ffplay your_video_file.mp4

Your video will appear in a separate window, ready to play. You can control it with commands like "q" to exit, "p" to pause, and the left and right arrows to fast forward or rewind. ⏪⏩
If you want to loop your video, run:
ffplay -loop 0 your_video_file.mp4
The option -loop 0
makes it loop indefinitely. You can replace 0 with any number to set how many times it repeats.

2. Here's how to play your local music collection in a Linux terminal window.
Typically, getting information about a video file involves navigating menus in a media player or even using a separate application. But with FFmpeg, getting all this information is just a command away. 📊
To get information about the medium, simply run:
ffmpeg -i your_video_file.mp4
In seconds, you'll see a complete overview, including codecs, bitrates, frame rates, and more. 📈

For even more detailed information about video, audio, and subtitle streams, use ffprobe
(an FFmpeg tool):
ffprobe -show_streams –i your_video_file.mp4
And for cleaner JSON output, run:
ffprobe -v quiet -print_format json -show_format -show_streams your_video_file.mp4

Also, let me tell you that all these commands help you efficiently analyze video files without actually playing them. 🔍
3 . Record your Screen
FFmpeg can also record your screen. Whether you want to show someone how to do something in Linux or create a quick demo, you don't need any software. screen recording extra. 🎤😉
Let's say you want to record your entire screen for 10 seconds. You can do this with:
ffmpeg -f x11grab -video_size 1920x1080 -r 30 -i :0.0+0.0 -t 10 output.mp4
This command captures your desktop at a resolution of 1920x1080 with a frame rate of 30 frames per second. Additionally, the option -i :0.0+0.0
tells FFmpeg which screen to record. For example, in our case, :0.0
refers to the main screen, and +0,0
means start recording from the top left corner.
If you don't know your screen size or position, you can find out with this:
xdpyinfo | grep dimensions
You should know that the FFmpeg command above records your desktop screen without audio. So, if you also want to record audio along with the video, you'll need to specify an audio input device along with the video input device.
For example, you can use the option -f alsa -i pulse
To capture both screen video and audio:
ffmpeg -f x11grab -video_size 1920x1080 -r 30 -i :0.0+0.0 -f alsa -i default -t 10 output.mp4
To record a specific window, the FFmpeg command is a bit more complex, but for quick full-screen recordings, FFmpeg is an excellent choice. Plus, if you like working from the terminal, it gives you full control over every aspect of the recording process. 🔥

4. Start capturing or streaming live using this free and open source program.
Ever wanted to extract a single frame from a video, maybe for a thumbnail or to capture a great shot? FFmpeg makes this task very simple. 📸
For example, let's say you want to extract an image every second from a video and save them as image files. To do this, run:
ffmpeg -i input.mp4 -r 1 imagen-%04d.jpg

Here, the option -r 1
Sets the capture rate to one frame per second. It extracts one frame from every second of the video. You can adjust this number to capture images more or less frequently. You can also change JPG to PNG or another image format if needed. 🖼️
5 . Convert Images into a Video
FFmpeg can not only extract images, but also assemble a series of images into a video. Whether you want to create a slideshow, an animation, or a time-lapse, FFmpeg simplifies the process. 🎞️
Before converting, make sure your images are named sequentially (e.g., image-0001.jpg, image-0002.jpg). Now, convert these sequential images into a video with the following command:
ffmpeg -framerate 1 -i imagen-%04d.jpg -c:v libx264 -r30 output.mp4
Here, we set the frame rate option to 1 FPS, which means if we have 5 frames and we prefer a 5-second video, the frame rate will be 1. You can adjust the frame rate value to speed up or slow down the video.
The above command converts images into a video without add music. But what if you want to include music in your video? Run this, replacing music.mp3
with the audio file you want:
ffmpeg -framerate 1 -i imagen_%04d.jpg -i music.mp3 -c:v libx264 -r30 -shortest slideshow.mp4
Here, the option -shortest
Makes the video the same length as the shortest entry. So, if the audio is longer than the presentation, the video will match the length of the slideshow. 🎶

ImageMagick is a set of command-line utilities for modifying and working with images.
6 . Convert a Video to MP3 or GIF
One of FFmpeg's most powerful features is converting videos to different formats, such as converting video to MP3 or creating a GIF animation from a video. 🔄
To extract audio from a video, use the option -vn, which forces FFmpeg to discard the video stream and convert only the audio to MP3:
ffmpeg -i input.mp4 -vn -acodec libmp3lame output.mp3
You can also change output.mp3
to output.wav
or other audio format if you need it.
To convert video to GIF, use:
ffmpeg -i sample_video.mp4 output.gif
You can also extract specific parts of the video and turn them into GIFs with this:
ffmpeg -ss 30.0 -t 2.1 -i sample_video.mp4 output.gif
This command trims 2.1 seconds from the beginning of the video length at 00:30 and converts it into a GIF. 🎉
7 . Add Subtitles to a Movie
Adding subtitles to a movie can be very useful, especially when watching content in a different language. FFmpeg simplifies the process of adding subtitles to your videos. 🎬
First, get a subtitle file, typically with an SRT extension. For example, if you have a subtitle file (such as subtitles.srt
) and a video (input.mp4
), you can permanently embed subtitles into your video using:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4
This command permanently embeds subtitles, ensuring they remain visible and cannot be turned off.
If you prefer optional subtitles that viewers can turn on or off, use this:
ffmpeg -i input.mp4 -i subtitles.srt -c copy -c:s mov_text output.mp4
This command keeps subtitles as a separate track, preserving the original video quality. 📝
8 . Reconstructing a Video's Index without Transcoding
Sometimes a video may appear glitchy—it may skip, freeze, or prevent fast-forwarding or rewinding. Often, this problem arises from a corrupted video index. To fix this, you may need to rebuild the index without re-encoding the video.
Fortunately, FFmpeg can often repair the index without altering the video itself. This process, known as remuxing, is fast because it preserves the original video and audio quality while correcting the file structure.
To rebuild a video index, run:
ffmpeg -i input.mp4 -c copy -copyts output.mp4
Here, the option -c copy
tells FFmpeg to copy the video and audio streams as is, preserving their quality and speeding up the process. The option -copyts
ensures that timing information is copied correctly, which is critical for smooth playback.
This approach is Useful to quickly check and repair your file video. However, if the problem persists, the video may be severely damaged. ⚠️
9 . Resize Videos
Resizing videos is one of FFmpeg's most useful features. You can easily adjust the video dimensions to social networks, mobile screens, or to optimize storage. Smaller videos take up less space, upload more fast and work best on connections slow. 📏
To scale a video to specific dimensions (for example, 1280×720), use:
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
If you want FFmpeg to maintain the aspect ratio automatically, specify only one dimension or use expressions:
ffmpeg -i input.mp4 -vf scale=640:-1 output.mp4
This sets the width to 640 pixels, and FFmpeg calculates the appropriate height to preserve the aspect ratio. However, keep in mind that scaling down can decrease quality, so choose resolutions carefully.
10 . Trim and Cut Videos
Trimming a video allows you to extract only the necessary sections without compromising quality. This is perfect for removing unwanted intros, endings, or any other errors. ✂️
For example, to extract a 20-second segment starting from 10 seconds into the video, run:
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:30 -c copy output_trimmed.mp4
Here, -ss 00:00:10
tells FFmpeg to start at second 10, while -to 00:00:30
stops the video at second 30. Also, the option -c copy
ensures that video and audio are copied without re-encoding, making the process much faster while preserving the original quality.
Crop removes unnecessary edges or zooms in on the most important part of a video. To crop a video to 640x480 pixels, starting from the top left corner, do this:
ffmpeg -i input.mp4 -vf "crop=640:480:0:0" output_cropped.mp4
The cut filter takes four values: width, height, and the x and y coordinates of where the cut should begin. In this case, the width and height are set to 640x480, and 0:0
Ensure the crop starts from the top left corner of the original video. 🎥

By practicing and learning these FFmpeg tricks, you can increase your productivity and optimize your workload easily. And remember—this is just the beginning. There's a lot in FFmpeg waiting to be explored, so dive in and keep experimenting! 🚀