我编写了这段代码来检查目录中的视频文件,并使用ffmpeg对其进行转换。当运行这个脚本时,我得到的put结果是“找不到错误的文件”,我把它放在了block.what中,否则脚本就会出错,我得不到文件。
#!/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发布于 2018-03-14 21:02:51
How to iterate over files in directory with bash?
bash for循环遍历给定的项目列表。它不知道目录或文件。你不能仅仅给一个for循环一个目录,然后期望它循环遍历这些文件。这不是它的工作方式。如链接所示,您需要执行for f in ${checkfiles},其中${checkfiles}将展开以列出该目录中的所有文件(就像ls *一样)- kaylum
https://stackoverflow.com/questions/40944819
复制相似问题