在shell脚本&QUOT内环路创建的`ffmpeg`叉;输了球"某些迭代 [英] Creating forks of `ffmpeg` in loop inside a shell script "loses" some iterations
问题描述
我有一个shell脚本,需要一个目录作为输入,读取所有 MP4中它
文件,并将其转换为 MP3
与的ffmpeg
:
#!/斌/庆典DIR = $ 1而阅读-rd的文件
做
基地= $(基名$文件)
文件名= $ {基地%(*}MP3
ffmpeg的-i$文件-vn -ar 44100 -ac 2 -ab 192000 -f MP3$文件名&放大器;
完成< ≤($找到-maxdepth DIR -iname 1* .MP4-print0)等待退出0
目前所有这些调用的ffmpeg
的分叉,因为当我离开了&安培;
末只有在转换和其他人都被忽略第一个文件。
但是,这是问题,因为有些事情失败像下面的一些文件的错误消息:
路径/到/文件/文件名 - 用空格(信息)(temp_information).MP4:没有这样的文件或目录
块引用>所有文件名通常包含空格,也许这就是为什么它失败一些文件的原因。
因此,我有以下问题:
- 当我不叉的
的ffmpeg
调用为什么只有第一个文件执行的?我预期该循环等待直到过程完成,然后与下一个迭代继续进行。- 为什么脚本无法找到某些文件(也许这是一个问题
的ffmpeg
)?- 如何解决这些问题,使脚本工作?
解决方案您不承认
标准输入
的ffmpeg -i$文件-blah -blah -nostdin$文件名&放大器;
要回答的评论:
您不应该反正分叉,FFmpeg的已经在多个线程中运行,以最大限度地提高CPU,你甚至可能会受到
rel=\"nofollow\">
通过派生它。I have a shell script that takes a directory as input, reads all
mp4
files in it and convert them to amp3
withffmpeg
:#!/bin/bash dir=$1 while read -rd "" file do base=$(basename "$file") filename=${base%(*}".mp3" ffmpeg -i "$file" -vn -ar 44100 -ac 2 -ab 192000 -f mp3 "$filename" & done < <(find $dir -maxdepth 1 -iname "*.mp4" -print0) wait exit 0
Currently all these calls to
ffmpeg
are forked because when I leave out the&
at the end only the first file in converted and the others are ignored.But this is problematic because somethings this fails on some files error messages like the following:
path/to/file/file name - with spaces(info)(temp_information).mp4: No such file or directory
All file names normally contain spaces, maybe that is the reason why it fails for some files.
Thus, I have the following questions:
- When I don't fork the
ffmpeg
calls why is only the first file executed? I expected that the loop waits until the process is finished and then continues with the next iteration.- Why is the script unable to find some files (maybe it is a problem of
ffmpeg
)?- How to solve all these problems and make the script to work?
解决方案You are not acknowledging
stdin
ffmpeg -i "$file" -blah -blah -nostdin "$filename" &
shell script ffmpeg stops after 2 jobs
To answer the comment:
You should not be forking anyway, FFmpeg already runs in multiple threads to maximize CPU, and you might even suffer from thrashing by forking it.
这篇关于在shell脚本&QUOT内环路创建的`ffmpeg`叉;输了球&QUOT;某些迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!