Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

run2thesun

macrumors newbie
Original poster
Nov 3, 2005
9
0
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.
 

run2thesun

macrumors newbie
Original poster
Nov 3, 2005
9
0
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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
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:
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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:

Code:
// 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

macrumors newbie
Original poster
Nov 3, 2005
9
0
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

macrumors newbie
Original poster
Nov 3, 2005
9
0
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:mad:"~/Movies/movie.aiff" withAttributes:settings])
NSLog(@"\nCould not save.\n");
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.