【问题标题】:Need to show Preview Video Thumbnails while seeking (Like youtube) for iOS需要在为 iOS 搜索(如 youtube)时显示预览视频缩略图
【发布时间】:2020-05-30 01:15:46
【问题描述】:

在 AVPlayer 中搜索时,我需要显示视频预览缩略图。 就像 youtube 显示它们一样。 (iOS) (也适用于直播)(Wowza/Amazon S3 首选解决方案)

【问题讨论】:

标签: ios amazon-s3 video-streaming video-processing wowza


【解决方案1】:

你可以试试这个 Youtube 助手 - https://github.com/youtube/youtube-ios-player-helper

【讨论】:

  • 这仅用于播放 youtube 视频,不适用于其他视频和直播。
【解决方案2】:

你可以试试这个:

extension AVAsset {

    func getPreviewImage(for timeInSeconds: Int = 0) -> UIImage? {
        let imageGenerator = AVAssetImageGenerator(asset: self)
        imageGenerator.requestedTimeToleranceBefore = .zero
        imageGenerator.requestedTimeToleranceAfter = .zero
        imageGenerator.appliesPreferredTrackTransform = true
        guard let cgImage = try? imageGenerator.copyCGImage(at: CMTime(value: CMTimeValue(timeInSeconds), timescale: 1), actualTime: nil) else { return nil }
        return UIImage(cgImage: cgImage)
    }

}

您不应该在主线程中获得预览。

如果需要一系列预览图,可以试试this:

如果您需要一个系列 图像,您可以使用 异步方法, generateCGImagesAsynchronously(forTimes:completionHandler:),其中 采用与播放期间类似的解码效率。

【讨论】:

  • 问题是这种方法不能为我提供流畅的滚动或移动缩略图显示。 (在特定时间获取特定缩略图需要一些时间)
  • @RajPahelajani 你在后台线程中获得预览吗?
  • 我试过了,但这不是我所期望的,同样对于扩展名为“m3u8”的视频,这种方法不会为我提供缩略图。
  • @RajPahelajani 我看到一个经过编辑的帖子。也许是因为直播,我不知道。我将它用于常规视频。
  • @RajPahelajani 我更新了我的答案。为了提高效率,您可以尝试generateCGImagesAsynchronously。我还没有发现为什么这不适用于扩展“m3u8”。
猜你喜欢
  • 2014-08-18
  • 1970-01-01
  • 2011-03-25
  • 1970-01-01
  • 1970-01-01
  • 2017-05-15
  • 2017-09-13
  • 1970-01-01
  • 2011-11-11
相关资源
最近更新 更多