我编写了这段代码来检查目录中的视频文件并使用ffmpeg进行转换。 在运行这个脚本的时候,我把它作为“找不到[错误的文件”,我把它放在了else块中。我没有得到文件的脚本出了什么问题。
#!/bin/bash
# set PATH to check existance of video file in this directory
checkfiles='/home/webuser/public_html/shareportal/convertedUp_videos/'
#format of output video file
webm='webm'
for f in checkfiles
do
fullfilename="$f"
filenamewithpath=$(basename "$fullfilename")
filewithoutext="${filename%.*}"
fileextention="${filename##*.}"
changeextension=mv --"$f" "${f%.$fileextention}.$webm"
outputfilename="/home/webuser/public_html/shareportal/converted_videos/$changeextension"
echo "File FUll NAME : $fullfilename"
echo "File name with full path : $filenamewithpath"
echo "File name without extention : $filewithoutext"
echo "File extention : $fileextention"
echo '1 File Converted'
if (ffmpeg -i "$f" "$outputfilename")
then
confullfilename="$outputfilename"
confilenamewithpath=$(basename "$confullfilename")
confilewithoutext="${filename%.*}"
confileextention="${filename##*.}"
echo "File FUll NAME : $confullfilename"
echo "File name with full path : $confilenamewithpath"
echo "File name without extention : $confilewithoutext"
echo "File extention : $confileextention"
echo '1 File Converted'
else
echo "Could Not Convert File"
fi
#get Image of video file on provided time stamp
image_path='/home/webuser/public_html/shareportal/video_images/$filewithoutext.png'
if (ffmpeg -ss 00:00:03 -i "$f" -vframes:v 1 "$image_path")
then
echo "Image Extracted"
else
echo "Could not Extract Image"
fi
done
rm -r f
答案 0 :(得分:0)
How to iterate over files in directory with bash?
bash for
循环遍历给定的项目列表。它不知道目录或文件。您不能只为for
循环提供一个目录,并期望它循环遍历文件。这不是它的工作原理。如链接所示,您需要执行for f in ${checkfiles}
,其中${checkfiles}
将展开以列出该目录中的所有文件(就像ls *
)
- kaylum