I've used Tomcat and JWPlayer to create a web client to consume the flash video stream. FFMpeg also gets used at various points.
Streaming Video-on-Demand (VOD)
- Download Flazr from flazr.com, unzip into a folder and run server-start.bat.
- Download a binary distribution of Tomcat from tomcat.apache.org, unzip into a folder and run bin\startup.bat.
- Download JWPlayer from longtailvideo.com and unzip it.
- Within the Tomcat's webapps\ROOT directory create a folder called streaming, and copy jwplayer.js, player.swf and preview.jpg from the JWPlayer bundle into it.
- Copy a sample .flv file into the home\apps\vod folder. Call it video.flv or change the following HTML.
Example flv files are a bit hard to find so you may need to convert a .mp4 with FFMpeg. Try converting the video.mp4 file that came with JWPlayer:
ffmpeg -i video.mp4 -f flv video.flv - Create the following HTML file as webapps\ROOT\streaming\vodtest.html within the Tomcat directory. (See the JWPlayer setup wizard for other configuration options)
<html>
<head>
<script type='text/javascript' src='jwplayer.js'>
</script>
</head>
<body>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': 'player.swf',
'image': 'preview.jpg',
'file': 'video.flv',
'streamer': 'rtmp://localhost/vod',
'controlbar': 'over',
'duration': '34',
'fullscreen': 'true',
'stretching': 'fill',
'width': '470',
'height': '320'
});
</script>
</body>
</html>
- Now browse to http://localhost:8080/streaming/vodtest.html and click the play button.
Streaming a Live Video Stream
Here we use a client to stream a video to the Flazr server which it then relays to connected clients.- Create the following HTML file as webapps\ROOT\streaming\livetest.html within the Tomcat directory.
<html>
<head>
<script type='text/javascript' src='jwplayer.js'>
</script>
</head>
<body>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': 'player.swf',
'image': 'preview.jpg',
'file': 'mystream',
'streamer': 'rtmp://localhost/myapp',
'controlbar': 'none',
'autostart': 'true',
'width': '470',
'height': '320'
});
</script>
</body>
</html>
- Publish the FLV file as a stream to server using the Flazr client:
client.bat -live -host localhost -app myapp mystream video.flv You can send it multiple times:
client.bat -loop 100 -live -host localhost -app myapp mystream video.flv - Now browse to http://localhost:8080/streaming/livetest.html. You should see the stream playing.
You can use FFMpeg to do the same thing, and we need to use it in the next section:
ffmpeg -i video.flv -re -f flv rtmp://localhost/myapp/mystream
For more information see the FFMpeg Streaming Guide.
Streaming a Webcam
This re-uses the stream we set up above.- List the devices on your machine using FFMpeg to find the name of your webcam and microphone:
ffmpeg -f dshow -list_devices true -i dummy - List the options on your webcam device using its name - this will tell you what sizes and frame rates it supports:
ffmpeg -y -f dshow -list_options true -i video="<webcam-name>" - Stream your webcam using FFMpeg in the following way:
ffmpeg -y -loglevel warning -f dshow
-i video="<webcam-name>":audio="<mic-name>"
-r <frame-rate> -s <width>x<height> -threads 2
-f flv rtmp://localhost/myapp/mystream - Browse to http://localhost:8080/streaming/livetest.html and you should see your webcam output.
For me the capture command is:
ffmpeg -y -loglevel warning -f dshow -i
video="HP HD Webcam [Fixed]":audio="Integrated Microphone Array (ID"
-r 15 -s 320x240 -threads 2
-f flv rtmp://localhost/myapp/mystream
For more info see: FFMpeg Guide to Capturing Webcam Input.
Things to bear in mind
- Licenses -Flazr is LGPL. JWPlayer has a number of conditions attached to its commercial use. FFMpeg is mainly LGPL but some options are GPL.
- No security implications has been looked at. Without further work (firewalls etc) anyone could send and receive streams with your Flazr server.
No comments:
Post a Comment