Search code examples
objective-cmacoscocoaqtkit

QTMovie addImage:forDuration:withAttributes: can't be played by QuickTime Player X


I have a mov file, that I am modifying by adding a track with an image to the beginning of the movie (using QTMovie's -addImage method). When I flatten such a movie (using -writeToFile: method of QTMovie), I get an another .mov file with this "watermark" in the beginning. But when I try to play it, I end up with the message that QuickTime 7 needs to be installed in order to play such a file (original not-processed mov file didn't require QuickTime Player 7 and could be played fine in QT Player X which comes with Snow Leopard and Lion).

I am wondering whether it is possible to make this file be able to be played on QuickTime Player X? I wouldn't like the users of my application to be obliged to install this old version of the player. Furthermore, some applications like Final Cut Pro 7, Telestream Episode Engine encoder, Autodesk Smoke - just do not understand this "file format" correctly, after adding an image track to it.

Would it be possible to add an image as a movie track, not as an image track, somehow? Maybe using an old QT API? (QTKit seems to be raw still, anyway).

I am specifying "mpv4" as an image encoder (in the -addImage method), but still this watermark image is not considered as a movie track but rather as an image track encoded with the movie encoder.

Thank you!


Solution

  • Make a new movie and set the attribute to allow editing:

    QTMovie* trailerMovie = [QTMovie movie];
    [trailerMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
    

    Select the time ranges in the original movie and append them to the new one:

    QTTimeRange selectionRange = QTMakeTimeRange(QTMakeTime(...), QTMakeTime(...));
    [originalMovie setSelection:selectionRange];
    [trailerMovie appendSelectionFromMovie:originalMovie];
    

    Add images:

    [trailerMovie addImage:image forDuration:duration withAttributes:nil];
    

    Save the movie to a file with QTMovieFlatten attribute:

    [trailerMovie writeToFile:@"trailer.mov" withAttributes:[NSDictionary dictionaryWithObj:[NSNumber numberWithBool:YES] forKey:QTMovieFlatten]]
    

    Try this scenario, please let me know how it went.