iOS - AVPlayer using closedcaptions
Asked Answered
S

3

10

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!!!!

Shill answered 26/11, 2012 at 8:38 Comment(2)
anybody have this solution?Shill
Check these if it helps, #11312618 and #12179747Sthilaire
L
6

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/

Languet answered 17/3, 2014 at 22:16 Comment(0)
D
1

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.

Danelaw answered 14/2, 2014 at 21:18 Comment(0)
S
0

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)
}
Shanitashank answered 19/8, 2019 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.