I have just made a simple app which uses QTKit to merge two videos together
Here is the problem:
I have just discovered that if I try to merge two videos with different width & height the output is a video whose height and width is the same of the big video but contains the small one with black and wide borders.
Question:
How can i merge two videos together and get an output video with a correct format (width/height) ?
Example to understand better what i need:
I have two videos:
Video 1 = 1920 x 1280 VIdeo 2 = 1280 x 960
What i want: A video in 1920 x 1280 (Need to up-scale and crop the small one)
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);
}