MKMP4: An automated H264 / HE-AAC (aacPlus) encoder script for Mac and Linux / Unix

I have been nothing but amazed about the feedback that i got on my prior tutorials on how to automate the whole chain of free and open source tools to create amazing quality video at really low bitrates (great for flash streaming, etcetera).

I usually write such tools and scripts for myself or for clients, but due to the fact that it seems a lot of people is interested in the process, I’m releasing here the new version of my encoding tools for the Mac and any Linux / Unix variant.

Needed tools and applications

For all this to work, you will need the following things

Extra pre-requisites for Mac OS X

Mac OS X users need to install the Apple Developer Tools (aka XCode) in order to compile software, also, for building the x264 encoder, you will need to get and install YASM.

Now, you have to build and install all the tools, AND they have to be on any directory in your executable path. My scripts assume that all the tools are in your executable path.

Building x264

Building x264 is usually a matter of just typing:

./configure

in the source directory, and then the usual:

make

and

make install

If you happen to have any problem with the building process, usually a simple google search with the error string is all you need.

Building mplayer

The process of building mplayer is certainly similar, BUT if you plan to use the video thumbnail and poster frame generation on my scripts, you will have to get and compile the jpeg libraries (if you don’t have them already) BEFORE building mplayer, this should be also a really easy thing to do: go get the libjpeg sources from HERE, and then configure, build and install.

Now, you have to download the latest SVN version of mplayer, assuming that you have the subversion client enabled, you can get the whole source tree by typing:

svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

Now, you need to enable some things at configure time for mplayer and mencoder to work nice with the scripts, so our configure line will look something like this

./configure --disable-gui --enable-png --enable-jpeg

Note: there should be no reason at all for the –enable-jpeg flag, but for some reason that I ignore, mplayer wont detect my libjpeg install if i don’t force it like that, also, the –disable-gui option is to save some compile time, since we don’t plan to use any of the GUI features on mplayer.

Now, its time to build, so type:

make

and then, if you get no errors, you are safe to type:

make install

At this point you should have a working install, but since we want to be 100% sure that you REALLY have a working install, in any terminal type this:

mencoder -ovc help

and you should get something like this (please notice the x264 part, that is fundamental for everything to work)

Available codecs:

   copy     - frame copy, without re-encoding. Doesn't work with filters.
   frameno  - special audio-only file for 3-pass encoding, see DOCS.
   raw      - uncompressed video. Use fourcc option to set format explicitly.
   lavc     - libavcodec codecs - best quality!
   vfw      - VfW DLLs, read DOCS/HTML/en/encoding-guide.html.
   qtvideo  - QuickTime DLLs, currently only SVQ1/3 are supported.
   x264     - H.264 encoding

now let’s verify the mplayer part, again, in any terminal type:

mplayer -vo help

and you should get something like this (here, notice the PNG and JPEG bits, this is fundamental if you plan to use the thumbnail and poster generation features).

Available video output drivers:
	macosx	Mac OSX Core Video
	quartz	Mac OSX (Quartz)
	xv	X11/Xv
	x11	X11 ( XImage/Shm )
	xover	General X11 driver for overlay capable video output drivers
	gl	X11 (OpenGL)
	gl2	X11 (OpenGL) - multiple textures version
	null	Null video output
	mpegpes	MPEG-PES file
	yuv4mpeg	yuv4mpeg output for mjpegtools
	png	PNG file
	jpeg	JPEG file
	tga	Targa output
	pnm	PPM/PGM/PGMYUV file
	md5sum	md5sum of each frame

Very Important!

After you compile and install mplayer, you need to copy the midentify.sh script into any directory inside your executable path, for example /usr/local/bin. This is mandatory, because the MKMP4 script will NOT be able to correctly identify the source video files without this tool. The midentify script (called midentify.sh) is located inside the TOOLS directory in the mplayer source tree.

At this point, almost everything is ready, now it is time for the next step.

Building and configuring the GPAC utilities

If you are on Linux / Unix, building the GPAC utilities is a really simple process.

Get the latest stable release from here, and then do the usual ./configure, make and make install.

For Mac OS users there is an extra step that you have to do if you want to be able to build and install the GPAC utilities without headaches, and it involves the editing of a source file in the package.

So, after you have downloaded the sources, open the file src/utils/os_net.c , line 78 reads:

#ifndef __DARWIN__

right AFTER it, add the following:

typedef unsigned long u_long;

save the file, and you can now configure, build and install the GPAC utilities (MP4Box) on Mac OS without any problem.

Installing the HE-AAC (aacPlus) audio encoder.

This is a pretty simple step, if you are on a Mac, get this encoder that i have built myself from the 3GPP sources and copy it to /usr/local/bin, and if you are on linux, get the Nero Digital Audio Encoder from HERE and again, copy it to /usr/local/bin. You can actually move the encoders to any directory that IS inside your executable path, /usr/local/bin is a good choice though ;).

Putting it all togheter.

At this point, you have pretty much everything you would need to encode amazing quality H264 video and aacPlus audio, the only one remaining thing is some tool to put all this togheter in an *easy to use* way, so i have created the following bash script which pretty much simplifies the whole process.

#! /bin/bash

# This bash script has been created by Diego Massanti
# www.massanti.com
#
# set -x # uncomment this for debugging
shopt -s nullglob # so the glob expands to nothing when there are no .mov files.

# User settings:

fileext=".mov" # Set this variable to the video file extension that you want to search for when encoding whole directories.

# End user settings
# You should not change anything below this line unless you know what you are doing.

usage()
{
cat << EOF
usage: $0 -f  [-w ] -b  [-q][-k][-t][-o ]

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* h264 video with he-aac audio encoding script by Diego Massanti. *
*                September 2008, Made in Argentina.               *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

OPTIONS:
   	-h	Show this message
-f	Path to the file to encode < REQUIRED
   	-w	Resize video to fit inside this width while keeping the aspect ratio < OPTIONAL
   	-b	Desired video bitrate < REQUIRED
-o	Output directory for compressed media < OPTIONAL (will use same as source if ommited)
   	-q 	Better quality encoding using 2 passes (slower) < OPTIONAL
-k	Do not delete (keep) temporary files < OPTIONAL
EOF
}
audiobitrate=48000
platform=""
uname=`uname`
if [ $uname == "Darwin" ]; then
## 99% of chances that this is a Mac
platform="Mac"
else
platform="Linux"
fi

width=""
bitrate=
deltemp=TRUE
quality=FALSE
poster=FALSE
filename=""
rsize=""
outdir=`pwd`
outFileName=""
itemVideoBitrate=""

while getopts ":f:w:o:b:qktv" OPTION; do
case $OPTION in
w ) width=$OPTARG;;
f ) filename=$OPTARG;;
b ) bitrate=$OPTARG;;
k ) deltemp=FALSE;;
q ) quality=TRUE;;
t ) poster=TRUE;;
o ) outdir=`cd "$OPTARG"; pwd`;;
h ) usage;;
\? ) usage
exit 1;;
* ) echo $usage
exit 1;;
esac
done

if [ "$1" == "" ]; then
usage
exit 0
fi

if [ "$filename" == "" ]; then
echo
echo you MUST supply a file to encode!, use the -f parameter. i.e: -f mymovie.avi
echo
usage
exit 1
fi
if [ "$bitrate" == "" ]; then
echo
echo you MUST specify a target bitrate!, use the -b parameter. i.e: -b 512
echo
usage
exit 1
fi

if [ "$width" != "" ]; then
rsize="-vf scale=$width:-3"
rsizemsg="fit into $width pixels wide"
else
rsize=""
rsizemsg="Movie is not being resized."
fi

# Check if output directory exists
if [ -d "$outdir" ]; then
echo "Target directory set to: $outdir"

else
echo "Error: '$outdir' does not exist!!"
echo "Can not continue, please make sure that the specified output directory exists. Exiting..."
exit 1
fi

# Start the magic...

showMessage() {
echo "MKMP4 : "$1""
}

initialize() {
if [ -d "$filename" ]; then
$filename = `cd $filename; pwd`
showMessage "Output directory set to: $outdir."
showMessage "Triggering the encoder with all media files in directory: $filename."
for file in "$filename"*$fileext; do
if [ -f "$file" ]; then
showMessage "Will encode file: $file"
startEncoders "$file"

fi
done
elif [ -f "$filename" ]; then
showMessage "Triggering the encoder with source media: $filename."
startEncoders "$filename"

else
# input is no file and no directory ? WTF ?
echo "Something really weird has happened here: $filename is not valid, exiting..."
exit 1
fi
}

startEncoders() {
firstPass "$1"
if [ "$quality" == "TRUE" ]; then
secondPass "$1"
fi
extractAudio "$1"
encodeAAC "$1"
mux "$1"
if [ $poster == "TRUE" ]; then
createThumbnail "$1"
fi
if [ $deltemp == "TRUE" ]; then
cleanTemporaryFiles "$1"
fi
}
firstPass() {
local iFile="${1##*/}"	# remove directory and keep only file name.
# First, lets get some basical information about this file, as FPS.
MOVIE_FPS=`midentify "$1" | grep FPS | cut -d = -f 2`
# Lets print some info to stdout.
showMessage "Encoding: $1"
showMessage "Resizing to: $rsizemsg."
showMessage "Total Bitrate: $bitrate kbps."
let "caudiobitrate = $audiobitrate / 1000"
let "itemVideoBitrate = $bitrate - $caudiobitrate"
showMessage "Video Bitrate: $itemVideoBitrate kbps."
showMessage "Audio Bitrate: $caudiobitrate kbps."
showMessage "Platform: $platform."
# Lets start the encoding for the first pass.
showMessage "Starting video encoding pass 1..."
mencoder "$1" -o "$outdir/${iFile%%.*}_temp.264" -passlogfile "$outdir/${iFile%%.*}"_temp.log $rsize -ovc x264 -x264encopts bitrate=$itemVideoBitrate:frameref=8:bframes=3:b_adapt:b_pyramid:weight_b:partitions=all:8x8dct:me=umh:subq=6:trellis=2:brdo:threads=auto:pass=1:analyse=all -of rawvideo -nosound

}

secondPass() {
local iFile="${1##*/}"	# remove directory and keep only file name.
showMessage "Starting video encoding pass 2..."
mencoder "$1" -o "$outdir/${iFile%%.*}_temp.264" -passlogfile "$outdir/${iFile%%.*}"_temp.log $rsize -ovc x264 -x264encopts bitrate=$itemVideoBitrate:frameref=8:bframes=3:b_adapt:b_pyramid:weight_b:partitions=all:8x8dct:me=umh:subq=6:trellis=2:brdo:threads=auto:pass=2:analyse=all -of rawvideo -nosound
}

extractAudio() {
local iFile="${1##*/}"	# remove directory and keep only file name.
showMessage "Extracting Audio..."
mplayer "$1" -af resample=48000:0:2,channels=2,volnorm=1:0.25,format=s16le -ao pcm:file="$outdir/${iFile%.*}_temp.wav" -vc dummy -vo null
}

encodeAAC() {
local iFile="${1##*/}"	# remove directory and keep only file name.
if [ "$platform" == "Mac" ]; then
enhAacPlusEnc "$outdir/${iFile%.*}_temp.wav" "$outdir/${iFile%.*}_temp.aac" $audiobitrate s
else
neroAacEnc -br 48000 -he -if $outdir/${iFile%.*}_temp.wav -of $outdir/${iFile%.*}_temp.mp4
fi
}

mux() {
local iFile="${1##*/}"	# remove directory and keep only file name.
MP4Box -add "$outdir/${iFile%.*}_temp.264#video:fps=$MOVIE_FPS" "$outdir/${iFile%.*}.m4v"
if [ "$platform" == "Mac" ]; then
MP4Box -add "$outdir/${iFile%.*}_temp.aac" -sbr "$outdir/${iFile%.*}.m4v"
else
MP4Box -add "$outdir/${iFile%.*}_temp.mp4#audio" "$outdir/${iFile%.*}.m4v"
fi
name=$outdir/${iFile%.*}
album="The Mac Video Archive"
author="Apple Computer // massanti.com"
comment="Professionally encoded by Diego Massanti"
created="2007"
MP4Box -inter 500 -itags album="$album":artist="$author":comment="$comment":created="$created":name="$name" -lang English "$outdir/${iFile%.*}".m4v
}

createThumbnail() {
local iFile="${1##*/}"	# remove directory and keep only file name.
mplayer "$1" -ss 10 -nosound $rsize -ssf lgb=1.0 -sws 7 -vo jpeg:outdir=$outdir -frames 1
mv "$outdir/00000001.jpg" "$outdir/${iFile%.*}.jpg"
mplayer "$1" -ss 10 -nosound -vf scale=150:-3 -ssf lgb=1.0 -sws 7 -vo jpeg:outdir=$outdir -frames 1
mv "$outdir/00000001.jpg" "$outdir/${iFile%.*}_small.jpg"
}

cleanTemporaryFiles() {
local iFile="${1##*/}"	# remove directory and keep only file name.
showMessage "Removing temporary files..."
rm "$outdir/${iFile%.*}"_temp*
}

initialize

You can also download the script by clicking here in order to keep proper code formatting. Installation is really simple, just move it to /usr/local/bin, give it execution rights (chmod +x /usr/local/bin/mkmp4) and done.

This script is really easy to use and implement, basically the script expects the following MANDATORY parameters in the command line:

  • -f to specify the source media (can be a single file or a whole directory with media files)
  • -b to specify the target bitrate for the final h264 encoded movie
  • -w to specify the target width for the final h264 encoded movie

So for example, typing:

mkmp4 -f /path/to/some/video.avi -b 512 -w 640

will create a MP4 video file with a bitrate of 512kbps and a frame width of 640 pixels (please note that mencoder will correctly take care of the aspect ratio for the final movie and the resize will just look OK.)

Optional parameters for the MKMP4 script:

  • -q turns on 2 pass encoding: This will increase the final quality (and the encoding time), but it worths the extra wait if you care about quality.
  • -k to keep temporary files: The script will create several temporary files during the encoding process, if for whatever reason you want to keep that files, you should use this option.
  • -o to specify a target directory: By default, the mkmp4 script will place the output video in the working directory (the directory from where you called the script), if you want to change that behavior, just use this option.
  • -t to turn ON thumbnail and poster frame generation: If you use this flag, mkmp4 will create a thumbnail and a poster frame that you can then use if you plan to publish your videos on the web.

The following command line will create a 512kbps video, will set the target width to 640 pixels AND will use 2 pass encoding, will not delete temporary files, will create thumbnails and poster frames, and will place the files on the /target/directory/ directory.

mkmp4 -f /path/to/some/video.avi -b 512 -w 640 -k -q -t -o /target/directory/

Some things you need to know and FAQ’s about this script:

  • By default, when the -f parameter is a directory, the script will search for any .mov file inside it, encode it, and place the final mp4 file into the directory set in the -o parameter (or the current directory if you have ommited that parameter), if you want to change that behavior, just change the value of the fileext variable inside the script to whatever file extension you want to process.
  • Why are you reducing the audio level by 5db ? This is because with some old audio formats, for some reason that I really ignore, mplayer will distort the audio output. Now, if you take a closer look, you will see that right after the volume filter, im applying a normalization filter to get the audio back to 0db, so the output audio level will always be correct no matter what happens.
  • Why are you forcing the audio output to be always stereo ? what if i want to encode mono material ?: Just modify the audio encoder trigger.
  • The output media produced by this script is automatically interleaved and is fully compatible (and has been tested) with Flash Media Server 3 and Wowza Media Server Pro.

There are a lot of things that could be improved around here, and so far i have not tested this in any platform other than Mac OS Leopard, but so far, this should work in any Linux / Unix variant too without too much work.

If you are interested to get an idea of how the video results will look, you can take a look a The Apple Video Archive here on this site.

As usual, comments / feedback and suggestions are welcome.

Be Sociable, Share!

Related posts:

No related posts.


70 Responses to “MKMP4: An automated H264 / HE-AAC (aacPlus) encoder script for Mac and Linux / Unix”

  1. [...] This post has been updated with a newer and improved script and instructions, please visit the new one HERE. [...]

    by Diego’s Rants » Blog Archive » Encoding high quality h.264 / aacPlus v2 media for web streaming with Flash 9, version 2., September 26th, 2008 at 7:46 pm


  2. Since you compiled x264 BEFORE you compiled GPAC (mp4box). So your x264 binary won’t have support for mp4 file type.
    Can you tell me how to do compile a standalone version of mp4box as appose to the one that links to libgpac.dylib.
    Btw i have been able to compile the latest cvs gpac on mac with minor edits to the code. I dunno if the cvs version of mp4box is any better than the 0.4.4 version of mp4box.
    Thank you for the rightup

    by MySchizoBuddy, September 26th, 2008 at 11:02 pm


  3. Also you never mentioned how you compiled your own AACplus encoder. macports won’t allow binaries i have to write a portfile to compile it from source so everyone can benefit from it.

    by MySchizoBuddy, September 26th, 2008 at 11:05 pm


  4. Hey there MySchizoBuddy, thanks for your comments.
    Regarding your x264 BEFORE GPAC question, I’m not really sure why should i want an x264 build with MP4 support, as in, im using MP4Box for the final muxing, so, at least on my specific situation, it is useless, unless I’m missing something, and in that case i ask you to explain me better.
    I would be interested to take a look at your fixes to the GPAC CVS version for building on Mac OS, to be honest, i didn’t take a lot of time dealing with the sources to figure out the problems, but if you have it working already, it would be great to update this post with that information.
    Regarding your question about the aac encoder, i use xCode for the building process, and i have released all my modified sources and xcode project months ago here: http://blog.massanti.com/2007/09/30/he-aac-plus-encoder-mac-universal-binary/
    Im not really good with the command line build tools, sorry :/, so again, if you are able to convert that to an automake/autoconf or whatever is needed for macports, that would be great too ;)
    Thanks for your feedback. Diego.

    by Diego Massanti, September 27th, 2008 at 2:43 am


  5. Sweet! This is fantastic. I was asking about this a couple of days ago :)

    BTW, your syntax-coloring routine goes off for a few lines there. The green threw me off until I realized it was an error in coloring.

    It’s great that you’re sharing this. You’ve licked some problems I knew I’d have to tackle myself (including compiling he-aac which I hadn’t realized you’d already make a package for).

    Three questions, tho’.

    For a lot of original files the streams contained are actually compatible with MP4 (say, they are already H264 or XViD). Doesn’t it make sense to demux these files and mux them back again into an MP4 container? Wouldn’t it be much faster in these cases than converting? Or are the possible problems not worth the gains in time and possible loss of quality after re-coding? (I am assuming MP4Box doesn’t do this automatically, on which I could be wrong, really. I hadn’t been able to compile mp4box before).

    Also, you’re assigning some tags at muxing time. I assume that if one wanted to also add iTunes-specific tags (say, for TV-Show or episode ID on a TV series) they could be input there as well.

    Finally, MP4Box has support for subtitles/MP4 Timed Text. It wouldn’t be hard to include an option to attach subtitles as well. I’d have to play with the script to see if this is possible (actually, multiple subs can be attached as timed text and have their own language tracks).

    by eduo, September 27th, 2008 at 6:48 pm


  6. Great tutorial, Diego! Thank you so much for making it available for us.

    I have a question, though. I was able to encode video and audio with your script, but there’s one problem. All my clips have their soundtrack end before the video finishes. Looking at the output of the script, I noticed that the original MPEG video has a 29.970 fps rate, while the output is at 25 fps. This would explain the above effect. Do you know how I can fix that?

    by Andrew, September 27th, 2008 at 6:51 pm


  7. I think MySchizoBuddy is implying you could do the h264 encode from mp4box directly and save a step.

    Off-topic: I found it poignant that the first video in your archived videos page shows Paul Newman in the thumbnail.

    by eduo, September 27th, 2008 at 7:04 pm


  8. @Andrew, there is a box with a red icon on the tutorial, and a title stating “Very Important”, please read that part and be sure that you have copied midentify to any directory inside your executable path.

    by Diego Massanti, September 27th, 2008 at 8:17 pm


  9. Weird. I can configure and compile jpeglib succesfully, but it won’t be later recognized by mplayer when compiling. I’ll try with disable-jpeg in the meantime.

    by eduo, September 27th, 2008 at 9:02 pm


  10. @eduo, No I’m not saying you could do h264 from mp4box. NO hell no
    You can get the output from x264 in mp4 format instead of the raw format. However, thats mute point cause the script uses mencoder and not x264 directly. so my bad for mentioning this.

    Just information for others, you can get mp4 directly from x264 if you compile GPAC before you compile x264.

    looks like since the 3GPP reference codec isn’t open sourced under GPL. i cannot add them to macports. So no solution to get HE-AAC in macports.

    @Diego, I’m making the GPAC portfile for macports, so next time all the necessary libs can be installed using macports (except HE-AAC) to make this process easier for everyone.

    by MySchizoBuddy, September 27th, 2008 at 9:17 pm


  11. Too bad that i don’t like macports and such things :p
    Thats amazing for macports users anyway, thanks for it!

    by Diego Massanti, September 27th, 2008 at 9:45 pm


  12. @eduo: All what you say is possible (About muxing without re-encoding, etc), the problem is that by doing that you lose the ability to process the source material (thats a MUST in my case), for doing what you want to do, you don’t need this script, you just need to read the MP4Box documentation, thats all you need.
    In my particular case, when i construct a batch encoder like this one, the purpose is to take a LOOOOOOOOOOOOT of source videos in different formats, sizes, etc, and standardize them all to one common format, and, while I’m on it, i usually apply several defacto standards to the audio tracks (like normalization to -0.1db) and some filters to the video too (like colorimetry conversion, etc).
    That is the purpose of tools like this one, to simplify that kind of process.

    by Diego Massanti, September 27th, 2008 at 11:56 pm


  13. @eduo: regarding your libjpeg issue, be sure that you do a “make install-libs” too :)

    by Diego Massanti, September 28th, 2008 at 12:05 am


  14. for people who hate command lines can use Penguin MP4 Encoder
    http://penguintool.blogspot.com/2008/04/penguin-encoder-mp4-097b4-was-released.html

    by MySchizoBuddy, September 28th, 2008 at 1:31 am


  15. @Diego: if your going to do LOOOOOOOT of files then you should look into how to leverage Xgrid like the folks at VisualHub do it.

    by MySchizoBuddy, September 28th, 2008 at 1:34 am


  16. Sure, if it wasn’t that i do LOOOOOOOOOOOT of files on servers running linux and that clustering is not my concern at this time ;)

    by Diego Massanti, September 28th, 2008 at 2:31 am


  17. Diego:

    I understood the purpose of the script. I had meant that it could (through midentify.sh, perhaps) know when to demux/remux and when to transcode.

    For the libjpeg and libpng (which came later) problems I was having I ended up downloading both, copying config.guess and config.sub from /usr/share/libtool and configure/make/make install normally and all was well.

    Some Notes for those that may need them:
    In Leopard there is a known bug with GL Libraries, so the configure commands need to be changed.

    In general, gpac gives me too many errors in Leopard. What are you compiling it on?

    by eduo, September 28th, 2008 at 7:01 pm


  18. Nope. I don’t have any XQuartz. It’s strange, the errors I’m getting.

    First of all the error with the GL libraries above, which seems to be common to Leopard. Then I got a strange error where the linker can’t find something, but can’t tell me what it is:

    “ld: file not found:
    collect2: ld returned 1 exit status
    make[1]: *** [libgpac.dylib] Error 1
    make: *** [lib] Error 2″

    It’s almost 2am, so I’ll get back to this tomorrow. Thanks for all the pointers and the guide!

    by eduo, September 28th, 2008 at 7:38 pm


  19. I forgot to ask, maybe you were implying it. Do you think having XQuartz would provide whatever dependencies are not being met? The error couldn’t be less useful, really.

    by eduo, September 29th, 2008 at 4:21 pm


  20. Hi Diego,
    thanks a lot for the great script. It just works right out of the box, no tweaking required…

    Tom

    by Tom, September 29th, 2008 at 6:18 pm


  21. Im compiling on Leopard 10.5.5 , do you happen to have any version of XQuartz installed ?

    by Diego Massanti, October 2nd, 2008 at 8:26 pm


  22. Hi,

    Very interesting script.
    Nevertheless, i ran it over a 1 hour movie, and I had audio desynchronization (more than 2 seconds at the end of the movie).
    Is there anyway to detect and fix that issue ?

    Carl

    by Carl, October 3rd, 2008 at 4:06 am


  23. Hi there Carl, are you sure you copied the midentify script as suggested in the guide ?

    by Diego Massanti, October 3rd, 2008 at 4:10 am


  24. Hi Diego,
    Thanks for your reply.

    Yes, indeed, midentify is giving the FPS (29.970), which is the same in the encoded file.
    Cheers, Carl

    by Carl, October 3rd, 2008 at 5:18 am


  25. What is the source format of the movie you are encoding ? If you are on a mac, could you paste a mediainfo report for the audio and video streams ?

    by Diego Massanti, October 3rd, 2008 at 6:48 am


  26. Sure, here is it :

    Format : AVI
    Format/Info : Audio Video Interleave
    File size : 860 MiB
    Duration : 1h 13mn
    Overall bit rate : 1 642 Kbps
    Writing application : VirtualDubMod 1.5.10.2 (build 2540/release)
    Writing library : VirtualDubMod build 2540/release

    Video
    Format : MPEG-4 Visual
    Format profile : Streaming Video@L1
    Format settings, BVOP : Yes
    Format settings, QPel : No
    Format settings, GMC : No warppoints
    Format settings, Matrix : Default
    Muxing mode : Packet Bitstream
    Codec ID : XVID
    Codec ID/Hint : XviD
    Duration : 1h 13mn
    Bit rate : 1 504 Kbps
    Width : 944 pixels
    Height : 528 pixels
    Display aspect ratio : 16/9
    Frame rate : 29.970 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.101
    Stream size : 788 MiB (92%)
    Writing library : XviD 1.1.2 (UTC 2006-11-01)

    Audio
    Format : MPEG Audio
    Format version : Version 1
    Format profile : Layer 3
    Codec ID : 55
    Codec ID/Hint : MP3
    Duration : 1h 13mn
    Bit rate mode : Variable
    Bit rate : 126 Kbps
    Channel(s) : 2 channels
    Sampling rate : 48.0 KHz
    Resolution : 16 bits
    Stream size : 65.0 MiB (8%)
    Alignment : Aligned on interleaves
    Interleave, duration : 24 ms (0.72 video frame)
    Interleave, preload duration : 502 ms

    I did several tests with small videos (less than 2 minutes) without any problem. This is my first try on a long one.

    cheers, Carl

    by Carl, October 3rd, 2008 at 8:20 am


  27. Carl, honestly, im totally lost on why you are having that problem… I indeed tried several long files (include whole movies, etc) and never had such a problem, so it makes me thing that maybe the libavcodec demuxer is doing something weird…

    I know for a fact (based on several user reports in the mplayer’s user lists) that using -nosound in mplayer (like this script uses) can cause audio sync problems, but i had never experimented that issue myself ’til now.

    So, if you have the time you could try this:

    Try modifying the script by removing the “-demuxer lavf” from both encoding passes, if that doesn’t makes a change, then i will have to find a better way to extract the audio into a .wav file without using the -nosound switch which i think is causing your issue here.

    by Diego Massanti, October 3rd, 2008 at 6:54 pm


  28. diego,

    No problem to make as many tests as neccessary to address this issue.
    From both release of your script, I don’t see any occurence of “-demuxer lavf”.
    Did I miss something ?

    Carl

    by Carl, October 4th, 2008 at 8:28 am


  29. [...] Register Home > Blog article: iPhone and iPod Touch compatible video encoding, server side. « MKMP4: An automated H264 / HE-AAC (aacPlus) encoder script for Mac and Linux / Unix [...]

    by Diego’s Rants » iPhone and iPod Touch compatible video encoding, server side., October 12th, 2008 at 2:51 am


  30. Hi Diego,
    thanks for this great script / tutorial. using this as the foundation we created a video sharing plattform which generated more than 100 GB traffic on its first day (yesterday).

    I modified the script in varios places – we call it from php and need to report back to php as soon as a video is done. Also i added some more parameters, e.g. I pass over width *and* height – using your code I sometimes had problems with 16:9 videos, now i am telling mencoder exactly what to do and it works flawlessly. The correct meta information we get from mediainfo, which we also use in order to get 2 screenshots from the middle of the video (10 secs like you do it didn’t work for us taht good, e.g. if someone uploads a 6 sec. clip) – oddly the first of them is just black most of the time, so i just use screenshot #2.

    Thanks again
    Thomas

    by Thomas, October 23rd, 2008 at 6:30 am


  31. Great Thomas, thanks a lot for reporting back.
    Actually, im working on yet another version. Mostly what I’m improving is the command line parsing area, and yes, i was thinking too of adding height as an optional parameter.
    You idea of using mediainfo instead to analyze the source files is good, and i will “steal” it :p.
    Thanks again for reporting back man.
    Best of lucks.

    Diego.

    by Diego Massanti, October 23rd, 2008 at 2:22 pm


  32. Target directory set to: /Users/kaaneryilmaz/Desktop/o
    MKMP4 : Triggering the encoder with source media: angel.mov.
    MKMP4 : Encoding: angel.mov
    MKMP4 : Resizing to: fit into 1024 pixels wide.
    MKMP4 : Total Bitrate: 600 kbps.
    MKMP4 : Video Bitrate: 552 kbps.
    MKMP4 : Audio Bitrate: 48 kbps.
    MKMP4 : Platform: Mac.
    MKMP4 : Starting video encoding pass 1…
    MEncoder dev-SVN-r27904-4.0.1 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz (Family: 6, Model: 15, Stepping: 6)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

    Option x264encopts: Unknown suboption brdo
    success: format: 0 data: 0×0 – 0x2bda462
    libavformat file format detected.
    [lavf] Video stream found, -vid 0
    [lavf] Audio stream found, -aid 1
    VIDEO: [avc1] 1280×544 24bpp 23.976 fps 0.0 kbps ( 0.0 kbyte/s)
    [V] filefmt:44 fourcc:0×31637661 size:1280×544 fps:23.976 ftime:=0.0417
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    Opening video filter: [scale w=1024 h=-3]
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    VDec: vo config request – 1280 x 544 (preferred colorspace: Planar YV12)
    VDec: using Planar I420 as output csp (no 1)
    Movie-Aspect is undefined – no prescaling applied.
    SwScaler: reducing / aligning filtersize 6 -> 8
    SwScaler: reducing / aligning filtersize 6 -> 8
    SwScaler: reducing / aligning filtersize 6 -> 5
    SwScaler: reducing / aligning filtersize 6 -> 5
    [swscaler @ 0x7fa2a0]BICUBIC scaler, from yuv420p to yuv420p using MMX2
    [swscaler @ 0x7fa2a0]using 8-tap MMX scaler for horizontal luminance scaling
    [swscaler @ 0x7fa2a0]using 8-tap MMX scaler for horizontal chrominance scaling
    [swscaler @ 0x7fa2a0]using n-tap MMX scaler for vertical scaling (YV12 like)
    [swscaler @ 0x7fa2a0]1280×544 -> 1024×436
    FATAL: Cannot initialize video driver.

    Exiting…

    Hi i’m using Mac Book Pro intel version with Leopard 10.5.5 and i get this msg. I searched the web and found nothing about this porblem (on os x at least), i have no problem working your script (by the way huge help thanks :)) on Ubuntu.

    Maybe you can help? or push me in the right direction so i can find a solution.

    by gumtez, November 12th, 2008 at 7:35 pm


  33. Hi Diego

    Thanks for the great info.

    I am trying to create .flv files for clipshare with h264 codec.

    Your script is great but at the end you get a .m2v file not a .flv file at the end.

    If you can give me some hints how your script could be modified to produce a .flv file with he h246 encoding inside then we could run flvtool2 on it to get the metadata injected.

    Please let me know about this, thank you very much.

    Madhu

    by Madhu, November 15th, 2008 at 5:56 pm


  34. Diego, thanks a lot for this script. You mentioned that you’re rewriting it to better fit little bugs and such, which is excellent. Any idea as to when that will happen?

    I also ran into a problem with audio sync problems. I converted a 40 minute long .flv file to mp4 (after removing brdo in both passes (kept having problems figuring out what video codec to use)) and the audio was progressively more and more out of sync. At the start of the video, the audio was slightly out of sync, and when progressing fairly deep into the video, the audio was very out of sync.

    Anyway, I’ll keep tinkering with mkmp4′s source and see if I can produce better results.

    Don

    by Don Wilson, December 2nd, 2008 at 4:00 am


  35. Diego, I’ve been looking for a scriptable he-aac codec and found your page, only to find the links to the nero codec broken. I’ve tried looking on their site and even calling to ask about the codec with mixed responses as to whether or not it’s still available (it doesn’t even seem to be available as part of nero linux 3.5). Do you know if it was removed for licensing reasons and/or if there is an alternative codec of similar quality? Thanks, John

    by John, December 2nd, 2008 at 4:41 pm


  36. John, regarding Nero’s linux codec, download this: http://www.nero.com/enu/downloads-nerodigital-nero-aac-codec.php and they’re inside /linux (in the .zip).

    by Don Wilson, December 2nd, 2008 at 8:15 pm


  37. Hi Diego – fantastic script.
    I’m struggling manually stepping down the framerate of a video [30fps > 24]

    Manually tweaked the MOVIE_FPS line – the video encodes correctly, but the audio is out of sync (runs in advance)

    Unsure where to narrow it down. Any pointers would be appreciated!

    Thanks kindly.

    by sn00k, December 7th, 2008 at 10:16 pm


  38. Have you been able to produce a Universal binary of gpac 0.4.5? I have all the prereq’s and I am running into roadblocks, still.

    by chuck, December 15th, 2008 at 7:49 pm


  39. I’m only getting audio output, and no mp4. I’m running the script (and all its dependent files) on a Centos 5 computer.

    In the middle of the mkmp4 output, I get:
    /usr/local/bin/mkmp4: line 162: midentify: command not found

    FATAL: Cannot initialize video driver.
    Exiting…

    Not sure if either of those will help y’all help me find the problem.

    Full output below. Any help would be greatly appreciated:

    ———————————————————

    MKMP4 : Triggering the encoder with source media: video_2571.mov.
    /usr/local/bin/mkmp4: line 162: midentify: command not found
    MKMP4 : Encoding: video_2571.mov
    MKMP4 : Resizing to: Movie is not being resized..
    MKMP4 : Total Bitrate: 512 kbps.
    MKMP4 : Video Bitrate: 464 kbps.
    MKMP4 : Audio Bitrate: 48 kbps.
    MKMP4 : Platform: Linux.
    MKMP4 : Starting video encoding pass 1…
    MEncoder dev-SVN-r28162-4.1.2 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Celeron(TM) CPU 1300MHz (Family: 6, Model: 11, Stepping: 1)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0
    Compiled for x86 CPU with extensions: MMX MMX2 SSE

    Option x264encopts: Unknown suboption brdo
    success: format: 0 data: 0×0 – 0x31ee56
    libavformat file format detected.
    [lavf] Audio stream found, -aid 0
    [lavf] Video stream found, -vid 1
    VIDEO: [avc1] 320×240 24bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    [V] filefmt:44 fourcc:0×31637661 size:320×240 fps:25.000 ftime:=0.0400
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    VDec: vo config request – 320 x 240 (preferred colorspace: Planar YV12)
    VDec: using Planar I420 as output csp (no 1)
    Movie-Aspect is undefined – no prescaling applied.
    FATAL: Cannot initialize video driver.

    Exiting…
    MKMP4 : Extracting Audio…
    MPlayer dev-SVN-r28162-4.1.2 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Celeron(TM) CPU 1300MHz (Family: 6, Model: 11, Stepping: 1)
    CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0
    Compiled for x86 CPU with extensions: MMX MMX2 SSE

    Playing video_2571.mov.
    libavformat file format detected.
    [lavf] Audio stream found, -aid 0
    [lavf] Video stream found, -vid 1
    VIDEO: [avc1] 320×240 24bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    ==========================================================================
    Forced video codec: dummy
    Cannot find codec matching selected -vo and video format 0×31637661.
    Read DOCS/HTML/en/codecs.html!
    ==========================================================================
    ==========================================================================
    Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
    FAAD: compressed input bitrate missing, assuming 128kbit/s!
    AUDIO: 32000 Hz, 2 ch, s16le, 128.0 kbit/12.50% (ratio: 16000->128000)
    Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio) decoder)
    ==========================================================================
    [AO PCM] File: /root/video_2571_temp.wav (WAVE)
    PCM: Samplerate: 48000Hz Channels: Stereo Format s16le
    [AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast
    [AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).
    AO: [pcm] 48000Hz 2ch s16le (2 bytes per sample)
    Video: no video
    Starting playback…
    A: 83.8 (01:23.8) of 83.8 (01:23.8) 3.9%

    Exiting… (End of file)
    *************************************************************
    * *
    * Nero AAC Encoder *
    * Copyright 2008 Nero AG *
    * All Rights Reserved Worldwide *
    * *
    * Package build date: Sep 17 2008 *
    * Package version: 1.3.3.0 *
    * *
    * See -help for a complete list of available parameters. *
    * *
    *************************************************************

    Processed 83 seconds…
    Cannot find H264 start code
    Error importing /root/video_2571_temp.264#video:fps=: BitStream Not Compliant
    IsoMedia import – track ID 1 – HE-AAC (SR 24000 – SBR-SR 48000 – 2 channels)
    Setting up iTunes/iPod file…
    Saving /root/video_2571.m4v: 0.500 secs Interleaving
    Setting up iTunes/iPod file…
    Saving /root/video_2571.m4v: 0.500 secs Interleaving
    MKMP4 : Removing temporary files…
    [root@trex ~]# cd /bin/
    [root@trex bin]# chmod +x midentify.sh
    chmod: cannot access `midentify.sh’: No such file or directory
    [root@trex bin]# cd /usr/bin
    [root@trex bin]# chmod +x midentify.sh
    [root@trex bin]# cd /usr/local/bin/
    [root@trex bin]# chmod +x midentify.sh
    [root@trex bin]# cd /root/
    [root@trex ~]# mkmp4 -f video_2571.mov -b 512
    Target directory set to: /root
    MKMP4 : Triggering the encoder with source media: video_2571.mov.
    /usr/local/bin/mkmp4: line 162: midentify: command not found
    MKMP4 : Encoding: video_2571.mov
    MKMP4 : Resizing to: Movie is not being resized..
    MKMP4 : Total Bitrate: 512 kbps.
    MKMP4 : Video Bitrate: 464 kbps.
    MKMP4 : Audio Bitrate: 48 kbps.
    MKMP4 : Platform: Linux.
    MKMP4 : Starting video encoding pass 1…
    MEncoder dev-SVN-r28162-4.1.2 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Celeron(TM) CPU 1300MHz (Family: 6, Model: 11, Stepping: 1)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0
    Compiled for x86 CPU with extensions: MMX MMX2 SSE

    Option x264encopts: Unknown suboption brdo
    success: format: 0 data: 0×0 – 0x31ee56
    libavformat file format detected.
    [lavf] Audio stream found, -aid 0
    [lavf] Video stream found, -vid 1
    VIDEO: [avc1] 320×240 24bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    [V] filefmt:44 fourcc:0×31637661 size:320×240 fps:25.000 ftime:=0.0400
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    VDec: vo config request – 320 x 240 (preferred colorspace: Planar YV12)
    VDec: using Planar I420 as output csp (no 1)
    Movie-Aspect is undefined – no prescaling applied.
    FATAL: Cannot initialize video driver.

    Exiting…
    MKMP4 : Extracting Audio…
    MPlayer dev-SVN-r28162-4.1.2 (C) 2000-2008 MPlayer Team
    CPU: Intel(R) Celeron(TM) CPU 1300MHz (Family: 6, Model: 11, Stepping: 1)
    CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0
    Compiled for x86 CPU with extensions: MMX MMX2 SSE

    Playing video_2571.mov.
    libavformat file format detected.
    [lavf] Audio stream found, -aid 0
    [lavf] Video stream found, -vid 1
    VIDEO: [avc1] 320×240 24bpp 25.000 fps 0.0 kbps ( 0.0 kbyte/s)
    ==========================================================================
    Forced video codec: dummy
    Cannot find codec matching selected -vo and video format 0×31637661.
    Read DOCS/HTML/en/codecs.html!
    ==========================================================================
    ==========================================================================
    Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
    FAAD: compressed input bitrate missing, assuming 128kbit/s!
    AUDIO: 32000 Hz, 2 ch, s16le, 128.0 kbit/12.50% (ratio: 16000->128000)
    Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio) decoder)
    ==========================================================================
    [AO PCM] File: /root/video_2571_temp.wav (WAVE)
    PCM: Samplerate: 48000Hz Channels: Stereo Format s16le
    [AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast
    [AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).
    AO: [pcm] 48000Hz 2ch s16le (2 bytes per sample)
    Video: no video
    Starting playback…
    A: 83.8 (01:23.8) of 83.8 (01:23.8) 3.8%

    Exiting… (End of file)
    *************************************************************
    * *
    * Nero AAC Encoder *
    * Copyright 2008 Nero AG *
    * All Rights Reserved Worldwide *
    * *
    * Package build date: Sep 17 2008 *
    * Package version: 1.3.3.0 *
    * *
    * See -help for a complete list of available parameters. *
    * *
    *************************************************************

    Processed 83 seconds…
    Cannot find H264 start code
    Error importing /root/video_2571_temp.264#video:fps=: BitStream Not Compliant
    IsoMedia import – track ID 1 – HE-AAC (SR 24000 – SBR-SR 48000 – 2 channels)
    Setting up iTunes/iPod file…
    Saving /root/video_2571.m4v: 0.500 secs Interleaving
    Setting up iTunes/iPod file…
    Saving /root/video_2571.m4v: 0.500 secs Interleaving
    MKMP4 : Removing temporary files…

    by Jacob Heller, December 18th, 2008 at 6:52 pm


  40. OK, I’m an idiot and I figured it out–I just had to take “brdo” out of the mencoder -x264encopts options. Works like a charm.

    by Jacob Heller, December 19th, 2008 at 10:32 pm


  41. Yah sorry about that, the brdo option has been deprecated in x264, i will update the scripts soon to reflect that :)

    by Diego Massanti, December 20th, 2008 at 7:24 am


  42. Also, don’t know if this one is obvious, but changing “midentify.sh” -> “midentify” (or, conversely, changing the script to look for “midentify.sh” instead of “midentify”) solved the problem that my mkmp4 wasn’t finding midentify…

    by Jacob Heller, December 21st, 2008 at 5:20 am


  43. I had trouble compiling MP4Box on MacOSX and this download is for Intel [1].
    But this one works for PPC [6|.

    [1] http://www.tkn.tu-berlin.de/research/evalvid/
    [2] http://penguintool.blogspot.com/2007/07/mencoder-x264-aac-mp4box-binaries-for.html

    by Erik, December 25th, 2008 at 7:39 pm


  44. Works fine on Mac 10.4.11 G4 PPC.

    The provided examples are playing in very good quality in the flash player (http://blog.massanti.com/apple-video-archive/iphone/), compared to the files I generated locally. My video files seem to stutter in the JW Player 4.2, whereas yours do not. I compared the resulting codecs and they are the same.

    I tried to copy your flash player settings or to use a MOV file as input source, but this did not work well.

    I am new to video conversion and do not much about Flash … is there something that I am oblivious about? Could it be a tweak in the flash player? Or do I have to further process the video files? Is it dependent on the/a quality of the input files?

    Thanks!

    by Erik, December 26th, 2008 at 10:41 pm


  45. Hi, for me work only if subq=1, but converted videos with pink mask.
    If subq>1 – black screen, only sound, x264 generate only 0kb .264 videos.
    can you please help?

    Debug:

    root@server [~]# gdb mencoder
    GNU gdb 6.8
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type “show copying”
    and “show warranty” for details.
    This GDB was configured as “i686-pc-linux-gnu”…
    (no debugging symbols found)
    (gdb) run test/test.avi -o test/test_temp.264 -passlogfile test/test_temp.log -ovc x264 -x264encopts bitrate=1600:frameref=8:bframes=0:b_adapt:b_pyramid:weight_b:partitions=all:me=umh:subq=5:trellis=2:brdo:threads=auto:analyse=all -of rawvideo -nosound -ofps 24.985 -vf scale=576:432,harddup
    Starting program: /usr/bin/mencoder test/test.avi -o test/test_temp.264 -passlogfile test/test_temp.log -ovc x264 -x264encopts bitrate=1600:frameref=8:bframes=0:b_adapt:b_pyramid:weight_b:partitions=all:me=umh:subq=5:trellis=2:brdo:threads=auto:analyse=all -of rawvideo -nosound -ofps 24.985 -vf scale=576:432,harddup
    (no debugging symbols found)
    (no debugging symbols found)
    [Thread debugging using libthread_db enabled]
    MEncoder 1.0rc1-4.1.2 (C) 2000-2006 MPlayer Team
    CPU: Intel(R) Core(TM)2 CPU E8400 @ 3.00GHz (Family: 6, Model: 23, Stepping: 10)
    CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    success: format: 0 data: 0×0 – 0x5be4c0
    AVI file format detected.
    AVI_NI: No audio stream found -> no sound.
    VIDEO: [XVID] 736×544 24bpp 24.985 fps 1449.6 kbps (177.0 kbyte/s)
    [V] filefmt:3 fourcc:0×44495658 size:736×544 fps:24.99 ftime:=0.0400
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    Opening video filter: [harddup]
    Opening video filter: [scale w=576 h=432]
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg’s libavcodec codec family
    Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
    ==========================================================================
    VDec: vo config request – 736 x 544 (preferred colorspace: Planar YV12)
    VDec: using Planar I420 as output csp (no 1)
    Movie-Aspect is 1.35:1 – prescaling to correct movie aspect.
    SwScaler: reducing / aligning filtersize 7 -> 8
    SwScaler: reducing / aligning filtersize 7 -> 8
    SwScaler: reducing / aligning filtersize 7 -> 5
    SwScaler: reducing / aligning filtersize 7 -> 5

    SwScaler: BICUBIC scaler, from yuv420p to yuv420p using MMX2
    SwScaler: using 8-tap MMX scaler for horizontal luminance scaling
    SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling
    SwScaler: using n-tap MMX scaler for vertical scaling (YV12 like)
    SwScaler: 736×544 -> 576×432
    x264 [info]: using SAR=73/72
    x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2 SSSE3
    [New Thread 0xb7f93a80 (LWP 30456)]Trem: 0min 0mb A-V:0.000 [0:0]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xb7f93a80 (LWP 30456)]
    0x06cd2c4e in x264_pixel_satd_8x8_ssse3 () from /usr/lib/libx264.so.55

    (gdb) bt
    #0 0x06cd2c4e in x264_pixel_satd_8x8_ssse3 () from /usr/lib/libx264.so.55
    #1 0x06c84d16 in x264_slicetype_mb_cost (h=0x9022d30, a=0xbfcdbdd8,
    frames=0xbfcde654, p0=0, p1=0, b=0, dist_scale_factor=128)
    at encoder/slicetype.c:207
    #2 0x06c8500a in x264_slicetype_frame_cost (h=0x9022d30, a=0xbfcdbdd8,
    frames=0xbfcde654, p0=0, p1=0, b=0, b_intra_penalty=0)
    at encoder/slicetype.c:305
    #3 0x06c86b0e in x264_rc_analyse_slice (h=0x9022d30)
    at encoder/slicetype.c:531
    #4 0x06ca655e in rate_estimate_qscale (h=0x9022d30)
    at encoder/ratecontrol.c:1293
    #5 0x06ca6fe9 in x264_ratecontrol_start (h=0x9022d30, i_force_qp=0)
    at encoder/ratecontrol.c:640
    #6 0x06cc0576 in x264_encoder_encode (h=0x9022d30, pp_nal=0xbfcde9a8,
    pi_nal=0xbfcde9a4, pic_in=0x8ed6c68, pic_out=0xbfcde968)
    at encoder/encoder.c:1411
    #7 0x080d4b81 in encode_frame ()
    #8 0x080d54ba in put_image ()
    #9 0x080e0c7f in decode_video ()
    #10 0x080a2a84 in main ()

    by today, January 3rd, 2009 at 4:06 pm


  46. Hi Diego, first of all I want to thank you for the great work! Most of the script works without problems, but there are a few points that you should change in your script:

    I’m using Debian Etch on a normal server for the encoding.

    1. I had to install YASM on linux too for x264.
    2. If you copy the midentify.sh script to /usr/local/bin, be sure to remove the “.sh”-ending
    3. The HE-AAC (aacPlus) audio encoder is a real problem. First of all, the link isn’t valid anymore. So I used the one Don Wilson posted – works, but unfortunatly you get the following error on Debian:

    /usr/local/bin/neroAacEnc: /lib/tls/i686/cmov/libc.so.6: version `GLIBC_2.4′ not found (required by /usr/local/bin/neroAacEnc)

    Do you know a good alternative or a working version for it? As of now, I’m using ffmpeg with libfaac, so I changed your script:

    encodeAAC()
    Replace the neroAacEnc line with the following:
    ffmpeg -y -i “$outdir/${iFile%.*}_temp.wav” -acodec libfaac -ar 48000 -ab 128k -pass 1 -threads 2 “$outdir/${iFile%.*}_temp.aac”

    mux()
    Replace the MP4Box line for linux with the following:
    MP4Box -add “$outdir/${iFile%.*}_temp.aac” -sbr “$outdir/${iFile%.*}.m4v”

    4. The “brdo” in the mencoder -x264encopts options is deprecated

    I have also a question:
    Is it possible to use variable bitrates (VBR) for the video options?

    by michaeljk, January 6th, 2009 at 8:22 pm


  47. I’ve been using your method, but each time I encode a new file the amount of streams included in the output goes up by 2. It’s adding the file that I’m currently encoding to every other file that I’ve encoded in the past, and when I open it up with VLC, I get all the streams from that one file playing at once in separate windows. Would you know how to fix this? Do the previous streams get cached somewhere?

    by ryan, January 14th, 2009 at 6:50 am


  48. I feel pretty dumb right about now. It’s because I was using the same file and it never overwrote the previous file before writing out the newly encoded streams. Nevermind about my last post!

    by ryan, January 14th, 2009 at 10:56 am


  49. When trying to compile gpac I get the following error: “command not found”
    Changed the os_net.c , typed “./configure” and I get the error.
    What’s wrong?

    by Mark, February 5th, 2009 at 10:39 am


  50. Hi Diego,
    Love your script. I’m trying to use it convert WMVs to X264, but I’m getting some rendering issues with the output video. The audio quality is perfect, but the video seems to skip right through. A 5 minute video ends video playback within 2 minutes. When encoding I get a “duplicate frames detected” notice. Have you any insight into why this might be happening?

    Thanks.

    by Ashwin, February 13th, 2009 at 7:30 am


  51. Hi diego ,

    your script was good and interesting of your work done. mean while I need some sugestion from you. I have separated the video and aac audio raw data into separately using MP4BOX, Those are fine , and one more thing I did is generated H264 raw video and read as nalu by nalu and written in MP4 standard with streamable format information. Now I have to same thing for audio. Can u suggest me how can i do this using Gpac utilty API’s without using commands.

    by kumar, May 22nd, 2009 at 2:18 am


  52. I’m currently working on your script doing some minor modifications. I will send you the result when done.

    by Gunstick, October 18th, 2009 at 2:14 pm


  53. Hey great, i was actually working on a totally new script, but you’re free to send me back your mods for this one and i will be happy to publish it here with proper credit.
    Thanks!

    by Diego Massanti, October 18th, 2009 at 6:17 pm


  54. Hi diego, thx for the great mod :)
    However I am having troubles compiling gpac on centos 5.3

    here is the message :

    compositor/events.c:239: warning: passing argument 3 of ‘gf_utf8_wcstombs’ from incompatible pointer type

    and finally at the end ..

    collect2: ld returned 1 exit status
    make[1]: *** [libgpac.so] Error 1
    make[1]: Leaving directory `/root/gpac/src’
    make: *** [lib] Error 2
    [root@lnx-svr gpac]#

    I am lost at what could be the problem on this one :S

    by Nicolas, October 27th, 2009 at 1:06 pm


  55. Hi Diego, thanks again, I am running a UGC Site with your script in bckground now for months :)

    recently I started adding hd capabilities, everything was downsized to 512 px width – now I generate a secon version wit 1280 px widht max.

    I have one strange problem, the only difference between the small and the big version are different width/height, as I set the bitrate for the big version to 4000 I get multiple audio & video streams in one file – any hint on this?

    Mediainfo output:
    http://pastebin.com/m68940276

    Thanks :)

    by Thomas, October 29th, 2009 at 1:49 am


  56. ok, figured it out.

    was using different debian versions locally and on the server which led to various problems with mplayer, MP4Box and the Nero-Encoder…

    by Thomas, October 31st, 2009 at 6:17 am


  57. 멤피스의 생각…

    Diego’s Rants » MKMP4: An automated H264 / HE-AAC (aacPlus) encoder script for Mac and Linux / Unix…

    by cychong's me2DAY, November 28th, 2009 at 2:46 am


  58. Just a hint to others, I always had problems with ugly / grey / unsharp thumbnails. Solution: i just replaced Diegos screenshot-command by the corresponding ffmpeg command and now the thumbnails look fine – always.

    by Thomas, December 8th, 2009 at 8:19 am


  59. @Thomas, care to write your command here so others can benefit from the fix too ? Cheers.
    Diego.

    by Diego Massanti, December 8th, 2009 at 3:53 pm


  60. i call this command with php passthru, because I generate it in a different part of the process.

    $mplayer_command =’ffmpeg -y -i ‘ . $filename . ‘ -f image2 -ss ‘. $duration .’ -s 512x’.$screenshot_height.’ -vframes 1 -an ‘ . $directory . ’00000001.jpg ‘;

    I guess you get the idea. The quality is really much better compared to mplayer…

    by Thomas, December 8th, 2009 at 5:58 pm


  61. Thank you :)
    I will try this and see if it is better. Im actually redoing mkmp4 from scratch, so maybe i will use your approach instead, i honestly wasn’t happy at all with the quality of thumbs.

    by Diego Massanti, December 8th, 2009 at 6:00 pm


  62. Hello there, simply became alert to your weblog thru Google, and located that it is truly informative. I’m going to be careful for brussels. I’ll be grateful for those who continue this in future. A lot of folks shall be benefited out of your writing. Cheers!

    by princeton corporate solutions, March 22nd, 2013 at 6:01 am


  63. I agree with the author that we need to share the knowledge we gain!

    by Betty Elmer, April 9th, 2013 at 11:58 pm


  64. My brother recommended I might like this website.
    He was once entirely right. This submit truly made my day.

    You can not imagine simply how a lot time I had spent for this info!

    Thank you!

    my site – Brianna

    by Brianna, April 19th, 2013 at 1:43 pm


  65. My brother recommended I might like this blog. He was totally right. This submit truly made my day. You cann’t imagine just how so much time I had spent for this information! Thanks!

    by Lifelong Learning Program - Újra Tanulok Program, April 29th, 2013 at 6:20 am


  66. Undeniably believe that which you stated. Your favorite justification appeared to be at the net the easiest thing to take note of. I say to you, I definitely get irked at the same time as folks consider worries that they plainly don’t realize about. You controlled to hit the nail upon the top as smartly as outlined out the entire thing with no need side-effects , other people can take a signal. Will likely be again to get more. Thank you

    by Top XXX Videos, July 26th, 2013 at 4:40 am


  67. Somebody necessarily assist to make severely posts I’d state. That is the first time I frequented your web page and to this point? I surprised with the analysis you made to create this actual put up extraordinary. Fantastic activity!

    by ebay, November 30th, 2013 at 12:40 pm


  68. I like the valuable info you provide to your articles.
    I will bookmark your weblog and test once more here regularly.
    I am quite certain I will be informed lots of new stuff
    proper right here! Best of luck for the following!

    by how to play piano without knowing how to play piano, April 11th, 2014 at 6:44 am


  69. This excellent website truly has all of the information I wanted about this subject and didn’t know who
    to ask.

    by Dusty, June 1st, 2014 at 11:42 pm


  70. Nice weblog here! Additionally your website rather a lot up fast!

    What host are you using? Can I am getting your affiliate link for your
    host? I wish my site loaded up as fast as yours
    lol

    Feel free to visit my website … foxbuzz

    by foxbuzz, August 13th, 2014 at 8:31 pm