I have this script for conversion of video files to another folder with same hierarchy. This works fine.
#!/bin/bash
SAVEIFS=$IFS
IFS=$'\n'
find . \( -name '*.mkv' -o -name '*.mpg' -o -name '*.3gp' -o -name '*.m4v' -o -name '*.avi' \) -print | while read i ;do
mkdir -p ./converted`dirname "${i:1}"`
#avidemux2.7_qt5 --load "$i" --run ./to-mp4.py --save ./converted"${i:1:-4}".mp4 --quit
cp "$i" ./converted"${i:1:-4}".mp4
echo "$i" ./converted"${i:1:-4}".mp4 >> list
echo $i >> ./converted/done.txt
done
find ./ -type f \( -iname \*.idx2 -o -iname \*.stat \) -delete
IFS=$SAVEIFS
I am trying ffmpeg to convert audio files in the same manner but it does not work. Many unwanted folders like MP3. and MP3v are created and only a few files are converted. The file names are cut partially showing errors like this.
achi.amr: No such file or directory
while the file name is ammachi.amr
.
The script is:
#!/bin/bash
SAVEIFS=$IFS
IFS=$'\n'
find ./ -type f \( -name '*.wav' -o -name '*.amr' \) -print | while read i ;do
mkdir -p ./MP3`dirname "${i:1}"`
ffmpeg -i "$i" -f mp2 "MP3/${i%.*}.mp3"
echo "'$i'" ./MP3"${i:1:-4}".mp3 >>list
done
IFS=$SAVEIFS
@Wayne Vosberg thanks for the trouble. As suggested by Wayne Vosberg. I ran the script for error.log with and without the ffmpeg line of the script commented.
Relevant part of the logs:
relevent lines of error.log with the ffmpeg line commented
+ mkdir -p ./MP3/z
+ mkdir -p ./MP3/z
+ mkdir -p ./MP3/z
+ mkdir -p ./MP3/
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3/
+ mkdir -p ./MP3/
+ echo './z/cd ef.amr' './MP3/z/cd ef.mp3'
+ echo './z/cd ef-5.amr' './MP3/z/cd ef-5.mp3'
+ echo './z/cd ef-4.wav' './MP3/z/cd ef-4.mp3'
+ echo './cd ef-5.amr' './MP3/cd ef-5.mp3'
+ echo './v/cd ef-1.amr' './MP3/v/cd ef-1.mp3'
+ echo './v/cd ef-5.amr' './MP3/v/cd ef-5.mp3'
+ echo './v/cd ef-2.wav' './MP3/v/cd ef-2.mp3'
+ echo './v/cd ef-4.wav' './MP3/v/cd ef-4.mp3'
+ echo './v/cd ef-3.amr' './MP3/v/cd ef-3.mp3'
+ echo './abc d.wav' './MP3/abc d.mp3'
+ echo './cd ef-4.wav' './MP3/cd ef-4.mp3'
relevent lines of error.log with the ffmpeg line uncommented
+ mkdir -p ./MP3/z
+ mkdir -p ./MP3/z
+ mkdir -p ./MP3.
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3.
+ mkdir -p ./MP3/v
+ mkdir -p ./MP3.
+ mkdir -p ./MP3/
+ echo ''\''./z/cd ef.amr'\''' './MP3/z/cd ef.mp3'
+ echo ''\''./z/cd ef-4.wav'\''' './MP3/z/cd ef-4.mp3'
+ echo ''\''/cd ef-1.amr'\''' './MP3cd ef-1.mp3'
+ echo ''\''./v/cd ef-5.amr'\''' './MP3/v/cd ef-5.mp3'
+ echo ''\''cd ef-2.wav'\''' './MP3d ef-2.mp3'
+ echo ''\''./v/cd ef-4.wav'\''' './MP3/v/cd ef-4.mp3'
+ echo ''\''/abc d.wav'\''' './MP3abc d.mp3'
+ echo ''\''./cd ef-4.wav'\''' './MP3/cd ef-4.mp3'
+ ffmpeg -i './z/cd ef.amr' -f mp2 './MP3/z/cd ef'
+ ffmpeg -i './z/cd ef-4.wav' -f mp2 './MP3/z/cd ef-4'
+ ffmpeg -i '/cd ef-1.amr' -f mp2 './MP3cd ef-1'
+ ffmpeg -i './v/cd ef-5.amr' -f mp2 './MP3/v/cd ef-5'
+ ffmpeg -i 'cd ef-2.wav' -f mp2 './MP3d ef-2'
+ ffmpeg -i './v/cd ef-4.wav' -f mp2 './MP3/v/cd ef-4'
+ ffmpeg -i '/abc d.wav' -f mp2 './MP3abc d'
+ ffmpeg -i './cd ef-4.wav' -f mp2 './MP3/cd ef-4'
I think the ffmpeg command somehow alters the VAR $i as the script works fine with Avidemux and other commands e.g. cp, mv, etc.
Any suggestions or some other script for this purpose.
The first thing I see is that the script is failing when the parent directory is just
./
. Try this:With all the suggestions included and more. This script works.