はじめに

インストール

定時実行する


#!/bin/bash
LC_ALL=en_US.UTF-8
export LC_ALL

SOURCE_DIR="/var/video/src"
BACKUP_DIR="/var/video/original"
DEST_DIR="/var/video/h264"

# 1.) ロックファイルの存在チェック(2重起動の抑止)

LOCK_FILE="/tmp/toH264.lock"

if [ -f $LOCK_FILE ]; then
  PID=`cat $LOCK_FILE`
  PS_ENTRY=`ps -ae | grep $PID`
  echo $PS_ENTRY
  if [ -n "$PS_ENTRY" ]; then
    echo "Running. Terminate to start encoding." 
    echo `date`" This process is running." >> /var/log/toh264.log
    exit
  fi
  echo "Not Runnig. Delete lock file and start encoding."
  rm $LOCK_FILE
fi

# 2.) 処理対象が存在しない場合終了する

declare -i CNT
CNT=`find $SOURCE_DIR -type f | wc -l`
if [ $CNT -eq 0 ]
then
  echo `date`" There is no movie file." >> /var/log/toh264.log
  exit
fi

echo $$ > $LOCK_FILE

# ---------- MAIN PROCEDURE ----------
cd $SOURCE_DIR


# -- (ad-hoc) Convert Music File
ls | grep ".*WMA$" | while read line
do
  /usr/bin/ffmpeg -y -i $line -acodec libmp3lame -vn -ab 128k /var/video/mp3/${line%.WMA}.mp3 < /dev/null
  mv $line /var/video/original
done

for SOURCE_FILE in *
do
  echo "-------------------------"
  # 1) Analyze source aspect ratio

  echo "SOURCE FILE     : "$SOURCE_FILE
  ASPECT_RATIO=`/usr/bin/mediainfo "$SOURCE_FILE" | grep aspect | cut -c 36-` 
  echo "SOURCE ASPECT   : "$ASPECT_RATIO

  # 2) Decide dest resolution
  #    16:9            -> 960x544
  #     4:3 or unknown -> 960x720 

  WIDTH="960"
  HEIGHT="720"
  if [ $ASPECT_RATIO = "16:9" ]; then
    WIDTH="960"
    HEIGHT="544"
  fi
  if [ $ASPECT_RATIO = "2.35:1" ]; then
    WIDTH="960"
    HEIGHT="544"
  fi
  echo "DEST RESOLUTION : "$WIDTH"x"$HEIGHT

  # 3) Convert to Raw Format

  if [ -f /tmp/tmp.avi ]
  then
    rm -f /tmp/tmp.avi
  fi
  /usr/bin/ffmpeg -i "$SOURCE_FILE" -vcodec copy -acodec pcm_s16le /tmp/tmp.avi
  
  # 4) Convert to H.264

  DEST_FILE=${SOURCE_FILE%.*}
  DEST_FILE=${DEST_FILE//\#/_}
  DEST_FILE=${DEST_FILE// /}
  DEST_FILE=$DEST_FILE".mp4"

  echo `date`" START ENCODE: $DEST_FILE($WIDTHx$HEIGHT)" >> /var/log/toh264.log

  if [ -f "$DEST_DIR/$DEST_FILE" ]
  then
    rm -f "$DEST_DIR/$DEST_FILE"
  fi
  /usr/bin/HandBrakeCLI -i /tmp/tmp.avi -o "$DEST_DIR/$DEST_FILE"\
 --preset="iPhone 4" -2 -T -w $WIDTH -l $HEIGHT --crop 0:0:0:0

  echo `date`" END" >> /var/log/toh264.log

  # 5) Reserve original file and delete tmp file

  rm /tmp/tmp.avi
  mv "$SOURCE_FILE" "$BACKUP_DIR"

done 
# ---------- MAIN PROCEDURE ----------

rm $LOCK_FILE

敵は "LC_ALL" にあり

変換結果


Fedora 13 Server


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2011-06-05 (日) 23:45:26 (4930d)
Short-URL:
ISBN10
ISBN13
9784061426061