Skip to content

Instantly share code, notes, and snippets.

@AirManH
Last active May 19, 2023 08:04
Show Gist options
  • Save AirManH/81b37d2d9af29e5ecbaf7a87640a50d6 to your computer and use it in GitHub Desktop.
Save AirManH/81b37d2d9af29e5ecbaf7a87640a50d6 to your computer and use it in GitHub Desktop.

Cheatsheet for ffmpeg and sox

Examples

To wechat

  • -vf scale=960:-1: scale the resolution to 960*a (a is calculated automatically)
  • -b:v: set video bitrate in bps
  • -r: framerate in FPS
  • -b:a: set audio bitrate in bps
  • -af "volume=15dB": add a filter to increase audio volume
  • -preset veryslow: controls compression quality
ffmpeg -i .\VID_20220428_140425.mp4 \
  -c:v h264 -vf scale=960:-1 -b:v 2M -r 24 \
  -c:a aac -b:a 96k -af "volume=15dB" \
  -preset veryslow \
  out_15db.mp4

Extract audio track

See also https://stackoverflow.com/a/36324719

ffmpeg -i ./VID_20220428_140425.mp4 -map a -q:a 0 bgm.mp3

Combine audio and video

ffmpeg -i input.aac -i input.mp4 output.mp4

Audio denoise

See also http://sox.sourceforge.net/sox.html, search for "noisered".

noisered [profile-file [amount]]

How much noise should be removed is specified by amount-a number between 0 and 1 with a default of 0.5. Higher numbers will remove more noise but present a greater likelihood of removing wanted components of the audio signal.

sox music.mp3 -n noiseprof noise.prof
sox music.mp3 noisered noise.prof 0.1

Increase volume

gain [−e|−B|−b|−r] [−n] [−l|−h] [gain-dB]

Apply amplification or attenuation to the audio signal, or, in some cases, to some of its channels.

sox in.mp3 out.mp3 gain +6

Cut for Time Range

ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment