无缝循环 AVPlayer [英] Looping AVPlayer seamlessly

查看:23
本文介绍了无缝循环 AVPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前已经一些讨论关于如何循环AVPlayer 的视频项目,但没有任何解决方案"能够无缝地提供无延迟视频循环.

There has been some discussion before about how to loop an AVPlayer's video item, but no 'solution' is seamless enough to provide lag-less looping of a video.

我正在开发一个 tvOS 应用程序,它在其中一个视图的背景中具有高质量的 10 秒风景"剪辑,并且只需以标准"方式重新启动其 AVPlayer(订阅 NSNotification来捕捉它)太紧张了,不会注意到并影响用户体验.

I am developing a tvOS app that has a high-quality 10 second clip of 'scenery' in the background of one of its views, and simply restarting its AVPlayer the 'standard' way (subscribing to NSNotification to catch it) is too jumpy not to notice and detract from user experience.

似乎实现真正无缝循环的唯一方法是在较低级别(在 OpenGL 中)手动管理帧...

It seems as though the only way to achieve a truly seamless loop is to manually manage frames, at a lower-level (in OpenGL)...

尽管已尽最大努力阅读此内容,并且作为操作视频管道的新手,我还没有接近一个易于理解的解决方案.

Despite best efforts to read up on this, and as a novice in manipulating video pipelines, I have not come close enough to a comprehensible solution.

我知道存在外部库是为了能够更轻松地执行此行为;最值得注意的是 GPUImage.但是,我正在开发的应用程序是针对 tvOS 的,因此很难使用现有的大量 3rd 方 iOS 库,包括 GPUImage.我遇到的另一个库是 AVAnimator,它为轻量级动画视频提供了强大的功能,但是不适用于以 .H264 编码的源素材的密集、高质量视频剪辑.

I am aware that external libraries exist to be able to perform this behaviour more easily; most notably GPUImage. However, the app I am developing is for tvOS and therefore has difficulty using quite a lot of the 3rd party iOS libraries in existence, GPUImage included. Another library I have come across is AVAnimator, which provides great functionality for light-weight animation videos, but not for dense, high-quality video clips of source footage encoded in .H264.

到目前为止我最接近的是 Apple 自己的 AVCustomEdit 源代码,但是这主要处理过渡"的静态生成,虽然是无缝的,但对我来说太复杂了,无法辨别如何使其执行简单的循环功能.

The closest I have come so far is Apple's own AVCustomEdit source code, however this primarily deals with static production of a 'transition' that, while seamless, is too complex for me to be able to discern how to make it perform simple looping functionality.

如果有人可以在较低级别上操作 AVPlayer 的经验,即图像处理/缓冲区(或不依赖于外部库的 iOS 开发),我会非常感兴趣了解我如何开始.

If anybody can chip in with experience of manipulating AVPlayer at a lower level, i.e. with image processing/buffers (or iOS development that doesn't rest on external libraries), I would be incredibly interested to know how I could make a start.

推荐答案

我在流式传输视频时遇到了同样的问题.第一次播放后,第二次加载视频时出现黑屏.我通过搜索提前 5 毫秒的视频摆脱了黑屏.它制作了几乎无缝的视频循环.(Swift 2.1)

I had the same problem when streaming a video. After playing for the first time, there was a black screen when loading the video for second time. I got rid of the black screen by seeking video to 5ms ahead. It made nearly a seamless video loop. (Swift 2.1)

// Create player here..
let player = AVPlayer(URL: videoURL)

// Add notification block
NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem, queue: nil)
{ notification in
   let t1 = CMTimeMake(5, 100);
   player.seekToTime(t1)
   player.play()
}

这篇关于无缝循环 AVPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆