gpt4 book ai didi

iphone - AVAssetReader 读取视频样本的基本问题

转载 作者:可可西里 更新时间:2023-11-01 03:42:48 26 4
gpt4 key购买 nike

我想通过 AVAssetReader 阅读视频样本,但遇到了各种障碍。一些帖子代码可以从应用程序包中名为“Movie.m4v”的视频设置 AVAsset 并使用 AVAssetReader 循环播放视频帧 (CMSampleBufferRef)。

这是我现在使用的一些代码不起作用:

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Movie.m4v"];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:path] options:nil];
NSError *error = nil;
AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:avAsset error:&error]; // crashing right around here!

// I've gotten avassetreader to not crash upon initialization by grabbing an asset from the ALAssetsLibrary but it says it has 0 tracks!

NSArray *videoTracks = [avAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
AVAssetReaderTrackOutput *asset_reader_output = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:options];
[reader addOutput:asset_reader_output];
[reader startReading];

CMSampleBufferRef buffer;
while ( [reader status]==AVAssetReaderStatusReading ){

buffer = [asset_reader_output copyNextSampleBuffer];
NSLog(@"READING");



}

最佳答案

很可能因为 [NSURL URLWithString:path] 而崩溃。您应该改用 [NSURL fileURLWithPath:path]

关于iphone - AVAssetReader 读取视频样本的基本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6421170/

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