shouldOptimizeForNetworkUse实际上做了什么? [英] What does shouldOptimizeForNetworkUse actually do?

查看:1128
本文介绍了shouldOptimizeForNetworkUse实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 Apple文档它只是说:


当此属性的值为YES时,输出文件将为
以这样的方式编写,即只需下载
的小额文件即可开始播放。

When the value of this property is YES, the output file will be written in such a way that playback can start after only a small amount of the file is downloaded.

但是实际上是在发生吗?

But what is actually happening?

推荐答案

当shouldOptimizedForNetworkUse设置为YES时,调用finishWriting将从末尾移动MP4 moov atom(movie atom)文件的开头到文件的开头。 moov atom包含有关电影文件的信息,如时间刻度和持续时间。 moov还包含subatoms,其中包含跟踪信息,文件中的数据偏移等。

When shouldOptimizedForNetworkUse is set to YES calling finishWriting will move the MP4 moov atom (movie atom) from the end of the file to the beginning of the file. The moov atom contains information about the movie file like timescale and duration. The moov also contains "subatoms" witch contain information like the tracks, the data offsets in the file etc.

只能使用moov原子中的信息进行回放它位于文件的开头而不是文件的末尾,即使电影播放器​​只加载了文件的开头,也可以开始播放该文件。

Playback is only possible using the information in the moov atom and when its located in the beginning of the file rather than at the end of the file, a movie player can begin playing the file even if it has only loaded the beginning of it.

在实践中,现代浏览器将使用HTTP / 1.1 Range标头从文件末尾获取moov原子,以加载moov原子,即使它位于文件的末尾。

In practice modern browsers will fetch the moov atom from the end of the file using HTTP/1.1 Range header to load the moov atom even if it is at the end of the file.

将shouldOptimizedForNetworkUse设置为YES也有一些副作用:

Setting the shouldOptimizedForNetworkUse to YES also has a few side-effects:


  • 完成电影需要更长时间,因为文件必须与原子中的偏移一起被修改。

  • 输出文件被锁定且无法访问,因为finishWriting将需要修改整个文件(移动和更新原子)。设置为NO时,movieFragmentInterval设置用于写入输出视频文件的刷新间隔,使文件在写入期间可读,因为片段以最终形式刷新到文件中。 finishWriting只需要将moov原子附加到文件的末尾,而不是触及已经写好的片段。

这篇关于shouldOptimizeForNetworkUse实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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