AVUrlAsset 和 WebVTT

AVUrlAsset and WebVTTs

在 iOS/TVOS 上,是否可以从 URL 加载远程 .vtt 文件并将其用作字幕轨道,同时还从 URL 加载远程 HLS 视频(与在 m3u8 播放列表中指定的 VTT 相反)?

伪代码:

AVAsset* video_asset = AVAsset( "http://video.m3u8" );
AVAsset* subtitle_asset = AVAsset( "http://subtitle.vtt" );
AVPlayer player = player.playVideoWithSubtitle( video_asset, subtitle_asset );
player.play().

编辑:

文档提到使用 AVAsset 制作字幕,但是有人真的有例子吗?我只能找到有关将字符串添加为字幕而不是加载远程 VTT 的示例。

根据docs,这是可能的

AVAsset is an abstract class to represent timed audiovisual media such as videos and sounds. Each asset contains a collection of tracks that are intended to be presented or processed together, each of a uniform media type, including but not limited to audio, video, text, closed captions, and subtitles.

你应该使用 AVMutableComposition 来组合资产。您可以将资产与视频与带字幕的资产结合起来。文档:

You can insert AVAsset objects into an AVMutableComposition object in order to assemble audiovisual constructs from one or more source assets.

我在这里发布了一个解决方案: 基本上你需要使用 AVMutableComposition 来加入带有字幕的视频,然后播放该合成。