0

진단 할 수없는 메모리 누수가 있습니다. AVPlayerLooper 외에, 내가 만났고 시도한 모든 접근법은 AVPlayerItemDidPlayToEndTimeNotification을보고 나서 AVPlayer의 경우에는 비디오의 시작 부분을 찾거나 (AVPlayer의 경우) 관찰자를 만드는 작업과 관련이 있습니다. 루프 될 비디오를 비디오 대기열에 삽입합니다 (AVQueuePlayer의 경우). 둘 다 비슷한 성능을 갖고있는 것처럼 보이지만, 둘 다 seekToTime 메소드 (AVPlayer의 경우) 및 insertItem 메소드 (AVQueuePlayer의 경우)와 관련하여 일관된 메모리가 유지됩니다. 최종 목표는 기본적으로 루프하는 SKVideoNode의 하위 클래스를 만드는 것입니다. 아래는 서브 클래스 내 코드입니다 :루핑으로 인한 메모리 누수 SKVideoNode (실제 장치에서만)

#import "SDLoopingVideoNode.h" 
#import <AVFoundation/AVFoundation.h> 


@interface SDLoopingVideoNode() 
@property AVQueuePlayer *avQueuePlayer; 
@property AVPlayerLooper *playerLooper; 
@end 

@implementation SDLoopingVideoNode 

-(instancetype)initWithPathToResource:(NSString *)path withFiletype:(NSString *)filetype 
{ 
if(self == [super init]) 
{ 
    NSString *resourcePath = [[NSBundle mainBundle] pathForResource:path ofType:filetype]; 
    NSURL *videoURL = [NSURL fileURLWithPath:resourcePath]; 
    AVAsset *videoAsset = [AVAsset assetWithURL:videoURL]; 
    AVPlayerItem * videoItem = [AVPlayerItem playerItemWithAsset:videoAsset]; 


    self.avQueuePlayer = [[AVQueuePlayer alloc] initWithItems:@[videoItem]]; 

    NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; 
    [noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification 
          object:nil 
          queue:nil 
         usingBlock:^(NSNotification *note) { 
          AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:videoURL]; 
          [self.avQueuePlayer insertItem:video afterItem:nil]; 
          NSLog(@"Video changed"); 
         }]; 

    self = (SDLoopingVideoNode*)[[SKVideoNode alloc] initWithAVPlayer: self.avQueuePlayer]; 
    return self; 
} 
return nil; 
} 


@end 

가 그리고 여기에 서브 클래스가 didMoveToView에 초기화 방법은 다음과 같습니다

SDLoopingVideoNode *videoNode = [[SDLoopingVideoNode alloc]initWithPathToResource:@"147406" withFiletype:@"mp4"]; 
[videoNode setSize:CGSizeMake(self.size.width, self.size.height)]; 
[videoNode setAnchorPoint:CGPointMake(0.5, 0.5)]; 
[videoNode setPosition:CGPointMake(0, 0)]; 
[self addChild:videoNode]; 
[videoNode play]; 
+0

내가 알아 차 렸던 또 다른 이상한 점은 -이 메모리 누출은 단지 장치에 표시된다는 것입니다. 시뮬레이터에서 실행될 때 메모리 누출이 없습니다. –

답변

2

짧은 대답은, 당신이 얻을 수 없을 것 AVPlayer를 작업. 저를 믿으십시오, 나는 시도했다. 대신 H264 하드웨어를 사용하여 각 비디오 프레임을 디코딩 한 후 키 프레임으로 다시 인코딩하면 원활한 루프가 가능합니다 (github link here). 또한 완전한 알파 채널을 지원하는 원활한 루핑 레이어를 만들었습니다. 전체 화면 1x1 비디오 및 iPad 또는 iPad 전문가의 성능도 좋습니다. 또한이 코드에서는 메모리 누수가 발생하지 않습니다.

+0

답장을 보내 주셔서 감사합니다! 그게 당신 프로젝트입니까? 오늘 프로젝트를 다운로드하여 보았습니다. 반복은 훌륭하지만, 반복 된 비디오를 SKVideoNode에 삽입하는 방법을 알고 있습니까? 내가 원하는 효과는 스프라이트 키트의 비디오 배경입니다. –

+0

위 코드의 루핑은 잘 작동하지만 AVQueuePlayer로 SKVideoNode를 초기화하고 큐에 비디오를 추가하면 모든 비디오 루프에 메모리 링크가 생깁니다. –

+0

아니요, SKVideoNode에 직접 포함시킬 수 없습니다. 그러나 픽셀 버퍼에 비디오 프레임을 디코딩하고 렌더링 한 다음 해당 픽셀 버퍼를 일반 SKSpriteNode 노드의 텍스처로 설정할 수 있습니다. 메모리를 최소한으로 사용하려면 SKMutableTexture를 사용하고 비동기 콜백이 픽셀 버퍼 내용을 복사 할 때까지 기다려야합니다. – MoDJ