iOS - AVPlayer using closedcaptions

女生的网名这么多〃 提交于 2019-12-23 07:20:52

问题


I'm working with AVPlayer on iOS use to "closedCaptionDisplayEnabled property" to show captions or subtitle on the movie (hls or mp4), but the caption not show anything. I don't know why?

Have you any solution to show captions(subtitle) on movie(hls,mp4)?

And i see a few sample about app, youtube, netflix, tvguide and something used to closed caption.

Maybe all the app on iphone, ipad from netflix,youtube using one file and insert subtitle inside video, i think

But, i want to use to two file (one file hls or mp4, one file srt or WebVTT)

image1, image2

Thank you for read this article!!!!


回答1:


The iOS AVPlayer supports captions in one of two ways: Either encoding the captions with the CEA-608 standard (a modified version of CEA-708/ATSC legacy encoding) into the segmented MPEG2-TS video files, or by providing the captions in a segmented WebVTT file, which is specified in the master m38u playlist for the the HLS video. "Soft" subtitles (which can be toggled on and off) are supported by the WebVTT standard in a similar fashion to captions (they've both categorized as timed metadata); if you preferred "hard" subtitles (where they are "burned" into the video), you would provide the subtitle data to your video encoder during the transcoding process.

See the following links for more info:

https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/UsingHTTPLiveStreaming/UsingHTTPLiveStreaming.html

http://blog.zencoder.com/2012/07/13/closed-captioning-for-web-mobile-and-tv/




回答2:


Are you trying to use srt files as subtitles? Because the AVPlayer built-in closed captioning on iOS must be encoded as part of the stream (check the AVPlayer documentation). Search for a video editing software that can insert srt into the video (note: this are not baked-in subtitles that are part of the video; you can turn them on-off).

Now unless you can do that, the only other solution is to implement your own subtitles by parsing the srt file and displaying a UILabel on top of the video view.




回答3:


A very quick and easy way to do it would be to load it in a webView.

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    let html = """
        <video playsinline controls width="100%" autoplay src="https://example.com/xyz.mp4">
            <track default src="https://example.com/abc.vtt">
        </video>
    """
    webView.loadHTMLString(html, baseURL: nil)
}


来源:https://stackoverflow.com/questions/13561228/ios-avplayer-using-closedcaptions

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