Last active
August 29, 2015 14:15
-
-
Save barbolani/23a509b17215e177e92e to your computer and use it in GitHub Desktop.
Script to convert video files to a format that an iPad v1 is able to play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This is the script I use to convert video files to a format | |
# that my iPad 1 is able to play | |
# | |
# You use this script like this | |
# toipad [-o <output folder>] [FILE]... | |
# where | |
# -o <outputfolder> is optional and tells the destination folder for converted files | |
# | |
# [FILE] is the list of files to convert. Wildcards are accepted | |
# | |
# Default output folder | |
OUTFOLDER="./" | |
# These are the arguments I use for ffmpeg | |
FFMPEGARGS="-acodec aac -ac 2 -strict experimental -ab 160k -vcodec libx264 -r 30 -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -keyint_min 25 -f mp4 -threads 0 -y " | |
if [ "$1" = "-o" ] | |
then | |
shift | |
OUTFOLDER=$1"/" | |
shift | |
fi | |
# loop over all arguments | |
until [ -z "$1" ] | |
do | |
INPUTFILE=$(basename "$1") | |
# Remove file extension assuming it is what is after the last dot in the filename | |
FILENAME=$(echo $INPUTFILE | sed 's/\.[^.]*$//') | |
# Removes everything after the opening parenthesis or bracket and replaces | |
# remaining dots with spaces | |
OUTFILE=$(echo $FILENAME | sed "s/\[.*$//g" | sed -r "s/\(.*$//g" | sed "s/\./ /g" ) | |
# The resulting file will always have .mp4 extension | |
OUTPUTFILE=$OUTFOLDER${OUTFILE%.*}".mp4" | |
# And here is the complete command line | |
SCRIPTFLAGS="ffmpeg -i \"$1\" $FFMPEGARGS \"$OUTPUTFILE\"" | |
eval $SCRIPTFLAGS | |
shift | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment