0

Unfortunately my shell skills are very bad and I would need some help in running a simple script on my QNAP to fix some date problem on some videos.

The script I put in place is very easy:

  1. in a given folder
  2. check if there are .mp4 files starting with VID_
  3. if so, for each of them run a given exiftool command

Here is the script so far, but I guess I am not using the right way to call the variable:

#!/bin/sh

# set target directories
dir="/share/Multimedia/Pictures/"

# move to target directory
cd "$dir"

# check if there is some .mp4 file starting with "VID_" in the folder

VID=$(ls -A $dir | grep 'VID_' | grep './mp4')

if
    ["$VID"];

then

    # for each file in the list
    for f in $VID

        do

        # change all date metadata according to its filename
        exiftool "-*date<filename" -wm w $f

done

else

fi

Thanks for your help!

ps: the exiftool instruction is correct (except probably for the variable)

4

2 回答 2

0

不需要为此编写脚本,这样做只会减慢您的速度,因为您必须为每个文件调用 ExifTool。ExifTool 可以一次完成所有文件:
ExifTool -ext mp4 '-*date<filename' -wm w /path/to/dir/VID_*

这些-ext mp4选项将命令限制为仅 mp4 文件。由于您似乎在 linux/mac 系统上,因此必须将双引号更改为单引号。Windows系统需要双引号,linux/mac系统需要单引号。

于 2015-10-21T21:40:33.373 回答
0

您的代码可能由于以下原因而失败:

grep './mp4'

既然没有/之前mp4

最好将您的脚本设置为:

#!/bin/sh

# set target directories
dir="/share/Multimedia/Pictures/"

# move to target directory
cd "$dir"

for f in VID_*.mp4; do
   exiftool "-*date<filename" -wm w "$f"
done

无需解析ls此处的输出,也无需使用grep,因为 globVID_*.mp4将完成查找正确文件的工作。

于 2015-10-21T16:50:16.483 回答