gpt4 book ai didi

ios - Azure AMS : How to get Sidecar WebVTT for showing Captions/Subtitles in iOS native player?

转载 作者:行者123 更新时间:2023-12-01 16:20:39 27 4
gpt4 key购买 nike

我们已经在 Azure 媒体播放器中成功配置了字幕/字幕,它在 Web 端播放媒体。

但是,我们如何为 Native AVPlayer 在 iOS 中播放由 AMS 管理的媒体进行相同的配置呢?我们知道字幕/字幕可以通过 Sidecar WebVTT 文件在原生 iOS 播放器中播放,但是 AMS 生成的“transcript.vtt”文件是 Sidecar WebVTT 文件吗?

如果没有,我们如何生成 sidecar WebVTT 文件?

我们已经实现了如下代码,从 AMS 链接访问媒体文件和本地下载的 transcript.vtt 文件,但它失败了。

[编辑:20200413]

但是,当我们有本地媒体文件和本地 transcript.vtt 文件时,或者当我们直接访问媒体存储帐户 ( https://mediastorageaccount.blob.core.windows.net/container/file.mp4 ) 中的媒体文件时,它可以正常工作。但是,当我们从 AMS 转换 (https://mediaservice-inct.streaming.media.azure.net/788888-6666-4444-aaaa-823422j218/file.ism/manifest(format=m3u8-cmaf)) 生成的链接访问编码文件时,它会失败。

这里有什么问题?

func playVideo()

{
让 strUrl = " https://mediaservice-inct.streaming.media.azure.net/79510-6eb-340-a90-824218/German-FAST_Lesson-2-Dialog.ism/manifest(format=m3u8-cmaf)"
    localVideoAsset = AVURLAsset(url: URL(string: strUrl)!)

//We have to add tracks in AVMutableComposition same like bellow

//First we have to add video track on AVMutableComposition
let videoTrack = videoPlusSubtitles.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)

do{
guard localVideoAsset!.tracks.count > 0 else{
// error msg
return
}

try? videoTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: localVideoAsset!.duration),
of:localVideoAsset!.tracks(withMediaType: .video)[0],
at: seconds)
}


//After that we have to add subtitle track in AVMutableComposition
if isEnglishSubtitle {
setSubtitleTrack(subtitle: "transcript")

}else{
setSubtitleTrack(subtitle: "transcript_tr")
}



//After set the video track and subtitle track we have to set in the player same like bellow
player = AVPlayer(playerItem: AVPlayerItem(asset: videoPlusSubtitles))

playerLayer.removeFromSuperlayer()
playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.videoView.bounds
playerLayer.videoGravity = .resizeAspect
self.videoView.layer.addSublayer(playerLayer)

player.play()

}

func setSubtitleTrack(字幕:字符串){
打印(字幕)
打印(秒)
    //Here we have to check if any pre track available. If available then we have to remove it same like bellow
if subtitleTrack != nil{
videoPlusSubtitles.removeTrack(subtitleTrack!)
}


//We have to get subtitle file from path same like bellow
let subtitleAsset = AVURLAsset(url: Bundle.main.url(forResource: subtitle, withExtension: ".vtt")!)

// And we have to add new track from here
subtitleTrack = videoPlusSubtitles.addMutableTrack(withMediaType: .text, preferredTrackID: kCMPersistentTrackID_Invalid)
do{
guard subtitleAsset.tracks.count > 0 else{
//error msg
return
}

try? subtitleTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: localVideoAsset!.duration),
of:subtitleAsset.tracks(withMediaType: .text)[0],
at: seconds)
}

}

最佳答案

我怀疑这个问题不是由 AMS 流引起的。要仔细检查,您可能想尝试使用另一个流 HLS(例如,尝试 Apple 提供的 HLS)。 Apple 对在 AVPlayer 中播放 VTT 有特定要求。我包含了一个 Apple 文档链接,其中包含很多关于流媒体的示例,以及其他可能有用的链接:

https://developer.apple.com/streaming/examples/

How to add external .vtt subtitle file to AVPlayerViewController in tvOS

AVUrlAsset and WebVTTs

关于ios - Azure AMS : How to get Sidecar WebVTT for showing Captions/Subtitles in iOS native player?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60774865/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com