# 基于ffmpeg的流媒体服务器

OS：ubuntu 12.04
ffmpeg:N-47141-g4063bb2
x264:0.133.2334 a3ac64b

## ffserver.conf配置

Port 8090  #访问端口
RTSPPort 554 #rtsp端口
MaxHTTPConnections 2000 #允许的最大连接数
MaxClients 1000 #最大的客户数
MaxBandwidth 10000
CustomLog -

<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 1G
ACL allow 127.0.0.1 #只允许本地连接
</Feed>

################ asf ################

<Stream test.asf>
Feed feed1.ffm
Format asf #流媒体格式
VideoCodec libx264 #编码格式
VideoFrameRate 25 #桢率
VideoSize 1024x768 #播放大小
VideoBitRate 2M #码率
VideoBufferSize 10000000
VideoGopSize 24
StartSendOnKey
Preroll 5
#使用x264编码时必须有下面的4个参数
VideoQMin 3
VideoQMax 31
NOAudio
</Stream>

################ flv ################

<Stream test.flv>

Feed feed1.ffm
Format flv

NoAudio
#AudioBitRate  32
#AudioChannels 2
#AudioSampleRate  44100
#AudioCodec libmp3lame

#NoVideo
VideoBitRate  1024
VideoFrameRate  40
VideoSize 1280x720
VideoBufferSize 1000000
VideoCodec libx264

VideoQMin 3
VideoQMax 31

VideoBitRateTolerance 100
VideoGopSize 12
StartSendOnKey

AVOptionVideo qmin 3
AVOptionVideo qmax 31
#AVOptionVideo quality good
#AVOptionVideo cpu-used 0
#AVOptionVideo keyint_min 25
#AVOptionVideo qcomp 0.6
AVOptionVideo qdiff 4
#AVOptionVideo me_range 16
#Preroll 15
</Stream>

################ rtsp ################

<Stream live.h264>
Format rtp
Feed feed1.ffm
VideoCodec libx264
#VideoFrameRate 7
VideoBitRate 300
#VideoSize 480x272
VideoSize 352x288
#AVPresetVideo default
AVPresetVideo superfast

PixelFormat yuv420p
AVOptionVideo me_range 4
AVOptionVideo qdiff 4
AVOptionVideo qmin 2
AVOptionVideo qmax 51

#MulticastPort 5000
#MulticastTTL 1

NoAudio
#AudioCodec libfaac
#AudioBitRate 32
#AudioChannels 2
#AudioSampleRate 22050
</Stream>

################ html ################

<Stream stat.html>
Format status
# Only allow local people to get the status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>

# Redirect index.html to the appropriate site
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>

## 启动ffserver服务器

ffserver -d -f ./ffserver.conf


## 使用ffmpeg对本地文件流化

./ffmpeg -i  ./1.mov -vcodec libx264  -qmin 3 -qmax 31 -qdiff 4 -me_range 16 -keyint_min 25 -qcomp 0.6 -b 9000K    http://localhost:8090/feed1.ffm


## 捕捉本地摄像头数据

./ffmpeg -f video4linux2 -i /dev/video0 http://localhost:8090/feed1.ffm


## 为流媒体增加声音

#NoAudio
AudioBitRate  128kb
AudioChannels 2
AudioSampleRate 44100



ffmpeg  -f v4l2 -i  /dev/video0  -f alsa  -i hw:0,0 http://localhost:8090/feed_tv.ffm


## 使用ffplay播放

./ffplay  mmsh://localhost:8090/test.asf
./ffplay  http://localhost:8090/test.flv
./ffplay  rtsp://localhost:554/live.h264


### 16 replies ›

1. My husband and i were really glad when Emmanuel managed to round up his reports through your ideas he made in your site. It is now and again perplexing to just continually be making a gift of facts that many other folks may have been selling. Therefore we consider we have got you to be grateful to for that. These illustrations you have made, the simple website menu, the relationships you can make it possible to instill – it is many astonishing, and it’s assisting our son in addition to our family consider that that subject is interesting, and that’s extraordinarily serious. Many thanks for all the pieces!

2. I precisely wanted to thank you very much all over again. I’m not certain the things that I could possibly have done without these creative concepts contributed by you about this subject matter. It has been the alarming setting in my position, nevertheless seeing your professional style you handled it took me to leap with gladness. Now i’m happier for the work and thus expect you know what an amazing job you’re providing instructing others with the aid of your web page. Probably you haven’t met all of us.

3. Thank you a lot for giving everyone an extraordinarily terrific possiblity to check tips from this web site. It really is very excellent and also packed with fun for me and my office fellow workers to search your blog at minimum three times in 7 days to find out the latest stuff you will have. And definitely, I’m so certainly contented for the surprising things you give. Certain 4 facts in this article are ultimately the simplest we have all ever had.

4. My spouse and i ended up being joyful when Emmanuel managed to finish off his analysis using the precious recommendations he was given through the web page. It is now and again perplexing just to continually be releasing key points which usually people may have been trying to sell. And now we already know we need the blog owner to appreciate for this. The illustrations you’ve made, the easy website navigation, the friendships you will give support to instill – it’s got many astonishing, and it is letting our son in addition to the family recognize that the theme is brilliant, which is certainly unbelievably serious. Thank you for the whole lot!

5. Hellow my name is Martingauri. Wery proper article! Thx 🙂

6. I would like to convey my gratitude for your kindness giving support to folks who should have help with that matter. Your real commitment to getting the solution around has been amazingly beneficial and have constantly enabled some individuals much like me to get to their ambitions. Your own warm and friendly tips and hints signifies so much a person like me and further more to my fellow workers. Best wishes; from each one of us.

7. Thank you so much for giving everyone an extremely superb chance to read in detail from this site. It’s usually so cool and also stuffed with amusement for me personally and my office co-workers to visit your blog on the least three times in one week to learn the latest tips you will have. And lastly, I am always astounded with all the cool knowledge served by you. Selected 1 ideas in this posting are really the very best we have all had.

8. I must point out my affection for your kind-heartedness for men and women who really need guidance on your theme. Your very own dedication to getting the message all-around has been exceptionally good and has regularly made folks just like me to get to their targets. Your personal warm and helpful help and advice indicates much a person like me and additionally to my office colleagues. Warm regards; from all of us.

9. I want to show my admiration for your kindness giving support to individuals who actually need help on in this study. Your very own dedication to passing the solution all-around ended up being especially informative and has specifically encouraged individuals like me to arrive at their desired goals. Your important information implies this much to me and extremely more to my office colleagues. Regards; from everyone of us.

10. I together with my pals were viewing the best key points found on your site and so then came up with an awful suspicion I had not expressed respect to the web site owner for those techniques. All the boys had been joyful to study all of them and now have in truth been tapping into them. I appreciate you for turning out to be really considerate and for picking this form of impressive resources most people are really desirous to learn about. Our sincere regret for not expressing appreciation to earlier.

11. I must voice my respect for your generosity giving support to folks that really want assistance with the study. Your personal commitment to passing the solution all over had been wonderfully informative and have specifically helped some individuals just like me to get to their endeavors. Your new invaluable guide entails this much to me and extremely more to my mates. With thanks; from everyone of us.

12. I have to express some appreciation to you for rescuing me from this type of situation. Because of searching through the internet and seeing notions which are not beneficial, I figured my entire life was well over. Existing without the strategies to the problems you’ve solved by way of your review is a serious case, and those which might have in a wrong way affected my entire career if I hadn’t encountered your web blog. That know-how and kindness in playing with all the pieces was invaluable. I don’t know what I would have done if I hadn’t encountered such a subject like this. I’m able to at this moment look ahead to my future. Thanks for your time so much for this high quality and result oriented guide. I will not be reluctant to suggest your blog post to any person who should get guidance about this topic.