Showing 46 of 46 commands. Run loads the recipe into the console below, where you add your own file — nothing is uploaded.
Compress a video (H.264, quality based)
The default way to shrink a file. Lower CRF = better quality, bigger file.
Shellffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
CRF 18 is visually lossless, 23 is the default, 28 is small. Slower presets give smaller files at the same quality.
Compress with H.265 / HEVC (smaller files)
Roughly 30–50% smaller than H.264 at the same quality, but slower to encode.
Shellffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -tag:v hvc1 -c:a aac -b:a 128k output.mp4
-tag:v hvc1 keeps the file playable in QuickTime and on Apple devices.
Trim / cut without re-encoding
Instant cut between two timestamps, keeps the original quality.
Shellffmpeg -ss 00:00:30 -to 00:01:45 -i input.mp4 -c copy output.mp4
Cuts land on the nearest keyframe. Drop -c copy to re-encode for frame-accurate cuts.
Frame-accurate trim (re-encode)
Use when the fast copy cut starts a second early or freezes.
Shellffmpeg -ss 00:00:30 -to 00:01:45 -i input.mp4 -c:v libx264 -crf 20 -c:a aac output.mp4
Resize / scale to 1080p
Scale by height and let the width follow the aspect ratio.
Shellffmpeg -i input.mp4 -vf "scale=-2:1080" -c:v libx264 -crf 22 -c:a copy output.mp4
-2 keeps the dimension even, which H.264 requires.
Crop a region
crop=width:height:x:y measured in pixels from the top-left.
Shellffmpeg -i input.mp4 -vf "crop=1280:720:100:50" -c:a copy output.mp4
Rotate 90° or flip
transpose=1 rotates clockwise, 2 counter-clockwise, hflip mirrors.
Shellffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output.mp4
Change frame rate
Retime to 30 fps, dropping or duplicating frames as needed.
Shellffmpeg -i input.mp4 -vf "fps=30" -c:v libx264 -crf 22 -c:a copy output.mp4
Speed up 2× (video and audio)
setpts halves the timestamps, atempo speeds the audio to match.
Shellffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" output.mp4
atempo accepts 0.5–2.0; chain it (atempo=2.0,atempo=2.0) for 4×.
Add an image watermark
Overlay a PNG 20px from the bottom-right corner.
Shellffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=W-w-20:H-h-20" -c:a copy output.mp4
Burn text onto a video
drawtext places a caption with a background box.
Shellffmpeg -i input.mp4 -vf "drawtext=text='Coders Hub':fontsize=48:fontcolor=white:box=1:boxcolor=black@0.5:x=(w-tw)/2:y=h-100" -c:a copy output.mp4
Join several videos (same codec)
List the files then concatenate without re-encoding.
Shellprintf "file 'a.mp4'\nfile 'b.mp4'\n" > list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
All inputs must share codec, resolution and frame rate. Otherwise re-encode with the concat filter.
Reverse a clip
Plays video and audio backwards. Needs enough RAM for the clip.
Shellffmpeg -i input.mp4 -vf reverse -af areverse output.mp4
Remove the audio track
-an drops audio, the video stream is copied untouched.
Shellffmpeg -i input.mp4 -c:v copy -an output.mp4
Fade in and out
One-second fade from black at the start and to black at 00:59.
Shellffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1,fade=t=out:st=59:d=1" -c:a copy output.mp4
Extract audio from a video
Copy the existing audio stream — no quality loss, no re-encode.
Shellffmpeg -i input.mp4 -vn -acodec copy output.m4a
Video to MP3
Convert the soundtrack to a 192 kbps MP3.
Shellffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k output.mp3
Convert WAV to MP3 / AAC / Opus
Swap the codec and bitrate for the target format.
Shellffmpeg -i input.wav -c:a libmp3lame -q:a 2 output.mp3
ffmpeg -i input.wav -c:a aac -b:a 192k output.m4a
ffmpeg -i input.wav -c:a libopus -b:a 96k output.opus
Trim an audio file
Cut 30 seconds starting at 1:00 without re-encoding.
Shellffmpeg -ss 00:01:00 -t 30 -i input.mp3 -c copy output.mp3
Normalise loudness (EBU R128)
Bring speech or music to the −16 LUFS podcast target.
Shellffmpeg -i input.mp3 -af loudnorm=I=-16:TP=-1.5:LRA=11 -c:a libmp3lame -b:a 192k output.mp3
Change the volume
1.5 is +50%, 0.5 is half. Use dB with volume=6dB.
Shellffmpeg -i input.mp4 -filter:a "volume=1.5" -c:v copy output.mp4
Downmix to mono 16 kHz (speech / Whisper)
The format most speech-to-text models expect.
Shellffmpeg -i input.mp4 -vn -ac 1 -ar 16000 -c:a pcm_s16le output.wav
Replace a video's audio track
Keep the video stream, take audio from a second file.
Shellffmpeg -i video.mp4 -i music.mp3 -map 0:v -map 1:a -c:v copy -shortest output.mp4
Mix background music under a voice track
Lower the music, then merge both streams.
Shellffmpeg -i voice.wav -i music.mp3 -filter_complex "[1:a]volume=0.25[m];[0:a][m]amix=inputs=2:duration=first" output.mp3
Strip leading and trailing silence
Useful before publishing recordings.
Shellffmpeg -i input.mp3 -af "silenceremove=start_periods=1:start_threshold=-50dB:start_silence=0.3,areverse,silenceremove=start_periods=1:start_threshold=-50dB:start_silence=0.3,areverse" output.mp3
MKV to MP4 (remux, instant)
Change the container only when the codecs are already MP4-friendly.
Shellffmpeg -i input.mkv -c copy output.mp4
MOV / AVI to MP4
Re-encode legacy footage to a widely supported MP4.
Shellffmpeg -i input.mov -c:v libx264 -crf 22 -preset medium -c:a aac -b:a 160k -movflags +faststart output.mp4
MP4 to WebM (VP9 + Opus)
Open format for the web, good compression.
Shellffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 32 -b:v 0 -c:a libopus -b:a 96k output.webm
Make an MP4 stream instantly
Moves the moov atom to the front so playback starts before the download finishes.
Shellffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4
Video to high-quality GIF (palette)
Two passes: build an optimal palette, then encode with it.
Shellffmpeg -i input.mp4 -vf "fps=15,scale=480:-1:flags=lanczos,palettegen" palette.png
ffmpeg -i input.mp4 -i palette.png -lavfi "fps=15,scale=480:-1:flags=lanczos [x]; [x][1:v] paletteuse" output.gif
GIF to MP4
Far smaller than a GIF and plays everywhere.
Shellffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4
Grab a single frame / thumbnail
One JPEG from the 5-second mark.
Shellffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 -q:v 2 thumb.jpg
Export every frame (or one per second)
Numbered PNG sequence in the current folder.
Shellffmpeg -i input.mp4 -vf fps=1 frame_%04d.png
Contact sheet / storyboard
A 4×4 grid of evenly spaced frames.
Shellffmpeg -i input.mp4 -vf "select=not(mod(n\,300)),scale=320:-1,tile=4x4" -frames:v 1 sheet.png
Image sequence to video
Turn numbered stills into a 30 fps clip.
Shellffmpeg -framerate 30 -i frame_%04d.png -c:v libx264 -pix_fmt yuv420p output.mp4
Download an HLS (.m3u8) stream to MP4
Saves the whole playlist and remuxes it into an MP4.
Shellffmpeg -i "https://example.com/stream.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4
Add -headers "Referer: https://example.com\r\n" when the CDN checks the referer.
Package a video as HLS segments
10-second segments plus a playlist for web players.
Shellffmpeg -i input.mp4 -c:v libx264 -crf 22 -c:a aac -hls_time 10 -hls_playlist_type vod -hls_segment_filename "seg_%03d.ts" playlist.m3u8
Stream to YouTube / Twitch (RTMP)
Live push of a local file or capture device.
Shellffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k -c:a aac -b:a 128k -f flv rtmp:
Record the screen
Platform-specific capture inputs.
Shell
ffmpeg -f x11grab -framerate 30 -i :0.0 -c:v libx264 -preset ultrafast out.mp4
ffmpeg -f avfoundation -framerate 30 -i "1:0" -c:v libx264 -preset ultrafast out.mp4
ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast out.mp4
Burn subtitles into the picture
Hard-coded captions that always show.
Shellffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='FontSize=24'" -c:a copy output.mp4
Add a soft subtitle track (toggleable)
Embeds the SRT as a stream the player can switch off.
Shellffmpeg -i input.mp4 -i subs.srt -c copy -c:s mov_text -metadata:s:s:0 language=eng output.mp4
Extract subtitles from an MKV
Pull the first subtitle stream out as SRT.
Shellffmpeg -i input.mkv -map 0:s:0 subs.srt
Inspect streams, codecs and duration
ffprobe prints everything about the file as JSON.
Shellffprobe -v error -show_format -show_streams -of json input.mp4
Print only the duration in seconds
Handy inside shell scripts.
Shellffprobe -v error -show_entries format=duration -of csv=p=0 input.mp4
Print resolution and frame rate
Compact output ready to parse.
Shellffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate -of csv=p=0 input.mp4
Batch convert every file in a folder
Loop over MOV files and write MP4s next to them.
Shellfor f in *.mov; do ffmpeg -i "$f" -c:v libx264 -crf 22 -c:a aac "${f%.mov}.mp4"; done