小编adi*_*225的帖子

AVFoundation将第一帧添加到视频

我试图控制由我的应用程序制作的视频在iOS上的“照片”应用程序中的显示方式。我制作的所有视频均以黑框开始,然后事物淡入淡出,依此类推。将这些保存到“照片”后,Apple会获取第一帧(黑色正方形)并将其用作“照片”中的缩略图。我想更改此设置,以便我可以设置自己的缩略图以使人们轻松识别视频。

由于找不到与此相关的内置API,因此我试图通过添加作为视频第一帧生成的缩略图来对其进行破解。我正在尝试为此使用AVFoundation,但遇到了一些问题。

我的代码抛出以下错误:[AVAssetReaderTrackOutput copyNextSampleBuffer] cannot copy next sample buffer before adding this output to an instance of AVAssetReader (using -addOutput:) and calling -startReading on that asset reader',尽管调用了该方法。

这是我的代码:

AVAsset *asset = [[AVURLAsset alloc] initWithURL:fileUrl options:nil];
UIImage *frame = [self generateThumbnail:asset];

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:640], AVVideoWidthKey,
                               [NSNumber numberWithInt:360], AVVideoHeightKey,
                               nil];

AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:asset error:nil];
AVAssetReaderOutput *readerOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[asset.tracks firstObject]
                                                                               outputSettings:nil];
[assetReader addOutput:readerOutput];

AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:path
                                                       fileType:AVFileTypeMPEG4
                                                          error:nil];
NSParameterAssert(videoWriter); …
Run Code Online (Sandbox Code Playgroud)

objective-c avfoundation ios

4
推荐指数
1
解决办法
933
查看次数

标签 统计

avfoundation ×1

ios ×1

objective-c ×1