objective c - How do I Extract Raw Audio from movie using QTKit -


i'm trying extract raw audio movie using qtkit can draw waveform. i'm using following code of output frames zero. ideas might doing wrong? (you can download project here: http://richcollins.net/audiosample.zip)

nserror *error;  qtmovie *movie = [qtmovie moviewithfile:[[nsbundle mainbundle] pathforresource:@"sosumi" oftype:@"aiff"] error:&error];  if(error) {     nslog(@"moviewithfile error: %@", [error localizeddescription]);     exit(1); }  osstatus err = noerr;  movieaudioextractionref extractionsessionref = nil; err = movieaudioextractionbegin([movie quicktimemovie], 0, &extractionsessionref);  audiostreambasicdescription asbd; err = movieaudioextractiongetproperty(extractionsessionref,                                       kqtpropertyclass_movieaudioextraction_audio,                                       kqtmovieaudioextractionaudiopropertyid_audiostreambasicdescription,                                       sizeof (asbd), &asbd, nil);  if (err) {     nslog(@"movieaudioextractiongetproperty error: %i", err);     exit(1); }  audiobufferlist *bufferlist = calloc(1, sizeof(audiobufferlist) + asbd.mchannelsperframe*sizeof(audiobuffer)); bufferlist->mnumberbuffers = asbd.mchannelsperframe;  qttime duration = [[movie attributeforkey:qtmoviedurationattribute] qttimevalue]; long long estimatedframecount = (long long)ceil(((double)duration.timevalue*asbd.msamplerate)/duration.timescale);  int i; (i = 0; < asbd.mchannelsperframe; ++) {     audiobuffer audiobuffer = bufferlist->mbuffers[i];     audiobuffer.mnumberchannels = 1;     audiobuffer.mdatabytesize = estimatedframecount*sizeof(float32);     audiobuffer.mdata = calloc(1, estimatedframecount*sizeof(float32));     bufferlist->mbuffers[i] = audiobuffer; }  uint32 numframes; uint32 flags; uint32 actualframecount = 0;  while (true) {     err = movieaudioextractionfillbuffer(extractionsessionref, &numframes, bufferlist, &flags);     if (err)     {         nslog(@"movieaudioextractionfillbuffer error: %i", err);         exit(1);     }     actualframecount += numframes;     if (flags & kqtmovieaudioextractioncomplete)     {         nslog(@"break");         break;     } }  (i = 0; < asbd.mchannelsperframe; ++) {     printf("channel %i\n", i);     float32 *frames = (float32 *)bufferlist->mbuffers[i].mdata;     int j;     (j = 0; j < actualframecount; j ++)     {         printf("%f,", frames[j]);     }     printf("\n"); }  err = movieaudioextractionend(extractionsessionref); if (err) {     nslog(@"movieaudioextractionend error: %i", err);     exit(1); } 

it turns out numframes has set before passing reference movieaudioextractionfillbuffer.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -