IOS - AVPlayer using closed captions

I am working with AVPlayer when using iOS for the "closedCaptionDisplayEnabled" property to show subtitles or subtitles in the movie (hls or mp4), but the title does not show anything. I do not know why?

Do you have a solution to display captions (subtitles) in a movie (hls, mp4)?

And I see some examples about the application, youtube, netflix, tvguide and something that is used for closed captions.

Perhaps the whole application on iphone, ipad from netflix, youtube, using one file and inserting subtitles inside the video, I think

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

image1 , image2

Thanks for reading this article !!!!

+10
source share
3 answers

iOS AVPlayer supports captions in one of two ways: either encode the headers with the CEA-608 standard (a modified version of the obsolete CEA-708 / ATSC encoding) into segmented MPEG2-TS video files, or by providing captions in the segmented WebVTT file that is listed in the m38u main playlist for HLS video. Soft subtitles (which can be turned on and off) are supported by the WebVTT standard similar to captions (they are both classified as temporary metadata); if you prefer โ€œhardโ€ subtitles (where they are โ€œburnedโ€ in the video), you must provide the subtitle data to your video encoder during the transcoding process.

For more information, see the following links:

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/

+6
source

Are you trying to use srt files as subtitles? Since the embedded closed caption of AVPlayer in iOS must be encoded as part of the stream (check the AVPlayer documentation). Find a video editing software that can insert srt into the video (note: these are not baked subtitles that are part of the video, you can disable them).

Now, if you cannot do this, the only other solution is to implement your own subtitles by analyzing the srt file and displaying the UILabel on top of the video image.

+1
source

A very quick and easy way to do this is to upload it to a web view.

@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) } 
0
source

All Articles