HTTP 直播
好吧,我一直在努力理解这个 http 直播。我只是不明白它,是的,我已经阅读了所有苹果文档并观看了 wwdc 视频,但仍然非常困惑,所以请帮助一个想成为程序员的人!
你写的代码放在服务器上?不在 xcode 中? 如果我是对的我该如何设置? 我需要在我的服务器上设置一些特殊的东西吗?比如php什么的? 如何使用Apple..segmenter等提供的工具?
请帮我, 谢谢
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!!!
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HTTP Live Streaming
HTTP Live Streaming 是 Apple 提出的流媒体标准。请参阅最新的标准草案。
涉及的文件是
.m4a
(如果您只想要音频流)。.ts
用于视频。这是 MPEG-2 传输,通常带有 h.264/AAC 有效负载。它包含 10 秒的视频,是通过分割原始视频文件或转换实时视频而创建的。.m3u8
用于播放列表。这是 WinAmp 格式的 UTF-8 版本。即使称为直播,通常也会有一分钟左右的延迟,在此期间,视频转换、ts 和 m3u8 文件写入、客户端刷新 m3u8 文件。
所有这些文件都是服务器上的静态文件。但在现场活动中,会添加更多 .ts 文件,并更新 m3u8 文件。
由于您在 iOS 上标记了此问题,因此有必要提及相关的 App Store 规则:
示例
获取流媒体工具
要下载 HTTP 直播流媒体工具,请执行以下操作:
安装的命令行工具:
手册页中的说明:
创建视频
安装 Macports,转到终端并
sudo port install ffmpeg
。然后使用此 FFMpeg 脚本将视频转换为传输流 (.ts):这将生成一个 .ts 文件。现在我们需要将文件分成片段并创建一个包含所有这些文件的播放列表。为此,我们可以使用 Apple 的
mediafilesegmenter
:这将为视频的每 10 秒生成一个 .ts 文件,以及指向所有这些文件的 .m3u8 文件。
设置网络服务器
要在 iOS 上播放
.m3u8
,我们使用 mobile safari 指向该文件。当然,首先我们需要将它们放在网络服务器上。为了让 Safari(或其他播放器)识别 ts 文件,我们需要添加其 MIME 类型。在 Apache 中:
在 lighttpd 中:
要从网页链接此内容:
要检测设备方向,请参阅 检测并设置 iPhone &使用 JavaScript、CSS 和元标记的 iPad 视口方向。
您可以做的更多事情是创建视频的不同比特率版本,嵌入元数据以在播放时作为通知读取它,当然还可以使用 MoviePlayerController 和 AVPlayer 进行有趣的编程。
HTTP Live Streaming
HTTP Live Streaming is a streaming standard proposed by Apple. See the latest draft standard.
Files involved are
.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.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.
All these files are static files on your server. But in live events, more .ts files are added, and the m3u8 file is updated.
Since you tagged this question iOS it is relevant to mention related App Store rules:
Example
Get the streaming tools
To download the HTTP Live Streaming Tools do this:
Command line tools installed:
Descriptions from the man page:
Create the video
Install Macports, go to the terminal and
sudo port install ffmpeg
. Then convert the video to transport stream (.ts) using this FFMpeg script: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:This will generate one .ts file for each 10 seconds of the video plus a .m3u8 file pointing to all of them.
Setup a web server
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:
In lighttpd:
To link this from a web page:
To detect the device orientation see Detect and Set the iPhone & iPad's Viewport Orientation Using JavaScript, CSS and Meta Tags.
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.
这可能对 swift 有所帮助:
MPMoviePlayerController 从 iOS 9 开始已被弃用。我们可以使用 AVPlayerViewController() 或 AVPlayer 来达到此目的。看看:
AVPlayerViewController :
AVPlayer :
This might help in swift:
MPMoviePlayerController is deprecated from iOS 9 onwards. We can use AVPlayerViewController() or AVPlayer for the purpose. Have a look:
AVPlayerViewController :
AVPlayer :
Cloudinary 的另一个解释 http://cloudinary.com/documentation/video_manipulation_and_delivery#http_live_streaming_hls
Another explanation from Cloudinary http://cloudinary.com/documentation/video_manipulation_and_delivery#http_live_streaming_hls