并行和转码视频问题



嘿伙计们,我遇到了一个奇怪的错误,即使set -x没有向我显示任何明显的信息。看起来我的cmds实际上并没有被并行处理,或者至少这是假设。下面的脚本应该执行以下操作

  • 查找所有内容
  • 将它们全部推入开关,以确保不会发生相同格式的重写
  • 将它们重新编码为HTML5视频格式(WebM OGG和MP4通过H264)
  • 移动这些文件

有人可以简要运行此代码并让我知道发生了什么吗?我确定这很简单,但它正在逃避我的 atm......

#!/bin/bash
# Video transcoder
# CPR : Jd Daniel
# MOD : 2014-02-20 @ 10:51:25
# VER : Beta 1
# proto: cd drop ; types=(asf asx avi flv m4v mov mp4 mpg rm swf vob wmv); for i in "${types[@]}"; do touch "video.${i}"; done;
inp="drop"
out="export"
## test for reqs of exit
for requires in ffmpeg parallel; do
    hash $requires 2>/dev/null || { 
        echo >&2 "I require $requires to run but it's not installed.  Aborting."; exit 1; 
    }
done

## dectypes
declare -r fpath=$( cd "$(dirname "$0")" ; pwd -P )
declare -r types="asf|asx|avi|flv|m4v|mov|mp4|mpg|ogg|rm|swf|vob|webm|wmv"
declare -r allow=( mp4 ogg webm )
##
    for dir in "$inp" "$out"; do
        [ -d "$fpath/$dir" ] || { mkdir -p "$fpath/$dir"; } # create if not available
    done
        [ -z "$(ls $fpath/$inp)" ] && { "$fpath is empty, finished..."; exit 0; } # exit when empty

    ## start video conversion
    cd $fpath ; for video in $(find . -type f -iregex ".*(${types})" -printf '%P '); do
        skip=0 #reset skip flag 
        name=$(echo $video |awk -NF '.' '{print $1}')
        exts=$(echo $video |awk -NF '.' '{print $2}')
        # assign predetermined pos
        for (( i = 0; i < ${#allow[@]}; i++ )); do
           if [ "${allow[$i]}" = "${exts}" ]; then
               skip=$(($i + 1));
           fi
        done
        cmds=() # empty
        [[ $skip = 1 ]] || { cmds+=("'$video' -b 1500k -vcodec libx264   -vpre   slow      -vpre baseline -g 30          '$name.mp4' ") ; }
        [[ $skip = 2 ]] || { cmds+=("'$video' -b 1500k -vcodec libvpx    -acodec libvorbis -ab   160000   -f webm -g 30  '$name.webm'") ; }
        [[ $skip = 3 ]] || { cmds+=("'$video' -b 1500k -vcodec libtheora -acodec libvorbis -ab   160000   -g 30          '$name.ogg' ") ; }
        echo "${cmds[@]}" | parallel --gnu -j10 ffmpeg -i $fpath/$inp/{/};
        for ext in "${allow[@]}"; do
            [ -a "${fpath}/${inp}/${name}.{ext}" ] && mv "${fpath}/${inp}/${name}.{ext}" "${fpath}/${out}/"
        done
    done

可以在此处找到存储库的链接 转码器.请随意在您自己的项目上使用它!!!谁知道它是如何派上用场的,但我很想看到它被共享;)

最终,

不再使用并行,但仍执行后台任务

#!/bin/bash
# Video transcoder
# CPR : Jd Daniel :: Ehime-ken
# MOD : 2014-02-24 @ 16:34:29
# VER : Beta 3

inp="drop"
out="export"
clear # set -x
## test for reqs of exit
for requires in ffmpeg parallel; do
    hash $requires 2>/dev/null || {
        echo >&2 "I require $requires to run but it's not installed.  Aborting."; exit 1;
    }
done

## dectypes
declare -r fpath=$( cd "$(dirname "$0")" ; pwd -P )
declare -r types="asf|asx|avi|flv|m4v|mkv|mov|mp4|mpg|ogg|rm|swf|vob|webm|wmv"
declare -r allow=( mp4 ogg webm )
##
    for dir in "$inp" "$out"; do
        [ -d "$fpath/$dir" ] || { mkdir -p "$fpath/$dir"; } # create if not available
    done
    [ -z "$(ls $fpath/$inp)" ] && { "$fpath is empty, finished..."; exit 0; } # exit when empty

    ## start video conversion
    cd $fpath ; while IFS= read -r video; do
        skip=0 #reset skip flag
        name="${video%.*}"
        exts="${video##*.}"
        # assign predetermined pos
        for (( i = 0; i < ${#allow[@]}; i++ )); do
           if [ "${allow[$i]}" = "${exts}" ]; then
               skip=$(($i + 1));
           fi
        done

        pids=() # pid track if we want to use it later for something
        [[ $skip = 1 ]] || { ffmpeg -y -i "$inp/$video" -vb 1500k -vcodec libx264 -vpre slow -vpre baseline -g 30 "$out/${name}.mp4" 2> /dev/null & } # n pid+="$! " # if we're going to do post proc kill work later
        [[ $skip = 2 ]] || { ffmpeg -y -i "$inp/$video" -vb 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30 "$out/${name}.webm" 2> /dev/null & }
        [[ $skip = 3 ]] || { ffmpeg -y -i "$inp/$video" -vb 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 "$out/${name}.ogg" 2> /dev/null & }

        # move out of path
        for ext in "${allow[@]}"; do
            [ -a "$inp/$name.$ext" ] && cp -f "$inp/$name.$ext" "$out/" &
        done
        for job in `jobs -p`; do
            echo "Job: $job"
            wait $job || let "FAIL+=1"
        done
        [ "0" == "$FAIL" ] && echo "YAY!" || echo "FAIL! ($FAIL)"
    done <<< $(find "$fpath/$inp" -type f -iregex ".*(${types})" -printf '%P ')

相关内容

  • 没有找到相关文章

最新更新