LweshaKj FFmpeg Ultimate Edition
Introduction to FFmpeg
FFmpeg is a powerful multimedia framework that can decode, encode, transcode, mux, demux,
stream, filter, and play almost anything that humans and machines have created. It's widely used for
video and audio processing tasks.
Installation
Windows:
1. Download from https://ffmpeg.org
2. Extract and add bin/ folder to PATH
Linux:
sudo apt update && sudo apt install ffmpeg
macOS:
brew install ffmpeg
Basic Commands
- Convert Format:
ffmpeg -i input.mp4 output.avi
- Compress Video:
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
- Extract Audio:
ffmpeg -i input.mp4 -vn -acodec copy output.aac
- Cut Video (without re-encoding):
ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:00 -c copy output.mp4
- Merge Videos:
Prepare list.txt with:
file 'part1.mp4'
file 'part2.mp4'
Then run:
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
Video Processing
- Resize Video:
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
- Rotate Video:
ffmpeg -i input.mp4 -vf transpose=1 output.mp4
- Crop Video:
ffmpeg -i input.mp4 -vf "crop=640:480:10:10" output.mp4
Audio Processing
- Increase Volume:
ffmpeg -i input.mp3 -filter:a "volume=1.5" output.mp3
- Merge Audio Tracks:
ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex amerge=inputs=2 output.mp3
Subtitle Handling
- Burn Subtitles into Video:
ffmpeg -i input.mp4 -vf subtitles=subtitlefile.srt output.mp4
- Extract Subtitles:
ffmpeg -i input.mkv -map 0:s:0 subs.srt
Advanced Encoding and Compression
- H.264 Encoding (good quality):
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 22 output.mp4
- H.265 Encoding (better compression):
ffmpeg -i input.mp4 -c:v libx265 -preset medium -crf 28 output.mp4
Filters
- Grayscale Filter:
ffmpeg -i input.mp4 -vf format=gray output.mp4
- Add Blur:
ffmpeg -i input.mp4 -vf boxblur=10:1 output.mp4
GIF Creation
- From Video:
ffmpeg -i input.mp4 -vf "fps=15,scale=320:-1:flags=lanczos" output.gif
Streaming
- Stream to RTMP Server:
ffmpeg -re -i input.mp4 -c:v libx264 -f flv rtmp://yourserver/live/streamkey
- Create HLS (HTTP Live Streaming):
ffmpeg -i input.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index.m3u8
Batch Processing
- Convert All MP4 to AVI:
for f in *.mp4; do ffmpeg -i "$f" "${f%.mp4}.avi"; done
Troubleshooting Common Errors
- Invalid Data Found:
Usually codec mismatch. Try re-encoding explicitly.
- Codec Not Found:
Install FFmpeg with all libraries.
- Output File Already Exists:
Use -y option to overwrite automatically.
Pro Tips and Best Practices
- Use CRF for balancing size and quality (18-28 range)
- Always test short clips first before full processing
- Use -preset slow or slower for better compression efficiency
- Keep FFmpeg updated for best codec support