Advertisement
spookybathtub

copra-dragndrop

May 20th, 2014
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.56 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Directories must be defined without trailing slash
  4. output_dir="/Volumes/RAID/temp/tenerte"
  5. ffopts="-vf \"scale=hd720, format=pix_fmts=rgb24, lut3d=file=/Users/elliott/scripts/BMD_LogC_709.dat, format=pix_fmts=yuv420p\" -vcodec libx264 -preset veryfast -tune film -crf 20 -level 31 -profile:v high -g 8 -maxrate 4M -bufsize 10M"
  6. ffpreopts="-loglevel warning -stats"
  7.  
  8. echo "This script will encode source files for copra and save to:"
  9. echo "$output_dir."
  10. echo "Source files will not be modified."
  11.  
  12. #Check if any arguments were passed
  13.  
  14. if [ -z "$1" ]
  15. then
  16.     echo
  17.     echo "Usage:    copra-dragndrop [OPTION]... SRC [SRC]..."
  18.     echo " Options"
  19.     echo "  -r  RATE    conform source frame rate to 23.98 timebase"
  20.     else
  21.         # check for command-line options
  22.         while getopts ":r:" opt; do
  23.         case $opt in
  24.         r)  # set frame rate
  25.             rate="$OPTARG""000/1001"
  26.             echo "Conforming input $OPTARG fps to 24 with NTSC convention"
  27.             ffpreopts="$ffpreopts -r $rate"     # force input frame rate
  28.             ffopts="$ffopts -r 24000/1001"      # assume 23.98 timebase
  29.             ;;
  30.         \?)
  31.             echo "Invalid option -$OPTARG"
  32.             exit 1
  33.             ;;
  34.         :)
  35.             echo "Option -$OPTARG requires an argument."
  36.             exit 1
  37.             ;;
  38.         esac
  39.     done
  40.     shift $((OPTIND-1))     # remove opts, leaving only positional parameters
  41.  
  42.     mkdir -p $output_dir
  43.     echo "Errors:" > /tmp/dailies-encode.log
  44.     echo "Processing $# files..."
  45.     for f # without arguments automatically uses positional parameters
  46.     do
  47.         filename=$(basename "$f")
  48.         # get number of audio channels
  49.         num_channels=`ffprobe -loglevel error -show_streams -select_streams a "$f" | grep channels | cut -d = -f 2`
  50.         base="${filename%.*}"
  51.  
  52.         # check if output file already exists and log the error
  53.         if [ -f "$output_dir/$base.mp4" ]; then
  54.             echo "$output_dir/$base.mp4 already exists. Skipping."
  55.             echo "$output_dir/$base.mp4 already exists. Skipping." >> /tmp/dailies-encode.log
  56.             continue
  57.         fi
  58.        
  59.         echo $ffopts
  60.         # encode either 0, 1, or 2 audio channels
  61.             if [ -z "$num_channels" ]; then
  62.                 echo "Encoding" $filename "with zero audio channels"
  63.                 ffmpeg $ffpreopts -i "$f" -an $ffopts "$output_dir/$base.mp4"
  64.             elif [ "$num_channels" -le 2 ]; then
  65.                 echo "Encoding" $filename "with $num_channels audio channels"
  66.                 ffmpeg $ffpreopts -i "$f" -acodec libfdk_aac -b:a 128k $ffopts "$output_dir/$base.mp4"
  67.             else
  68.                 echo "Encoding" $filename "with first two audio channels only"
  69.                 ffmpeg $ffpreopts -i "$f" -acodec libfdk_aac -b:a 128k -map_channel 0.1.0 -map_channel 0.1.1 $ffopts "$output_dir/$base.mp4"
  70.             fi
  71.     done
  72.     echo
  73. fi
  74.  
  75. # cat /tmp/dailies-encode.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement