I am trying to convert different files to a flash compatible .mp4
file with ffmpeg, but I can\'t seem to get it to work. Of course the objective is to get the great
I use a sequence of commands to do this, starting with mencoder. (see script below). The trick is that ffmpeg's (and mencoder's) mp4 file output is not generally flash compatible due to the way it's interleaved and they don't offer good control over this behavior. So, I produce an AVI file and then use mp4box to remux it the way I want. Here's my complete script, that expects to be given an .avi file, and produces a flash-playable .mp4 file.
#!/bin/bash
#
ORIGDIR=`pwd`
FILE=$@
VID_OUTPUT=${FILE/.AVI/.tmp.avi}
FINAL_OUTPUT=${FILE/.AVI/.mp4}
MENCODER=~/src/mplayer/svn/mplayer/mencoder
BITRATE=500
RES=640:480
LOG=mencoder.$FILE.log
TEMPDIR=`mktemp -d /tmp/transcode.XXXXXXXX`
pushd $TEMPDIR
echo "Pass 1"
PARAMS=keyint=250:bframes=0:qp_min=10:qp_max=51:turbo=1:mixed_refs=0:frameref=1:deblock=0,0:qblur=0:vbv_bufsize=10000:vbv_maxrate=10000:keyint_min=25:me=hex:me_range=16:ip_factor=1.4:pb_factor=1.3:chroma_qp_offset=0:vbv_init=0.9:ratetol=1.0:cplx_blur=20:nocabac:noweight_b:nob_pyramid:partitions=p8x8,b8x8,i4x4:no8x8dct:nossim:deadzone_inter=21:deadzone_intra=11
EXTRA_PARAMS=subq=5:trellis=0:
$MENCODER $ORIGDIR/$FILE -o $VID_OUTPUT -oac faac -srate 44100 -ovc x264 -x264encopts bitrate=$BITRATE:$PARAMS:pass=1 -vf scale=$RES 2>&1 >> $LOG
echo "Pass 2"
$MENCODER $ORIGDIR/$FILE -o $VID_OUTPUT -oac faac -srate 44100 -ovc x264 -x264encopts bitrate=$BITRATE:$PARAMS:pass=2 -vf scale=$RES 2>&1 >> $LOG
MP4Box -aviraw video $VID_OUTPUT
MP4Box -aviraw audio $VID_OUTPUT
TEMP_AUDIO=${VID_OUTPUT/.avi/}_audio.raw
AAC_AUDIO=${TEMP_AUDIO/.raw/.aac}
H264_VIDEO=${VID_OUTPUT/.avi/}_video.h264
echo TEMP is $TEMP_AUDIO
echo AAC is $AAC_AUDIO
echo H264 is $H264_VIDEO
mv $TEMP_AUDIO $AAC_AUDIO
MP4Box -add $H264_VIDEO:fps=29.97 -add $AAC_AUDIO $FINAL_OUTPUT
mv $LOG $ORIGDIR
mv $FINAL_OUTPUT $ORIGDIR
popd
echo Files left in $TEMPDIR
# rm -fr $TEMPDIR