Drupal FlashVideo Streaming with PHP and JW Player

Submitted by tomo on January 24, 2011 - 5:17pm

1. First get FlashVideo working for a content type so you can upload videos. This post doesn't cover getting FlashVideo working, so make sure you can upload videos first.

2. You need ffmpeg to convert anything not in flv format into flv. This is also a requirement for FlashVideo without streaming.

3. For streaming, you'll also need to process the flv to have metadata with keyframes to allow "scrubbing" (going to a time in the video that hasn't been downloaded yet). This can also be accomplished with flvmdi for Windows. Otherwise, you'll need to install flvtool2 (http://rubyforge.org/projects/flvtool2/) which is a Ruby package. Configure FlashVideo's universal settings for flvtool2 Path to point to it. It will be run with the "-U" option. This is different from flvmdi, so flvmdi is not really supported but you can run it manually when testing (remember to include "keyframes" object) to ensure your .flv file is in the proper format.

yamdi http://yamdi.sourceforge.net/ is another option although it also doesn't take "-U" as an arg, so you'd have to hack FlashVideo.

I've attached an example .flv that is in the proper format for testing.

4. xmoov-php can be downloaded from http://stream.xmoov.com/download/xmoov-php/ as an old version of "xmoovStream".

xmoov-php is a version of PHP streaming. What it does isn't very complicated and there are simpler versions like the attached stream.php. However, there is an expected interface between the Flash video player and the streaming PHP script. JW Player will pass "file" and "start" to the PHP script so xmoov-php needs to be hacked to change XMOOV_GET_POSITION from 'position' to 'start'. You'll also want to change XMOOV_PATH_ROOT to your Drupal root directory and XMOOV_PATH_FILES to the path from there to where you store your video files, probably 'sites/default/files/'. You could also leave XMOOV_PATH_ROOT blank and just set XMOOV_PATH_FILES to the full path containing the files, as the two constants are simply concatenated.

Test that xmoov-php is working by going to the path you setup in FlashVideo's content type settings for xmoov-php Server Configuration (make sure you enable streaming here and select xmoov-php for Streaming Method). Add "?file=somefileinyourfilesdir.flv&start=0" to xmoov.php and you should be downloading a video.

5. I got this working using JW Player, but there are other players that work with FlashVideo although these instructions may not work for streaming with them. The FV module assumes that the player takes a FlashVar of "streamer" which points to the URL of xmoov.php (note: in older versions of the player it was "streamscript").

Using DashPlayer or JW Player (FlowPlayer?):
Custom FlashVars remains "[email protected]"

XXX - I don't know how DashPlayer supports "streamer", it doesn't appear to.

Using player_flv_maxi from http://flv-player.net/:
Set Content Type's FlashVideo settings for Flash Player to:
Custom FlashVars: [email protected]

XXX - doesn't support "streamer" FlashVar, so I don't know how it would work with FlashVideo. It does have "phpstream" and "netconnection" so maybe you can set these manually in your custom FlashVars.

Now pop open a node with a video and inspect the embedded flash object. You should see some embed node with the "flashvars" attribute set something like:

flashvars="file=656-2178-legoshay_656.flv&image=656-2178-legoshay_656.jpg&rotatetime=3&autostart=false&streamer=/sites/all/modules/flashvideo/xmoov-php/xmoov.php"

The value for streamer won't work. The problem is that FlashVideo's streamer settings expect the path to the xmoov.php file on the local filesystem whereas JW Player expects "streamer" to be set to a URl and relative URLs won't work. So you'll need to hack flashvideo/plugins/flashvideo_streaming/flashvideo_streaming.module in function _flashvideo_streaming_admin_validate to append to the var for streamer.

You can just apply the attached patch flashvideo_streaming.patch to the flashvideo module's parent directory.

Now streaming and scrubbing should work. When you look in your web server's access logs you should see hits for your xmoov.php file with file and start set.

TODO: There's another way to stream without a full streaming server: mod_flv for Apache, which purportedly works with FlowPlayer (when you have the pseudostreaming plugin?) but not sure about JW Player - interface appears dissimilar.

Read the rest of this article...
© 2010-2014 Saigonist.