?! HowTheFu.cc ?!
<< OpenBSD: Setup a Static Website and a Gitea Instance
>> Git: Cheat Sheet

2023.11.16
FFMPEG: Quick Commands

Here is a list of commands I always have to look up:


# Convert input file to mp4
> ffmpeg -i input.mkv -vcodec copy -acodec copy output.mp4


# Convert and rescale
> ffmpeg -i input.mkv -s 720x480 -c:a copy output.mp4


# Create a short clip from a longer video, 
# using a start and an end point.
# Format: HH:MM:SS.MILLISECONDS
> ffmpeg -ss 01:14.00 -to 04:28.00 -i input.webm -c copy output.mp4


# Convert the (stereo) left audio channel to mono
> ffmpeg -i input.mp4 -map_channel 0.1.0 -c:v copy output.mp4


# Duplicate the (stereo) left audio channel to both channels 
> ffmpeg -i input.mp4 -map_channel 0.1.0 -map_channel 0.1.0 -c:v copy output.mp4

# Switch stereo audio channels
> ffmpeg -i input.mp3 -map_channel 0.0.1 -map_channel 0.0.0 output.mp3


# Re-encode video + audio, where:
# Video Codec: x264 with "constant quality 20"
# Audio Codec: AAC with 160k Bitrate
> ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 20 -c:a aac -b:a 160k -vf format=yuv420p -movflags +faststart output.mp4


# Re-encode video into x265 (with ffmpeg defaults), copy audio
> ffmpeg -i input.mp4 -c:v libx265 -acodec copy output.mp4


# Crop video
# Use "in_w" or "in_h" to refer to the original dimensions
# You can omit startx/starty to center the crop
# You can do math in these expressions, e.g. "in_w-40" or "320/2"
> ffmpeg -i in.mp4 -filter:v "crop=[WIDTH]:[HEIGHT]:[START_X]:[START_Y]" -c:a copy out.mp4


# Convert audio file to mp3
> ffmpeg -i input.ogg -acodec libmp3lame output.mp3


<< OpenBSD: Setup a Static Website and a Gitea Instance
>> Git: Cheat Sheet
?! HowTheFu.cc ?!