If you spend time in terminals trimming clips, transcoding formats, or fixing playback issues, you probably reach for FFmpeg a lot. In community threads, the same question pops up: which options are actually worth memorizing, and what do they do in real workflows like social uploads, previews, and batch processing?
Hi all, I use FFmpeg for quick edits and transcodes, but there are so many flags that it is hard to know what matters day to day. In practice, what are the most useful FFmpeg command-line options, when should I use them, and can you share a few copy-paste snippets for common tasks like H.264 exports, trimming, remuxing, and HLS packaging?
FFmpeg has hundreds of options, but a small set covers 90 percent of use cases. Below are the options I recommend learning first, with short examples you can adapt. For background reading, see the high-level overview of FFmpeg’s role in modern pipelines in this guide.
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium -pix_fmt yuv420p \
-c:a aac -b:a 128k -movflags +faststart output.mp4Code language: CSS (css)
-c:v libx264selects H.264. See tuning tips in this H.264 best practices guide.-crf 18–28controls quality. Lower is higher quality. 23 is a good default.-presetbalances encode time vs. compression. From veryslow to ultrafast. Start at medium.-pix_fmt yuv420pmaximizes compatibility with players.- -movflags +faststart moves the
moovatom to the front for faster streaming start.
ffmpeg -i input.mp4 -vf "scale=1280:-2,fps=30,format=yuv420p" \
-c:v libx264 -crf 20 -preset slow -c:a copy out_720p30.mp4Code language: JavaScript (javascript)
-vfapplies filters.scale=width:height with -2 preserves aspect on the other axis.fpssets output frame rate. format assures a compatible pixel format.-c:acopy keeps the original audio to save time if compatible.
# Fast, keyframe-aligned (may cut on nearby keyframe)
ffmpeg -ss 00:00:05 -to 00:00:12 -i input.mp4 -c copy clip_fast.mp4
# Frame-accurate (decodes input)
ffmpeg -i input.mp4 -ss 00:00:05 -to 00:00:12 -c:v libx264 -crf 20 -c:a aac clip_exact.mp4Code language: CSS (css)
-ssbefore-iis fast but keyframe aligned. After-iis accurate.-tosets end time. You can also use-tfor duration.
# Copy streams as-is into a new container
ffmpeg -i input.mkv -c copy output.mp4Code language: CSS (css)
If a stream is incompatible with the target container, you may need to transcode just that stream, for example audio to AAC.
# Select specific video and audio tracks
ffmpeg -i input.mkv -map 0:v:0 -map 0:a:1 -c:v libx264 -crf 22 -c:a aac selected.mp4Code language: CSS (css)
-map 0:v:0chooses the first video track,-map 0:a:1the second audio track.- Use
-map_metadata 0to preserve metadata if needed.
# Burn SRT subtitles into video
ffmpeg -i input.mp4 -vf "subtitles=subs.srt,format=yuv420p" \
-c:v libx264 -crf 20 -c:a copy with_subs.mp4Code language: PHP (php)
# Extract audio as MP3 (quality scale 0-9, lower is better)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3Code language: CSS (css)
ffmpeg -i input.mp4 -c:v libx264 -crf 21 -preset medium -c:a aac -b:a 128k \
-f hls -hls_time 6 -hls_playlist_type vod -hls_segment_filename "seg_%03d.ts" master.m3u8Code language: CSS (css)
For choosing output formats for the web, see a quick comparison in MP4 vs WebM.
-hide_bannerto reduce log noise.-loglevelinfo or warning for quieter output; append -stats for progress.-yto overwrite or -n to refuse overwrites.-shortestto end when the shortest stream finishes, useful with loops.
If you are transcoding lots of variants, thumbnails, and social cuts, you can offload common FFmpeg jobs to Cloudinary. Upload once, then request on-demand transforms and format delivery via URLs or SDKs. You can manage and deliver your media assets, generate poster frames, normalize codecs, and ship web-ready streams without maintaining your own encoding farm.
- Example on-demand URL idea: convert to MP4, optimize quality, and resize:
https://res.cloudinary.com/your_cloud/video/upload/f_mp4,q_auto,w_1280/sample
- For context on codec choices and tradeoffs you might otherwise handle with FFmpeg, review H.264 best practices and this FFmpeg features overview.
- Transcoding:
-c:v libx264 -crf 18–28 -preset medium -pix_fmt yuv420p -movflags +faststart. - Resize and FPS:
-vf "scale=WIDTH:-2,fps=NN". - Trim:
-ssand-to, with-ssbefore-ifor fast cuts or after-ifor precision. - Remux and mapping:
-c copyand-mapfor clean stream selection. - Quality of life:
-hide_banner -loglevel info -stats -y -shortest. - At scale: Consider delegating routine transcodes and delivery to Cloudinary to simplify pipelines.
Ready to streamline video workflows from upload to delivery? Create a free Cloudinary account and start optimizing today.