Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming
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:
1 | /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')
to
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $ mencoder \\ orig_file.ext \\ -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 \\ -lavcopts vcodec=flv:keyint=50:vbitrate=300:mbd=2:mv0:trell:\\ 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.
Related posts:
- Flash Video (FLV) Streaming With Nginx
- Google Educational Seminars (techtalks) and Saving Google Video to Local Disk
- High-Performance Ruby On Rails Setups Test: mongrel vs lighttpd vs nginx
- Using X-Accel-Redirect in Nginx to Implement Controlled Downloads
- Unofficial Debian GNU/Linux Repositories Overview

69 Responses to this entry
2alex: Мы писали сами… Наш флеш-девелопер за день наколбасил хотя до этого ваще не видел флеш-фидео. Потому я уверен, что не сильно сложно. Хотя, может, есть и готовое.
Спасибо за пост. mplayer forever.
Достойной заменой может послужить Yamdi, делающая то же самое в контексте задачи и работающая в на порядки быстрее.
Но flvtool2 в силу свой чистой скриптовости имхо жутко тормозная штука и на больших роликах массовую конвертацию делает тяжким трудом
2lhotski: Wow! Great thanks really useful thing!
[...] If you don’t want to upload your video at Youtube[1] and if you don’t want to set up a streaming server[2] here are some instructions mainly from Netzspielwiese[3] First convert you video with Riva encoder[4] to Flash format, then install the Wordtube[5] plugin and insert some cryptic code in your blog and your video will look like this one. [...]
Здравствуйте! Спасибо за информацию! Есть вопрос – какая конфигурация сервера подойдёт для создания работоспособного сайта с видеоконтентом (на начальной стадии)?
Спасибо.
[...] If you don’t want to upload your video at Youtube[1] and if you don’t want to set up a streaming server[2] here are some instructions mainly from Netzspielwiese[3] for an alternative. [...]
[...] Использование lighttpd, Mplayer/Mencoder и Flvtool2 для реализации потоковой раздачи Flash Video [...]
[...] Использование lighttpd, Mplayer/Mencoder и Flvtool2 для реализации потоковой раздачи Flash Video [...]
[...] I started from this blog entry. But as I’m using ubuntu dapper, I have the nice debian apt tool [...]
[...] あと配信に関しては http://blog.kovyrin.net/2006/10/08/lighttpd-memcoder-flvtool-for-streaming/ http://blog.lighttpd.net/articles/2006/03/09/flv-streaming-with-lighttpd あたりはどうでしょう。 [...]
[...] Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming [...]
Hi, I have use the same mencoder command above listed and it works fine. But my video player is a bit big, and when I play the converted flv video, its pixelated,i.e the quality is not good.
What are the things I need to change to make it a size of 407×305 and quality will be better.
[...] read more | digg story Posted by seethepost Filed in news [...]
[...] to create your own video sharing service with flash video streaming using only open-source tools.read more | digg story [?] Share [...]
[...] to create your own video sharing service with flash video streaming using only open-source tools.read more | digg story Posted in Uncategorized | Leave a [...]
[...] Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming [...]
Есть проблема при конвертации mov (QuickTime) файла в flv. Вот такая команда.
mencoder input.mov -o output.flv -of lavf \
-oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc \
-lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 \
i_certify_that_my_video_stream_does_not_use_b_frames
С -nosound работает. То есть как я понял проблема с
аудио кодеком.
Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
AUDIO: 44100 Hz, 2 ch, s16le, 64.0 kbit/4.54% (ratio: 8000->176400)
Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio) decoder)
Но итоге получаю ошибку.
Cannot initialize muxer.
Exiting…
Кто-нибудь сталкивался с подобным?
You should probably use flvmeta (http://code.google.com/p/flvmeta/) instead of flvtool2.
It’s a small tool written in C that is much faster than flvtool2, which is written in ruby, and uses way too much memory.
[...] mi buscador me dice que mire en Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming y allí me indican sustituya en /opt/lib/site_ruby/1.8/flv/amf_string_buffer.rb la línea 163 [...]