Video processing and publishing

From FSCONS wiki
Jump to navigation Jump to search

Scripts

encode_all.sh

#!/bin/bash

# Copyright (c) 2011 Rikard Fröberg <rikard@ffkp.se>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

NAS_MOUNT="YOUR_NAS_MOUNT_POINT_HERE"
START_TIME=$(date)
STARTSECS=$(date +%s)
ENCODE_DIR="encoding"
OUTPUT_DIR="$ENCODE_DIR/encoded_vids"
PREPEND_DIR="$ENCODE_DIR/prepends"
CREDITS="$PREPEND_DIR/1920-title.avi"
LICENSE="$PREPEND_DIR/cc-1920.avi"
MENCODER_OPTS="-oac copy -ovc copy -o"

if [ ! -e "$ENCODE_DIR" ] ; then
 echo "$ENCODE_DIR not found. Exiting."
 exit 1
fi

echo Starting at $START_TIME
echo Dir to process: $ENCODE_DIR

# Directories starting with a number contains MTS video files in our case
for SESSION_DIR in $ENCODE_DIR/[0-9]*
do
 countMTS=0
 echo ============================
 echo $(date) Processing $SESSION_DIR
 echo

 # Our raw files all end with .MTS
 for SESSION_MOVIE in ${SESSION_DIR}/*.MTS
 do
  ((++countMTS))
  SESSION_SHORT=${SESSION_MOVIE##encoding/}
  AVI="${SESSION_SHORT%%/*}-$countMTS.avi"
  FINAL_AVI="${SESSION_SHORT%%/*}-$countMTS-all.avi"
  echo $(date) Running: "bin/encode.sh $SESSION_MOVIE $OUTPUT_DIR/$AVI"

  # Our nas was mounted over the network, double check that the
  # mount has not been lost due to network problems
  if [ ! -e "$SESSION_MOVIE" ]
  then
    echo "$SESSION_MOVIE" NOT FOUND.
    if [ -d "$NAS_MOUNT" ]
    then
      echo "NAS mounted on $NAS_MOUNT"
    else
      echo "NAS NOT mounted!"
    fi 
    exit 2
  fi
  bin/encode.sh "$SESSION_MOVIE" "$OUTPUT_DIR/$AVI"
  echo $(date) Running: "mencoder $MENCODER_OPTS $OUTPUT_DIR/$FINAL_AVI $CREDITS $LICENSE $OUTPUT_DIR/$AVI"
  /usr/bin/mencoder $MENCODER_OPTS $OUTPUT_DIR/$FINAL_AVI $CREDITS $LICENSE $OUTPUT_DIR/$AVI 
  echo $OUTPUT_DIR/$FINAL_AVI created at $(date)
  echo "++++++++++++++"
 done
done
ENDSECS=$(date +%s)
TOTAL_SECS=$((ENDSECS-STARTSECS))
ENDTIME=$(date)
echo "Report:"
echo "Encoding started at $START_TIME"
echo "Encoding ended at   $ENDTIME"
echo "Encoding took       ${TOTAL_SECS}secs or"
echo "                    $((TOTAL_SECS/60))mins and $((TOTAL_SECS%60))secs or"
echo "                    $((TOTAL_SECS/3600))hrs and $((TOTAL_SECS/60%60))mins and $((TOTAL_SECS%60))secs"

encode.sh

  1. !/bin/bash
  1. Copyright (c) 2011 Rikard Fröberg <rikard@ffkp.se>.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. Prerequisites
  14. In order to run the encoding scripts, a number of tools, libraries and
  15. codecs need to be installed.
  16. The video transformation tools are:
  17. * ffmpeg
  18. * mencoder
  19. The codecs are:
  20. * libavcodec-extra-52
  21. * libaften0 - Not required if you have the license and title AVIs!
  22. (for creating the title and license AVI, we needed it to have fake
  23. silent audio as AC3 to match the AVIs created from the Session MTS
  24. files, or mencoder would protest)
  25. To test the results:
  26. * mplayer

infile=$1 outfile=$2 inputopts="-i $infile" audioopts="-acodec copy" videoopts="-vcodec libx264 -s 1280x720 -vpre default -b 2000000 -r 25"


echo "ffmpeg command:" echo $inputopts $audioopts $videoopts $outfile /usr/bin/ffmpeg $inputopts $audioopts $videoopts $outfile


Back to 2011 main planning page