How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?
little php script to do it:
#!/usr/bin/env php
<?php
declare(strict_types = 1);
if ($argc !== 2) {
fprintf ( STDERR, "usage: %s dir\n", $argv [0] );
die ( 1 );
}
$dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
if (! is_readable ( $dir )) {
fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
die(1);
}
if (! is_dir ( $dir )) {
fprintf ( STDERR, "supplied path is not a directory!" );
die(1);
}
$files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
foreach ( $files as $file ) {
system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
}
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
For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:
https://sourceforge.net/projects/ffmpeg-batch
It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.
Only this one Worked for me, pls notice that you have to create "newfiles" folder manually where the ffmpeg.exe file is located.
Convert . files to .wav audio Code:
for %%a in ("*.*") do ffmpeg.exe -i "%%a" "newfiles\%%~na.wav"
pause
i.e if you want to convert all .mp3 files to .wav change ("*.*")
to ("*.mp3")
.
The author of this script is :
https://forum.videohelp.com/threads/356314-How-to-batch-convert-multiplex-any-files-with-ffmpeg
hope it helped
Also if you want same convertion in subfolders. here is the recursive code.
for /R "folder_path" %%f in (*.mov,*.mxf,*.mkv,*.webm) do (
ffmpeg.exe -i "%%~f" "%%~f.mp4"
)
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