重击while循环,直到任务完成 [英] Bash while loop wait until task has completed

查看:67
本文介绍了重击while循环,直到任务完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个bash脚本,用于处理文件夹及其子文件夹中的视频:

find . -type f -name '*.mkv' | while read file;
do
  ffmpeg -i $file ...
done

问题:它不是在等待ffmpeg的while循环中完成,而是继续循环遍历.最终结果是文件未得到处理.我需要一种方法来让当前的while循环迭代等待ffmpeg完成,然后再继续执行下一个.或者选择一种排队这些物品的方法.

因此,迭代一组文件时的解决方案是将-nostdin参数传递给ffmpeg.希望这对其他可能遇到类似问题的人有所帮助.

也有文件-> $ file是复制/粘贴错字.

解决方案

我知道我前不久发布了此消息,但我找到了解决方案.感谢您的所有回复.向ffmpeg提供-nostdin参数将达到目的.在移动到下一个文件进行处理之前,它将仅处理当前文件.

ffmpeg的-nostdin选项避免尝试从stdin读取用户输入,否则将解释视频文件本身.

ffmpeg -i <filename> ... -nostdin

关于使用上述内容的最好之处在于,如果输出中出现错误,您可以继续使用详细程度:

ffmpeg -i <filename> ... -nostdin -loglevel panic 

或者,如果您希望将输出报告到文件中,请按照以下方式进行操作:

# Custom log name (optional). Helpful when multiple files are involved.
# FFREPORT=./${filename}-$(date +%h.%m.%s).log
ffmpeg -i <filename> ... -nostdin -report

您也可以同时使用两者的组合.也感谢@Barmar提供解决方案!

I have a bash script that I created to process videos from within a folder and it's subfolders:

find . -type f -name '*.mkv' | while read file;
do
  ffmpeg -i $file ...
done

The problem: Instead of the while loop waiting ffmpeg to complete, it continues iterate through the loop. The end result is, files not getting processed. I need a way to have the current while loop iteration to wait until ffmpeg is complete before continuing to the next. Or alternatively a way to queue these items.

Edit: So The solution when iterating over a set of files is to pass the -nostdin param to ffmpeg. Hope this helps anyone else who might have a similar issue.

Also file --> $file was a copy/paste typo.

解决方案

I realize I posted this a while ago but I found the solution. Thanks for all of the responses. Providing the -nostdin param to ffmpeg will do the trick. It will process only the current file before moving onto the next file for processing.

ffmpeg's -nostdin option avoids attempting to read user input from stdin otherwise the video file itself is interpreted.

ffmpeg -i <filename> ... -nostdin

The best part about using the above is that you can continue to use verbosity in case an error is thrown in the output:

ffmpeg -i <filename> ... -nostdin -loglevel panic 

OR if you would rather report the output to a file do so this way:

# Custom log name (optional). Helpful when multiple files are involved.
# FFREPORT=./${filename}-$(date +%h.%m.%s).log
ffmpeg -i <filename> ... -nostdin -report

You can also use a combination of the two as well. Also thanks @Barmar for the solution!

这篇关于重击while循环,直到任务完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆