I would like to run this command in the terminal:
ffmpeg -i <input-file> -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 <output-file.mp3> on every mp3 file in a folder.
The input and output could be the same (an overwrite), but if this is not possible, if there was a way to take the filename and append _converted maybe?
I'm not a bash expert, but I know that I need to pipe the results of an ls command into the ffmpeg command using a variable perhaps?
Could you please try following, since I don't have ffpmeg command so couldn't test it. This should save output into same Input_file itself, better to test it on a test folder and once happy with results could run on actual folder.
for file in *.mp3
do
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "temp" && mv "temp" "$file"
done
OR as per OP you want to take output _converted string into output file name then try following.
for file in *.mp3
do
output_file="${file}_converted"
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "$output_file"
done
OR as per @Gordon Davisson sir's comment use following.
for file in *.mp3
do
output_file="${file%.mp3}_converted.mp3"
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "$output_file"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With