我正在编写一个bash脚本来使用FFMpeg处理文件,这取决于文件的数量。
我正在编写一个if / elif语句来检查有多少个文件与一个字符串匹配,但首先去掉字符串末尾的一部分。这种比较似乎行不通,我试过==和-eq。不确定有没有更好的方法来做这件事
#!/bin/bash
#Generate Quads from 4 video files, Trio from 3 and duo from 2
#InputVariables
inputpath=$( pwd | awk -F/ '{ print $0"/" }' )
outputpath=$( pwd | awk -F/ '{ print $0"/" }' ) #TEMP TEST OUTPUT
#outputpath=$( pwd | awk -F/ '{ print "/"$2"/projects/"$5"/Library/Ref/ProcessedWitcam/"$6"/" }' )
#Command Start
if [ "$( echo $inputpath | grep -F witcam )" ]; then
#Create only 1 instance of this script to avoid clashes
if [ ! "$(ls /var/run/ | fgrep -i quadGen.pid)" ]; then
yes no | nice -n 15 touch /var/run/wrangling/quadGen.pid
echo "PID created"
for videofile in $(find *_1_BTC.mp4 -type f); do
if [ "$(ls $outputpath | fgrep -i ${videofile%_1_BTC.mp4}.mp4)" ]; then
echo "Converted $videofile Already"
else
echo find "${videofile%_1_BTC.mp4}"* | wc -l
if [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 5 ]; then
echo "QUAD GEN"
timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq )
ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile -i ${videofile%_1_BTC.mp4}_3.mxf -i ${videofile%_1_BTC.mp4}_4.mxf -filter_complex "[0:v][1:v]hstack[top]; [2:v][3:v]hstack[bottom]; [top][bottom]vstack,format=yuv420p[v]" -map "[v]" -ac 2 -flags global_header -timecode $timecode -c:v libx264 $outputpath/${videofile%_1_BTC.mp4}.mp4
elif [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 4 ]; then
echo "TRIO GEN"
timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq )
ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile -i ${videofile%_1_BTC.mp4}_3.mxf -filter_complex "[0:v][1:v][2:v]hstack=inputs=3[v]" -map "[v]" -ac 2 -flags global_header -timecode $timecode -c:v libx264 $outputpath/${videofile%_1_BTC.mp4}.mp4
elif [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 3 ]; then
echo "DUO GEN"
timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq )
ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile -filter_complex "hstack" -ac 2 -flags global_header -timecode $timecode -c:v libx264 $outputpath/${videofile%_1_BTC.mp4}.mp4
else
echo "Error: incorrect number of files"
fi
fi
done
yes no | nice -n 15 rm -f /var/run/wrangling/quadGen.pid
fi
fi这部分:
echo find "${videofile%_1_BTC.mp4}"* | wc -l这是正确的,因为我得到了一个值,我不知道如何正确地比较它
发布于 2021-04-30 16:59:34
双引号引入一个字符串,而不是要运行的命令。不要使用它们。
请改用命令替换:
if [ $(find ${videofile%_1_BTC.mp4}* | wc -l) == 5 ]; then你可以在这里同时使用==和-eq:==比较字符串,-eq比较整数。
https://stackoverflow.com/questions/67330901
复制相似问题