QTKit Question

Discussion in 'Mac Programming' started by run2thesun, Nov 3, 2005.

  1. macrumors newbie

    Joined:
    Nov 3, 2005
    #1
    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.
     
  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    Have you checked the sample code on the Apple developer site? They have quite a few examples of doing this sort of thing.
     
  3. thread starter macrumors newbie

    Joined:
    Nov 3, 2005
    #3
    OK I just found the sample code on their website. Thanks a bunch!
     
  4. thread starter macrumors newbie

    Joined:
    Nov 3, 2005
    #4
    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.
     
  5. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #5
    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:
     
  6. thread starter macrumors newbie

    Joined:
    Nov 3, 2005
    #6
    Damn! Now I have to learn the C API!

    Anyways, thanks.

    -- Mel.
     
  7. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #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 :)
     
  8. thread starter macrumors newbie

    Joined:
    Nov 3, 2005
    #8
    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.
     
  9. thread starter macrumors newbie

    Joined:
    Nov 3, 2005
    #9
    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");
    }
     

Share This Page