FFmpeg Command Mastery Guide
1. Convert Video Format (MP4 to MKV, etc.)
---------------------------------------------
Command:
ffmpeg -i input_video.mp4 output_video.mkv
Explanation:
- -i input_video.mp4: Input video file (your source video)
- output_video.mkv: Output video file with the desired format
Template:
ffmpeg -i "input_video.mp4" "output_video.mkv"
Example:
ffmpeg -i "C:/Users/Imon/Downloads/video.mp4" "C:/Users/Imon/Downloads/video_converted.mkv"
2. Compress Video Without Losing Quality
-----------------------------------------
Command:
ffmpeg -i input_video.mp4 -vcodec libx264 -crf 23 -preset fast output_video.mp4
Explanation:
- -vcodec libx264: Use H.264 codec for compression
- -crf 23: CRF (Constant Rate Factor) controls the quality. 23 is default, lower = better quality.
- -preset fast: Faster compression speed with some compromise on compression rate.
Template:
ffmpeg -i "input_video.mp4" -vcodec libx264 -crf 23 -preset fast "output_video_compressed.mp4"
Example:
ffmpeg -i "C:/Users/Imon/Downloads/video.mp4" -vcodec libx264 -crf 23 -preset fast
"C:/Users/Imon/Downloads/video_compressed.mp4"
3. Cut/Trim Video Without Re-encoding
--------------------------------------
Command:
ffmpeg -i input_video.mp4 -ss 00:01:30 -to 00:05:00 -c copy output_video.mp4
Explanation:
- -ss 00:01:30: Start at 1 minute 30 seconds
- -to 00:05:00: End at 5 minutes
- -c copy: Copy video/audio without re-encoding (fast and quality-preserving)
Template:
ffmpeg -i "input_video.mp4" -ss [start_time] -to [end_time] -c copy "output_video.mp4"
Example:
ffmpeg -i "C:/Users/Imon/Downloads/video.mp4" -ss 00:01:30 -to 00:03:00 -c copy
"C:/Users/Imon/Downloads/video_trimmed.mp4"
4. Merge/Join Multiple Videos
------------------------------
Command:
ffmpeg -f concat -safe 0 -i file_list.txt -c copy output_video.mp4
Explanation:
- -f concat: Use the concatenate protocol to join multiple videos
- -safe 0: Allows file paths with spaces and non-standard characters
- -i file_list.txt: A text file listing the video files to be joined
- -c copy: Copy streams without re-encoding
Creating file_list.txt:
file 'C:/path/to/video1.mp4'
file 'C:/path/to/video2.mp4'
file 'C:/path/to/video3.mp4'
Template:
ffmpeg -f concat -safe 0 -i "file_list.txt" -c copy "output_video_merged.mp4"
5. Resize/Crop or Change Aspect Ratio
--------------------------------------
Command (Resize):
ffmpeg -i input_video.mp4 -vf "scale=1280:720" output_video.mp4
Explanation:
- -vf "scale=1280:720": Resizes video to 1280x720 resolution
Command (Crop):
ffmpeg -i input_video.mp4 -vf "crop=out_w:out_h:x:y" output_video.mp4
Explanation:
- crop=out_w:out_h:x:y: Crops video to specific dimensions
Template (Resize):
ffmpeg -i "input_video.mp4" -vf "scale=[width]:[height]" "output_video_resized.mp4"
Template (Crop):
ffmpeg -i "input_video.mp4" -vf "crop=[width]:[height]:[x_offset]:[y_offset]"
"output_video_cropped.mp4"
6. Extract Frames as Images (JPG, PNG)
----------------------------------------
Command:
ffmpeg -i input_video.mp4 -vf "fps=1" output_frame_%04d.png
Explanation:
- -vf "fps=1": Extract 1 frame per second
- output_frame_%04d.png: Save frames as PNGs with numbered names
Template:
ffmpeg -i "input_video.mp4" -vf "fps=[fps]" "output_frame_%04d.png"
Example:
ffmpeg -i "C:/Users/Imon/Downloads/video.mp4" -vf "fps=1"
"C:/Users/Imon/Downloads/frame_%04d.png"
7. Add Subtitles or Burn Them In
---------------------------------
Command (Add Subtitle File):
ffmpeg -i input_video.mp4 -i subtitles.srt -c:v copy -c:a copy -c:s srt output_video.mp4
Explanation:
- -i subtitles.srt: Add subtitle file
- -c:v copy -c:a copy: Copy video and audio streams without re-encoding
- -c:s srt: Add subtitle stream
Template:
ffmpeg -i "input_video.mp4" -i "subtitles.srt" -c:v copy -c:a copy -c:s srt
"output_video_with_subs.mp4"