TSバッチ変換
bash+mencoder+cygwin のTS変換用シェルスクリプト.TSからXVIDに変換する.当然「私家版」,つまりは書き換え必至.自分でも必要に応じて書き換えながら使っています.それ故に,たまに後戻りできなくなるので,ここに保存を兼ねて公開.
#! /usr/bin/sh # # TS動画ファイルをXVIDファイルに変換する # # <scale> # 形式は width:height で記述する.例えば,1280:720 などとする. # # <target drive> # ターゲットドライブ内に入力パスと同じツリー構造を強制的に作成する. # ################################## # 関数 # function error_mssg { echo "usage: -i <input file> [-s <scale>] [-d <target drive>]" } ################################## # 引数処理 # while getopts "i:s:t:" opt; do case $opt in \?) error_mssg; exit 1; break;; i) input_path="$OPTARG";; s) scale="$OPTARG";; t) target_drive="$OPTARG";; esac done # 入力ファイル if [[ -z $input_path ]]; then error_mssg; exit 1; fi # ターゲットドライブ if [[ -z $target_drive ]]; then output_path=${input_path%.*}.avi else folder=$(cd $(dirname "$input_path") && pwd) output_path=$(echo $folder|sed -e "s/^\(\/cygdrive\/\).\//\1$target_drive\//") mkdir -p "$output_path" output_path=$output_path/$(basename "$input_path") output_path=${output_path%.*}.avi fi # スケール if [[ -z $scale ]]; then video_format="" else video_format="-vf scale=${scale}" fi ####################################### # 変換 # mencoder.exe "$(cygpath -w "$input_path")" \ -ovc xvid -xvidencopts fixed_quant=4:vhq=4:threads=8 \ -oac mp3lame -lameopts cbr:br=128 \ $video_format \ -o "$(cygpath -w "$output_path")" # メッセージ抑制時のオプション # -quiet/-really-quiet # 変換の質を高めるオプション # chroma_opt:bvhq=1:quant_type=mpeg
エンコードオプションメモ
関連シェル技
フォルダ中のTSファイルを全部エンコード
$ for f in *.ts > do > toxvid.sh -i "$f" -s "1280:720" > done
フォルダ以下のTSファイルを再帰的に全部エンコード
$ find . -type f -a -path "*.ts" -exec toxvid.sh -i {} -s 1280:720 \;
あるいは,シェル化して(down-steps.shという名前にします),
#! /usr/bin/sh find . -type f -a -path "*.ts" -exec $1 {} \;
次のように使います.
$ down-steps.sh any4archive.sh
例えば,any4archive.sh は次のような,ファイル名を唯一の引数とするシェルです.
#! /usr/bin/sh toxvid.sh -i $1 -s 800:450
あるいは,down-step.sh を書き換えて所望の変換の仕方に変更して実行します.改めて・・・「私家版」というのは完全性と手間のトレードオフで作られるてきとーなものという意味です.
10/18の記事で,複数引数用に書き換えました.理由は,複数引数が必要となる事情があったからです.これが私家版の肝.先の事は考えずに,必要になった時点で泥縄式に書き進めるということになります.汎用性はゴミ箱にしまっとくという事です.