Try doing this :
#!/bin/bash
checkFile(){
[[ -s $1 && -f $1 ]] && return 0 || return 1
}
mp42flv(){
for arg; do
checkFile "$arg" || continue
/usr/bin/ffmpeg \
-i "$arg" \
-s '480x320' \
-vcodec libx264 \
-acodec libmp3lame \
-ab '64k' \
-vpre fast \
-crf '30' \
-ar '22050' \
-f flv \
-y "${arg%.*}.flv" ||
echo >&2 "Error treating $arg"
done
}
if [[ -t 0 ]]; then
mp42flv "$@"
else
while IFS= read -r a; do
checkFile "$a" || continue
mp42flv "$a"
done
fi
Usage
- with a glob
./script.sh /home/user/videos/converted/video_file*.mp4
- with a filename
./script.sh /home/user/videos/converted/video_file_01.mp4
- with find via a pipe
find /home/user/videos/converted -type f -name '*video*mp4' |./script.sh
(the script detect the use ofSTDIN
)