Flash Video (FLV) Streaming With Nginx

Posted by Oleksiy Kovyrin under Uncategorized · русский

I was looking forward for this feature for last 3 months! And at last, it is there! Now, nginx works on our streaming servers perfectly and flv streaming will not be Lighttpd’s unique feature anymore. :-) This post is about how to use new Nginx module http_flv_module introduced in 0.4.7 (but there was a bug in its implementation, that can be fixed with my patch) and made completely perfect in 0.4.8.

First of all, to use new module, you should (re)complile nginx with –with-http_flv_module option:

# ./configure --with-http_flv_module ...SOME-OTHER-OPTS...

Next your action should be activation of flv streaming module for your flv files in nginx.conf:

1
2
3
4
5
6
7
8
9
10
11
12
...
http {
    ...
    server {
        ...
        location ~ \.flv$ {
            flv;
        }
        ...
    }
    ...
}

This option will instruct nginx to add special “header” information to data stream if user asked for some flv file and passed parameter “?start=XXX”, which means “give me that flv file from byte XXX to the end of file” (this is the idea of flv streaming).

Last your action, if it was not done before, should be conversion of your video files to FLV format and adding meta info to your created flv files. You can read how to do it in my previous post.

As always, I want to ask you, if you like this post, support it on Digg.com


Related posts:

  1. Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming
  2. Monitoring nginx Server Statistics With rrdtool
  3. Google Educational Seminars (techtalks) and Saving Google Video to Local Disk
  4. Nginx With PHP As FastCGI Howto
  5. Typical Configurations Overview For Nginx HTTP(S) Reverse Proxy/Web Server

26 Responses to this entry

Boo says:

Сделал все, как сказано в статье, но nginx выдает ошибку 404. В чем может быть проблема?

nginx/0.4.12

Zenny says:

Impressive article. But I could not make nginx work with php, ruby etc in my debian 3.1 VPS with debian etch as HN with OpenVZ.

I followed a tutorial at http://concentrationstudios.com/2006/8/26/nginx-and-rimuhosting-a-grand-ol-time but it does not behave like it is stated after executing the php-spin script in the article.

Debian certainly has nginx binary package in their repositories but I am not sure whether they support all the nginx modules and scripting languages.

Here I have noticed wonderful experts in nginx and lighttpd. I wish experts here (particularly Scondrel) could advise me how to proceed?

Thank you! Spaciva bolshoi!

lhotski says:

А как реализовать flv-стриминг в nginx вместе с его внутренним редиректом (X-Accel-Redirect)? $request_uri после редиректа уже не содержит первоначального параметра start..

Scoundrel says:

2lhotski: А что мешает передавать этот параметр в редиректе? Скрипт получает его через GET и отдает назад в редиректе вместе с именем файла.

lhotski says:

2Scoundrel: Насколько я понял, параметр для X-Accel-Redirect не парсится как URI, а воспринимается как путь к файлу, который приаттачивается еще к пути в root внутри location. и при отсутсвии файла “/path/some.flv?start=XXX” естественно выдает 404.
Может URI можно как то дополнительным заголовком сформировать? или я жестко туплю?

Kareem Kouddous says:

Is there any way to secure the streams so that users cannot download the flv directly?

vadimka says:

немогу сообразить обязательно указывать file.flv?&start=123
а если без этой переменной то должно отдать файл с 0 байта, правильно я понимаю?

Jeremy says:

Hello,
how can I do live streaming video with Nginx ? It is possible ?

allendale says:

нашёл небольшой баг в nginx, если flv-директива стоит после защиты от хотлинка, то стриминг нихрена не работает – отдаёт весь файл целиком, если же до хотлинка – то работает.
вот пример правильной конфигурации:
location ~ \.flv$ {
flv;
}
location ~ \.(jpg|jpeg|gif|mpg|mpeg|wmv|avi|flv)$ {
access_log off;
valid_referers none blocked server_names *.site.com/;
if ($invalid_referer) {
return 403;
}
}

steveking says:

YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune

Jordan says:

location ~ \.flv$ { – I had a problem with this line of code, it gave me and 404 error, but when removed the space before \.flv everything was ok

conxway says:

PSP Downloads at Ultra High Speed! Download Games for PSP and More! Download as much PSP content as you want to your computer and transfer it to your PSP device. It is easy, fast & fun! Personalize your PSP with themes, wallpapers, screensavers, and never buy a game again. Simply download everything for free! http://www.allfreepspdownloads.com

conxway says:

This website was a godsend, and has already saved me so much money; almost $400 dollars already! I, like most users, came here from a search engine a little weary; however, you guys really pulled through with me every step of the way http://allfreepspdownloads.com

Videos says:

Just wondering, what advantages are there for streaming videos using Nginx, I mean does it provide optional features, stress a server CPU and resources less, could be awesome for a video website to use.