V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
sshnuke
V2EX  ›  Linux

关于 bash 中使用 ffmpeg 的一个神奇的现象

  •  
  •   sshnuke · 2023-03-28 15:41:29 +08:00 · 1018 次点击
    这是一个创建于 366 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如我用这样的
    ls *.jpg |while read id;do echo ffmpeg -i "$id" ../new/${id}_new.jpg;done
    输出成一串命令 然后在 bash 中执行这船命令 是不会出问题的

    但是如果我换成这样的
    ls *.jpg |while read id;do ffmpeg -i "$id" ../new/${id}_new.jpg;done
    那么就一定会一个隔一个文件报文件名不存在而执行失败
    这是为什么呢
    AoEiuV020CN
        1
    AoEiuV020CN  
       2023-03-28 16:18:12 +08:00
    上个图看看,
    意思是一个 jpg 执行了两次 ffmpeg 其中一次报错,还是说有一半的 jpg 执行 ffmpeg 报错了?
    sshnuke
        2
    sshnuke  
    OP
       2023-03-28 17:04:17 +08:00
    有一半的 jpg 报错,错误原因是文件名错误

    比如我的文件夹是 11.jpg 12.jpg 13.jpg 14.jpg 15.jpg 16.jpg 17.jpg 18.jpg 19.jpg 20.jpg 21.jpg 22.jpg

    那么报错的是 12 14 16 18 这样的偶数文件名的

    报错信息是 2.jpg: No such file or directory 这样的 也即文件名被吃掉了开头的 1

    而奇数文件名的文件无影响
    julyclyde
        3
    julyclyde  
       2023-03-28 21:37:22 +08:00
    @sshnuke 说实话,我不信
    sshnuke
        4
    sshnuke  
    OP
       2023-03-29 14:08:32 +08:00
    @julyclyde 你自己试一试不就知道了
    在 centos 和 ubuntu 上都复现了
    aloxaf
        5
    aloxaf  
       2023-03-29 16:20:11 +08:00   ❤️ 1
    和 bash 无关,你需要加上 -nostdin ,

    https://man.archlinux.org/man/ffmpeg.1#stdin
    sshnuke
        6
    sshnuke  
    OP
       2023-03-29 17:12:00 +08:00
    @aloxaf 解决了
    非常感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3534 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.