PDA

View Full Version : QTKit Question




run2thesun
Nov 3, 2005, 02:05 PM
Hi,

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!

-- Mel.



caveman_uk
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.

run2thesun
Nov 5, 2005, 12:47 PM
OK I just found the sample code on their website. Thanks a bunch!

run2thesun
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.

caveman_uk
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:

run2thesun
Nov 9, 2005, 10:29 AM
Damn! Now I have to learn the C API!

Anyways, thanks.

-- Mel.

kainjow
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];
long lIndex;
for (lIndex=1; lIndex<=GetMovieTrackCount(movie); lIndex++)
{
Track track = GetMovieIndTrack(movie, lIndex);
OSType dwType;
GetMediaHandlerDescription(GetTrackMedia(track), &dwType, NULL, NULL);
if (dwType != SoundMediaType)
{
SetTrackEnabled(track, false);
//DisposeMovieTrack(track);
//lIndex--;
}
}
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 :)

run2thesun
Nov 9, 2005, 12:38 PM
Hey,

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?

Thanks,

-- Mel.

run2thesun
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
doExportByDisablingTracks();

ComponentDescription description;
description.componentType = 'spit';
description.componentSubType = 'AIFF';
description.componentManufacturer = 'soun';
description.componentFlags = 0;
description.componentFlagsMask = 0;

Component c = FindNextComponent(0, &description);

MovieExportComponent exporter = OpenComponent(c);

QTAtomContainer atomSettings;
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)]
forKey:QTMovieExportSettings];

if (![qtMovie writeToFile:@"~/Movies/movie.aiff" withAttributes:settings])
NSLog(@"\nCould not save.\n");
}