#!/bin/bash # start date # base variables INPUT=$1 OUTPUT=$2 WIDTH=$(mplayer -identify "$INPUT" -ao null -vo null -frames 0 2>/dev/null | grep WIDTH | gawk -F = '{print $2}') HEIGHT=$(mplayer -identify "$INPUT" -ao null -vo null -frames 0 2>/dev/null | grep HEIGHT | gawk -F = '{print $2}') # set new size and margins NEW_WIDTH=320 NEW_HEIGHT=$(($NEW_WIDTH*100/($WIDTH*100/$HEIGHT))) TOP=$(((240-$NEW_HEIGHT)/2)) BOTTOM=$TOP # all values must be a multiple of 2 NEW_WIDTH=$(($NEW_WIDTH+$NEW_WIDTH%2)) NEW_HEIGHT=$(($NEW_HEIGHT+$NEW_HEIGHT%2)) TOP=$(($TOP-$TOP%2)) BOTTOM=$(($BOTTOM+$BOTTOM%2)) # extract video ffmpeg -i "$INPUT" -f mp4 -vcodec mpeg4 -r 25 -b 400 -padtop $TOP -padbottom $BOTTOM -s "$NEW_WIDTH"x"$NEW_HEIGHT" -aspect 4:3 -an temp.mp4 mp4creator -extract=1 temp.mp4 temp.divx rm temp.mp4 # extract audio ffmpeg -i "$INPUT" -ab 96 -ar 44100 temp.wav faac -o temp.mp4 temp.wav mp4creator -extract=1 temp.mp4 temp.aac rm temp.wav temp.mp4 # mux audio/video test -e "$OUTPUT" && rm "$OUTPUT" mp4creator -H -i -I -c temp.divx -r 25 "$OUTPUT" mp4creator -H -i -I -c temp.aac "$OUTPUT" mp4creator -optimize "$OUTPUT" rm temp.divx temp.aac # finish date