【问题标题】:Renaming the output file name from ffmpeg when using find and xargs使用 find 和 xargs 时从 ffmpeg 重命名输出文件名
【发布时间】:2020-06-29 00:43:01
【问题描述】:

我正在尝试重命名来自我使用 find 和 xargs 生成的 ffmpeg 进程的输出文件。我有一个文件目录,我想将其转换为某种格式,所有这些文件最终都应命名为 .mov。所以我过滤掉 .mp4 & .mov 文件,然后使用 xargs 将其传递给 ffmpeg。

假设当前工作目录中有 abc.mp4、abcd.mp4、abcde.mp3、bcd.mov 等文件,然后我正在做这样的事情来过滤掉 mp4 和 mov 文件并传递它转到ffmpeg进行编码:

find . -type f -name "*.mp4" -o -name "*.mov" | xargs -n 1 -p 5 -I '{}' ffmpeg -i '{}' ....... $PWD/{}"_h264.mov"

这将做我想让 ffmpeg 做的事情,但它会将文件命名为

abc.mp4_h264.mov,abcd.mp4_h264.mov,bcd.mov_h264.mov

我最理想的目标是将输出文件命名为

abc_h264.mov,abcd_h264.mov,bcd_h264.mov

在我指定 ffmpeg 的输出文件的地方,我没有想到如何做到这一点。我知道我可以像这样使用 xargs 调用 basename 命令

find . -type f -name "*.mp4" -o -name "*.mov" | xargs -n 1 basename | rev | cut -d . -f 2 | rev

并提取不带扩展名的文件名,但如果我使用它,那么我如何将其作为输入文件传递给 ffmpeg,因为当它从 xargs 出来时会丢失扩展名,而 ffmpeg 会抛出错误。

谁能帮我一次性实现这一点,我可以指定“basename”在做什么,但我在哪里指定 ffmpeg 的输出文件名?

非常感谢您提供的任何帮助。非常感谢社区。​​p>

【问题讨论】:

  • 最好制作一个小脚本来处理输入和输出名称的所有处理,然后使用更正的参数调用ffmpeg。祝你好运。

标签: bash file find rename xargs


【解决方案1】:

请您尝试以下方法:

find . -type f -name "*.mp4" -o -name "*.mov" | xargs -I {} -n 1 -P 5 bash -c 'org="{}"; new="$PWD/${org%.*}_h264.mov"; ffmpeg -i "$org" {options} "$new"'

但是将bash命令作为子进程产生效率不高 多次。如果您没有特定理由使用findxargs,说起来会更简单:

for org in *.mp4 *.mov; do
    new="$PWD/${org%.*}_h264.mov"
    ffmpeg -i "$org" {options} "$new"
done

【讨论】:

  • 我的男人!这解决了问题。非常感谢您扩展了我对 xargs 的理解。我同意使用 for 循环是一种更简单的方法。我只是想处理一些文件,比如批处理,因为我有足够的能力来处理它,而不是一次处理一个文件。非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2016-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-14
  • 2014-02-11
  • 2018-06-17
  • 2011-06-15
相关资源
最近更新 更多