Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Directories must be defined without trailing slash
- output_dir="/Volumes/RAID/temp/tenerte"
- 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"
- ffpreopts="-loglevel warning -stats"
- echo "This script will encode source files for copra and save to:"
- echo "$output_dir."
- echo "Source files will not be modified."
- #Check if any arguments were passed
- if [ -z "$1" ]
- then
- echo
- echo "Usage: copra-dragndrop [OPTION]... SRC [SRC]..."
- echo " Options"
- echo " -r RATE conform source frame rate to 23.98 timebase"
- else
- # check for command-line options
- while getopts ":r:" opt; do
- case $opt in
- r) # set frame rate
- rate="$OPTARG""000/1001"
- echo "Conforming input $OPTARG fps to 24 with NTSC convention"
- ffpreopts="$ffpreopts -r $rate" # force input frame rate
- ffopts="$ffopts -r 24000/1001" # assume 23.98 timebase
- ;;
- \?)
- echo "Invalid option -$OPTARG"
- exit 1
- ;;
- :)
- echo "Option -$OPTARG requires an argument."
- exit 1
- ;;
- esac
- done
- shift $((OPTIND-1)) # remove opts, leaving only positional parameters
- mkdir -p $output_dir
- echo "Errors:" > /tmp/dailies-encode.log
- echo "Processing $# files..."
- for f # without arguments automatically uses positional parameters
- do
- filename=$(basename "$f")
- # get number of audio channels
- num_channels=`ffprobe -loglevel error -show_streams -select_streams a "$f" | grep channels | cut -d = -f 2`
- base="${filename%.*}"
- # check if output file already exists and log the error
- if [ -f "$output_dir/$base.mp4" ]; then
- echo "$output_dir/$base.mp4 already exists. Skipping."
- echo "$output_dir/$base.mp4 already exists. Skipping." >> /tmp/dailies-encode.log
- continue
- fi
- echo $ffopts
- # encode either 0, 1, or 2 audio channels
- if [ -z "$num_channels" ]; then
- echo "Encoding" $filename "with zero audio channels"
- ffmpeg $ffpreopts -i "$f" -an $ffopts "$output_dir/$base.mp4"
- elif [ "$num_channels" -le 2 ]; then
- echo "Encoding" $filename "with $num_channels audio channels"
- ffmpeg $ffpreopts -i "$f" -acodec libfdk_aac -b:a 128k $ffopts "$output_dir/$base.mp4"
- else
- echo "Encoding" $filename "with first two audio channels only"
- 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"
- fi
- done
- echo
- fi
- # cat /tmp/dailies-encode.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement