7

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.

kristianp
  • 5,496
  • 37
  • 56
Abubakar
  • 116
  • 1
  • 1
  • 6
  • With Bash you can use [brace expansion](https://www.linuxjournal.com/content/bash-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` – Matthias Braun May 16 '20 at 18:20

6 Answers6

5

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
Isaac Abramowitz
  • 542
  • 5
  • 17
  • Is 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` – Edmund Rojas Feb 14 '19 at 20:47
  • Hmm not sure. Probably. If you can't find a question like that already posted, I would suggest posing that question on this site. – Isaac Abramowitz Feb 15 '19 at 15:13
3

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
double-beep
  • 5,031
  • 17
  • 33
  • 41
David Blum
  • 41
  • 1
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) 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. – double-beep Mar 29 '19 at 14:11
  • 2
    Consider checking your (overly complex) script with shellcheck.net. There are several issues to address. – llogan Mar 29 '19 at 17:18
  • The question explicitly states that ffmpeg should only be invoked once. Your solution invokes it once per input file. – Hugh W Apr 16 '20 at 11:39
2

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
kristianp
  • 5,496
  • 37
  • 56
  • 1
    [This](https://stackoverflow.com/questions/5784661/how-do-you-convert-an-entire-directory-with-ffmpeg) might help you simplify this command. – Matthias Braun May 16 '20 at 18:16
1

find ./ -name "*.wav" -exec ffmpeg -i {} -c:a libopus {}.opus \;

Alex
  • 51
  • 1
  • 6
0

Maybe you could try using Different parallel outputs as in the FFMPEG documentation ?

cubitouch
  • 1,929
  • 15
  • 28
  • Thank 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`. – Abubakar Jan 17 '14 at 11:45
  • @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 ? – cubitouch Jan 17 '14 at 11:52
  • Sorry i could not do that. – Abubakar Jan 17 '14 at 12:06
  • And what about Parallel Encoding ? (see http://ffmpeg.org/pipermail/ffmpeg-user/2013-April/014898.html) – cubitouch Jan 17 '14 at 13:26
0

When I have more files to work, I create a spreadsheet sheet and I do the command with "holes".

Every hole match to a file (filename).

I copy/paste in a file which become a script.

I know it is not perfect bet if it can help you.

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Seb
  • 65
  • 1
  • 6