Skip to content

Instantly share code, notes, and snippets.

@thewheat
Last active March 8, 2020 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewheat/9c2fd0ee03191925ec4f9369a9f62307 to your computer and use it in GitHub Desktop.
Save thewheat/9c2fd0ee03191925ec4f9369a9f62307 to your computer and use it in GitHub Desktop.
Document typical ffmpeg commands I use

Extract only video from file

ffmpeg -i input.mov -c:v copy -an input_video.mov

Extract only audio from file

ffmpeg -i input.mov -c:a copy -vn input_audio.aac

Combine video and audio file

ffmpeg -i video.mov -i audio.aac -c:v copy -c:a copy video_new.mov
ffmpeg -i input.mov -metadata:s:v rotate="-90" -codec copy output.mov
ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
ffmpeg -i video.mov -vf "fps=6" -loop 0 output.gif
ffmpeg -i video.mov -vf "fps=6,scale=WIDTH:-1" -loop 0 output.gif
ffmpeg -i video.mov -vf "fps=6,scale=-1:HEIGHT" -loop 0 output.gif
  • ss: number of seconds to skip from start
  • t: number of seconds to convert
  • fps frame rate
  • scale convert video to resolution WIDTH:HEIGHT. Use -1 for auto -loop: number of times to loop. 0 = infinite looping.

Concatenate / Combine several files into one

https://trac.ffmpeg.org/wiki/Concatenate

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav
  • The -safe 0 above is not required if the paths are relative.
  • mylist.txt a list of all files to concatenated in the following form (lines starting with a # are ignored):
# this is a comment
file '/path/to/file1.wav'
file '/path/to/file2.wav'
file '/path/to/file3.wav'

Automatically generating the input file

*nix / macOS

# with a bash for loop
for f in ./*.wav; do echo "file '$f'" >> mylist.txt; done
# or with printf
printf "file '%s'\n" ./*.wav > mylist.txt

Windows

Command-line

(for %i in (*.wav) do @echo file '%i') > mylist.txt

Powershell

foreach ($i in Get-ChildItem .\*.wav) {echo "file '$i'" >> mylist.txt}

bat-file

(for %%i in (*.wav) do @echo file '%%i') > mylist.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment