> ffmpeg
multimedia framework — convert, trim, filter, and process audio and video
// basic conversion
6 commandsConvert MP4 to WebM
$ ffmpeg -i input.mp4 output.webmConvert MKV to MP4 without re-encoding
$ ffmpeg -i input.mkv -c copy output.mp4Remux container without transcoding
$ ffmpeg -i input.mkv -c copy output.mp4Convert to H.265 HEVC for smaller file size
$ ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a aac output.mp4Convert AVI to MP4 with H.264
$ ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac output.mp4Convert video to audio-only format
$ ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3// trimming
4 commandsTrim video without re-encoding
$ ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4Trim with re-encoding for frame accuracy
$ ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:00 -c:v libx264 -c:a aac output.mp4Split video into equal segments
$ ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment -reset_timestamps 1 output_%03d.mp4Extract a specific time range
$ ffmpeg -ss 00:05:00 -i input.mp4 -t 30 -c copy output.mp4// audio
7 commandsExtract audio from video
$ ffmpeg -i input.mp4 -vn -acodec copy audio.aacRemove audio from video
$ ffmpeg -i input.mp4 -an -c:v copy output.mp4Replace audio in a video
$ ffmpeg -i input.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4Adjust volume level
$ ffmpeg -i input.mp4 -af "volume=2.0" output.mp4Normalize audio loudness with EBU R128
$ ffmpeg -i input.mp4 -af loudnorm=I=-16:TP=-1.5:LRA=11 output.mp4Convert audio sample rate
$ ffmpeg -i audio.mp3 -ar 44100 output.mp3Mute a specific time range
$ ffmpeg -i input.mp4 -af "volume=enable='between(t,5,10)':volume=0" output.mp4// video filters
7 commandsResize video to 720p
$ ffmpeg -i input.mp4 -vf "scale=-1:720" output.mp4Crop video to square
$ ffmpeg -i input.mp4 -vf "crop=ih:ih" output.mp4Rotate video 90 degrees
$ ffmpeg -i input.mp4 -vf "transpose=1" output.mp4Add text overlay with timestamp
$ ffmpeg -i input.mp4 -vf "drawtext=text='%{pts\:hms}':x=10:y=10:fontsize=24:fontcolor=white" output.mp4Deinterlace video
$ ffmpeg -i input.mp4 -vf yadif output.mp4Add a watermark image overlay
$ ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=W-w-10:H-h-10" output.mp4Apply blur to a region of the video
$ ffmpeg -i input.mp4 -vf "split[original][copy];[copy]crop=200:200:100:100,boxblur=10[blurred];[original][blurred]overlay=100:100" output.mp4// speed & reverse
4 commandsDouble the playback speed
$ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -af "atempo=2.0" output.mp4Slow down to half speed
$ ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" output.mp4Reverse a video
$ ffmpeg -i input.mp4 -vf reverse -af areverse output.mp4Create a boomerang loop
$ ffmpeg -i input.mp4 -filter_complex "[0:v]reverse[r];[0:v][r]concat=n=2:v=1:a=0" output.mp4// gif & images
6 commandsConvert video to GIF
$ ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1" output.gifConvert video to GIF with optimized palette
$ ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,palettegen" palette.pngExtract one frame per second as images
$ ffmpeg -i input.mp4 -vf fps=1 frame_%04d.pngExtract a single frame at a timestamp
$ ffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 thumbnail.jpgCreate slideshow from images
$ ffmpeg -framerate 1 -i frame_%04d.png -c:v libx264 -pix_fmt yuv420p output.mp4Create a video thumbnail grid
$ ffmpeg -i input.mp4 -vf "select='not(mod(n\,100))',scale=320:180,tile=4x4" -frames:v 1 thumbnail.jpg// concatenation
4 commandsConcatenate videos from a file list
$ ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4Merge audio and video from separate files
$ ffmpeg -i input.mp4 -i audio.mp3 -c:v copy -c:a aac -shortest output.mp4Join videos with different codecs using re-encoding
$ ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4Loop a video N times
$ ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4// subtitles
4 commandsBurn subtitles permanently into video
$ ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt" output.mp4Add a selectable subtitle track
$ ffmpeg -i input.mp4 -i subtitles.srt -c copy -c:s mov_text output.mp4Extract subtitles from a video
$ ffmpeg -i input.mp4 -map 0:s:0 subtitles.srtConvert subtitle format from SRT to ASS
$ ffmpeg -i subtitles.srt subtitles.ass// compression
5 commandsCompress video with CRF quality control
$ ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4Two-pass encoding for target file size
$ ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 1 -f null /dev/nullHardware-accelerated encoding with VideoToolbox
$ ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 5M output.mp4Hardware-accelerated encoding with NVENC
$ ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -cq 23 output.mp4Reduce file size by limiting bitrate
$ ffmpeg -i input.mp4 -b:v 1M -maxrate 1M -bufsize 2M -c:a aac output.mp4// streaming
3 commandsDownload an HLS stream to MP4
$ ffmpeg -i "https://example.com/stream.m3u8" -c copy output.mp4Record an RTMP stream to file
$ ffmpeg -i "rtmp://example.com/live/stream" -c copy output.mp4Stream a video file to an RTMP server
$ ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f flv "rtmp://example.com/live/stream"// inspection
5 commandsGet video file information
$ ffprobe input.mp4Get video stream details like codec and resolution
$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height,r_frame_rate -of csv=p=0 input.mp4Get audio stream details
$ ffprobe -v error -select_streams a:0 -show_entries stream=codec_name,sample_rate,channels -of csv=p=0 input.mp4Read and display all metadata tags
$ ffprobe -v error -show_entries format_tags -of default=noprint_wrappers=1 input.mp4Check video duration
$ ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp4# useful tips
9 commandsConvert audio to Whisper-compatible format
$ ffmpeg -i input.mp4 -ar 16000 -ac 1 -c:a pcm_s16le output.wavMove metadata to the beginning of the file
$ ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4Apply a retro VHS effect
$ ffmpeg -i input.mp4 -vf "curves=vintage,noise=alls=40:allf=t,hue=s=0.5,eq=contrast=1.3:brightness=-0.05:saturation=0.7" output.mp4Reverse a video for boomerang effect
$ ffmpeg -i input.mp4 -filter_complex "[0:v]split[fwd][rev];[rev]reverse[r];[fwd][r]concat=n=2:v=1:a=0,loop=3:size=999" output.mp4Create a thermal camera look
$ ffmpeg -i input.mp4 -vf "eq=brightness=0.06:saturation=2,hue=h=180,lutrgb=r='if(gt(val,200),255,0)':g='clip(val*2,0,255)':b='if(lt(val,50),255,0)'" output.mp4Generate Game of Life animation
$ ffmpeg -f lavfi -i life=s=320x240:mold=10:r=30:ratio=0.5:death_color=#C83232:life_color=#00ff00 -t 10 output.mp4Turn a video into pixel art style
$ ffmpeg -i input.mp4 -vf "scale=iw/10:ih/10:flags=neighbor,scale=iw*10:ih*10:flags=neighbor" output.mp4Create a timelapse from a long video
$ ffmpeg -i input.mp4 -vf "setpts=PTS/30" -an output.mp4Add a logo watermark to a video
$ ffmpeg -i input.mp4 -i logo.png -filter_complex "[0:v]split[base][ref];[1:v][ref]scale=rw/10:-1[logo];[base][logo]overlay=W-w-W*0.02:H*0.02" output.mp4