View Full Version : QTKit Question
Nov 3, 2005, 02:05 PM
I'm using QTKit in Objective-C with Cocoa. I'm trying to open a video file and save only the sound from the file to a seperate file. I was wondering if anyone knows how to do this? Thanks!
Nov 4, 2005, 03:06 AM
Have you checked the sample code on the Apple developer site? They have quite a few examples of doing this sort of thing.
Nov 5, 2005, 12:47 PM
OK I just found the sample code on their website. Thanks a bunch!
Nov 7, 2005, 01:42 PM
I looked at the code samples and there seem to be a few audio exraction examples but they all use the QuickTime C APIs. Is there any way to extract audio from movies using QTKit? Thanks.
Nov 7, 2005, 04:35 PM
Until recently the support for quicktime in Cocoa was pretty rubbish. If it's not in the recent source code examples then you're stuck searching the documentation or playing with the C API.:eek:
Nov 9, 2005, 10:29 AM
Damn! Now I have to learn the C API!
Nov 9, 2005, 10:40 AM
Here's some code that disables all non-audio tracks of a QuickTime movie. It works for me but I don't use the QTKit... so with your QTMovie object, just call quickTimeMovie on it to return a native Movie object:
// disables any non-audio tracks in the movie
Movie movie = [qtMovie quickTimeMovie];
for (lIndex=1; lIndex<=GetMovieTrackCount(movie); lIndex++)
Track track = GetMovieIndTrack(movie, lIndex);
GetMediaHandlerDescription(GetTrackMedia(track), &dwType, NULL, NULL);
if (dwType != SoundMediaType)
At the end, your QTMovie object should be changed, and you can export it now (although I haven't tested this). The disabled tracks shouldn't export.. If they still do, you can uncomment the lines above, and it will get rid of the tracks from the movie...
Let me know if it helps :)
Nov 9, 2005, 12:38 PM
This code seems to work since if the movie is playing in a QTMovieView, the video stops playing after I executed this code. So once I get the audio track, how can I export it to a file in AIFF format?
Nov 14, 2005, 12:15 PM
OK, I'm trying to used this code to export the movie to an audio file but it doesn't work. I would really appreciate some help with this. Thanks.
// The following line disables non-audio tracks
description.componentType = 'spit';
description.componentSubType = 'AIFF';
description.componentManufacturer = 'soun';
description.componentFlags = 0;
description.componentFlagsMask = 0;
Component c = FindNextComponent(0, &description);
MovieExportComponent exporter = OpenComponent(c);
ComponentResult err = MovieExportGetSettingsAsAtomContainer (exporter, &atomSettings);
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings setObject:[NSNumber numberWithBool:YES] forKey:QTMovieExport];
[settings setObject:[NSNumber numberWithLong:kQTFileTypeAIFF] forKey:QTMovieExportType];
[settings setObject:[NSNumber numberWithLong:SoundMediaType] forKey:QTMovieExportManufacturer];
[settings setObject:[NSData dataWithBytes:*atomSettings length:GetHandleSize(atomSettings)]
if (![qtMovie writeToFile:@"~/Movies/movie.aiff" withAttributes:settings])
NSLog(@"\nCould not save.\n");