Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert an entire directory with ffmpeg?

People also ask

How do I change my FFmpeg folder?

In Terminal, navigate to the folder containing the ffmpeg file using the "cd" (change directory) command. Type "cd" followed by the file path to your Downloads folder.

How do I use FFmpeg without losing quality?

Instead of -sameq (removed by FFMpeg), use -qscale 0 : the file size will increase but it will preserve the quality.


For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done

Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.

for i in *.avi;
  do name=`echo "$i" | cut -d'.' -f1`
  echo "$name"
  ffmpeg -i "$i" "${name}.mov"
done

And on Windows:

FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"

For Windows:

Here I'm Converting all the (.mp4) files to (.mp3) files.
Just open cmd, goto the desired folder and type the command.

Shortcut: (optional)
1. Goto the folder where your (.mp4) files are present
2. Press Shift and Left click and Choose "Open PowerShell Window Here"
or "Open Command Prompt Window Here"
3. Type "cmd" [NOTE: Skip this step if it directly opens cmd instead of PowerShell]
4. Run the command

for %i in (*.mp4) do ffmpeg -i "%i" "%~ni.mp3"

If you want to put this into a batch file on Windows 10, you need to use %%i.


A one-line bash script would be easy to do - replace *.avi with your filetype:

for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done

To convert with subdirectories use e.g.

find . -exec ffmpeg -i {} {}.mp3 \;