Published - 3 years ago ( Updated - 3 years ago )
This article introduces how I convert multiple file formats in one directory.
When you learn it, you can definitely conjure up new tricks.
How to list files, here is a simple sample.
The second echo is to keep the file name and change the file extension to mp3.
Actual execution example: (Any similarity to the following file names is purely fictitious - Any similarity files name are purely fictitious)
After learning this trick, you can make the following changes..
Therefore, by pasting the above command on the terminal, you can easily convert all webm files in the directory to mp3, and skip the converted files.
When you learn it, you can definitely conjure up new tricks.
How to list files, here is a simple sample.
FILES=*.webm
for f in $FILES
do
file="$f"
echo "$f"
echo ${file%.*}.mp3
done
In this example, for the first echo, I will print all files with the extension webm. The second echo is to keep the file name and change the file extension to mp3.
Actual execution example: (Any similarity to the following file names is purely fictitious - Any similarity files name are purely fictitious)
After learning this trick, you can make the following changes..
FILES=*.webm
for f in $FILES
do
file="$f"
ls -l "${file%.*}.mp3" > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "$f to ${file%.*}.mp3"
ffmpeg -i "${f}" -vn -ab 128k -ar 44100 -y "${file%.*}.mp3"
the fi
done
I use ls to check whether there is an mp3 with the same file name in the directory, if not, I will convert it through the ffmpeg command. Therefore, by pasting the above command on the terminal, you can easily convert all webm files in the directory to mp3, and skip the converted files.
No Comment
Post your comment