- Posted in: Uncategorized
It will be really short post about using set of free tools to implement fully functional flash video streaming server. So, what we are going to get at the end of our setup? We are going to get some type of completely free streaming support that is available with Macromedia’s non-free Flash Communication Server (Flash Media Server) (FCS).
First our step as in any video streaming technology will be to prepare some videos for streaming by converting them to specific video format called “Flash Video” (flv) and adding some meta-information there to make stream rewind posible. There lots of small articles in Internet, that saying “just use ffmpeg tool and everything will be fine”, but I should say “no” to these articles authors. Ffmpeg sucks because it supports only small subset of input video formats and we don’t want to do any transcoding of original video to some video formats that ffmpeg can handle (it takes lots of resources, etc). So, my choice for video transcoding is really cool free software called mplayer, that has converting utility mencoder and can handle almost any original format and convert video file to flv format very quickly.
First of all you will need to get mplayer sources from mplayer we site and compile them. I will not describe how to do it because there are lots of articles about this process, but I want to get your attention to simple fact: Try to minimize set of disabled video codecs in compile time by installing all required libraries from your distribution repositories or from sources, because more codecs you will have, more videos you will be able to handle”.
When you’ve installed your mplayer/mencoder tools, you will need to install Ruby language interpreter to be able to run flvtool2 software. Please, ensure, that you have 1.8.4+ version of Ruby.
Next step is to install flvtool2 – tool, that allows us to inject meta-information to video files to make possible video stream rewinds in flash players. You can get it from its home page, but I would suggest you to install this software from SVN repository as described on its home page.
Small notice: current version of flvtool2 has really annoying bug, that prevents it from working with mencoder generated flv files. When you are trying to use it, you’ll get something like this:
/usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:163: [BUG] Segmentation fault
To solve this problem you can go to lib/flv/amf_string_buffer.rb file in flvtool2 source tree and change line 163 from
write [(time.to_i * 1000.0)].pack('G')
write [(time.to_f * 1000.0)].pack('G')
I want to say BIG THANKS to Dmytro Steflyuk for this fix.
So, as for now you are ready to convert your movies from any video format to flv. You can use following set of command to produce file for streaming:
$ mencoder \\
-ofps 25 \\
-o dest_file.flv \\
-of lavf \\
-oac mp3lame \\
-lameopts abr:br=64 \\
-srate 22050 \\
-ovc lavc \\
-lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \\
v4mv:cbp:last_pred=3 -vop scale=320:240
$ flvtool2 -UP dest_file.flv
This set of commands will convert orig_file.ext
file to dest_file.flv and will add meta flash information there.
Last thing you should do is to get Lighttpd web server from their site and install it. Then, enable flv-streaming module in its config and you’ll be able to use any flash player, that understands flash streaming idea to create your own Youtube and to get your our own billion of US dollars. And to thank author of this article, you can simply support it on digg.com.
Notice: Read my new article about flash streaming “Flash Video (FLV) Streaming with Nginx” to learn, how to implement streaming server with nginx.