Encoding high quality h.264 / aacPlus v2 media for web streaming with Flash 9, version 2.

Update Notice

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

It was some months ago when I wrote a tutorial about how to encode good quality h.264 video with aacPlus audio in order to use the great capabilities of the new flash player version 9.0.115 (that in case you missed it, now can play h264 video and aacPlus v2 audio).
Due to some personal convictions for my prior tutorial, i decided to use FFMPEG, and while it does the job pretty well, it has some limitations (specially in the video scaling / resizing area). So in my particular case, I had to use several php / bash scripts in order to feed the encoders with the proper resizing data, etcetera.
Well, let me introduce you to the 2nd version of my h.264 / aacPlus v2 tutorial.

This time I used Mencoder, an amazing tool that comes with the mPlayer package, and i also created what i think is a really nice bash script to make the process almost 100% smooth and simple.

These are the things you will need:

So let’s start. As usual, I wont dig a lot in the details about how to install or build software on linux / unix / mac, because you can find several tutorials about those matters by using google.

Building and installing the x264 encoder

In order to compile and install the x264 encoder, i recommend you to get the latest SVN version and build it yourself.
There are not any specific parameters at all for x264 other than the install path because the bash script that i will show you later assumes that you have all the tools in a directory that is inside your executable path.
So… get the latest sources for x264:
svn co svn://svn.videolan.org/x264/trunk x264
and then just run:
./configure --prefix=/usr
make install

After you have the x264 encoder installed, its time to get and build mPlayer.

Installing mPlayer and Mencoder

Again, get the latest sources for mPlayer:
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
and this is the configuration that you **should** use:
./configure --prefix=/usr

If you are on MacOS and you get errors when building, do this:
./configure --prefix=/usr --disable-encoder=flac --disable-encoder=cavs --disable-decoder=cavs
and then the usual…
make install

Very Important:

After you compile and install all the tools, you will find a directory called “TOOLS” inside the mplayer source tree, go inside it, and look for an small script called “midentify”, you MUST COPY this script to your /usr/bin directory or any other dir inside your executable path for the bash script to work. This is mandatory.

 The bash magic…

Ok, so after you have all the tools built, **AND** in your path, let me show you this simple script that i have written in order to make things really simple.

#! /bin/bash   

# This bash script has been created by Diego Massanti
# You are free and welcome to do whatever you want with it.
# www.massanti.com

cat < < EOF
usage: $0 -f  [-w ] -b  [-q][-k]

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

   	-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
   	-q 	Better quality encoding using 2 passes (slower) < OPTIONAL
 -k	Do not delete (keep) temporary files < OPTIONAL
if [ $uname == "Darwin" ]; then
 ## 99% of chances that this is a Mac


while getopts ":f:w:b:qkv" OPTION; do
  case $OPTION in
    w ) width=$OPTARG;;
 f ) filename=$OPTARG;;
    b ) bitrate=$OPTARG;;
    k ) deltemp=FALSE;;
 q )	quality=TRUE;;
    h ) usage;;
    \? ) usage
         exit 1;;
    * ) echo $usage
          exit 1;;

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

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

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

MOVIE_FPS=`midentify "$filename" | grep FPS | cut -d = -f 2`
echo "*    Encoding: $filename"
echo "*    Resizing to: $rsizemsg."
echo "*    Total Bitrate: $bitrate kbps."
let "caudiobitrate = $audiobitrate / 1000"
let "bitrate = $bitrate - $caudiobitrate"
echo "*    Video Bitrate: $bitrate kbps."
echo "*    Audio Bitrate: $caudiobitrate kbps."
echo "*    Platform: $platform."

# Encoding phase starts here...
# Encoding Video...
echo "* * * Starting video encoding pass 1... * * *"
mencoder "$filename" -o "${filename%.*}_temp.264" -passlogfile "${filename%.*}"_temp.log $rsize -ovc x264 -x264encopts bitrate=$bitrate: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

if [ "$quality" == "TRUE" ]; then
echo "* * * Starting video encoding pass 2... * * *"
mencoder "$filename" -o "${filename%.*}_temp.264" -passlogfile "${filename%.*}"_temp.log $rsize -ovc x264 -x264encopts bitrate=$bitrate: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

# Extracting audio to a 48khz WAV file.
echo "* * * Extracting Audio... * * *"
mplayer "$filename" -af resample=48000:0:2,volnorm=2:0.25 -ao pcm:file="${filename%.*}_temp.wav" -vc dummy -vo null

# Encoding Audio to HE-AAC plus file
echo "* * * Encoding Audio... * * *"

if [ "$platform" == "Mac" ]; then
enhAacPlusEnc "${filename%.*}_temp.wav" "${filename%.*}_temp.aac" $audiobitrate s
neroAacEnc -br 48000 -he -if ${filename%.*}_temp.wav -of ${filename%.*}_temp.mp4

# Muxing
echo "* * * Generating final MP4 container... * * *"

MP4Box -add "${filename%.*}_temp.264#video:fps=$MOVIE_FPS" "${filename%.*}.m4v"
if [ "$platform" == "Mac" ]; then
MP4Box -add "${filename%.*}_temp.aac" "${filename%.*}.m4v"
MP4Box -add "${filename%.*}_temp.mp4#audio" "${filename%.*}.m4v"

# MetaData and interleaving
album="Some Album"
author="Some Author"
comment="Some Comment"
MP4Box -inter 500 -itags album="$album":artist="$author":comment="$comment":created="$created":name="$name" -lang English "${filename%.*}".m4v

# Clean up temporary files...
if [ $deltemp == "TRUE" ]; then
 echo "* * * Removing temporary files... * * *"
 rm "${filename%.*}"_temp*

You can also download the mkmp4 shell script in order to keep proper tabulations and code formatting.

You should save the code here into a simple text file, give it any name you want (i call mine “mkmp4”) and dont forget to chmod +x it.
Usage is really simple:
The scripts expects 2 main parameters that are mandatory:

  • -f
  • -b

So for example, typing ./mkmp4 -f myvideo.avi -b 512 will create a H.264 video file, with aacPlus v2 audio inside an MP4 container with a total bitrate of 512kbps and using myvideo.avi as source.
The resulting file is ready for HTTP Streaming or FlashMedia Streaming Server 3, and of course, it will also play in any video player out there capable of H.264 and aacPlus v2 decoding.
The script also accepts some other optional parameters.

  • -q to use 2 pass encoding, slower, but better quality specially at low bitrates
  • -w to resize the output video, for example “-w 480” will resize the video to 480 pixels wide while keeping the correct aspect ratio.
  • -k to keep temporary files
  • -h to show inline help

The script will detect if you are running it on a Mac or on any kind of linux / unix variant, and use the proper audio encoder for each platform.
Also, in lines 133 to 136 in the script code, you will find some meta information variables that you can customize. That information is used by players like QuickTime, iTunes and many others in order to correctly organize the file inside a user’s media library.

Final considerations

This script can use as source, any video format supported by mPlayer, wich in other words means that almost any kind of video file can be transcoded by using this method.
If you are wondering what kind of quality / bitrate relation you will get by using this method, you are free to watch this 512kbps video stream (feel free to press the fullscreen button on the player :) )
When i released the first version of this tutorial 3 months ago, somebody asked how to get better quality for screencasts, and i guess the answer to that question would be something like: Framerate is not important at all, anything over 10FPS is useless for a screencast, by lowering the video framerate you get more quality at the same bandwidth, also, if you are doing a screencast, most probably you want your viewers to be able to “read” at texts, etc, so, a resolution of at least 640×480 is a must, and for bitrate, i think 512kbps with a two pass encoding process will be more than enough.

If you have any comment or suggestion you can leave a coment below. Thanks for reading !

78 Responses to “Encoding high quality h.264 / aacPlus v2 media for web streaming with Flash 9, version 2.”

  1. […] tutorial has been updated (and improved) a lot, for the new version please follow this link. UPDATE: I realized that when i read a tutorial about anything, in most cases, i want to first […]

    by Diego’s Rants » Creating good quality h264 video for the upcoming Flash Player and Flash Media Server, January 1st, 2008 at 10:23 pm

  2. uh, bad luck with compiling mplayer on mac OS X 10.5.1

    The ./configure step fails, saying:

    Unknown parameter: –enable-libx264

    Very strange, looks like a problem with the build system itself. After all I have been using successfully libx264 with the setup as described in the previous version of this tutorial. Anyone knows this issue and knows how to make it configure / compile ?

    by Roberto Saccon, January 6th, 2008 at 5:02 pm

  3. It looks like the latest MPlayer svn does a lot more autodetection, and only provides the –disable forms of most of these argument. In fact, the only flag that seems to work is –prefix. Weird.

    by Jeff Hodges, January 6th, 2008 at 10:16 pm

  4. Though now the damn thing blows up because it can’t find dts.h in /opt/local/include/ to build ad_libdca.c. Argh. Stupid MPlayer.

    by Jeff Hodges, January 6th, 2008 at 10:36 pm

  5. Hey Jeff and Roberto:
    This is certainly interesting…. it seems that the configuration script changed a lot in the latest SVN versions, so i have updated the configure commands on this page to reflect that.
    It looks that (as Jeff said) you can only “disable” codecs, but codecs are now flawlessly detected if they are on your system, so, as long as you have the x264 encoder installled, it should just work with the much smaller configure command that i just posted. Thanks for warning me about this :)

    by Diego Massanti, January 7th, 2008 at 6:30 am

  6. Thanks for the hints, got a microstep further, but now ./configure complains about:

    Error: Cannot find header either inttypes.h or bitypes.h. There is no chance for compilation to succeed.

    anybody knows how to fix this ?

    by Roberto Saccon, January 8th, 2008 at 2:06 pm

  7. Thanks a lot for the guide! I used it to cook up my own .bat file on a windows system (will do a more dynamic one using Ruby when I have time). One problem in your script though – you’re not using the $audiobitrate variable for non-mac users so the total bitrate will not be accurate.

    by David Backeus, January 8th, 2008 at 3:02 pm

  8. Hello Roberto, i remember that i used to have that same problem when trying to statically-link mplayer. Are you sure that you are not using the –enable-static switch ?
    If not, try adding –disable-static and see what happens. Hopes that helps. Also try to upgrade the Apple Developer tools (xCode) to the latest version (2.5 if you are on tiger, and 3.0 if you are on Leopard).

    by Diego Massanti, January 9th, 2008 at 3:23 am

  9. Diego, I have tried with –disable-static and I have latest XCode tools, without success. These type of error I had many years ago, compiling ffmpeg on windows, and there I just added myself a inttypes.h, but I don’t think this is the recommended solution here !

    by Roberto Saccon, January 9th, 2008 at 9:01 am

  10. Are you on a PowerPC or Intel Mac ?
    inttypes.h should be in /usr/include or /usr/local/includes, also in case you are using the LDFLAGS that i recommended, try compiling without them. Im still running Tiger btw (10.4.11).

    by Diego Massanti, January 9th, 2008 at 11:01 am

  11. thanks, without the LD flags it worked ! It is compiling now.

    by Roberto Saccon, January 9th, 2008 at 11:07 am

  12. Hey David, I’m glad that you found this tutorial usefull, and i will be interested to get a copy of your windows version if you finish it, and i will also be happy to post a link to it here for windows users.

    by Diego Massanti, January 9th, 2008 at 1:12 pm

  13. […] Diego’s Rants » Encoding high quality h.264 / aacPlus v2 media for web streaming with Flash 9, ve… […]

    by Lifestream for 01/09/08 : Alexander Grundner, January 10th, 2008 at 12:18 am

  14. Hi Diego. First of all, thank you very much, you saved me days of work. I have some issues though. Performance seems a bit slow to me with resolution 572×720 in fullscreen flash 9.0.0,115. Have you had similar issues? I have a rather strong machine, so I think it should perform much better. I am encoding with 700kbps bitrate. Thanks!

    by Armand, January 15th, 2008 at 10:30 am

  15. Be sure that both the width and height of your final movie are mod16 values (if you are not the mathematical type of person, that means that if you divide the number by 16, the mod must be 0), because that affects performance when encoding and when playing.
    Also, reducing the number of b-frames will reduce the processing power needed to decode the video stream without too noticeable difference in quality, so, in the script you could replace “bframes=3” with “bframes=0” for both video passes.
    If you are using the JW media player, look at the documentation for it, there are some variables that you can pass to the player in order to reduce the post-processing (like realtime denoising, smoothing and deblocking), that will improvie a lot the performance too.
    Hope it helps.

    by Diego Massanti, January 15th, 2008 at 2:44 pm

  16. how to run the script on a mac?

    by Pete, January 29th, 2008 at 7:56 pm

  17. I quote: “So for example, typing ./mkmp4 -f myvideo.avi -b 512 will create a H.264 video file…”

    by Diego Massanti, January 29th, 2008 at 11:13 pm

  18. terminal! i’ve got the error message “permission denied”
    what about all the other binaries? where to copy them?
    the aac-encoder, the gpac tools???

    by Pete, January 30th, 2008 at 3:31 am

  19. Hi again Pete, this tutorial assumes that you have some skills about building software from sources, etcetera.
    I will quote from my post again “and dont forget to chmod +x it.”, that means that before being able to use the script, you must give it execution rights: chmod +x thescript
    I recommend you to stop here anyway, most probably you will finish breaking your Mac.
    Do a google search about how to build and install software from sources on the Mac (or linux for that matter, it is almost the same), and then return to trying this again.

    by Diego Massanti, January 30th, 2008 at 3:38 am

  20. i understand some basics of compiling source codes for mac, so you describe it here too!
    my question is only where to put in the aac-encoder, you just tell me to compile mencoder and x264 – nothing else to put everywhere. mencoder is in /usr/bin and x264 in /usr/local/bin.
    my script is on my desktop and i put the aac-encoder in usr/bin + usr/local/bin already.

    question #1: is there any more detailed summary of where to put anything (maybe in rev. 3 of this tutorial)? cause i realy need to know how to get this work.

    thank you

    by pete, January 30th, 2008 at 6:14 am

  21. Ok, Pete, i will try to explain you, but really, you should try to read better.
    In the tutorial i clearly state that “all the tools must be in any dir in your executable path”.
    If you are on a Mac, those directories are usually /usr/bin and /usr/local/bin.

    So as long as you have the enhAacPlusEncoder, MP4Box, mencoder, mplayer and midentify in any of those dirs, you are ready to go.
    How to check that ?
    Just type the name of each of those tools in a simple terminal window, and if you get the program output instead of a “not found” error, then you’re ready to go.
    If you dont get the program output for any of the tools, you need to copy it.
    But if you issued the “make install” command for all the tools, they should be there already.
    Keep in mind that the “make install” NEEDS root privileges, so you should type “sudo make install” instead, and then your password when asked, that way, the tools will be automatically installed in the right places.
    The only tool that you need to copy manually, is my build of the aac encoder that im sure you downloaded from here, so, lets assume that you downloaded the executable to your desktop, you should issue a command like this:

    sudo cp /Users/yourusername/Desktop/enhAacPlusEnc /usr/local/bin
    and done.


    by Diego Massanti, January 30th, 2008 at 2:24 pm

  22. all right so far!
    the problem is i don’t get the gpac installed, wether sudo + chmod a.s.o.
    ./configure etc.
    it wont me do the installation!
    i don’t find anything on their website.

    by Pete, January 30th, 2008 at 6:02 pm

  23. hey diego.
    got it work!
    thank you for writing me.

    is there any way of doing this with multiple audio-tracks?

    by Pete, January 31st, 2008 at 5:04 pm

  24. Yes that is possible by doing the following: After you have the final m4v file created you can add as many audio tracks as you want like this:

    MP4Box -add youraudiotrack.aac thevideofile.m4v

    You can use the -add command on MP4Box not only for audio tracks, but also for video and subtitle tracks.

    by Diego Massanti, January 31st, 2008 at 5:08 pm

  25. many thanks diego.
    as far as i see the x264-code in your script puts out an high-profile stream, isn’t it?

    by Pete, January 31st, 2008 at 7:35 pm

  26. by quicktime, February 2nd, 2008 at 12:32 am

  27. I was about to delete this comment, but I’m going to take the time to answer.

    1) Quicktime blocks most of the exporting features unless you BUY the “pro” version, while all the tools in this tutorial are free and open source.

    2) Quicktime can not export aacPlus audio (and much less a high-profile AVC stream).

    3) The h264 encoder in Quicktime can not be compared to x264.

    4) Quicktime can not run on Linux.

    5) No matter what setting you try, or how many prayers you say, you will never EVER get with QuickTime the quality that you are going to get by using the tools described in this post, that is the reason because some tools like “Episode Pro” with a price tag of $999 exist.

    As a foot note, people that anonymously comments in a blog with a “LOL” and trying to look “smart” when they clearly have no idea about what is being said, should really be banned from the whole earth.

    by Diego Massanti, February 2nd, 2008 at 12:51 am

  28. diego thank you so much for the script and article. im going to use it with a rails/lighthttpd extreme setup. that was very helpful, you saved a lot and thanks a lot. secondly im absolutely agree with QT opinions. i’m trying any possible encoding solution to make a streaming h264 video. and qt sucks. it has serious limitations. imho ffmpeg or mencoder , they both make pretty quality videos.

    btw i’ve just installed mp4box (it’s in ports/multimedia/gpac-mp4box on freebsd boxes) and actually it is “mp4box” :) is it “MP4Box” on linux?

    by onur gunduz, February 2nd, 2008 at 4:05 pm

  29. Yah, i usually build from sources, and at least on Linux and MacOS, the binary is MP4Box :).

    I’m glad that this tutorial helped you in some way.

    by Diego Massanti, February 2nd, 2008 at 4:24 pm

  30. This is a great tutorial!, we have managed to get this up and running on debian sarge and it works great!

    My question is: For slower connections, do you just lower the bitrate? – is it that simple?

    by Simon, February 6th, 2008 at 5:58 pm

  31. All I can say is… its a beautiful thing! Just got it working and its.. well AMAZING! :) rock on! I’ve been scratching my head for the last week fighting with mencoder & ffmpeg and well THANKS A LOT!

    by Francis, February 8th, 2008 at 1:52 pm

  32. Amazing article Diego! After installing the tools mentioned on my Debian (testing) your script works out of the box. Thank you.

    by EpicSquirt, February 9th, 2008 at 2:02 pm

  33. Do you have xcode project for gpac?

    by MySchizoBuddy, February 10th, 2008 at 1:29 am

  34. Sweet guide! Helped me a lot.

    I had to rewrote the bash script in php for windows servers [only windows boxes here sadly].

    Was able to find a windows build of the tools listed up there, except for midentify. I’m using a php library for finding the frame rate right now, but it doesn’t work on all codecs.

    Still, major thanks for getting me on the right track with this guide!

    by micksam7, February 22nd, 2008 at 6:29 pm

  35. I have installed the latest version of mencoder and x264 on my linux machine but everytime I encode a file with mencoder/x264 it fails with a Segmentation fault.

    x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2
    Pos: 0.0s 2f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
    1 duplicate frame(s)!
    Segmentation faultf ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]

    I tested mencoder with the same input files and avi as output format… that works.
    Can somebody help me to get the x264 codec working? Did someone encounter the same problems?

    by Stefan, February 25th, 2008 at 7:10 pm

  36. […] Then I found this guide. […]

    by A Dolphin’s Journal of Events » Blog Archive » Flash Video Encoding - Capped, March 6th, 2008 at 2:29 am

  37. stefan,
    I also encounter same problem
    mencoder svn with x264 always crashes during first pass (segmantation fault)
    diego, can you assist?

    31 duplicate frame(s)!
    Pos: 0.0s 1f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
    32 duplicate frame(s)!
    Segmentation faultf ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]

    used command is
    mencoder video.wmv -o temp.264 -passlogfile dosya_temp.log -ovc x264 -x264encopts bitrate=400: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

    by Murat, March 9th, 2008 at 3:31 am

  38. I’ve removed 8×8dct option which was causing crash
    but now it fails in second pass
    telling me bitrate is too low (I chose 400, it asks for 605kbit minimum)
    first method (ffmpeg style) was much easier

    by Murat, March 9th, 2008 at 6:53 am

  39. Murat & Stefan: Update your GCC version, that problem usually happens if you are building with an old version of GCC.
    Use at least 4.1.3 (4.2 is better).

    by Diego Massanti, March 9th, 2008 at 8:31 am

  40. diego,

    MEncoder dev-SVN-r26203-4.2.3 (C) 2000-2008 MPlayer Team
    it still crashes
    it took 3 hours to compile gcc 4.2.3
    I compiled x264 and mplayer with gcc 4.2.3 twice, result is same.

    by Murat, March 9th, 2008 at 11:16 am

  41. I had an issue with the script where the audio seems to jump in volume level on many of our videos after approx 3 secs into the video. Found the solution just if anyone is interested: to change: volnorm=2:0.25 to volnorm=1:0.25. So it maximises the volume based on one sample rather than several. Which is a bit bizare… it starts sampling the audio for a couple of secs then changing the volume from that point rather than from the start. Anyway cool script!

    by Francis, March 19th, 2008 at 5:26 pm

  42. I used the script with no problems while logged in as root in my linux box. I get issues when trying to have php call the script. One of the major issues is that MP4Box will only add one track. Going by the order of code in the script it only puts out video, which is the first track. I verified that it is only putting out 1 track by making MP4Box add audio first then video with a result of only audio in the final m4v.

    I would appreciate any help given.

    by bryan, March 26th, 2008 at 9:04 pm

  43. Audio did not work, how to install this damn Neroaac under Linux ?

    by Ask, March 30th, 2008 at 9:18 am

  44. Hey, there is nothing to install, just copy the nero binary to /usr/bin or /usr/local/bin and you’re ready to go :)

    by Diego Massanti, March 30th, 2008 at 9:26 am

  45. Hi! Thanks for the script.

    I use it to compress my DVB rips, although in order to keep the correct aspect ratio I had to change the following line in your script.

    on line 80, instead of
    I use

    by laskoune, March 31st, 2008 at 2:28 pm

  46. Hey laskoune, thanks for the comment, and yes, i have noticed that be4, im planning to release an improved script really soon, and a better management of that was on my plans.

    by Diego Massanti, April 3rd, 2008 at 2:55 pm

  47. Diego,
    Any ideas why there isn’t any video?

    by John Giotta, April 3rd, 2008 at 4:03 pm

  48. there isn’t any video….. where ? how? when ?, would you care to formulate a proper question ? :p

    by Diego Massanti, April 3rd, 2008 at 4:18 pm

  49. I’ve installed everything, ran you shell script, but it produces a imageless video with only audio.

    I’m sure x264 or mencoder is at fault though.

    by John Giotta, April 3rd, 2008 at 5:19 pm

  50. Hey guys, having trouble with getting video. the script runs and outputs the mp4 file with audio but without any video. the mencoder reports “Forced video codec: dummy. Cannot find codec matching selected -vo and video format 0x32564D57” i’ve tried this on mpg, mov, wmn files.

    Any clues to how to resolve this?

    by Adrian, April 13th, 2008 at 9:15 am

  51. Hola! Glad to see an extensive explanation, finally! I’ve been reading on Flash and H.264 for days upon days, and I still cannot get the hang of it! Sad part is, my Mac broke (fell, long story), so now I have to use an XP box to do my work… I still have not found an explanation on how to create Flash-playable mp4s on XP. I use a program called SUPER by eRightSoft to convert from my screen-capture-AVIs (via Cam Studio) to mp4/H.264, but Flash either doesn’t play the files, or they appear garbled. I don’t even know whether it’s the app’s fault, or the codec (I believe it’s x264, but I am already completely confused with all that codec stuff!).

    IF anyone here knows of a nice blog, tutorial, etc. on creating mp4s for Flash on Windows – PLEASE, please, let me know!

    Gracias everyone! :)

    by Aoironeko, April 15th, 2008 at 6:35 am

  52. Worked fine for me untill the mp4box operation. It returns an error saying:

    Input file (466.535329) shorter than requested split start offset (314648735213803264100660537358820825393248519131983688773301404032495998624074190217531347691730689614434880748184274448685576739894580207978132813023861090025472.000000)

    This is interesting as we don’t ask mp4box to split anything at all.

    Any ideas?

    by reltnek, April 15th, 2008 at 9:59 pm

  53. interesting indeed, I wonder why that could happen…..
    I’m going to rebuild all my tools with latest svn versions to see of something has changed.

    by Diego Massanti, April 16th, 2008 at 2:30 am

  54. Hi Diego or shall I write Insphire.
    First of all this is totally off topic, but I could’nt find were to reach you. Do you remember a long time ago that I had a song of you, called Eternity on my website, you had placed a comment there. Now I’ll find you here :-) I want to let you know that I have buy your CD through iTunes, so I have made you happy :-)
    I hope that it not bother you that I’ve wrote this here to you. I have bookmarked this site, so I can read all of your posts.
    Have a great week.

    by Truus, April 16th, 2008 at 10:06 am

  55. […] streaming compatible with the new Adobe Flash Player, all this with FREE and open source tools.http://massanti.com/2008/01/01/encoding-h264-aacplus-with-mencoder-for-flash/MP3 Producer Bitrate Comparisons – winamp bit rate mp3 mpeg3After that is where the differences […]

    by bitrate, April 17th, 2008 at 10:33 am

  56. @ reltnet: Try getting the latest version of MP4Box from SVN, it solved some problems for me too, maybe thats the issue :p
    In any case, I will post an updated version of this script in the following days, so keep an eye on this blog for updates ;)
    Regards, Diego.

    by Diego Massanti, April 24th, 2008 at 9:52 pm

  57. thanks for the info and the mac Aac encoder. I got everything working except that mp4box won’t compile on my mac for some reason. It’s a real cryptic error and i haven’t found a resolution by searching the internet. Any chance you could email your binary to me? I’m on an intel mac book pro.

    by seth, May 2nd, 2008 at 5:14 pm

  58. @reltnek try running your line with a shorter output filename. It may help. I wish I could explain why.

    by Weird, May 9th, 2008 at 9:59 pm

  59. svn co svn://svn.videolan.org/x264/trunk x264

    returns a request for userid and password which I don’t have. Further exploration reveals that VideoLan prefers you to “git clone git://git.videolan.org/x264.git” to acquire x264 these days. I did so and ./configure && MAKE && SUDO MAKE INSTALL successfully.

    Next up is “svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer” which works equally as well. I’ve got your script, audio encoder and mplayer, mencoder, x264 ALL responding nicely at the bash. Yay me.

    Running your script informs me that “-x264encopts is not an MEncoder option”

    Saddest thing I ever saw. Thoughts? I’ve done an svn update in both x264 and mplayer with ./configure and MAKE and MAKE INSTALL’s but MEncoder doesn’t see to know what -x264encopts is.

    by bill, May 28th, 2008 at 8:23 pm

  60. Working. This seemed to do the trick. Now mencoder recognizing x264.

    $ cd x264
    $ ./configure –prefix=/opt/local –enable-pthread –enable-pic
    $ make
    $ sudo make install

    by bill, May 28th, 2008 at 9:02 pm

  61. Thank you Diego for sharing this nice script with us! I would have two questions, if you don’t mind:

    – About resizing (scale) option: Would you know a way to make the output file perfectly match given width and height? The video would have to be “zoomed” of course (like in a Pan & Scan mode) but we would not have black bars anymore.

    – Some input files can be interlaced (DV for example). In order to have a good output result, the file needs to be deinterlaced before scaling. Would you know a way to deinterlace a video if it is interlaced?

    by Arnaud, June 2nd, 2008 at 3:16 pm

  62. Hola Diego!! Despues de leer tu primer tutorial y ya tenerlo todo listo para codificar con ffmpeg, me he encontrado con este otro y me he decidido también a probar mencoder y ver los resultados de ambos. Enhorabuena por tus posts y tu script. Saludos desde España!!

    by Huge, June 6th, 2008 at 7:28 am

  63. Excellent job! Tnx!

    by Arthur, June 11th, 2008 at 12:02 am

  64. @Diego
    Thanks for the advice, the latest version of mp4box (v 0.4.4) seems to have fixed it. Look forward to the update… :)

    by reltnek, June 13th, 2008 at 1:06 am

  65. @Diego
    Thank you *so* much for taking the time to make this script and then letting others use it!

    I’ve been trying to get H264 encoding working for hours, let alone with HE-AAC.

    Just thought I’d tell you that all of the videos produced played the video faster than the audio and so gradually went badly out of sync and I tracked the issue down to the fact that your script calls midentify (which I didn’t have) to get the original video’s FPS and so mencoder was defaulting to 25 FPS (which was slightly faster than the ~23 FPS of the original).

    So I guess if anybody is having issues with out of sync output, make sure you have the midentify script ;)

    Thanks again: you’ve just saved me hours of researching and a truck load of space and bandwidth for videos on my server!

    by Michael, July 6th, 2008 at 9:43 am

  66. Is there a way this script can encode multiple files in a directory. I have a lot to convert.

    Thanks and great script!

    by George, July 18th, 2008 at 3:09 am

  67. Hi.
    I made everything through this tutorial and seems encoding fine.
    But my video length is getting longer. For example 206 second video gets 247 second.
    Audio is ok and finishes before video.

    Can you help?

    by bayasaa, July 24th, 2008 at 10:16 am

  68. @bayasaa: I don’t suppose you read my comment :|

    by Michael, July 27th, 2008 at 8:48 am

  69. I was wondering if anyone on this forum would be interested in developing an H.264/AAC video transcoder for a flash video sharing website. The transcoder would need to convert .avi, .mov/quicktime, mpeg, and .wmv uploaded files into .flv output. If you are interested in this project, please email me at deemarklit@gmail.com. Thank you

    by Dave, July 31st, 2008 at 2:41 pm

  70. Thanks to diego, I have mastered my encoding solution based on his tutorial and my own x264 quality / size settings.

    by Murat, August 2nd, 2008 at 10:40 am

  71. hi about flv files

    on the clipshare forums there is a mod based on this tuturial, all it seems to do is at the end of the conversion steps is @@@@@ rename(“$config[flvdodir]/” . $vid . “.m4v”, “$config[flvdodir]/” . $vid . “.flv”); @@@@@@@, it looks like its simply renaing the mv4 file to a flv file, just trying to rename the resulting file from the batch script to see what happens and if it still plays in a flv player correctly

    by wingchun22, September 12th, 2008 at 11:54 pm

  72. i’m having this extact same problem as adrian did

    mplayer reports “Forced video codec: dummy. Cannot find codec matching selected -vo and video format 0×32564D57″

    by Adrian

    by wingchun22, September 13th, 2008 at 1:39 am

  73. Quick question on GPAC utilities:

    What’s the best way to build these? They can have as many dependencies as you care to number and builds tend to be incomplete.

    I see you’ve only linked to their ill-documented (for Mac OS) site. Do you have any recommended build instructions (download, additional libraries, etc) for GPAC Utilities in Mac? Maybe edit this or complement it? GPAC utilities are an oddisey on their own.

    by eduo, September 24th, 2008 at 4:29 am

  74. Eduo (and everybody, for that matter) im about to release in the following days a MUCH BETTER script, with updated instructions, etc.
    Just wait some days :)

    by Diego Massanti, September 24th, 2008 at 5:11 am

  75. Sweet. Thanks for the prompt response. I’ve been hitting these issues a lot and finding this entry was like a godsend.

    I wanted to make myself a remuxer for a lot of specific cases where you need only to demux the streams and remux them in a different container and everything I found insisted on transcoding and recoding (even to the same original settings). I plan on doing MP4 video too and for that mp4box is the best option (especially for demuxing AVIs, damn rubbish container).

    I’m looking at including subtitle tracks as timed text and only mp4box and muxo can do that (and Muxo -for mac- has no command-line support).

    I’m subscribing to your RSS to make sure I don’t miss that follow-up script :)

    by eduo, September 24th, 2008 at 6:56 am

  76. By the way, I’m happy to have found your site. I’ve just been browsing around and must say I didn’t know aboud Media Info. I once made a program to do the exact same thing (in RealBasic, tho’).

    Very sweet. You’ve made my day.

    This may be documented elsewhere: What do you code your apps on? Cocoa? I’m in the office and can’t run them but that’s what it looks like.

    by eduo, September 24th, 2008 at 7:02 am

  77. eduo: yes, pure cocoa and Obj-C magic ;)

    by Diego Massanti, September 24th, 2008 at 8:05 pm

  78. H264 codec for youtube clone php script…

    Output file is MP4 H264 can be played into Flash Player or streamed through Adobe’s Flash conversion process can be integrated into php scripts MP4Box & Neo codecs. Infrenion supports Bitmoov on Shared / VPS and Hosting youtube youtube clone youtube …

    by kimom.com, February 18th, 2009 at 10:37 pm