Marcio Cunha

How to convert and resize videos via terminal with FFmpeg

Learn practical FFmpeg commands to resize videos, extract audio tracks, and quickly optimize media files directly from your terminal.

Marcio Cunha•3 min
Also available in:PortuguêsEspañol
Summary
  • FFmpeg acts as a universal command-line toolkit for manipulating audio and video files effortlessly.
  • Respending resolutions and altering frame rates requires understanding codecs and specific encoding parameters.
  • Extracting audio tracks saves bandwidth and disk space without reprocessing unnecessary visual streams.
  • Quick video resizing reduces file weight for web sharing and optimized local storage.
  • Command-line utilities prevent sluggish graphical interfaces and enable complete script automation.

What is FFmpeg and why use it in the terminal

FFmpeg is a powerful open-source tool executed entirely through the command line, designed to record, convert, and stream audio and video. In practice, this means instead of opening heavy visual editors on your screen, you type direct instructions for your computer to process multimedia files surgically. If you ever needed how to convert audio to text offline on PC with Whisper, you know the terminal offers unmatched speed. The main advantage is that it handles virtually any format created in recent decades without lagging.

Many people avoid the terminal out of fear of complex code, but mastering basic FFmpeg commands solves everyday problems in seconds. Whether you need to shrink a giant file generated by your smartphone or separate the soundtrack from a recording, the utility processes entire batches of files while you grab a coffee. For those already dealing with technical tasks, such as how to audit file permissions on Linux using native commands, using FFmpeg fits seamlessly into daily automation workflows.

How to extract audio tracks without losing quality

Extracting sound from a video file is one of the most common tasks for podcast editors and lecture archivers. FFmpeg accomplishes this by directly copying the original audio stream without needing to reprocess the entire file, ensuring maximum speed and zero quality loss. In practice, the command isolates the desired sound track and saves it in lightweight formats like MP3 or AAC.

To perform this operation on your machine, use the following command while adapting the file names to your actual needs:

ffmpeg -i video.mp4 -vn -acodec copy audio.aac

In this command, the -i parameter indicates the input file, -vn disables video capture (excluding imagery), and -acodec copy tells the program to simply copy the original sound without spending processing power re-encoding everything. The result is a ready-to-use audio file generated in just a few seconds.

How to quickly resize videos through the terminal

Videos recorded on modern smartphones usually have extremely high resolutions and consume gigabytes of unnecessary disk space. Resizing these media files to smaller resolutions, such as 720p or 1080p, is essential for fast internet sharing or saving storage space. FFmpeg uses scaling filters to change dimensions while maintaining the correct image aspect ratio.

The following command resizes a heavy video file to a standard height of 720 pixels, adjusting the width automatically:

ffmpeg -i input.mp4 -vf scale=-2:720 output.mp4

The -vf parameter activates video filters, and the instruction scale=-2:720 forces the height to 720 lines while the -2 value calculates the width to keep the video proportional and compatible with modern codecs. This direct manipulation prevents visual distortion and drastically reduces the final file size.

How to optimize and compress multimedia files

Beyond cutting and resizing, fine-tuning the compression rate helps balance file size and visual quality. FFmpeg allows you to control this through the constant quality factor parameter, known as CRF. The higher this value, the smaller the file will be, though there is a threshold where the image begins to lose definition visibly.

Run the command below to apply efficient compression while maintaining an excellent visual ratio:

ffmpeg -i original.mp4 -vcodec libx264 -crf 23 compressed.mp4

The libx264 encoder is the universal standard for the MP4 format, widely accepted across browsers and mobile devices. The value -crf 23 represents the ideal balance recommended by developers for general-purpose files, ensuring the video takes up much less space without looking pixelated. To explore these architectural concepts further in production, see our related technical analysis on Monitor has no light? How to test backlight with multimeter.

Final considerations on media automation

Mastering FFmpeg in the terminal turns repetitive tasks into simple automated routines. Whether reducing resolutions to fit email attachment limits or extracting audio for transcription, the command line offers absolute control over every bit of your file. Integrating these commands into small shell scripts saves hours of manual work and eliminates the need for heavy, ad-laden commercial software.

Constant practice with basic parameters reveals the true power of this open-source tool. Try combining audio and video filters in your daily projects and discover how terminal efficiency simplifies managing large volumes of media.