Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Last active June 7, 2025 00:32
Show Gist options
  • Save DavidEGrayson/4c7a11861a46bc4101c4f01af1907891 to your computer and use it in GitHub Desktop.
Save DavidEGrayson/4c7a11861a46bc4101c4f01af1907891 to your computer and use it in GitHub Desktop.
ffmpeg commands to extract AAC audio from an MP4, edit it, and replace it
# Reduce file size. Might need '-vcodec libx264' in some cases?
ffmpeg -i foo.mp4 -crf 28 foo_out.mp4
# Reduce file size, rescale to 1080p, and crop in time and space.
ffmpeg -i foo.mp4 -crf 28 -ss 00:00:25 -to 00:01:15 -vf "scale=1920:-1,crop=1920:800:0:1900" foo_out.mp4
# Reduce file size, crop a video in time and scale it to 1080p
ffmpeg -i foo.mp4 -crf 28 -ss 00:01:00 -to 00:00:10 -vf scale=1920:-1 output.mp4
ffprobe foo.mp4 # Make sure the audio stream is aac.
ffmpeg -i foo.mp4 -vn -acodec copy foo.aac
ffmpeg -i foo.aac -acodec pcm_s16le foo.wav
# Edit foo.wav with audacity, save to foo_edited.wav.
ffmpeg -i foo_edited.wav -acodec aac foo_edited.aac
ffmpeg -i foo.mp4 -codec copy -an foo_silent.mp4
ffmpeg -i foo_silent.mp4 -i foo_edited.aac -shortest -c:v copy -c:a aac foo_edited.mp4
# Reduce file size and remove sounds
ffmpeg -i foo.mp4 -vcodec libx264 -crf 28 -an foo_out.mp4
# Extract some audio from a video
ffmpeg -i foo.mp4 -ss 3:50.2 -t 2.4 -vn output1.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment