A small Quick Start note to help Linux users to collect, encode and stream video in a MP4 Quiktime compliant format. While most of Linux articles explain how to move from DVD to a DIVX, this note explain how to:
- Encode a MP4 Quicktime compliant video stream
- How to Stream it
- How to Embed it into an HTML page.
Encoding MP4 Quicktime compliant Video.
You first need to acquire your video stream. In order to make test the easiest way is to mount an existing DCD and to copy one of the video VOB from the VIDEO_TS directory, if your stream is coming from a video camera of a TV setup box you probably get some MP2 files.
In my case video acquisition is very simple, I'm the lucky owner of a USB video camera that store my video directly in MP2 format, depending on your source video acquisition might be simple or complex, but what ever option you chose at some point you need to end up with a video source stream that is compliant with mplayer.
In order to encode we will use mencode, from mplayer's family tool, If your distribution does not include it "OpenSuSE does not" you need to install it. In order not to recompile everything from scratch I recommend you to get it from http://packman.links2linux.de binary package are available for Debian, Redhat, Fedora, SuSE and Ubuntu. If like me you're using OpenSuSE 10.2 the easiest way to solve all dependencies automatically is to add packman OpenSuSE repository into YaST. What ever is your distribution and chosen package repository before moving further you need:
- mplayer package (commands mplayer, mencoder)
- mpeg4ip package (command mp4creator)
- a video source in mpeg2 or any other mplayer compliant format.
Taking as an example the your source video is name "source-video.mpg" and that destination video will be name "destination-video.mp4" you need to:
- menencode (two pass) to move from what ever source encoding you have to x264 for Video and aac for Audio.
- mp4Create to love your result from an AVI container into an mp4 container compatible with Quicktime.
Mencoder is in two pass
You have an H264/AAC video but inside an AVI container, unfortunately if mplayer can read it QuickTime cannot |
We now need to extract Video and Audio from the AVI container to reinsert them into an MP4 container. We will user mplayer to extract video and audio stream into a raw format and them mp4creator to insert them into our final MP4 file. This operation is mandatory because mencoder cannot generate an mp4 container directly and mp4creator only accept raw audio and video stream container.
Extract Audio and Video into a raw file.
Remux raw audio and video file into an MP4 container.
Make our MP4 file playable before load completion
Check result
Track Type Info1 audio MPEG-4 AAC LC, 61.312 secs, 71 kbps, 24000 Hz2 video H264 Main.5.1, 61.269 secs, 152 kbps, 320x176 @ 23.976236 fps3 hint Payload mpeg4-generic for track 14 hint Payload H264 for track 2Warning: Audio must be "AAC LC" or Quicktime wont play it. You have now a file named "destination-video.mp4" that is compliant with QuickTime 7.x |
Streaming Server
I chose Apple Darwin Streaming server because it is easy to install and opensource. The only unpleasant thing is that you MUST register on Apple website before downloading it http://developer.apple.com/opensource/server/streaming/index.html
When you have the package use "./Buildit" and "./Install" scripts to compile and install. You obviously need a "gcc+make" plus typical development libraries, but nothing complex, in fact any Linux real person should have everything already on board. By default Apple server install into /usr/local and if everything when smoothly you should find your startup script into /usr/local/sbin/streamingadminserver.pl
DarwinStreamingSrvr Install
|
If everything went smoothly you have a working streaming server ready to stream your video. Note than server administration console is waiting on port TCP/1220, for basic streaming console is useless but if needed to not forget to open your firewall. Streaming by itself is on port UDP/554 and this port should be open to the public. Note that Apple Streaming server can be use to broadcast or proxy video in multicast mode, but for on demand streaming no further configuration is required.
Start Streaming you Video
I fail to stream video with mplayer and have to use vlc for my test, which prove I still miss something |
Embed final result into an HTML page
I must admit that I do not understand why we need something as complex as this, but following sample pages should work on Linux with mplayer and vlc plugin as well as on Windows for both Firefox and Explorer with Apple Quicktime 7.1 plugin. I recommend the second method using Apple JavaScript and expect for special usage I do not see any advantages to realtime streaming. Progressive download is easier to handle, do not require a dedicated streaming server (a dumb Apache will do the job), no special firewall config outside of the video to be store on local disk I only see advantages.
Do it yourself mode
| <html> <head> <title>Fulup Small test using Object for Windows ActiveX and Embed tag for Mozilla and Others</title><script ""src="http://www.apple.com/main/js/ac_quicktime.js" language="JavaScript" type="text/javascript"></script></head><body> <!-- Quicktime rtsp --><OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width="320" height="255" codebase='http://www.apple.com/qtactivex/qtplugin.cab'> rtsp://movies.fridu.org:554/quicktime/fulup-streaming-intro-150kbit.mp4"> width="320" height="255" ""src="http://movies.fridu.org/images/fulup-320x255.jpg" ""href="/rtsp://movies.fridu.org:554/quicktime/fulup-streaming-intro-150kbit.mp4" loop="false" type="video/quicktime" controller="true" autoplay="true" target="myself" pluginspage='http://www.apple.com/quicktime/download/'> <!-- end Quicktime rtsp --> <p> My Video using Quicktime/MP4 streaming <P> </body> </html> Note: RTSP as today fails to work on Linux browsers with any plugins I tried. |
Rely on Apple to generate those stupid Object/Embed tags, you can download Apple JavaScript sample from http://developer.apple.com/internet/ieembedfix.html
| <html> <head> <title>Fulup Small test using Apple JavaScript Library to genreate Object and Embed Tags</title><script src="http://www.apple.com/main/js/ac_quicktime.js" language="JavaScript" type="text/javascript"> </script></head><body> <!-- start Progressive Quicktime --> QT_WriteOBJECT_XHTML( 'http://movies.fridu.org/images/fulup-320x255.jpg', '320', '255','', 'href','http://movies.fridu.org/quicktime/fulup-streaming-intro-150kbit.mp4' , 'target','myself', 'type', 'video/quicktime', 'controller','true', "autostart","true");</script><!-- End Progressive Quicktime --><p> My Video using Quicktime/MP4 streaming <P> </body> </html> )Note:
|
Use a PHP script to build everything for you
Download PHP script from [here for MP4] [here for DIVX] rename it "something.php" in any PHP enable directory on your web server. Incude a link to where you want your video under in your web page under following form <a href=/MyScriptDirectory/fulup-mp4player.php?video=/dir/video.mp4&preview=/dir/preview.jpg&width=xxx&height=yyy> My Video</a> example:http://movies.fridu.org/scripts/fulup-mp4player.php?video=/quicktime/Fulup-Video-Test-150kbit.mp4&preview=/divx/Erwan-Test.jpg&width=520&height=288 Try it:
|
RTSP (Real Time Streaming Protocol) versus Progressive download
RTPS is using port 554 (don't forget your firewall) you can also stream on port 80 while this will help to handle client firewalls (that you do not control) it will nevertheless conflict with you normal web server. In fact outside of having a dedicated IP for your RTPS streaming server using port 80 for RTSP does not look like a good strategy.
The main advantage of RTSP is that not only you can display the video while receiving it, but furthermore you can jump forward on the video. If progressive download allows you to go backward (the video is cached on disk), going forward is impossible (video not received). The other tiny advantage of RTPS over progressive download is a better handling of Copyright, even if this argument is reduced by the fact that today every smart video player will propose a disk copy while streaming.
The main disadvantaged of RTSP is that you do not have a cache version of the video on disk, as a result you need a more stable download bandwidth. my experience shows that a basic ADSL connection (8Mbits download) will not allow you to go above 350kbits/s without taking the risk not to see you video to play as smooth as it should.
Conclusion: Outside of long video (conferences, training, ....) where having the option of moving forward/backward is important progressive download looks like a better option for most of non professional users, and If you want your video to display embeded inside a Linux browser it is the only working option.
Ready for a test
If you have Quicktime or compatible MP4/H264 plugin installed then following pages should play a video from my streaming server. I tested them on Windows-XP with both Firefox+Explorer, and under Linux using Firefox (I fail with Konqueror and did not try Opera). I had many trouble with VLC plugin that from time to time scratch my browser, mPlayer and xine plugin usually work. On my system OpenSuSE-10.2 progressive mode will run with both mPlayer and Xine plugins, VLC will miserably scratch and no plugin support realtime streaming (avoid to installed more than one quicktime plugin at a time, or you will never know which one is selected).
NOTE: since I wrote this article Flash pluging started to support H264 natively and is now avaliable for Linux,M$ and MacOS this makes MP4 the best option for video on web site. See the two samples 150/350Kbit using FLV player in next chapter.
If you click on the image, you will start a standard Quicktime/MP4 video. Unfortunatly this option prove to be unstable, and next option using a Flash player is from far my prefered choice.
Progressive download (using a Flash player)
Using FLV Player http://www.longtailvideo.com/players/jw-flv-player Flash player is now rendering perfectly MP4/H264 the main adantage is that is works on every single computer (MacOS, M$ & Linux)
- Hight 350Kbit/s StartVideo
- Medium150Kbits/s StartVideo
Direct stream
- http://movies.fridu.org/quicktime/Fulup-Video-Test-150kbit.mp4
- http://movies.fridu.org:554/quicktime/Fulup-Video-Test-350kbit.mp4
Some Ressources
- http://www.apple.com/trailers (Quicktime test page denies Linux mplayer/vlc plugin, nevertheless this movies demo page is working perfectly fine)
- http://allvideos.fritz-elfert.de/ (video plugin for Joomla allow mp4/h264 using a flash player)
- A small vob2mp4 script that does everything for you Download
Comparing with DivX
DivX is a very valid alternative to mp4, for windows and MacOS divxwebplayer is doing a wonderfull job, and on Linux mplayer firefox plugin rendering is very good. DivX like mp4/h264 support good quality video with small files, it also provides progressive download but no streaming. The only real limit for most people will be it limitted resising capability and video should be render to the exact target definition.
I wrote a small javascript to help provide browser embeded DivX under both Linux and Windows, you can check for a demo (here) and if interested download my javascript from (here). Note that I did not check MacOS and if anyone could make the test and provide back his result, please let me know.
Comparing with Flash
At least using mencoder flash video (.flv) are much bigger for a lower quality, nevertheless they are easier to distribute this because FlashPlugin is available on almost every platform when Apple only provide Quicktime for MacOS and Windows XP/Vista. Furthermore while flash is working with almost every single browser Quicktime tend to be more sensitive. My advice, if you have long and video where the image quality is important (ex: events) then use Quicktime, on the other hand if you have few motion and short video then use Flash.
Since Flash version 10, H264 and MP4 container are now perfectly supported within Flash Payer. Knowing that traditionnal FLV is quality is very poor my current advice is to encode in H264/MP4 and to levarage a flash reader to render the image as in provious sample. See here after a how to embed an mp4/h264 within jw-flv-player
<body>
<script type="text/javascript" src="/../scripts/swfobject.js"></script>
<div id="player">This text will be replaced</div>
<script type="text/javascript">
var so = new SWFObject('../scripts/player.swf','mpl','400','300','9');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addParam('flashvars','&author=Fulup Ar Foll&description=Fulup MP4&file=/download/video/mp4/Fulup-Video-Test-150kbit.mp4&autostart=true');
so.write('player');
</script>
<a href="/fulup-posts/32-ip-multimedia-ims/47-linux-mp4-quicktime-streaming> For further information</a>
</body>
Composing your Video
- kdenlive (the I use, simple and pretty) http://kdenlive.org/
- kino (very good for Firewire/1394 DV aquisition) http://www.kinodv.org
- mainactor (a very good Linux commercial product) http://www.mainconcept.com
Conclusion
Today for any major Linux distributions, It is possible to aquire, compose, encode, stream and display video with 100% free and open software, without having to recompile anything tools (a special reward to Packman). I nevertheless see two major area for improvement:
- Encoding: simplify command line options, I vote for a dump mode with only tree option (display-size, result-file-size, video/sound-quality-level) providing two on three should be enough. A smart encoding command should compute 3rd one automatically, don't you think so ?
- Plugin: Linix has 3 major plugin quicktime compatible (VLC, mPlayer and Xine). While I think VLC is the easiest standalone reader, mPlayer the best Swiss toolkit but some time froze Firefox, Xine looks like the best plugin for Video/MP4, faster than mPlayer and for what I've seen is very stable.
- Embeding inside HTML: I used Jommla for my personal web site. For a small FAQ Click Here
Références:
Everything you need is here





