Installation
1 2 3 |
# Linux: Using snap sudo snap install ffmpeg sudo snap connect ffmpeg:camera |
Basic Usage
File format conversion
1 |
ffmpeg -i source_file dest_file |
Specifying Quality
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# For AVI # quality: lower the better, 20-30 (common) ffmpeg -i <source_file> -q <quality> <dest_file> # For MP4 ffmpeg -i <source_file> -crf <quality> <dest_file> # Specifying bit rate # For audio ffmpeg -i inFile.mp3 -b:a 320k outFile.mp3 # For video ffmpeg -i inFile.avi -b:v 1000k outFile.mp4 # For both video and audio ffmpeg -i inFile.avi -b:v 1000k -b:a 128k outFile.mp4 |
Input Format, Encoding and Copy
1 2 3 4 5 6 7 8 |
# Stream copy the MJPEG video stream (no re-encoding): ffmpeg -f v4l2 -input_format mjpeg -i /dev/video0 -c:v copy output.mkv # Re-encode the raw webcam video to H.264: ffmpeg -f v4l2 -input_format yuyv422 -i /dev/video0 -c:v libx264 -vf format=yuv420p output.mp4 # Same as above but manually choose frame rate and video size (v4l2-ctl --list-formats-ext for available frame rate and video sizes): ffmpeg -f v4l2 -input_format yuyv422 -framerate 30 -video_size 640x480 -i /dev/video0 -c:v libx264 -vf format=yuv420p output.mp4 |
Video Functions
Cropping
1 2 3 |
# Absolute Values # w: width, h: height, (x, y): coordination from top left corner ffmpeg -i inFile -filter:v "crop=w=640:h=480:x=100:y=200" outFile |
Scaling
1 2 3 4 5 6 7 8 |
# Absolute Values ffmpeg -i inFile -filter:v "scale=w=640:h=480" outFile # Scaling with arithmetic and variables ffmpeg -i inFile -filter:v "scale=w=2/3*in_w:h=2/3*in_h" outFile # Proportional Scaling ffmpeg -i inFile -filter:v "scale=w=852:h=-1" outFile |
Rotation
1 2 |
# Rotate 45 degree clockwise ffmpeg -i inFile -filter:v "rotate=45*PI/180" outFile |
Transcoding
1 2 |
# Converting an H264 (AVC) video to an H265 (HEVC) ffmpeg -i bunny_1080p_60fps.mp4 -c:v libx265 bunny_1080p_60fps_h265.mp4 |
Transmuxing
Converting from one container format to another
1 2 |
# Converting a mp4 to a ts (no transcoding required) ffmpeg -i bunny_1080p_60fps.mp4 -c copy bunny_1080p_60fps.ts |
Transrating
Changing the bit rate of video file
1 |
ffmpeg -i bunny_1080p_60fps.mp4 -minrate 964K -maxrate 3856K -bufsize 2000K bunny_1080p_60fps_transrating_964_3856.mp4 |
Transizing
Converting from one resolution to another
1 2 |
# converting a 1080p to a 480p resolution ffmpeg -i bunny_1080p_60fps.mp4 -vf scale=480:-1 bunny_1080p_60fps_transsizing_480.mp4 |
Audio Functions
Adjust Volume
1 2 3 4 5 |
# Double the volume ffmpeg -i inFile -filter:a "volume=2" outFile # Increase the volume by 50% ffmpeg -i inFile -filter:a "volume=1.5" outFile |
Convert stereo audio to mono
1 |
ffmpeg -i stereo.flac -ac 1 mono.flac |
Channel Remapping
1 2 3 4 |
# Convert Mono to Stereo # where 0-0 means mapping input source channel 0 to output channel 0 # and 0-1 means mapping input source channel 0 to output channel 1 ffmpeg -i inFile -filter:a "channelmap=0-0|0-1" outFile |
Split files
1 |
ffmpeg -i BIG_FILE -acodec copy -ss START_TIME -to END_TIME LITTLE_FILE |