Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -ne 1 ]; then
- echo Usage: $0 '<source>'
- exit 1
- fi
- test -e $1 || { echo No such file $1. Aborting. ; exit 1 ; }
- export TMPNAME=`echo $1 | sed -e 's/\..*$//'`
- export MAXWIDTH=800
- export MAXHEIGHT=480
- export VHEIGHT=`mplayer -ao null -vo null -frames 0 -identify $1 2>/dev/null | grep ^ID_VIDEO_HEIGHT | sed -e 's/ID_VIDEO_HEIGHT=//'`
- export VWIDTH=`mplayer -ao null -vo null -frames 0 -identify $1 2>/dev/null | grep ^ID_VIDEO_WIDTH | sed -e 's/ID_VIDEO_WIDTH=//'`
- if [ ${VWIDTH} -ne ${MAXWIDTH} ]; then
- export SF=`echo "scale=4; ${MAXWIDTH}/${VWIDTH}" | bc`
- export VWIDTH=`echo ${VWIDTH}'*'${SF} | bc | sed -e 's/\..*$//'`
- export VHEIGHT=`echo ${VHEIGHT}'*'${SF} | bc | sed -e 's/\..*$//'`
- fi
- if [ ${VHEIGHT} -gt ${MAXHEIGHT} ]; then
- export SF=`echo "scale=4; ${MAXHEIGHT}/${VHEIGHT}" | bc`
- export VWIDTH=`echo ${VWIDTH}'*'${SF} | bc | sed -e 's/\..*$//'`
- export VHEIGHT=`echo ${VHEIGHT}'*'${SF} | bc | sed -e 's/\..*$//'`
- fi
- export VKBPS=2000
- export AKBPS=44100
- export MPLAYER_VERBOSE="all=0:mencoder=1:statusline=5"
- export X264OPTS="-x264encopts bitrate=$VKBPS:frameref=8:bframes=0:b_adapt:weight_b:partitions=all:8x8dct:me=umh:subq=6:trellis=2:threads=auto:analyse=all:pass="
- export FAACOPTS="-faacopts br=192:mpeg=4:object=2 -channels 2 -srate $AKBPS"
- export MISCOPTS="-ofps 24000/1001 -vf harddup -vf scale=${VWIDTH}:${VHEIGHT},expand=${MAXWIDTH}:${MAXHEIGHT} -msglevel $MPLAYER_VERBOSE"
- export PASSLOGFILE="div2pass_$1.log"
- trap cleanup INT
- echo '***********************************'
- echo Converting $1 to mp4
- echo '***********************************'
- for pass in 1 2; do
- echo '***********************************'
- echo Pass $pass
- echo '***********************************'
- test -e "$2" && rm "$2"
- mencoder "$1" -passlogfile "$PASSLOGFILE" -o "$TMPNAME.avi" -ovc x264 $X264OPTS$pass -sws 2 -oac faac $FAACOPTS $MISCOPTS
- done
- echo '***********************************'
- echo Splitting A/V streams
- echo '***********************************'
- mplayer "$TMPNAME.avi" -dumpaudio -dumpfile "$TMPNAME.aac" 2>/dev/null
- mplayer "$TMPNAME.avi" -dumpvideo -dumpfile "$TMPNAME.h264" 2>/dev/null
- echo '***********************************'
- echo Merging to MP4 Container
- echo '***********************************'
- test -e "$TMPNAME.mp4" && rm -f "$TMPNAME.mp4"
- mp4creator -force3GPCompliance -create="$TMPNAME.h264" -rate=23.976 "$TMPNAME.mp4"
- mp4creator -force3GPCompliance -create="$TMPNAME.aac" -interleave -optimize "$TMPNAME.mp4"
- cleanup() {
- for file in "$PASSLOGFILE" "$PASSLOGFILE.mbtree" "$TMPNAME.avi" "$TMPNAME.aac" "$TMPNAME.h264" ; do
- test -e $file && rm $file
- done
- }
- cleanup
- echo '***********************************'
- echo All work completed for ${TMPNAME}.mp4
- echo '***********************************'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement