www.fridu.net

  • Increase font size
  • Default font size
  • Decrease font size

Linux MP4 Quicktime Streaming

Print

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

  • nice mencoder  source-video.mpg -o /dev/null -ss 32 -ovc x264 -x264encopts pass=1:turbo:bitrate=900:bframes=1:\me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -vf crop=720:352:0:62,scale=-10:-1,harddup -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 -ofps 24000/1001
  • nice mencoder source-video.mpg  -o encoded-video.avi -ss 32 -ovc x264 -x264encopts pass=2:turbo:bitrate=900:frameref=5:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -vf crop=720:352:0:62,scale=-10:-1,harddup -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 -ofps 24000/1001

 You have an H264/AAC video but inside an AVI container, unfortunately if mplayer can read it QuickTime cannot Frown



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.

  • nice mplayer -nolirc -nojoystick encoded-video.avi -dumpaudio -dumpfile encoded-audio.aac
  • nice mplayer -nolirc -nojoystick encoded-video.avi -dumpvideo -dumpfile encoded-video.h264
     Note: my mplayer finish its job by printing "Core dumped ;" as an OK status !!!

 Remux raw audio and video file into an MP4 container.

  • nice mp4creator -create=encoded-audio.aac   destination-video.mp4
  • nice mp4creator -create=encoded-video.h264 -rate=23.976 destination-video.mp4
     Note: Message "Error decoding sei message" for Video looks OK.

 Make our MP4 file playable before load completion

  • mp4creator -hint=1 destination-video.mp4
  • mp4creator -hint=2 destination-video.mp4
  • mp4creator -optimize destination-video.mp4
    Note: "MP4ERROR: MP4File::FindIntegerProperty: no such property" looks OK.

 Check result

  • mp4creator -list destination-video.mp4
Track   Type    Info
1       audio   MPEG-4 AAC LC, 61.312 secs, 71 kbps, 24000 Hz
2       video   H264 Main.5.1, 61.269 secs, 152 kbps, 320x176 @ 23.976236 fps
3       hint    Payload mpeg4-generic for track 1
4       hint    Payload H264 for track 2
    Warning: 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 Smile 

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

  • Get Source code from http://developer.apple.com/opensource/server/streaming/index.html 
  • tar -xzf DarwinStreamingSrvr5.5.5-Source.tar.gz
  • cd DarwinStreamingSrvr5.5.5-Source
  • ./Buildit install (Bug: MUST build binary distrib or install will fail)
  • tar -xzf DarwinStreamingSrvr5.5.5-Linux.tar.gz
  • cd ./DarwinStreamingSrvr5.5.5-Linux
  • ./Install (installation will ask for admin login+passwd)
  • echo "qtss:x:33:" >>/etc/group  ;# add qtss group as Install fail to make it
  • strip  /usr/local/sbin/DarwinStreamingServer  ;# move binary from 4M to 900K
  • /usr/local/sbin/streamingadminserver.pl

  1. Warning:  You MUST uncompress DarwinStreamingSrvr5.5.5-Linux.tar.gz that is generated by "./Builit" and "cd ./DarwinStreamingSrvr5.5.5-Linux" before using "./install" or installation script will fail to find streamingadminserver.pl 
  2. Check:     Your streaming server is now waiting for you http browser request on port 1220 Cool

 


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

  • scp destination-video.mp4 root@my-streaming-host:/usr/local/movies
  • vlc rtsp://my-streaming-host:554/fulup-streaming-intro-150kbit.mp4 

 I fail to stream video with mplayer and have to use vlc for my test, which prove I still miss somethingFrown

 

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:

  • replacing html:// by rtsp:// will work on M$ and Apple but not under Linux mPlayer,Xine,VLC plugin
  • replacing href with qtsrc will skip introduction src=image.jpg and will start the video automatically.
  • type='video/quicktime is very sensitive and look like the only type accepted by everyone

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:

 

  • A Link attached with a Javascript Popup to create the impression of an independant player[demo]
  • A full page with frame and a menu list that provide a fully integrated MP4/DivX vision [demo]

 

 

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).

 Image

  • Progressive
  • Direct stream
  • http://movies.fridu.org/quicktime/Fulup-Video-Test-150kbit.mp4
  • rtsp://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)
  • 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.

As soon as I will have some time I will place here the equivalent explanation for flash. 

Composing your Video 


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 

 

Add your comment

Your name:
Subject:
Comment: