Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Capturing live audio from camera and adding to qtmovie



The basic problem is I need to create a QTMovie instantly from the camera which I hold in memory and can play back...

With the new QTKit api I can easily get the image and create a live qtvideo...
- (CIImage *)view:(QTCaptureView *)view willDisplayImage:(CIImage *)ciImage
{
...
[current_movie addImage:image forDuration:current_time withAttributes: [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg", QTAddImageCodecType, [NSNumber numberWithLong:codecMinQuality] ,QTAddImageCodecQuality ,nil]]; // this is on the main thread.
}


You could also use the QTCaptureDecompressedVideoOutput delegates

The problem is how do I get the audio feed from the camera and add it to the qtmovie (current_movie) I am creating....
QTCaptureAudioPreviewOutput does not seem to have any useful information besides GUI type stuff
My only option seems to get it from the compressed recording file delegate with something like this...


-(void)startRecording
{
...
Track soundTrack = NewMovieTrack ([current_movie quickTimeMovie], FixRatio (0, 1), FixRatio(0, 1), kFullVolume);
Handle dataRef = NULL;
Handle hMovieData = NewHandle (0);
OSStatus err = PtrToHand (&hMovieData, &dataRef, sizeof(Handle));
Media soundMedia = NewTrackMedia (soundTrack, SoundMediaType, GetMovieTimeScale([current_movie quickTimeMovie]), dataRef, HandleDataHandlerSubType);
InsertMediaIntoTrack (soundTrack, 0, 0, [current_movie duration].timeValue, fixed1);
sound_track = [QTTrack trackWithQuickTimeTrack: soundTrack error: &error];
...
}


- (void)captureOutput:(QTCaptureFileOutput *)captureOutput didOutputSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection: (QTCaptureConnection *)connection
if ([[connection formatDescription] mediaType]==QTMediaTypeSound)){
AudioStreamBasicDescription asbd = {0};
[[[sampleBuffer formatDescription] attributeForKey:QTFormatDescriptionAudioStreamBasicDescriptionAttribute ] getValue:&asbd];
long asbd_size = sizeof(AudioStreamBasicDescription);
// AudioChannelLayout *channelLayout = (AudioChannelLayout *) [[[sampleBuffer formatDescriptionNewHandle(<#Size byteCount#>)teForKey:QTFormatDescriptionAudioChannelLayoutAttribute] bytes];


SoundDescriptionHandle sdh=(SoundDescriptionHandle)NewHandle(0);
OSStatus err = QTSoundDescriptionCreate(&asbd,NULL,0,NULL, 0,kQTSoundDescriptionKind_Movie_LowestPossibleVersion,&sdh);
BeginMediaEdits([[sound_track media] quickTimeMedia]);
AddMediaSample2([[sound_track media] quickTimeMedia], // the Media
(UInt8 *)[sampleBuffer bytesForAllSamples], // const UInt8 * dataIn
[sampleBuffer lengthForAllSamples], // ByteCount size
1, // TimeValue64 decodeDurationPerSample
GetMediaDuration([[sound_track media] quickTimeMedia]), // TimeValue64 displayOffset
(SampleDescriptionHandle)sdh, // SampleDescriptionHandle sampleDescriptionH
[sampleBuffer numberOfSamples], // ItemCount numberOfSamples
0, // MediaSampleFlags sampleFlags. mediaSampleNotSync
NULL ); // TimeValue64 * sampleDecodeTimeOut
EndMediaEdits([[sound_track media] quickTimeMedia]);
}


Which all seems rather complex and involved (with a lot of guess work) as I am mixing old quicktime routines with the new API. I realise there will be background thread issues which the above code. I am not sure even that the new audio data will be playable instantly.

My question is what is the easiest/best way to add the audio to the video frames I create with the QTMovie's addImage method I get from the camera.

Thanks in advanced for any help
Simon

_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.