Search code examples
objective-ccocoaavfoundationquicktime

Determine if a video file is NDF or DF (Drop Frame or Non-Drop Frame)


I need to find whether a movie is Drop Frame or Non-Drop Frame.

I'm trying to find it in the attributes for a video file in one of the xcode video frameworks (either QTMovie or something from AVFoundation). Not having much luck.

I'm doing this to fill in necessary information in an FCP-X XML file.

Does anyone have any experience with this?

Important note, I am working in a 64 bit environment, and must stay there.


Solution

  • You can use CMTimeCodeFormatDescriptionGetTimeCodeFlags() to get the time code flags for a given timecode format description ref. You can get the format description ref by asking an AVAssetTrack for its formatDescriptions.

    I think it would look something like this:

    BOOL isDropFrame (AVAssetTrack* track)
    {
        BOOL result = NO;
        NSArray* descriptions = [track formatDescriptions];
        NSEnumerator* descriptionEnum = [descriptions objectEnumerator];
        CMFormatDescriptionRef nextDescription;
        while ((!result) && ((nextDescription = (CMFormatDescriptionRef)[descriptionEnum nextObject]) != nil))
        {
            if (CMFormatDescriptionGetMediaType(nextDescription) == kCMMediaType_TimeCode)
            {
                uint32_t timeCodeFlags = CMTimeCodeFormatDescriptionGetTimeCodeFlags ((CMTimeCodeFormatDescriptionRef)nextDescription);
                result = ((timeCodeFlags & kCMTimeCodeFlag_DropFrame) != 0);
            }
        }
        return result;
    }