The FFmpeg Commands Every Video Developer Should Know
The FFmpeg Commands Every Video Developer Should Know
FFmpeg is the backbone of virtually every video processing pipeline on the internet. It is powerful, flexible, and notoriously difficult to learn. Here are the essential commands that every developer working with video needs in their toolkit.
Basic Operations
Get Video Information
Before processing any video, understand what you are working with:
ffmpeg -i input.mp4 -hide_banner
This displays codec, resolution, duration, bitrate, and audio format. Always inspect your input before building a processing pipeline.
Convert Between Formats
ffmpeg -i input.mov -c:v libx264 -c:a aac output.mp4
This converts any input to H.264 video with AAC audio in an MP4 container. This combination is the universal web-compatible format.
Extract Audio
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
The -vn flag strips the video stream. Useful for creating podcast episodes from video recordings.
Clipping and Trimming
Extract a Segment
ffmpeg -ss 00:01:30 -i input.mp4 -t 00:00:45 -c copy output.mp4
This extracts 45 seconds starting at the 1:30 mark. The -c copy flag means no re-encoding, which is fast but only cuts at keyframes. For precise cutting:
ffmpeg -ss 00:01:30 -i input.mp4 -t 00:00:45 -c:v libx264 -c:a aac output.mp4
Re-encoding gives frame-accurate cuts at the cost of processing time.
Vertical Video and Cropping
Crop Landscape to Vertical (9:16)
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih" output.mp4
This center-crops a landscape video to vertical orientation. For dynamic cropping that follows faces or action, you need more sophisticated tooling, which is exactly what platforms like ClipSpeedAI provide through AI-powered reframing.
Scale to Specific Resolution
ffmpeg -i input.mp4 -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2" output.mp4
This scales video to 1080x1920 (vertical HD) while maintaining aspect ratio and adding black padding where needed.
Caption and Text Operations
Burn In Subtitles
ffmpeg -i input.mp4 -vf "subtitles=captions.srt:force_style='FontSize=24,PrimaryColour=&HFFFFFF&'" output.mp4
This burns SRT subtitles directly into the video. The force_style parameter controls appearance. For professional-quality animated captions, tools like ClipSpeedAI generate styled, word-by-word highlighted captions automatically.
Encoding for Web
Optimized H.264 for Web Delivery
ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k -movflags +faststart output.mp4
The key flags:
-crf 23: Quality setting (lower = better quality, larger file). Range 18-28 is typical.-preset medium: Balance between encoding speed and compression efficiency.-movflags +faststart: Moves metadata to the beginning of the file for progressive web playback.
Two-Pass Encoding for Target File Size
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 1 -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 2 output.mp4
Two-pass encoding produces better quality at a given bitrate by analyzing the video first and then encoding with that analysis.
Batch Processing
Process Multiple Files
for f in *.mp4; do ffmpeg -i "$f" -c:v libx264 -crf 23 "output/${f}"; done
Simple bash loop for batch processing. For production pipelines with many files, a proper job queue is essential.
Performance Tips
Use hardware acceleration when available. On machines with compatible GPUs, -c:v h264_nvenc (NVIDIA) or -c:v h264_videotoolbox (macOS) dramatically speeds up encoding.
Pipe between processes. FFmpeg can read from and write to pipes, enabling streaming architectures that avoid writing intermediate files to disk.
Profile your commands. Add -benchmark to measure actual encoding performance and identify bottlenecks.
Beyond FFmpeg
FFmpeg handles the raw video manipulation, but building a complete video processing pipeline, one that identifies the best clips, adds smart cropping, and generates professional captions, requires layers of intelligence on top. That is what ClipSpeedAI provides: the AI layer that turns raw FFmpeg power into a usable content creation tool.
Master these FFmpeg basics, and you will have the foundation for any video processing work you encounter.