Want to do more with the Linux terminal? You might not instinctively put videos and the command line together, but with FFmpeg you may actually do a lot with a video file just by typing a simple command in your terminal.

In case you haven’t heard of it,FFmpegis a command line tool that can handle anything related to media. It’s available in most Linux distros' repositories, so you just need to find and install the package to start using it.

Playing video in the terminal using ffplay.

Whether you want to quickly play a video, retrieve some information, or perform cool video-editing tricks, FFmpeg has got you covered. Here are some useful things you can do with FFmpeg on your Linux machine.

10Playing a Video

You might already have a favorite video player, and that’s great. But sometimes, you just need a quick and simple way to watch something without opening a full graphical application. You can do that using FFmpeg’s built-in player, ffplay.

For example, to play a video, open your terminal and run:

Displaying video information using FFmpeg in the terminal.

Your video will pop up in a separate window, ready to play. You can control it with commands like “q” to quit, “p” to pause, and the left or right arrow keys to fast-forward or rewind.

If you desire to play your video on a loop, run:

Displaying video information in proper JSON format in the terminal window.

The -loop 0 option makes it loop indefinitely. You can replace 0 with any number to set how many times it repeats.

9Get Media Information

Normally, getting video file information involves digging through menus in a media player, or maybe even using a separate app. But with FFmpeg, getting all this info is just a command away.

To get media information, simply run:

In just seconds, you’ll see a comprehensive readout, including codecs, bitrates, frame rates, and more.

For even more detailed information about video, audio, and subtitle streams, use ffprobe (a tool of FFmpeg):

Extracted images displaying in a specific folder.

And for a cleaneroutput in JSON format, run:

Plus, let me tell you that all of these commands help you efficiently analyze video files without actually playing them.

8Record Your Screen

FFmpeg can alsorecord your screen. Whether you want to show someone how to do something on Linux or create a quick demo, there’s no need for extra screen recording programs.

Let’s say you want to record your whole screen for 10 seconds. You can do this with this:

This command captures your desktop at 1920x1080 resolution with a frame rate of30 frames per second. Further, the “-i :0.0+0,0” option tells FFmpeg what screen to record. For example, in our case, the “:0.0” refers to the main screen, and “+0,0” means start recording from the top-left corner.

If your system usesWaylandinstead of Xorg, you may sometimes encounter a black screen issue, as FFmpeg’s x11grab works best with Xorg. Switching to a Xorg session should fix the problem.

If you don’t know your screen size or position, you can find out with this:

You should be aware the FFmpeg command earlier records your desktop screen without any audio. So, if you also want to record audio along with the video, then you need to specify an audio input device alongside the video input.

For example, you can use the “-f alsa -i pulse” option to capture both the screen video and audio:

For recording a specific window, the FFmpeg command is slightly more complex, but for quick full-screen recordings, FFmpeg is an excellent choice. Plus, if you love working from the terminal, it gives you full control over every aspect of the recording process.

7Extract Images From a Video

Have you ever wanted to extract a single frame from a video—perhaps for a thumbnail or to capture a cool shot? FFmpeg makes this tasks very simple.

For example, suppose you want to extract one picture every second from a video and save them as image files. To do this, run:

Here, option “-r 1” sets the capture rate to one picture per second. It extracts one frame from each 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.

6Convert 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 conversion, ensure that 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:

Here, we set the frame rate option to 1 FPS, meaning that if we’ve got 5 pictures and 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 previous command converts images into a video without adding music. But what if you want to include music in your video? Run this, replacing “music.mp3” with the audio file you want:

Here, the -shortest option makes the video as long as the shorter input. So, if the audio is longer than the slideshow, the video will match the slideshow’s length.

5Convert a Video to MP3 or GIF

One of FFmpeg’s strongest features is converting videos into different formats, such as transforming video into MP3 or creating a GIF animation from video.

To extract the audio from a video, use the-vnoption, which forces FFmpeg to discard the video stream and convert only the audio to MP3:

you’re able to also change output.mp3 to output.wav or another audio format if needed.

To convert video to GIF, use:

You can also extract specific parts of the video and convert them into GIFs with this:

This command trims 2.1 seconds from the front of the 00:30 duration of the video and converts it to a GIF.

4Add 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, obtain 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’re able to hardcode the subtitles into the video using:

This command permanently embeds the subtitles, ensuring they remain visible and cannot be turned off.

If you prefer optional subtitles that viewers can turn on or off, use this:

This command keeps the subtitles as a separate track, preserving the original video quality.

3Rebuild a Video’s Index Without Transcoding

Sometimes a video may appear glitchy—it might skip, freeze, or prevent fast-forwarding or rewinding. Often, this issue arises from a corrupted video index. To fix this problem, 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’s structure.

To rebuild a video index, run:

Here, the -c copy option instructs FFmpeg to copy the video and audio streams exactly as they are, preserving their quality and speeding up the process. The -copyts option ensures that the timing information is copied correctly, which is crucial for smooth playback.

This approach is useful for quickly checking and repairing your video file. However, if the issue persists, the video may be severely corrupted.

2Resize Videos

Resizing videos is one of FFmpeg’s most useful features. you may easily adjust video dimensions for social media, mobile screens, or storage optimization. Smaller videos take up less space, upload faster, and perform better on slower connections.

To scale a video to specific dimensions (e.g., 1280x720), use:

If you want FFmpeg to maintain the aspect ratio automatically, specify only one dimension or use expressions:

This sets the width to 640 pixels, and FFmpeg calculates the appropriate height to preserve the aspect ratio. However, note that downscaling may reduce quality, so choose resolutions carefully.

1Trim and Crop Videos

Trimming a video allows you to extract only the necessary sections without affecting quality. This is perfect for eliminating unwanted intros, outros, or any mistakes.

For instance, to extract a 20-second segment starting from 10 seconds into the video, run:

Here, “-ss 00:00:10” tells FFmpeg to start at the 10-second mark, while “-to 00:00:30” stops the video at 30 seconds. Also, the “-c copy” option ensures that the video and audio are copied without re-encoding, making the process much faster while preserving the original quality.

Cropping 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, execute this:

The crop filter takes four values: width, height, and the x and y coordinates for where the crop should start. In this case, the width and height are set to 640x480, and 0:0 ensures the cropping starts from the top-left corner of the original video.

By practicing and learning these FFmpeg tricks, you can easily boost your productivity and streamline your workload. And remember—this is only the beginning. There are many things in FFmpeg waiting to be explored, so dive in and keep experimenting!