我正在使用 QTCaptureSession 从 iSight 摄像头录制视频。
我想在视频末尾添加图像,因此我实现了 didFinishRecordingToOutputFileAtURL 委托(delegate)方法。这是我到目前为止所做的:
- (void)captureOutput:(QTCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL forConnections:(NSArray *)connections dueToError:(NSError *)error
{
// Prepare final video
QTMovie *originalMovie = [QTMovie movieWithURL:outputFileURL error:nil];
[originalMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
NSImage *splashScreen = [NSImage imageNamed:@"video-ending.jpg"];
NSImage *tiffImage = [[NSImage alloc] initWithData:[splashScreen TIFFRepresentation]];
id attr = [NSDictionary dictionaryWithObjectsAndKeys:@"tiff",
QTAddImageCodecType,
[NSNumber numberWithLong:codecHighQuality], QTAddImageCodecQuality,
nil];
[originalMovie addImage:tiffImage forDuration:QTMakeTime(2, 1) withAttributes:attr];
[tiffImage release];
[originalMovie updateMovieFile];
}
这段代码的问题是,虽然 Quicktime 播放得很好,但其他播放器却不然。我确信我在这里遗漏了一些基本的东西。
在保存视频之前将图像添加到视频中也很酷(以避免两次保存)。以下是我现在停止录制的方法:
- (void)stopRecording
{
// It would be cool to add an image here
[mCaptureMovieFileOutput recordToOutputFileURL:nil];
}
最佳答案
虽然我使用了 Cocoa touch,但这可能仍然适用。根据我将图像写入电影的经验,我有两个技巧。首先,虽然我敢打赌 addImage:forDuration 会处理 AVAssetExportSessions 不会处理的很多事情,但我必须确保图像添加的频率高于每秒几次,否则它们无法与所有玩家一起正常工作。其次,如果有一个网络流选项,例如 AVAssetExportSession shouldOptimizeForNetworkUse
来在电影中向前移动尽可能多的元数据和标题,我发现它也使视频与更多播放器兼容。
关于objective-c - cocoa 在视频末尾添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6424737/