在shell脚本&QUOT内环路创建的`ffmpeg`叉;输了球"某些迭代 [英] Creating forks of `ffmpeg` in loop inside a shell script "loses" some iterations

查看:136
本文介绍了在shell脚本&QUOT内环路创建的`ffmpeg`叉;输了球"某些迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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:没有这样的文件或目录


所有文件名通常包含空格,也许这就是为什么它失败一些文件的原因。

因此​​,我有以下问题:


  1. 当我不叉的的ffmpeg 调用为什么只有第一个文件执行的?我预期该循环等待直到过程完成,然后与下一个迭代继续进行。

  2. 为什么脚本无法找到某些文件(也许这是一个问题的ffmpeg )?

  3. 如何解决这些问题,使脚本工作?


解决方案

您不承认标准输入

 的ffmpeg -i$文件-blah -blah -nostdin$文件名&放大器;

shell脚本的ffmpeg停止后2个任务

要回答的评论:

您不应该反正分叉,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 a mp3 with ffmpeg:

#!/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:

  1. 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.
  2. Why is the script unable to find some files (maybe it is a problem of ffmpeg)?
  3. 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屋!

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