首页 > ffmpeg, nginx, 媒体服务 > iphone 流媒体服务

iphone 流媒体服务

2011年4月20日 eric 发表评论 阅读评论

iPhone HTTP Streaming with FFMpeg and an Open Source Segmenter

由于项目需要,需要搭建一个手机流媒体服务器,之前有做过流媒体服务器,不过都是PC客户端的•首选的是 flash media server。但是这次客户端是手机,手机客户端的种类很多,Nokia,iphone, android,他们没有一个支持 rtmp协议的而且支持的格式也很少,后来查询google,得知 android 支持rtsp,又是一路的 google 后来锁定在 live555 和 feng stream server,经过试验•用VLC 播放是可以的,在android上rtsp播放就是个废物不给力,也许是我研究的不够透彻,也在网上看其他网站的手机视频,时光网直接给的是http协议mp4•没有做任何处理•这样有一个弊端就是客户端与服务端建立连接一直下载视频,占用服务器带宽和资源,好处是解决各个手机客户端的不兼容问题。就在准备直接使用http 协议播放mp4的时候,有同事提到视频切片,就在google 上搜索,搜索到 一篇老外的文章,通过ffmpeg把视频转码,转成TS流文件,而后通过开源的 segmenter 把流文件切割成几个TS流文件,生成一个播放列表维护切成的散文件。经过试验,效果不错•该作者的 ffmpeg 参数是专门真多 iphone做了优化•在vlc上播放的效果远不如iphone上的效果~下面我把我安装过程与遇到的一些小问题都记录下来•

1. 我只需要支持 mp4所以我编译ffmpeg 只需要添加几个库•如果你需要支持的视频格式多请参考

http://www.nginxs.com/linux/57.html
wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
wget http://www.tortall.net/projects/yasm/releases/yasm-1.1.0.tar.gz
svn checkout http://svn.assembla.com/svn/legend/segmenter/ segmenter
git clone git://git.videolan.org/x264.git

2,安装 ffmpeg需要的库文件

tar jvf faac-1.28.tar.bz2
cd faac-1.28
./configure
make
make install
tar jxvf faad2-2.7.tar.bz2
cd faad2-2.7
./configure
make
make install
tar zxvf yasm-1.1.0.tar.gz
cd yasm-1.1.0
./configure
make
make install
tar zxvf lame-3.98.4.tar.gz
cd lame-3.98.4
./configure --enable-nasm
make
make install
cd x264
./configure
make
make install

3.安装 ffmpeg 和 segmenter

cd ffmpeg-0.5.4
make clean
./configure --enable-gpl --enable-nonfree --enable-pthreads --disable-ffplay --disable-ffserver  --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264
make
make install
cd segmenter
gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac -lmp3lame -lx264 –lfaad

如果你遇到与我一样的错误:

/usr/local/lib/libavcodec.a(pthread.o): In function `avcodec_thread_free':
/home/finney/ffmpeg/libavcodec/pthread.c:95: undefined reference to `pthread_join'
/usr/local/lib/libavcodec.a(pthread.o): In function `avcodec_thread_init':
/home/finney/ffmpeg/libavcodec/pthread.c:159: undefined reference to `pthread_create'
/usr/local/lib/libx264.a(encoder.o): In function `x264_encoder_close':
encoder.c:(.text+0x23ee): undefined reference to `pthread_join'
/usr/local/lib/libx264.a(encoder.o): In function `x264_encoder_frame_end':
encoder.c:(.text+0x34ec): undefined reference to `pthread_join'
/usr/local/lib/libx264.a(encoder.o): In function `x264_encoder_encode':
encoder.c:(.text+0×7053): undefined reference to `pthread_create'
collect2: ld Return 1

请用下面参数编译:

gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac -lmp3lame -lx264 –lfaad -lpthread
mv segmenter /usr/bin/

4.创建转码脚本我就贴老外的参数了,如果大家对参数意思有兴趣我会写下篇我文章解释参数含义:

cat convert.sh
#!/bin/sh
BR=800k

ffmpeg -i $1 -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 320*240 -vcodec libx264 -b $BR -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 96k -maxrate $BR -bufsize $BR -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 31 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 1 sample_$BR_pre.ts

segmenter sample_$BR_pre.ts 30 sample_$BR stream-$BR.m3u8 http://192.168.1.28/

rm -f sample_$BR_pre.ts

# $1 是input的 要转码的视频 也就是 mp4文件
# sample_$BR_pre.ts 是生成的 TS 流文件
# sample_800k-【1…10】.ts 被 segmenter 切片的TS 流文件
# stream-800k.m3u8 是 segmenter切片的维护列表•我也就就给nginx 或者apache 这个url
# http://192.168.1.28/ 是 你的 nginx 或者 apache nameserver
# 最后客户端访问的 url地址是 http://192.168.1.28/stream-800k.m3u8

5. 修改 nginx 或 apache 配置,支持 TS 和 m3u8
Nginx 修改:

Vim /usr/local/nginx/conf/mime.types

#最后添加

application/x-mpegURL                 m3u8;
video/MP2T                                       ts;

apache 修改:
centos :

vim /etc/httpd/conf/httpd.conf
AddType application/x-mpegURL .m3u8
AddType video/MP2T .ts

Ubuntu:

vim /etc/apache2/mods-enabled/mime.conf
AddType application/x-mpegURL .m3u8
AddType video/MP2T .ts

6.转码测试。
在 apache 的根目录 执行脚本

./convert.sh 3333.mp4

# 有的媒体文件可能会提示:

[aac @ 0x8a17960]SBR not implemented. Update your FFmpeg version to the newest one from SVN. If the problem still occurs, it means that your file has a feature which has not been implemented.

他会提示更新,不是致命错误,不会有影响不需要去理会。

ls
3333.mp4  convert.sh  sample_.ts  sample_800k-1.ts  sample_800k-2.ts  sample_800k-3.ts  sample_800k-4.ts  stream-800k.m3u8

7.在iphone 模拟器播放器访问 http://192.168.1.28/stream-96k.m3u8
或者用vlc 播放器

由于截图 截视频会黑屏,所以没办法看到图像,但是我用红字标出了我播放的流是sample_800k-2.ts

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/459.html

  1. 2017年10月25日03:29 | #1

    Your method of describing all in this piece of writing is really good, all can simply
    be aware of it, Thanks a lot.

  2. 2017年10月25日03:35 | #2

    Hello, its nice piece of writing concerning media print, we all be familiar with media is a enormous source
    of information.

  3. 2017年10月25日08:13 | #3

    Someone necessarily lend a hand to make seriously posts I’d state.
    This is the very first time I frequented your website page and to this point?
    I surprised with the research you made to create this actual
    put up extraordinary. Great process!

  4. 2017年10月25日09:00 | #4

    I like it when people come together and share views.
    Great website, stick with it!

  5. 2017年10月25日16:44 | #5

    I have to thank you for the efforts you have put in penning this
    website. I’m hoping to see the same high-grade
    blog posts from you in the future as well. In truth, your creative writing abilities
    has inspired me to get my own, personal blog now ;)

  6. 2017年10月27日18:58 | #6

    Excellent pieces. Keep posting such kind of information on your blog.
    Im really impressed by your blog.
    Hello there, You’ve done an excellent job. I will certainly digg it and individually suggest to my friends.
    I am sure they will be benefited from this website.

  7. 2017年10月27日22:34 | #7

    Hello colleagues, its impressive piece of writing concerning educationand fully defined,
    keep it up all the time.

  8. 2017年10月27日22:37 | #8

    I really like your blog.. very nice colors & theme. Did you design this website
    yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to construct my own blog and would like to know where u got this from.
    cheers

  9. 2017年10月29日05:17 | #9

    Good response in return of this issue with firm arguments and explaining
    everything regarding that.

  10. 2017年10月31日12:07 | #10

    An impressive share! I have just forwarded this onto a coworker who has
    been doing a little homework on this. And he actually ordered me dinner
    because I discovered it for him… lol. So allow me to reword this….
    Thank YOU for the meal!! But yeah, thanx for spending
    the time to discuss this subject here on your web page.

  11. 2017年10月31日16:04 | #11

    Hi there to all, how is the whole thing, I think
    every one is getting more from this site, and your views are pleasant designed for new visitors.

  12. 2017年11月3日18:43 | #12

    Hmm it appears like your site ate my first comment (it was super long) so I
    guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your
    blog. I too am an aspiring blog blogger but I’m still new
    to the whole thing. Do you have any tips for novice blog writers?
    I’d really appreciate it.

  13. 2017年11月8日12:27 | #13

    I am now not sure the place you’re getting your info, but great topic.
    I must spend a while studying much more or understanding
    more. Thank you for fantastic information I was searching for this information for my mission.

  14. 2017年11月10日07:18 | #14

    Hi, i think that i saw you visited my site so i came to “return the favor”.I’m trying to
    find things to enhance my website!I suppose its ok to use some of your ideas!!

  15. 2017年11月10日16:36 | #15

    I’m really enjoying the theme/design of your weblog.
    Do you ever run into any web browser compatibility problems?
    A few of my blog audience have complained
    about my site not operating correctly in Explorer but looks
    great in Chrome. Do you have any solutions to help fix this issue?

  16. 2017年11月11日15:19 | #16

    Right away I am ready to do my breakfast, afterward
    having my breakfast coming again to read more news.

  17. 2017年11月11日23:58 | #17

    I know this if off topic but I’m looking into starting my
    own weblog and was curious what all is required to get
    setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% sure. Any recommendations
    or advice would be greatly appreciated. Thank you

  18. 2017年11月12日04:39 | #18

    Hi, yeah this paragraph is genuinely fastidious and I have learned lot of things from
    it concerning blogging. thanks.

  19. 2017年11月12日09:21 | #19

    certainly like your web-site but you need to test the spelling on several of your posts.
    Many of them are rife with spelling issues and I find it very troublesome to
    tell the truth on the other hand I’ll certainly come back again.

  20. 2017年11月12日23:17 | #20

    Definitely imagine that that you stated. Your favourite reason seemed
    to be on the net the easiest thing to bear in mind of. I say to you,
    I definitely get irked while people consider worries that they plainly do not know
    about. You controlled to hit the nail upon the highest and also defined out
    the entire thing with no need side-effects , other people could take a signal.
    Will probably be back to get more. Thank you

  21. 2017年11月13日13:35 | #21

    After exploring a handful of the articles on your website, I truly like your technique of writing a blog.
    I bookmarked it to my bookmark site list and will be checking back soon. Please check
    out my web site too and let me know how you feel.

  22. 2017年11月13日20:02 | #22

    May I just say what a relief to uncover an individual who actually understands what they’re discussing online.
    You definitely know how to bring an issue to light and
    make it important. More people must check this out and understand this side of
    your story. I was surprised that you aren’t more popular because
    you certainly possess the gift.

  23. 2017年11月13日23:47 | #23

    Please let me know if you’re looking for a writer for your site.
    You have some really great posts and I think I would be a good asset.
    If you ever want to take some of the load off, I’d absolutely love to write some content
    for your blog in exchange for a link back to mine. Please shoot me an email if interested.
    Cheers!

  24. 2017年11月15日02:24 | #24

    Every weekend i used to visit this website, as i want enjoyment, as this
    this website conations genuinely nice funny stuff too.

  25. 2017年11月15日09:42 | #25

    If you want to get a great deal from this piece of writing then you
    have to apply these methods to your won web site.

  26. 2017年11月15日19:09 | #26

    Do you have these people could be more plug
    to your home?

  27. 2017年11月16日09:20 | #27

    Are you gonna be occupied with all your family members?

  28. 2017年11月18日09:03 | #28

    It’s appropriate time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I wish to suggest you few interesting things or advice.

    Maybe you could write next articles referring to this article.
    I want to read more things about it!

  29. 2017年11月20日20:57 | #29

    Hello! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading your blog and look forward
    to all your posts! Carry on the outstanding work!

  30. 2017年11月21日19:06 | #30

    Hey! I realize this is kind of off-topic however I had to ask.
    Does operating a well-established blog like yours take a
    lot of work? I’m brand new to running a blog but I do write in my
    diary every day. I’d like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any kind of recommendations or tips for brand
    new aspiring blog owners. Thankyou!

  31. 2017年11月23日23:12 | #31

    I have learn some good stuff here. Certainly price bookmarking for revisiting.

    I surprise how so much effort you place to create any such wonderful informative
    web site.

  32. 2017年11月26日07:17 | #32

    Hi to all, how is the whole thing, I think every one is getting more from this site,
    and your views are nice in support of new visitors.

  33. 2017年11月27日09:48 | #33

    Great post. I used to be checking constantly this blog and I am inspired!
    Very helpful information specifically the last phase :)
    I care for such info a lot. I was looking for this certain info for a long time.
    Thanks and good luck.

  34. 2017年12月3日21:13 | #34

    Hi to all, it’s actually a fastidious for me to visit this site, it includes precious Information.

  35. 2017年12月15日08:29 | #35

    Hi there are using WordPress for your site
    platform? I’m new to the blog world but I’m trying to get started and
    create my own. Do you need any html coding expertise to make your own blog?
    Any help would be really appreciated!

  36. 2017年12月29日14:27 | #36

    online casino
    online casino
    online casino
    real money casino
    free casino games

  37. 2018年1月16日08:03 | #37

    payday loans no credit check
    loans no credit
    payday loans online no credit check
    loans for bad credit
    payday loans online no credit check

  38. 2018年1月18日09:36 | #38

    online slots
    online slots
    online casino
    casino games
    real money casino

  39. 2018年1月20日21:00 | #39

    I was able to find good information from your blog posts.

  40. 2018年1月21日15:35 | #40

    payday loans online
    payday loans online
    payday loans
    payday loans online
    payday loans

评论分页
1 2 3 4 459
订阅评论
5+6= (必填)