ffmpeg: Transcoding multiple input files to multiple output files with single command
Solution 1
Using -map
helps with specifying which input goes with which output.
I used this code to convert multiple audio files:
ffmpeg -i infile1 -i infile2 -map 0 outfile1 -map 1 outfile2
also use -map_metadata
to specify the metadata stream:
ffmpeg -i infile1 -i infile2 -map_metadata 0 -map 0 outfile1 -map_metadata 1 -map 1 outfile2
Solution 2
I wrote bash script for it.
You can modify as you want:
#!/bin/sh
BASE_DIR=$HOME/Videos/mov
OUTPUT_DIR=$BASE_DIR/avi
FILES=$(ls $BASE_DIR | grep .MOV)
for FILE in $FILES
do
FILENAME="${FILE:0:-4}"
ffmpeg -i $BASE_DIR/$FILE $OUTPUT_DIR/$FILENAME.avi
done
Solution 3
I have tried David Blum's script, there was a problem with spaces in filenames. Here's my modified script that uses basename
to remove the file extension from filenames. It operates on the current directory, assuming a subdirectory called 'avi':
#!/bin/sh
OUTPUT_DIR=./avi
#IFS=$'\n' # split only on newlines
for FILE in *MOV
do
FILENAME=`basename "${FILE}" .MOV`
ffmpeg -i "$FILE" "$OUTPUT_DIR/$FILENAME.avi"
#echo $FILENAME
done
Solution 4
find ./ -name "*.wav" -exec ffmpeg -i {} -c:a libopus {}.opus \;
Abubakar
Updated on July 07, 2021Comments
-
Abubakar about 3 years
I want to convert three files with a single command. I used the following command:
-i "C:\fil1.mp4" -i "C:\file2.mp4" -i "C:\file3.mp4" -acodec libmp3lame -ab 32k -ar 22050 -ac 2 -b:v 128k -r 20 -s 176x144 -y file1.mp4 -acodec libmp3lame -ab 32k -ar 22050 -ac 2 -b:v 128k -r 20 -s 176x144 -y file2.mp4 -acodec libmp3lame -ab 32k -ar 22050 -ac 2 -b:v 128k -r 20 -s 176x144 -y file3.mp4
but it converts the first files with names fil1.mp4, fil2.mp4, fil3.mp4 but I want all files should be convert with its output file names.
-
Matthias Braun about 4 yearsWith Bash you can use brace expansion to run
ffmpeg
on a range of files:for i in MVI_{2967..2970}.MOV; do ffmpeg -i "$i" -crf 24 ~/"$i"; done
-
-
Abubakar over 10 yearsThank you for involvement. cubitouch you can see my command fulfill the criteria which is given in FFMPEG documentation as
ffmpeg -i input1 -i input2\ -acodec .. -vcodec .. output1\ -acodec .. -vcodec .. output2\ -acodec .. -vcodec .. output3
. -
cubitouch over 10 years@Abubakar Why don't you try factorise the "-acodec libmp3lame -ab 32k -ar 22050 -ac 2 -b:v 128k -r 20 -s 176x144" part, and try parallelize the encodings ?
-
Abubakar over 10 yearsSorry i could not do that.
-
cubitouch over 10 yearsAnd what about Parallel Encoding ? (see ffmpeg.org/pipermail/ffmpeg-user/2013-April/014898.html)
-
Edmund Rojas over 5 yearsIs it possible to do this with creating multiple videos from multiple audio files and a single image?
-y -i input1.mp3 -i input2.mp3 -f image2 -loop 1 -r 2 -i imagefile.png -shortest -c:a aac -c:v mpeg4 -crf 18 -preset veryfast -movflags faststart -map 0 output1.mp4 -map1 output2.mp4
-
Isaac Abramowitz over 5 yearsHmm not sure. Probably. If you can't find a question like that already posted, I would suggest posing that question on this site.
-
double-beep over 5 yearsWhile this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
-
llogan over 5 yearsConsider checking your (overly complex) script with shellcheck.net. There are several issues to address.
-
Hugh W about 4 yearsThe question explicitly states that ffmpeg should only be invoked once. Your solution invokes it once per input file.
-
Matthias Braun about 4 yearsThis might help you simplify this command.