Create and Stream Video With Flash On The Buntu

The other day I was handed a quicktime mov file and told to put it on the company website. The catch was that the file was obscenely large, and we didn’t want the clients to have to download Quicktime or an equivalent to view it. It pretty much boiled down to “can you make it work like Youtube without actually uploading it there?”

Sure I can! I can do it faster than Lex Luthor can fucking steal the cakes. All 40 of them. I mean, this will be done in 4 easy steps – observe, and be amazed:

Step 1

First we need to get something that will convert the MOV format to the FLV format. There are several encoders out there that can do it, but the one that is both fast and free is FFMPEG. So let’s get it, shall we?

sudo aptitude install ffmpeg

Step 2

Let’s actually do the conversion. If you want to keep it simple (and I do) you don’t really have to do much beyond:

ffmpeg -i movie.flv

Now just sit back, and enjoy the blinkenlights till it finishes.

Step 3

Now we need something to play the movie. Sticking the FLV on the server just doesn’t cut it. We want Youtube like experience where people can pause the movie, skip ahead or rewind it back at will. Enter JW FLV Player.

Go to that website, download the zip, stick it in some web accessible directory along with the movie file, edit the HTML to take out all the useless examples, then point it to the correct FLV and you are done!

Step 4

This is the point at which you try to watch the movie and realize it has no fucking sound. Why? Because you are using Ubuntu – that’s why. Let me explain – ffmpeg usually needs to be compiled and linked with stuff like mp3 and AAC encoders. Unfortunately on Ubuntu (and debian for that matter) mp3lame and faac end up in different repositories based on their licensing terms. So the default Ubuntu ffmpeg package does not have these things included. This makes the package virtually useless for our purpose.

Good news is: there is a solution. Bad news is that you will need to roll your own copy of ffmpeg. Fortunately Paul Battley wrote a very good step by step guide on how to do it. I will replicate some of these steps here for the lazy part of the readers.

Step 4a

First let’s prepare and download all the build dependencies and tools you will need:

sudo apt-get build-dep ffmpeg
sudo aptitude install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev checkinstall fakeroot
apt-get source ffmpeg

Note that aptitude does not have build-dep or source parameters, so we use our good old apt. First line fetches build dependencies for ffmpeg (there may be quite a few of them). Second one installs the mp3 and aac libraries on your system, along side with checkinstall and fakeroot which we will use for building.

Step 4b

Now you will have a directory that starts with ffmpeg-0.cvs*. Cd into that directory. We will have to edit the debian rules file to include the mp3lame and faac in the build. Add the two following lines directly under all the other confflags entries:

confflags += --enable-mp3lame --enable-faad
confflags += --enable-faac --enable-xvid

Step 4c

Let’s fucking build this shit! But let’s do it the Ubuntu way. Screw Mrs. Configure and her two friends Mr. Make, and Mr. Make Install. We are using fakeroot!

fakeroot debian/rules binary
sudo checkinstall

Fakeroot may generate all kinds of funky warnings, but as long as you don’t run into any errors you should be just fine. You can safely just ignore the output and go grab some coffee.

When you do checkinstall change the version of your package to something bigger (ie increment the build number by 1 or something). Otherwise when you update your system, apt may want to replace your version with the current copy from the repository – and you don’t want that. Also change the name of the package to ffmpeg instead of whatever is there by default.

Once you are done, you should have a brand new ffmpeg on your system that will convert your MOV file to a FLV with sound.

So, go back to Step 2 and re-encode your video and re-embed it as in Step 3.

That’s it. Not entirely in 4 easy steps (thanks Ubuntu!) but close enough. The build process is really not that bad. And you only have to go through it once. Once you do it, you should be all set. Best part is that your newly built ffmpeg is a deb package. You can easily remove or upgrade it via apt or aptitude the way God intended.

[tags]ffmpeg, mp3lame, mov, flv, jw flv player, flash, flv movie, ubuntu, fakeroot[/tags]

This entry was posted in sysadmin notes and tagged , , . Bookmark the permalink.

2 Responses to Create and Stream Video With Flash On The Buntu


    Reply  |  Quote
  2. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says:

    3 things:

    1. xkcd FTW!!!
    2. I actually own that T-shirt
    3. this comment probably belongs in the geek joke thread ;)

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *