HTTP LIve Streaming [英] HTTP LIve Streaming

查看:112
本文介绍了HTTP LIve Streaming的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我一直试图围绕这个http直播流媒体。我只是不明白,是的,我已经阅读了所有的苹果文档并观看了wwdc视频,但仍然非常困惑,所以请帮助一个想要编写程序!

Ok, I have been trying to wrap my head around this http live streaming. I just do not understand it and yes I have read all the apple docs and watched the wwdc videos, but still super confused, so please help a wanna be programer out!!!

你写的代码在服务器上?不是在xcode?
如果我是对的,我如何设置它?
我是否需要在服务器上设置一些特殊的东西?喜欢php还是什么?
如何使用Apple .. segmenter等提供的工具?

The code you write goes on the server? not in xcode? If I am right how do i set this up? Do I need to set up something special on my server? like php or something? How do use the tools that are supplied by Apple.. segmenter and such?

请帮助我,
谢谢

Please help me, Thanks

推荐答案

HTTP直播



HTTP直播是Apple提出的流媒体标准。查看最新的草案标准

涉及的文件是


  • .m4a 的音频(如果你想要的话)仅限音频流。。

  • .ts 用于视频。这是MPEG-2传输,通常具有h.264 / AAC有效载荷。它包含10秒的视频,它是通过拆分原始视频文件或转换实时视频来创建的。

  • .m3u8 for播放列表。这是WinAmp格式的UTF-8版本。

  • .m4a for audio (if you want a stream of audio only).
  • .ts for video. This is a MPEG-2 transport, usually with a h.264/AAC payload. It contains 10 seconds of video and it is created by splitting your original video file, or by converting live video.
  • .m3u8 for the playlist. This is a UTF-8 version of the WinAmp format.

即使它被称为直播,通常会有一分钟左右的延迟,在此期间视频转换,ts和写入m3u8文件,并且您的客户端刷新m3u8文件。

Even when it's called live streaming, usually there is a delay of one minute or so during which the video is converted, the ts and m3u8 files written, and your client refresh the m3u8 file.

所有这些文件都是服务器上的静态文件。但是在直播活动中,会添加更多的.ts文件,并且会更新m3u8文件。

All these files are static files on your server. But in live events, more .ts files are added, and the m3u8 file is updated.

由于您标记了这个问题iOS,因此提及相关的App Store规则是相关的:

Since you tagged this question iOS it is relevant to mention related App Store rules:


  • 对于小于10分钟或每5分钟5 MB的视频,您只能使用渐进式下载。否则,您必须使用HTTP Live Streaming。

  • 如果您使用HTTP实时流式传输,则必须提供至少一个64 Kbps或更低带宽的流(低带宽流可能仅限音频或带有静止图像的音频)。

要下载HTTP Live Streaming Tools,请执行以下操作:

To download the HTTP Live Streaming Tools do this:

  • Get a Mac or iPhone developer account.
  • Go to http://connect.apple.com and search for "HTTP Live Streaming Tools", or look around at http://developer.apple.com/resources/http-streaming/.

安装了命令行工具:

 /usr/bin/mediastreamsegmenter
 /usr/bin/mediafilesegmenter
 /usr/bin/variantplaylistcreator
 /usr/bin/mediastreamvalidator
 /usr/bin/id3taggenerator

手册页中的描述:


  • 媒体流分段器:从用于HTTP直播流的MPEG-2传输流创建片段。

  • 媒体文件分段:为媒体文件中的HTTP直播流创建片段。

  • Variant Playlist Creator:创建播放列表,用于从mediafilesegmenter创建的HTTP Live流媒体片段切换流。

  • 媒体流验证器:验证H TTP实时流媒体流和服务器。

  • ID3标记生成器:创建ID3标记。

  • Media Stream Segmenter: Create segments from MPEG-2 Transport streams for HTTP Live Streaming.
  • Media File Segmenter: Create segments for HTTP Live Streaming from media files.
  • Variant Playlist Creator: Create playlist for stream switching from HTTP Live streaming segments created by mediafilesegmenter.
  • Media Stream Validator: Validates HTTP Live Streaming streams and servers.
  • ID3 Tag Generator: Create ID3 tags.

安装Macports,转到终端并 sudo port install ffmpeg 。然后使用此FFMpeg脚本将视频转换为传输流(.ts):

Install Macports, go to the terminal and sudo port install ffmpeg. Then convert the video to transport stream (.ts) using this FFMpeg script:

# bitrate, width, and height, you may want to change this
BR=512k
WIDTH=432
HEIGHT=240
input=${1}

# strip off the file extension
output=$(echo ${input} | sed 's/\..*//' )

# works for most videos
ffmpeg -y -i ${input} -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s ${WIDTH}x${HEIGHT} -vcodec libx264 -b ${BR} -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 0 -refs 0 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate ${BR} -bufsize ${BR} -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 30 -qmax 51 -qdiff 4 -level 30 -aspect ${WIDTH}:${HEIGHT} -g 30 -async 2 ${output}-iphone.ts

这将生成一个.ts文件。现在我们需要分段分割文件并创建包含所有这些文件的播放列表。我们可以使用Apple的 mediafilesegmenter

This will generate one .ts file. Now we need to split the files in segments and create a playlist containing all those files. We can use Apple's mediafilesegmenter for this:

mediafilesegmenter -t 10 myvideo-iphone.ts

这将为视频的每10秒生成一个.ts文件加上a。 m3u8文件指向所有这些文件。

This will generate one .ts file for each 10 seconds of the video plus a .m3u8 file pointing to all of them.

播放 .m3u8 在iOS上,我们指向带有移动版Safari的文件。
当然,首先我们需要将它们放在Web服务器上。要让Safari(或其他播放器)识别ts文件,我们需要添加其MIME类型。在Apache中:

To play a .m3u8 on iOS we point to the file with mobile safari. Of course, first we need to put them on a web server. For Safari (or other player) to recognize the ts files, we need to add its MIME types. In Apache:

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

在lighttpd中:

In lighttpd:

 mimetype.assign = ( ".m3u8" => "application/x-mpegURL", ".ts" => "video/MP2T" )

要从网页链接:

<html><head>
    <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head><body>
    <video width="320" height="240" src="stream.m3u8" />
</body></html>

要检测设备方向,请参阅检测并设置iPhone和放大器; iPad的视口方向使用JavaScript,CSS和元标签

To detect the device orientation see Detect and Set the iPhone & iPad's Viewport Orientation Using JavaScript, CSS and Meta Tags.

您可以做的更多事情是创建视频的不同比特率版本,嵌入元数据以读取它作为通知播放,当然还可以使用MoviePlayerController和AVPlayer进行有趣的编程。

More stuff you can do is create different bitrate versions of the video, embed metadata to read it while playing as notifications, and of course have fun programming with the MoviePlayerController and AVPlayer.

这篇关于HTTP LIve Streaming的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆