![]() |
ffmpeg: batch process all files in folder to single channel
Hello
I sometimes wish to convert mp3 files to single channel only. I would normally do this in the shell by typing: Code:
ffmpeg -v 5 -y -i "my_stereo_file.mp3" -acodec libmp3lame -ac 1 -ab 128k "my_stereo_file 1chan.mp3" If I have a number of these to do, it would be good to automate the process. I have scripts that, for example, convert all m4a files in a directory to mp3: Code:
for x in *.m4a; do ffmpeg -ab 140k -i "$x" "`basename "$x" .m4a`.mp3"; done Could anyone suggest the script line I would need to convert all mp3 files in that folder to mp3 with single channel, plus adding "1 chan" to each output filename as it does so? (I think it has something to do with the Basename function, but having fiddled with this, I keep getting an "unexpected EOF error" when running, which I suspect is due to mismatched quotes, but I cannot figure out which types of quotes go where.) Thank you for any advice you can give. Steve |
You can place applicable descriptive chars or texts somewhere in end of this line --> "`basename "$x" .m4a`.mp3" before or after that bold file suffix. Just try to play it. You will find interesting tricks in computing.
Hope that helps. m.m. |
Code:
for i in *.m4a; do Code:
for i in *.m4a; do |
Thank you for your solution. I had to put double quotes around the $i, or it couldn't handle filenames of more than one word.
I also got an error saying "Unrecognized option 'c:a'", but I suspect this was due to my ffmpeg version not being the latest. It tells me that I should use "avconv" now, so I replaced "ffmpeg" with "avconv" in your line, and it then worked perfectly! So my final function is: Code:
for i in *.mp3; do I struggle to understand Regular Expressions. Could you please tell me what the percent sign does in the output part of the command ("${i%.*}")? I see that .* means wildcard, but having Googled this, I can find no reference to a percent sign doing anything in this situation. Although I realise symbol in Regular Expressions have multiple uses! Steve |
A few examples:
i="my_file.txt" Code:
#Get file basename Code:
#Get file extension Code:
#Remove _ in filename Code:
#Get filename before _ Code:
#Get filename after _ Code:
#Replace space with _ Code:
#Remove space in filename |
Ah, so the percent sign in this context means "get the string before the next character". I see. I was mistaking ".*" for the wildcard, but it's the character indicator.
I just tried Code:
echo ${i%l*} Thanks for the information! We live and learn a little each day... Steve |
All times are GMT -5. The time now is 06:25 AM. |