0

我想用 linux shell 脚本自动化我的视频转换。我在 ubuntu 14.04 上使用 HandBrakeCLI 和我的个人选项。但我被困在某个点上。这是我想用伪代码完成的:

# watch a specific folder (A)
- if a (source) file is older then 1d process it
- as soon as the process is finished move the source file into folder (B)
- the target for the new file is folder (C)
# process the files
1. find all the new files (older then 1d) within (A)
2. get the full path of the file and store it
3. replace the source folder path (A) with the target folder (C)
4. start conversion with HandBrakeCLI like:
   HandBrake $options $sourcefile $targetfile

我用这段代码介绍的特定文件夹扫描的第一部分:

find $A -name "*.mkv" -ctime +1 -print0

我想将源文件的绝对路径从文件夹 (A) 传递到我的脚本“convertMkv”中。棘手的部分就在这里:

find $A -name "*.mkv" -ctime +1 -print0 | xargs -0 -I {} ./convertMkv "{}" "$C" ;

我想将文件夹 (A) 和目标文件夹 (C) 中的源文件传递给我的转换脚本,这将准备必要的路径并触发 HandBrakeCLI。

源文件的路径示例可能是:

“/tmp/感兴趣的视频.mkv”

“/tmp/文件\文件夹/Lion_King.mkv”

“/tmp/阿凡达.mkv”


这是我的“convertMkv”脚本:

#!/bin/bash
source="$HOME/handbrake/.raw"
target="$2"

OPT=""
OPT="$OPT --verbose"
OPT="$OPT --encode x264"
OPT="$OPT --quality 20.0"
OPT="$OPT --format mp4"
...

# -----------------------------------------------------------------------------
# mkv2mp4()
# -----------------------------------------------------------------------------
function mkv2mp4
{
    input=$1
    output=$2

    HandBrakeCLI $OPT -i "$input" -o "$output" 2>&1 | tee "/tmp/log/Test.log"
}

function main
{
    path="${1%/*}"
    file="${1##*/}"
    newPath="${path##/*/}"

    mkv2mp4 $1 $target/$newPath/$file
}

main $@
exit 0
4

1 回答 1

2

引用你的变量:

mkv2mp4 "$1" "$target/$newPath/$file"

和:

main "$@"
于 2015-11-18T23:08:33.207 回答