I'm writing a zsh script that automates some video encoding. The file to be converted will be the first parameter to the script, which contains this line:
ffmpeg -i $1 -ac 0 -vcodec libx264 -b:v 500k -crf 20 ${1:r}.mp4
I expected ${1:r}.mp4
to create a file with the same name as my .mov input, but with the .mp4 file extension replacing .mov. But instead I get input.mov.mp4. Why isn't the :r modifier stripping the file extension?
%. * will only remove the last extension; if you want to remove all the extensions, use %%. * .
`basename` command is used to read the file name without extension from a directory or file path. Here, NAME can contain the filename or filename with full path. SUFFIX is optional and it contains the file extension part that the user wants to remove. `basename` command has some options which are described below.
I experienced something similar and it seems like zsh doesn't accept :r on the positional arguments. Instead you could do something like this:
file=${1}
ffmpeg -i $1 -ac 0 -vcodec libx264 -b:v 500k -crf 20 ${file:r}.mp4
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