我刚刚制作了一个简单的应用程序,它使用 QTKit 将两个视频合并在一起
这里是problem:
我刚刚发现,如果我尝试合并两个宽度和高度不同的视频,输出的视频的高度和宽度与大视频相同,但包含带有黑色和宽边框的小视频。
问题:
如何将两个视频合并在一起并获得具有正确格式(宽度/高度)的输出视频?
更好地理解我需要什么的示例:
我有两个视频:
视频 1 = 1920 x 1280
视频 2 = 1280 x 960
我想要的: 1920 x 1280 的视频(需要放大并裁剪小视频)
Code:
-(void)voidMethodToCombine {
NSError *err = nil;
QTMovie *myCombinedMovie = [[QTMovie alloc] initToWritableData:[NSMutableData data] error:&err];
if (err)
{
NSRunAlertPanel(@"Errore nella creazione del video",[err localizedDescription], nil, @"Chiudi", nil, nil);
return;
return;
}
// Create the File Open Dialog class.
NSSavePanel *savePanel = [NSSavePanel savePanel]; //Dove salvo il video ?
if ([savePanel runModal])//Se premo ok
{
[indicatore setUsesThreadedAnimation:YES];
[indicatore startAnimation:self];
NSURL *saveURL = savePanel.URL;
NSString *savePath = [saveURL path];
//Prelevo i 2 percorsi e gli inserisco negli array
NSString *video1 = [URLVideo1 stringValue];
NSString *video2 = [URLVideo2 stringValue];
NSURL *theURLvideo1 = [NSURL fileURLWithPath:video1];
NSURL *theURLvideo2 = [NSURL fileURLWithPath:video2];
if((theURLvideo1) && (theURLvideo2)) {
NSArray *myMovieURLs = [NSArray arrayWithObjects:theURLvideo1,theURLvideo2, nil];
for (NSURL *url in myMovieURLs)
{
QTMovie *theMovie = [QTMovie movieWithURL:url error:&err];
if (err){
NSRunAlertPanel(@"Errore durante il caricamento di uno dei film",[err localizedDescription], nil, @"Chiudi", nil, nil);
return;
}
QTTimeRange timeRange = QTMakeTimeRange(QTZeroTime, [theMovie duration]);
QTTime insertionTime = [myCombinedMovie duration];
[myCombinedMovie insertSegmentOfMovie:theMovie timeRange:timeRange atTime:insertionTime];
}
NSDictionary *writeAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], QTMovieFlatten, nil];
//Pannello di path salvataggio
bool success = [myCombinedMovie writeToFile:savePath withAttributes:writeAttributes error:&err];
[indicatore stopAnimation:self];
NSBeep();
NSString *dove = [[NSString alloc] initWithFormat:@"Video esportato in:\n%@",savePath];
NSRunAlertPanel(@"Esportazione avvenuta con successo!", dove, @"Ok", nil, nil);
if (!success)
{
NSRunAlertPanel(@"Errore durante il salvataggio del video.",[err localizedDescription], nil, @"Chiudi", nil, nil);
return;
return;
}
}
//Se non esiste alcun percorso
else {
NSRunAlertPanel(@"Impossibile selezionare i file.", @"Controlla di aver specificato un percorso.", @"Chiudi", nil, nil);
}