首页 > 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. 2011年5月16日10:07 | #1

    你好, 请问直接使用fms能够支持ts流吗?谢谢你的答复

  2. 2011年5月17日10:21 | #2

    我不明白fms本来rtmp协议就是播放事实流的服务端,他能很好的播放flv文件,你知道一个TS流文件有多大吗?这样不浪费带宽和资源吗?

  3. 2011年5月21日09:44 | #3

    Nice post. Have you looked at USP from codeshop? Open source, but licensed for commercial use. http://usp.code-shop.com/

    It uses one base file to create the different indexes

  4. 2011年6月13日09:42 | #4

    Thanks for you sharing.That is good article.I like it.

  5. 2011年6月13日09:43 | #5

    I read with great interest.Thanks for you sharing.

  6. 2011年6月13日09:44 | #6

    Your article looks great!Thanks for you sharing. I love it.

  7. 2011年6月20日17:12 | #7

    This information is useful to us.That is very kind of you to write this share for us, thanks a lot.

  8. 2018年4月4日01:15 | #8

    Good merchandise – helpful and educated service.

  9. 2018年4月4日01:41 | #9

    Have you ever considered about adding a little bit more than just your articles?
    I mean, what you say is important and all. But
    imagine if you added some great photos or video clips to give your
    posts more, “pop”! Your content is excellent
    but with images and video clips, this blog could undeniably be one of the greatest in its
    field. Superb blog!

  10. 2018年4月4日02:59 | #10

    We are a bunch of volunteers and starting a new scheme in our community.

    Your site offered us with helpful information to work on. You have done an impressive task and our whole neighborhood can be thankful to you.

  11. 2018年4月4日03:15 | #11

    A completed basement is a superb addition to any house.

  12. 2018年4月4日04:46 | #12

    canadian pharmacy viagra
    king pharmacy
    pharmacy drug store

  13. 2018年4月4日05:21 | #13

    compare rx prices
    best online canadian pharcharmy
    legitimate online pharmacies

  14. 2018年4月4日05:56 | #14

    online pharmacy without prescription
    prescription drugs canada
    pharmacy canada

  15. 2018年4月4日06:14 | #15

    Hello to all, I am also truly keen of learning PHP programming, however I am new one, I every time used to read content related to PHP programming.

  16. 2018年4月4日06:31 | #16

    canada drug pharmacy
    best canadian mail order pharmacies
    visit poster’s website

  17. 2018年4月4日07:07 | #17

    canadian pharmacy 365
    candrugstore com
    pharmacy prices

  18. 2018年4月4日18:02 | #18

    I simply couldn’t leave your website before suggesting that I really enjoyed the usual
    info an individual provide to your visitors? Is going to be back continuously in order to
    inspect new posts

  19. 2018年4月4日20:56 | #19

    I’m curious to find out what blog platform you’re using? I’m experiencing some small security issues with my latest website and
    I would like to find something more safe. Do you have any suggestions?

  20. 2018年4月5日00:32 | #20

    Ridiculous quest there. What happened after? Good luck!

  21. 2018年4月6日11:38 | #21

    Thank you. I appreciate it.

  22. 2018年4月6日12:58 | #22

    Septic methods, sewer lines, septic providers.

  23. 2018年4月6日23:52 | #23

    We didn’t find outcomes for: water therapy services.

  24. 2018年4月8日02:11 | #24

    It could be time for a tree trimming.

  25. 2018年4月8日10:15 | #25

    Apply wooden stain with a foam applicator pad.

  26. 2018年4月8日20:33 | #26

    Each types of flooring needs to be saved dry.

  27. 2018年4月10日15:23 | #27

    Householders often need a tree service for three reasons.

  28. 2018年4月10日17:59 | #28

    This should fully remove the floor mould.

  29. 2018年4月11日00:02 | #29

    Best price generic canada http://drugstore-usa.science/ To buy australia.

  30. 2018年4月12日00:09 | #30

    Many damp basements are caused by these minor
    cracks.

  31. 2018年4月15日02:26 | #31

    Criminal records check calgary, http://background-check-services-for-employers.science san diego county court records online search.

  32. 2018年4月15日16:13 | #32

    HELLOMYSORRY
    I like what you guys are up too. Such intelligent work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website :)

  33. 2018年4月15日18:34 | #33

    Employee screening program, http://background-check-renter.science essex county massachusetts public records.

  34. 2018年4月15日21:26 | #34

    Black toxic mould appears black or dark inexperienced.

  35. 2018年4月17日08:55 | #35

    These are all signs of foundation points needing restore.

  36. 2018年4月18日00:08 | #36

    This is the right website for anyone who would like to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You certainly put a fresh spin on a topic that’s been written about for years. Excellent stuff, just wonderful!

  37. 2018年4月18日06:08 | #37

    Most leaks take solely minutes to repair.

  38. 2018年4月23日04:32 | #38

    You actually stated this fantastically!

  39. 2018年4月24日04:12 | #39

    These are all symptoms of foundation points needing
    repair.

订阅评论
3+8= (必填)