zoukankan      html  css  js  c++  java
  • 基于http live streaming, 使用vlc + mediastreamsegmenter + apache 实现iOS视频直播

    刚学ios一个多星期,这里基本没怎么提理论,需要的参考下其它资料

    HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议。是苹果公司QuickTime X和iPhone软件系统的一部分。它的工作原理是把整个流分成一个个小的基于HTTP的文件来下载,每次只下载一些。当媒体流正在播放时,客户端可以选择从许多不同的备用源中以不同的速率下载同样的资源,允许流媒体会话适应不同的数据速率。在开始一个流媒体会话时,客户端会下载一个包含元数据的extended M3U (m3u8) playlist文件,用于寻找可用的媒体流。

    HLS只请求基本的HTTP报文,与实时传输协议(RTP)不同,HLS可以穿过任何允许HTTP数据通过的防火墙或者代理服务器。它也很容易使用内容分发网络来传输媒体流。

    此协议详细内容请参考apple官方网站:https://developer.apple.com/resources/http-streaming/

    搭建HLS server有多种方式(可以参考http://www.yaosansi.com/post/1495.html),我是通过使用 VLC+mediastreamsegmenter+apache 来搭建HTTP Live Streaming系统:

    具体方案:

      一.视频源,由于没有摄像头,我用已有的视频文件,通过vcl来模拟视频源。

        1.在win7上安装vcl(2.0.6),ip为 192.168.1.187

        2.媒体-->流(S)-->添加,选择一个视频文件

        

        3.点击右下角 "串流(S)"按钮

        4.下一步

        5.选中RTSP ,然后点击 “添加”

        

        6.把端口设置为5544,路径修改为 /test

        

        7.下一步,最后点击串流,最终界面如图:

        

        

        二.视频的转码:从192.168.1.187机器上接收到视频流,封装成mpeg-ts通过UDP给192.168.1.249:1234

        1.在mac os 上按装vlc(2.0.6),ip为192.168.1.249

        2.选中 Open media...

              

        3.根据实际情况填上URL,然后勾选Streaming/Saving:,点击Settings...按钮

        

        4.按照图中填好,然后点击OK,注意Address是我mac机的ip

        

        5.回到界面3,点击Open 按钮,进入主界面如图

        

        三.参考资料,启动mac上的apache,在/Users/selfaccount/ 下新建 Sites/httpstream/目录,

                 在/Users/selfaccount/ 下新建index.html文件,内容如下          

              <html>
                <head>
                  <meda name="viewport" content="width=320;initial-scale=1.0;maximum-scale=1.0;user-scalable=0;"/>
                </head>
                <body>
                  <center><video src="http://localhost/~qqc/httpstream/prog_index.m3u8" controls autoplay></video></center>
                </body>
              </html>

        四.根据hls,生成*.ts片及索引文件*.m3u8

        1.打开终端,进入/usr/bin, 输入 mediastreamsegmenter -s 3 -D -f /Users/qqc/Sites/httpstream 127.0.0.1:1234

        

        2.进入/Users/qqc/Sites/httpstream/ 目录可看到如图,已经生成了相关的*.ts文件,及prog_index.m3u8文件。

        

        五.测试验证,我用xcode建了一个工程,用MPMoviePlayerController,简单实现了一个播放功能    

          NSURL* uri = [NSURLURLWithString:@"http://192.168.1.249/~qqc/httpstream/prog_index.m3u8"];

          _mplayer = [[MPMoviePlayerControlleralloc] initWithContentURL:uri];

          _mplayer.scalingMode = MPMovieScalingModeFill;

          _mplayer.shouldAutoplay =YES ;

          _mplayer.controlStyle = MPMovieControlStyleDefault; 

          [_mplayer.view setFrame:CGRectMake(0, 0, 360, 360)];

          [self.view addSubview:_mplayer.view];

          [_mplayer play];

        六.测试结果

        

    参考资料:

    http://developer.apple.com/library/mac/#technotes/tn2224/_index.html  (重要)

    http://blog.csdn.net/nmgfrank/article/details/6955105#comments  (搭建HTTP Live Streaming直播系统

    http://wenku.baidu.com/view/7b8162d228ea81c758f57808.html  (iphone直播流技术)

    http://www.aojie.biz/902  (ios(苹果)设备直播流媒体 服务搭建)

    http://dl.vmall.com/c0sr0coaxb (视频资源)

    http://my.oschina.net/gysutantoman/blog/73882  

    http://www.yaosansi.com/post/1495.html  (HTTP Streaming with segmenter在Linux和Windows下的多种实现方案)

    https://videolan.org/doc/streaming-howto/en/index.html (vlc)

    http://wenku.baidu.com/view/6b59be492b160b4e767fcf0e.html (vlc)

    http://wenku.baidu.com/view/d0fa8e0116fc700abb68fcc1.html  (vlc)

    http://wenku.baidu.com/view/fb7e4097dd88d0d233d46a9d.html

  • 相关阅读:
    命名空间
    XML
    关于命名空间
    gitbook 入门教程之 gitbook 简介
    git 入门教程之备忘录[译]
    git 入门教程之知识速查
    git 入门教程之忽略文件
    git 入门教程之个性化 git
    git 入门教程之里程碑式标签
    git 入门教程之本地和远程仓库的本质
  • 原文地址:https://www.cnblogs.com/qc0815/p/3099105.html
Copyright © 2011-2022 走看看