Skip to content

Instantly share code, notes, and snippets.

@ybagheri
Created July 28, 2024 12:21
Show Gist options
  • Save ybagheri/3b1136b3abe6b4a2006ab01efaa1fab4 to your computer and use it in GitHub Desktop.
Save ybagheri/3b1136b3abe6b4a2006ab01efaa1fab4 to your computer and use it in GitHub Desktop.
How do you convert an entire directory with ffmpeg?
link: https://stackoverflow.com/questions/38449239/converting-all-the-mp4-audio-files-in-a-folder-to-mp3-using-ffmpeg
# Windows
# first create a folder with name outputs inside video folder
FOR /F "tokens=*" %G IN ('dir /b *.mp4') DO ffmpeg -i "%G" -acodec mp3 "outputs\%~nG.mp3"
## convert lower quality and size
FOR /F "tokens=*" %G IN ('dir /b *.mp4') DO ffmpeg -i "%G" -acodec mp3 -ab 64000 -ar 22050 "outputs\%~nG.mp3"
# Linux, MacOS
#For converting only .mp4 files:
mkdir outputs
for f in *.mp4; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.mp4}.mp3"; done
#For converting .m4a, .mov, and .flac:
mkdir outputs
for f in *.{m4a,mov,flac}; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.*}.mp3"; done
#For converting anything use the "*" wildcard:
mkdir outputs
for f in *; do ffmpeg -i "$f" -c:a libmp3lame "outputs/${f%.*}.mp3"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment