【问题标题】:Loop with two variables at once in Bash在 Bash 中一次循环两个变量
【发布时间】:2017-03-01 17:16:22
【问题描述】:

我在一个目录中有两种文件名相同的文件类型:

file1.ts
file1.ec3
file2.ts
file2.ec3

我需要创建一个循环来一次处理一对文件(file1.ts + file1.ec3)。 然后需要用第二对(file2.ts + file2.ec3)重新启动循环。

这是我的代码:

for i in *.ts; do
    for e in *.ec3; do
        ffmpeg -i "$i" -i "$e" -map 0:v -map 1:a -codec copy "${i%.ts}_DD+.ts";
    done;
done

但是当第一个循环结束时,它会尝试处理 file1.ts + file2.ec3 并停止一切......

我怎样才能让它正常工作?

【问题讨论】:

    标签: bash loops command-line ffmpeg muxer


    【解决方案1】:

    试试这个:

    for file in *.ts; do
        [ -f "${file%.ts}.ec3" ] &&
            ffmpeg -i "$file" -i "${file%.ts}.ec3" -map 0:v -map 1:a \
                -codec copy "${file%.ts}_DD+.ts"
    done
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多