Skip to content

Instantly share code, notes, and snippets.

@bmatherly
Created May 10, 2013 02:17
Show Gist options
  • Save bmatherly/5551988 to your computer and use it in GitHub Desktop.
Save bmatherly/5551988 to your computer and use it in GitHub Desktop.
Scripts to convert a directory of mp4 files to SD mpg files.
#!/bin/sh
SRCFILE=$1
DSTFILE=$2
# Sanity checking, to make sure everything is in order.
if [ -z "$SRCFILE" -o -z "$DSTFILE" ]; then
echo "Usage: $0 <Source File> <Destination File>"
exit 5
fi
if [ ! -f "$SRCFILE" ]; then
echo "File does not exist: $SRCFILE"
exit 6
fi
vidinfo=`ffmpeg -i $SRCFILE 2>&1 | grep Video:`
width=`echo "$vidinfo" | sed "s/.* \([1-9][0-9]*\)x\([0-9]*\).*/\1/"`
height=`echo "$vidinfo" | sed "s/.* \([1-9][0-9]*\)x\([0-9]*\).*/\2/"`
if [ "$width" -gt 720 -o "$height" -gt 480 ]; then
ionice -c3 nice -19 ffmpeg -i $SRCFILE -vf "yadif, scale=-1:480" -vcodec mpeg2video -r 29.97 -qscale 4 -bf 2 -acodec mp2 -ac 2 -ar 48000 -ab 128k -y $DSTFILE
else
ionice -c3 nice -19 ffmpeg -i $SRCFILE -vf yadif -vcodec mpeg2video -qscale 4 -bf 2 -acodec mp2 -ac 2 -ar 48000 -ab 128k -y $DSTFILE
fi
# Make sure the transcode succeeded.
if [ ! -f $DSTFILE ]; then
echo "Transcode Failed"
exit 7
fi
#!/bin/bash
SRCDIR=$1
DSTDIR=$2
# Sanity checking, to make sure everything is in order.
if [ -z "$SRCDIR" -o -z "$DSTDIR" ]; then
echo "Usage: $0 <Source Directory> <Destination Directory>"
exit 5
fi
if [ ! -d "$SRCDIR" ]; then
echo "Source directory does not exist: $SRCDIR"
exit 6
fi
if [ ! -d "$DSTDIR" ]; then
echo "Destination directory does not exist: $DSTDIR"
exit 6
fi
shopt -s nullglob
for srcfile in $SRCDIR/*.mp4
do
# Cleanup the file name
dstfile=`echo $srcfile | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
dstfile=${srcfile%.*}
dstfile=${dstfile##*/}
dstfile="$DSTDIR/$dstfile.mpg"
echo "Convert $srcfile to $dstfile"
./convert_to_sd.sh $srcfile $dstfile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment