2011-06-21 24 views
2

我使用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]; 
} 
+0

我知道這是遲到了,這只是一個想法...也許你可以指定一個不同的壓縮(例如,與電影使用相同的壓縮),添加圖像時? – 2015-09-22 03:07:10

回答

1

雖然我用可可觸摸,但這仍然適用。我有兩個基於我寫影像的經驗的技巧。首先,雖然我敢打賭,addImage:forDuration會處理很多AVAssetExportSessions所沒有的功能,但我必須確保圖像的添加速度比每秒幾次還要多,否則它們不適合所有玩家。其次,如果有一個網絡流媒體選項,比如AVAssetExportSession shouldOptimizeForNetworkUse在電影中向前移動多少元數據和標題,我發現它使視頻與更多播放器兼容。

+0

不幸的是,使用不同的qttime,如QTMakeTime(1200,600)似乎不起作用。而不是顯示圖像的VLC播放器只是快速(在打開一個包含圖像的十分之一秒的新窗口之前)。 –