FFMpeg Console: A Beginner’s Guide to Command-Line Video Processing

Mastering the FFMpeg Console — Essential Commands and TipsFFMpeg is the swiss-army knife for audio and video manipulation: a single command-line tool that can record, convert, stream, filter, and inspect multimedia. This article walks through essential commands, practical tips, and example workflows to help you become confident using the FFMpeg console for everyday media tasks.


What is FFMpeg?

FFMpeg is an open-source suite of libraries and programs for handling multimedia data. The core command-line tool, ffmpeg, reads and writes most audio/video formats, applies filters, encodes/decodes using many codecs, and can livestream or capture from devices. The closely related tools ffprobe and ffplay help inspect media and play back files.


Installing FFMpeg

  • macOS: use Homebrew — brew install ffmpeg (add options for libx265, libvpx, etc., if needed).
  • Linux: use your package manager — e.g., sudo apt install ffmpeg (Debian/Ubuntu) or build from source for the latest features.
  • Windows: download static builds from the official site or use package managers like Scoop or Chocolatey.

Confirm installation with:

ffmpeg -version ffprobe -version 

Basic Command Structure

The simplest ffmpeg structure:

ffmpeg -i input.ext [input-options] [filterchain] [output-options] output.ext 
  • -i specifies an input file (can be repeated for multiple inputs).
  • Options before -i apply to the next input; options after inputs apply to the output.
  • Filters (audio/video) are applied via -vf (video filters) and -af (audio filters) or the more general -filter_complex for complex graphs.

Common Tasks and Example Commands

  1. Convert format (container change)
    
    ffmpeg -i input.mkv -c copy output.mp4 
  • -c copy copies streams without re-encoding (lossless & fast). Works only when codecs are compatible with the container.
  1. Re-encode video and audio
    
    ffmpeg -i input.mov -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k output.mp4 
  • libx264 for H.264 video, crf controls quality (lower → better), preset trades speed vs compression.
  1. Resize video
    
    ffmpeg -i input.mp4 -vf "scale=1280:720" -c:v libx264 -crf 20 -c:a copy output_720p.mp4 
  • Use -2 as a dimension to preserve aspect ratio with even-numbered sizes: scale=1280:-2.
  1. Extract audio
    
    ffmpeg -i input.mp4 -vn -acodec copy output.aac 
  • -vn disables video; -acodec copy copies audio stream.
  1. Convert audio format

    ffmpeg -i input.wav -c:a libmp3lame -b:a 192k output.mp3 
  2. Trim without re-encoding (fast)

    ffmpeg -ss 00:01:00 -to 00:02:30 -i input.mp4 -c copy -avoid_negative_ts 1 output_clip.mp4 
  • Place -ss before -i for fast seek (less accurate), or after -i for frame-accurate trimming with re-encoding.
  1. Concatenate multiple files
  • For files with identical codecs/containers (concat demuxer): Create files.txt:

    file 'part1.mp4' file 'part2.mp4' file 'part3.mp4' 

    Then:

    ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4 
  • For arbitrary inputs (re-encode with concat filter):

    ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -c:a aac output.mp4 
  1. Add subtitles (softburn)
    
    ffmpeg -i input.mp4 -i subs.srt -c copy -c:s mov_text output.mp4 
  • For hard-burned subtitles (rendered into video):
    
    ffmpeg -i input.mp4 -vf "subtitles=subs.srt" -c:v libx264 -c:a copy output_hard.mkv 
  1. Capture from webcam (Linux example)

    ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -i /dev/video0 output.mkv 
  2. Streaming (RTMP example for live to YouTube/Twitch)

    ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -b:v 3500k -maxrate 3500k -bufsize 7000k -c:a aac -b:a 160k -f flv rtmp://a.rtmp.youtube.com/live2/STREAM_KEY 
  • -re reads input in real time (useful for looping files).

Filters and filter_complex

  • Video filters: scale, crop, pad, transpose, drawtext, fps, overlay, hue, eq.
  • Audio filters: volume, aresample, aphasemeter, pan, earwax (fun), aecho.
  • Use -filter_complex for multi-input graphs (e.g., picture-in-picture, multi-track mixing).

Example: overlay watermark

ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-10:main_h-overlay_h-10" -c:v libx264 -crf 23 -c:a copy output_watermarked.mp4 

Performance and Encoding Tips

  • Use presets (x264/x265): ultrafast → placebo. Choose a preset that balances CPU and file size.

  • Use hardware acceleration when available: -hwaccel, -vaapi, -nvenc, -qsv depending on GPU. Example (NVENC):

    
    ffmpeg -i input.mp4 -c:v h264_nvenc -preset p5 -b:v 5M -c:a aac output_nvenc.mp4 

  • Two-pass encoding for bitrate targets (better quality at given size): Pass 1:

    ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2000k -pass 1 -an -f mp4 /dev/null 

    Pass 2:

    ffmpeg -i input.mp4 -c:v libx264 -b:v 2000k -pass 2 -c:a aac -b:a 128k output.mp4 
  • CRF is generally preferred for quality-based control; set CRF ~18–24 for x264, lower for higher quality.


Metadata and Inspection

  • Inspect streams:
    
    ffprobe -v error -show_entries format=duration,size,bit_rate -show_streams input.mp4 
  • Change metadata:
    
    ffmpeg -i input.mp4 -metadata title="My Title" -metadata artist="Me" -c copy output_meta.mp4 

Common Pitfalls & Troubleshooting

  • “Invalid data found when processing input”: often a corrupted file or unsupported container; try ffmpeg -i to see details or rewrap.
  • Audio/video sync issues after trimming with -c copy: use -avoid_negative_ts 1 or re-encode around cuts.
  • Codec/container mismatch when copying: some codecs aren’t supported in certain containers; re-encode or choose a compatible container.
  • Subtitles not visible in some players: ensure subtitle codec is supported by the container (e.g., mov_text for MP4).

Practical Workflows

  1. Quick social-media transcode: target 1080p H.264 with AAC audio, 30s clip:

    ffmpeg -i input.mov -ss 00:00:10 -to 00:00:40 -vf "scale=1920:-2,fps=30" -c:v libx264 -preset fast -crf 22 -c:a aac -b:a 128k -movflags +faststart output_social.mp4 
  2. Archive master to efficient H.265:

    ffmpeg -i camera.mov -c:v libx265 -preset slow -crf 22 -c:a copy output_hevc.mkv 
  3. Batch-convert a folder to MP4 (bash example)

    for f in *.mkv; do ffmpeg -i "$f" -c:v libx264 -crf 23 -c:a aac "${f%.*}.mp4" done 

  • Respect copyrights when downloading, converting, or streaming protected content.
  • Be careful running ffmpeg commands from untrusted scripts; they can overwrite files.

Learning Resources & Help

  • ffmpeg -h for quick help, ffmpeg -h full for all options.
  • ffprobe to inspect streams and debug.
  • Community forums, the official documentation, and examples on GitHub provide many use-case recipes.

ffmpeg is deep — once you know the basic command structure and a handful of filters/options, you can stitch together solutions for almost any audio/video problem. Experiment with small test files, keep copies of originals, and build up a library of commands that fit your regular workflows.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *