Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg: Transcoding multiple input files to multiple output files with single command

Tags:

ffmpeg

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.

like image 593
Abubakar Avatar asked Jun 19 '26 23:06

Abubakar


2 Answers

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
like image 138
Isaac Abramowitz Avatar answered Jun 23 '26 02:06

Isaac Abramowitz


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
like image 41
David Blum Avatar answered Jun 23 '26 00:06

David Blum