How to retrieve fourCC code from a video track in Quicktime, i.e. mov, file

After introduction of QTKit, I use more and more QTKit classes and methods to manipulate QuickTime movie file. However, there are still some, actually many, part of QuickTime movie file which can’t be accessed or controlled using the QTKit.

Recently I had to figure out FourCC code, which is a identifier for a codec used in a video track. Using QTTrack’s attribute, you can retrieve human-readable codec name used to encode the video track. However, you sometimes need to retrieve its FourCC code. Any QTKit class or its methods can’t support it.
Then, it is time to use QuickTime API functions.

I will pick QuickTime documents if people ask me to pick one which is the most poorly written among many Apple documents. It is pretty hard to figure out how different structures and functions are related one another from the documents.
For example, where the FourCC is saved? What structure should be asked to get the information?

So, I had to use dumpster, i.e. QuickTime tool which shows header information of movie files, and found out how to retrieve the information.

Here is the source code.

//  QTMovie_Extension.h
//  MovieCodec
//  Created by JongAm Park on 8/7/09.


@interface QTMovie (JAExtension)

- (NSString *)videoCodecFourCC;

//  QTMovie_Extension.m
//  MovieCodec
//  Created by JongAm Park on 8/7/09.

#import "QTMovie_Extension.h"

@implementation QTMovie (JAExtension)
- (NSString *)videoCodecFourCC
	QTTrack *track;
	NSDictionary *trackAttribute;
	NSString *trackType;
	BOOL isVideoTrack = NO;
	char codecType[5];
	OSType codecTypeNum;
	NSString *codecTypeString = nil;
	NSArray *tracksArray = [self tracks];
	int i, tracks = [tracksArray count];
	OSErr mediaSampleError = noErr;
	long descriptionCount;
	for (i=0; i 0 )
				GetMediaSampleDescription([videoMedia quickTimeMedia], 1, videoTrackDescH );
				mediaSampleError = GetMoviesError();
				NSLog(@"depth : %d",(*(ImageDescriptionHandle)videoTrackDescH)->depth );
				NSLog(@"width : %d",(*(ImageDescriptionHandle)videoTrackDescH)->width );
				NSLog(@"height : %d",(*(ImageDescriptionHandle)videoTrackDescH)->height );
				NSLog(@"name : %s",(*(ImageDescriptionHandle)videoTrackDescH)->name );
				NSLog(@"codec : %d",(*(ImageDescriptionHandle)videoTrackDescH)->cType ); 
				bzero(codecType, 5);			
				memcpy((void *)&codecTypeNum, (const void *)&((*(ImageDescriptionHandle)videoTrackDescH)->cType), 4);
				codecTypeNum = EndianU32_LtoB( codecTypeNum );
				memcpy(codecType, (const void*)&codecTypeNum, 4);
				NSLog(@" == %s", codecType );
				codecTypeString = [NSString stringWithFormat:@"%s", codecType];
				codecTypeString = [NSString stringWithFormat:@"Can't detect FourCC code"];
	return codecTypeString;


The code above also shows how to retrieve width, height, depth information as well as human readable codec name as name.

Because this information is retrieved from track, not movie, it is better to put the code as QTTrack’s class as category. ( Hey. I love Objective-C due to this. Without inheriting, I can add a method to existing class! )
And.. if a method to call the QTTrack’s method is put in QTMovie, it would be very nice.

However, in the source code above, I just put it in QTMovie directly because the QTMovie seems to be a convenient ‘gate’ class for Objective-C programmers and I, anyway, will access things with a pointer to QTMovie instance.

UPDATE : I just found out that this didn’t work with XDCAM clips. Although dumpster shows correct values,GetMediaSampleDescription() didn’t return correct address which contained proper information. I will figure out why and how to solve it.

UPDATE : The source code above is updated to handle the SampleDescription properly.

One response to this post.

  1. Thank you very much for the nice information! Helped me a lot!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: