0

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.

russellaugust
  • 358
  • 3
  • 17

1 Answers1

1

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;
}
russellaugust
  • 358
  • 3
  • 17
user1118321
  • 25,567
  • 4
  • 55
  • 86
  • Thanks! I've been spending some time trying to get this to work, and I'm not entirely clear on the syntax for it. I've called formatDescriptions from AVAssetTrack and it returns an array, but I'm not sure how to place the appropriate "CMTimeCodeFormatDescriptionRef desc" into the CMTimeCodeFormatDescriptionGetTimeCodeFlags(). Would you mind providing an example? – russellaugust Aug 29 '12 at 16:03
  • This looks like it might be it! The only change I had to make was casting the [descriptionEnum nextObject] as (CMFormatDescriptionRef). And one spelling error... I'll revise the answer. – russellaugust Sep 04 '12 at 20:26
  • Great! Glad I could help! If it worked, please check the green check on the right. :-) – user1118321 Sep 05 '12 at 02:27
  • How is it possible that I have 23.976 fps defined as `frameDuration: {1001/24000 = 0.042}` I think that should be dropframe. But `tcFlags: 2` that mean `timecodeFlags & kCMTimeCodeFlag_DropFrame` returns `nil` – JaSHin Dec 15 '21 at 09:33