无缝循环AVPlayer [英] Looping AVPlayer seamlessly

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

问题描述

之前有关于如何循环<$的一些讨论 c $ c> 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的,因此很难使用相当多的第三方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.

如果有人能够操纵<$ c $的经验c> 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.

推荐答案

我流的视频时有同样的问题。第一次播放后,第二次加载视频时出现黑屏。我通过向前5ms寻找视频摆脱了黑屏。它几乎形成了一个无缝的视频循环。 (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天全站免登陆