【问题标题】:bash while loop and ffmpegbash while 循环和 ffmpeg
【发布时间】:2013-06-13 12:48:50
【问题描述】:

很抱歉这个问题,我想答案很简单,但是我进行了搜索,但没有找到任何答案。

我写了以下内容:

while read p                        # reads in each line of the text
do                                  # file- folder_list.txt each iteration.
    echo "$p"                       # print out current line
    if [ -f  $p/frame_number1.jpg ] # checks if the image exists in the specific folder
    then
        echo "$p"                   #prints specific folder name
        sleep 1                     #pause for 1 second
        ffmpeg -f image2 -r 10 -i $p/frame_number%01d.jpg -r 30 $p/out.mp4  #create video
     fi                             # end if statement
done <folder_list.txt               #end of while loop

脚本应该读取包含文件夹树结构的文本文件,然后检查文件夹是否包含指定的 JPEG,如果包含,则代码应从指定文件夹中包含的图像创建视频。

然而,似乎正在发生的是脚本会跳过肯定包含图像的整个文件夹。我想知道 while 循环是否在创建视频时继续迭代,或者是否正在发生其他事情?

任何帮助将不胜感激。

提前非常感谢

劳伦斯

【问题讨论】:

  • 因此您无法在变量周围使用"
  • 感谢它似乎可以正常工作。
  • 任何 sudo 问题?如果它跳过某些文件夹而不是其他文件夹...尝试使用 sudo 运行您的脚本
  • 我发现了问题。在某些文件夹中,已经有一个 .mp4 文件,该文件之前已创建,并且由于某种原因,这对迭代产生了影响。我解决这个问题的方法是添加 yes 指令,即:yes y | ffmpeg -f image2 -r 10 -i $p/frame_number%01d.jpg -r 30 $p/out.mp4 #从图像创建视频感谢您抽出宝贵时间发表评论。
  • @Larry_b 这告诉您需要在脚本中添加调试输出和测试。

标签: bash ffmpeg while-loop


【解决方案1】:

这可能是因为某些文件夹包含空格或其他奇怪的字符。

试试这个(不适用于所有情况,但适用于大多数情况):

while read p            # reads in each line of the text file- folder_list.txt
do                      #each iteration
   echo "$p"               #print out current line
   if [  -f   "${p}/frame_number1.jpg"  ] #checks wether the image exists in the specific folder
   then echo "$p"      #printsout specific folder name
        sleep 1                 #pause for 1 second
        ffmpeg -f image2 -r 10 -i "${p}/frame_number%01d.jpg" -r 30 "${p}/out.mp4"  #create video
   fi                  # end if statement
done <folder_list.txt   #end of while loop

我只是在涉及“$p”的参数周围添加了引号,这样如果它包含空格(和其他东西),它就不会被分成几个参数,从而破坏命令

如果这不起作用,请准确告诉我们一些正常的目录和不正常的目录:

ls -ald  /some/ok/dir     /some/NOTOK/dir #will show which directories belong to who
id  #will tell us which user you are using, so we can compare to the previous and find out why you can't access some

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 2017-01-15
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多