我使用QTCaptureSession從iSight攝像頭錄製視頻。Cocoa在視頻結尾處添加圖像
我想在視頻的最後添加一個圖片,所以我實現了didFinishRecordingToOutputFileAtURL委託方法。這是我到目前爲止已經完成:
- (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];
}
我知道這是遲到了,這只是一個想法...也許你可以指定一個不同的壓縮(例如,與電影使用相同的壓縮),添加圖像時? – 2015-09-22 03:07:10