AVUrlAsset and WebVTTs

狂风中的少年 提交于 2021-01-28 04:37:15

问题


On iOS/TVOS, is it possible to load a remote .vtt file from a URL and use it as a subtitle track with a remote HLS video also loaded from a URL (as opposed to the VTT being specified within the m3u8 playlist)?

pseudocode:

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

Edit:

The docs mention using AVAsset for subtitles, but does anyone actually have an example? I can only find examples regarding adding strings as subtitles rather than loading a remote VTT.


回答1:


I've posted a solution over here: https://stackoverflow.com/a/37945178/171933 Basically you need to use an AVMutableComposition to join the video with the subtitles and then play back that composition.




回答2:


According to the docs, this is possible

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.

You should use AVMutableComposition to combine assets then. You would combine asset with the video with an asset with subtitles. Docs:

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



来源:https://stackoverflow.com/questions/35879678/avurlasset-and-webvtts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!