Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Last active March 2, 2025 23:39
Show Gist options
  • Save HirbodBehnam/a7d2f038833215a48e176c4d5361f2a9 to your computer and use it in GitHub Desktop.
Save HirbodBehnam/a7d2f038833215a48e176c4d5361f2a9 to your computer and use it in GitHub Desktop.
FFMpeg scripts I use to convert videos
# Simple FFMPEG scripts I use to convert videos or audios
# The ones with h264_nvenc codec only work with NVidia graphic cards. You also need to install the drives to use them
# The hevc_nvenc codec is pretty fast but the output file size is terrible. So I won't include that in. (Special thanks to Erfan Mojibi)
# The libx265 provides better quality to file size. So we can increase the crf in it (source: https://trac.ffmpeg.org/wiki/Encode/H.265#ConstantRateFactorCRF)
# The tag is provided by @alirezahabib
# Simple convert from webm to mp4. ACC audio codec at 128kb/s. Change 24 to change the quality (higher is worse)
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v h264_nvenc -cq:v 24 -profile:v high -c:a aac -b:a 128k -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx264 -crf 24 -c:a aac -b:a 128k -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx265 -crf 28 -c:a aac -b:a 128k -tag:v hvc1 -strict experimental out.mp4
# Same video codec as above but copy the audio channel (no re-encode)
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v h264_nvenc -cq:v 24 -profile:v high -acodec copy -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx264 -crf 24 -acodec copy -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx265 -crf 28 -acodec copy -tag:v hvc1 -strict experimental out.mp4
# General re-encode video and audio to h264 and opus
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -cq:v 24 -c:v h264_nvenc -c:a libopus -b:a 32K -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx264 -crf 24 -c:a libopus -b:a 32K -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx265 -crf 28 -c:a libopus -b:a 32K -tag:v hvc1 -strict experimental out.mp4
# Convert audio codec to opus only (do not touch the video codec)
ffmpeg -i in.mp4 -vcodec copy -c:a libopus -b:a 32K -strict experimental out.mp4
# Extract the audio from video file
ffmpeg -i in.webm -vn -acodec copy out.ogg
# Check video and audio size
ffmpeg -i in.webm -c copy -f null -
# Change the container
ffmpeg -i in.webm -c copy out.mkv
# Trim video https://stackoverflow.com/a/42827058/4213397
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:01:00 -c copy output.mp4
# Remove noise from class voices
ffmpeg -i input.aac -af "highpass=f=200, lowpass=f=3000" -c:a libopus -b:a 96K out.ogg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment