gpt4 book ai didi

bash - 这个单行 Bash 脚本的错误在哪里?

转载 作者:行者123 更新时间:2023-12-04 23:06:51 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Execute "ffmpeg" command in a loop [duplicate]

(3 个回答)



While loop stops reading after the first line in Bash

(5 个回答)


7 个月前关闭。




我在一个目录中有两个相同的 .mp4 文件。由于我无法理解的原因,第二个文件的文件名被下面的脚本破坏了。当我有更多 .mp4 文件时,每个其他文件的前两个或三个字符似乎都被删除了。这已经在不同的 .mp4 文件和多个系统上进行了测试。如果我删除 -printf '%P\n'或不要使用 ffmpeg它按预期工作。

$ ls -l
total 46944
-rw-rw---- 1 ubuntu ubuntu 24034673 Dec 23 09:59 file_one.mp4
-rw-rw---- 1 ubuntu ubuntu 24034673 Dec 23 09:59 file_two.mp4
$ find . -name '*.mp4' -printf '%P\n' |while read -r FILE; do ffmpeg -loglevel error -y -i "$FILE" -ss 00:00:01.000 -vframes 1 junk.png; done
le_two.mp4: No such file or directory
$
为什么会产生错误, le_two.mp4: No such file or directory ?

最佳答案

正如我们的 friend (philippe) 所说,您可以这样使用它。

find . -name '*.mp4' -printf '%P\n' | while read -r FILE; do ffmpeg -loglevel error -y -i "./${FILE}" -ss 00:00:01.000 -vframes 1 "junk_${FILE%.*}".png -nostdin; done
您通过 find 命令打印文件列表作为标准输入,并且循环中的所有命令都可以读取它,因此 ffmpeg 可以从标准输入数据中弄乱一个字节。
您也可以使用 < /dev/null对于 ffmpeg:
find . -name '*.mp4' -printf '%P\n' | while read -r FILE; do ffmpeg -loglevel error -y -i "./${FILE}" -ss 00:00:01.000 -vframes 1 "junk_${FILE%.*}".png < /dev/null; done

关于bash - 这个单行 Bash 脚本的错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70460657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com