Processing: Editing and Audio/Video Operations
General FFmpeg Usage
Common Processing Operations
5.4 Extracting a Segment
Start at one minute and output 30 seconds:
ffmpeg \
-ss 00:01:00 \
-i input.mp4 \
-t 30 \
-c copy \
clip.mp4With -c copy, copying can only begin at a nearby keyframe, so the start point may not be exact. Re-encode when frame-accurate trimming is required:
ffmpeg \
-ss 00:01:00 \
-i input.mp4 \
-t 30 \
-c:v libx264 \
-crf 23 \
-c:a aac \
clip-accurate.mp45.5 Software Scaling, Cropping, and Rotation
Scale proportionally to 720p:
ffmpeg -i input.mp4 -vf 'scale=-2:720' -c:v libx264 -crf 23 -c:a copy output-720p.mp4Crop the center to 1280x720:
ffmpeg \
-i input.mp4 \
-vf "crop=1280:720:(iw-ow)/2:(ih-oh)/2" \
-c:v libx264 \
-crf 23 \
-c:a copy \
output-crop.mp4Rotate clockwise by 90 degrees:
ffmpeg -i input.mp4 -vf 'transpose=clock' -c:v libx264 -crf 23 -c:a copy output-rotate.mp45.6 Screenshots
Extract one frame at 10 seconds:
ffmpeg -ss 10 -i input.mp4 -frames:v 1 screenshot.pngOutput one image every five seconds:
ffmpeg -i input.mp4 -vf 'fps=1/5' 'frame-%05d.jpg'5.7 Audio Processing
Extract an AAC audio stream without re-encoding:
ffmpeg -i input.mp4 -vn -c:a copy output.m4aConvert to 48 kHz stereo AAC:
ffmpeg \
-i input.mp4 \
-vn \
-ar 48000 \
-ac 2 \
-c:a aac \
-b:a 192k \
output.m4aAdjust the volume:
ffmpeg -i input.wav -af 'volume=1.5' output.wav
