bash 循环删除前导 '.'每隔一次迭代循环变量中的字符

bash 循环删除前导 '.'每隔一次迭代循环变量中的字符

到目前为止,我只有空格和单引号需要处理,所以我在它周围加了双引号

#!/bin/bash
#ffmpeg -i Muppets\ Most\ Wanted_KBYUT_2017_07_08_18_56_00.wtv  -f ffmetadata metadata.txt
#ffmpeg -i Gene\ Roddenberry\'s\ Andromeda_COMET_2017_12_14_20_05_51.wtv  -f ffmetadata metadata1.txt
find . -type f | grep 'wtv$' | while read file; do
    echo "----"
    echo "----"
    echo "----"
    echo "$file"
    ls -alh "$file"
    echo "$file.txt"
    #ffmpeg -i "$file" -f ffmetadata "$file.txt"
done

打印出来

stephen@B450-AORUS-M:~/Videos$ ./ffmetadata.sh 
./Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv
-rw------- 1 stephen stephen 7.9G Sep  6  2019 './Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv'
./Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv.txt
./Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv
-rw------- 1 stephen stephen 794M Dec 16  2017 "./Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv"
./Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv.txt

看起来不错,所以我尝试让 ffmpeg 做它的事情,通过取消注释一行,我得到

stephen@B450-AORUS-M:~/Videos$ ./ffmetadata.sh 
./Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv
-rw------- 1 stephen stephen 7.9G Sep  6  2019 './Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv'
./Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv.txt
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  ...
Input #0, wtv, from './Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv':
  Metadata:
    WM/MediaClassPrimaryID: db9830bd-3ab3-4fab-8a371a995f7ff74
    WM/MediaClassSecondaryID: ba7f258a-62f7-47a9-b21f4651c42a000
    Title           : Muppets Most Wanted
    ...
Output #0, ffmetadata, to './Muppets Most Wanted_KBYUT_2017_07_08_18_56_00.wtv.txt':
  Metadata:
    WM/MediaClassPrimaryID: db9830bd-3ab3-4fab-8a371a995f7ff74
    WM/MediaClassSecondaryID: ba7f258a-62f7-47a9-b21f4651c42a000
    Title           : Muppets Most Wanted
    ...
Stream mapping:
Press [q] to stop, [?] for help
size=       2kB time=-577014:32:22.77 bitrate=N/A speed=N/A    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded 
----
----
----
/Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv
ls: cannot access "/Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv": No such file or directory
/Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv.txt
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
...
  libpostproc    54.  7.100 / 54.  7.100
/Gene Roddenberry's Andromeda_COMET_2017_12_14_20_05_51.wtv: No such file or directory

第一个文件有效,但第二个文件丢失了前导点,将相对路径更改为绝对路径。我尝试了文件夹中的 3 个文件,其中 2 个有效。 4 个文件 2 个工作。 6 个文件 3 个工作。

答案1

前导“.”正在被ffmpeg(当它询问流映射时)消耗,它与read.

您应该使用find的功能:

find . -type f -name '*wtv' -ls -exec ffmpeg -i {} -f ffmetadata {}.txt \;

这会查找名称以 结尾的文件wtv,显示其详细信息(这是一个 GNU 扩展;-print如果您find不支持,请使用ls),然后运行ffmpeg它们。

相关内容