1. <small id='NiiCp'></small><noframes id='NiiCp'>

      <tfoot id='NiiCp'></tfoot>
        <legend id='NiiCp'><style id='NiiCp'><dir id='NiiCp'><q id='NiiCp'></q></dir></style></legend>
        • <bdo id='NiiCp'></bdo><ul id='NiiCp'></ul>
        <i id='NiiCp'><tr id='NiiCp'><dt id='NiiCp'><q id='NiiCp'><span id='NiiCp'><b id='NiiCp'><form id='NiiCp'><ins id='NiiCp'></ins><ul id='NiiCp'></ul><sub id='NiiCp'></sub></form><legend id='NiiCp'></legend><bdo id='NiiCp'><pre id='NiiCp'><center id='NiiCp'></center></pre></bdo></b><th id='NiiCp'></th></span></q></dt></tr></i><div id='NiiCp'><tfoot id='NiiCp'></tfoot><dl id='NiiCp'><fieldset id='NiiCp'></fieldset></dl></div>
      1. 从 AVAssetReaderOutput 读取数据时,iOS 5.0 崩溃

        时间:2023-06-01
          <tbody id='KY2jK'></tbody>
            <bdo id='KY2jK'></bdo><ul id='KY2jK'></ul>
              <tfoot id='KY2jK'></tfoot>
              <i id='KY2jK'><tr id='KY2jK'><dt id='KY2jK'><q id='KY2jK'><span id='KY2jK'><b id='KY2jK'><form id='KY2jK'><ins id='KY2jK'></ins><ul id='KY2jK'></ul><sub id='KY2jK'></sub></form><legend id='KY2jK'></legend><bdo id='KY2jK'><pre id='KY2jK'><center id='KY2jK'></center></pre></bdo></b><th id='KY2jK'></th></span></q></dt></tr></i><div id='KY2jK'><tfoot id='KY2jK'></tfoot><dl id='KY2jK'><fieldset id='KY2jK'></fieldset></dl></div>

              <small id='KY2jK'></small><noframes id='KY2jK'>

              <legend id='KY2jK'><style id='KY2jK'><dir id='KY2jK'><q id='KY2jK'></q></dir></style></legend>

                1. 本文介绍了从 AVAssetReaderOutput 读取数据时,iOS 5.0 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有这段用于从 AVAssetReaderOutput 读取数据的代码片段,该方法在 iOS 4.0 中运行良好,但在 5.0 中它会因访问错误而崩溃,不知道为什么,任何人都有有什么意见吗?

                  I have this snippet of code used to read data from an AVAssetReaderOutput, the method works fine in iOS 4.0, however in 5.0 it crashes towards the end with bad access, not sure why, anyone have any input?

                  AVAssetReaderOutput *output=[myOutputs objectAtIndex:0];
                   int totalBuff=0;
                  while(TRUE)
                  {
                       CMSampleBufferRef ref=[output copyNextSampleBuffer];
                      if(ref==NULL)
                          break;
                      //copy data to file
                      //read next one
                      AudioBufferList audioBufferList;
                      NSMutableData *data=[[NSMutableData alloc] init];
                      CMBlockBufferRef blockBuffer;
                      CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
                  
                  for( int y=0; y<audioBufferList.mNumberBuffers; y++ )
                  {
                      AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
                      Float32 *frame = audioBuffer.mData;
                  
                  
                      NSLog(@"Gonna write %d", audioBuffer.mDataByteSize);
                      //crashes here
                      [data appendBytes:frame length:audioBuffer.mDataByteSize];
                  
                  
                  
                  }
                  
                  totalBuff++;
                  CFRelease(blockBuffer);
                  CFRelease(ref);
                  
                  
                     [fileHandle writeData:data];
                      [data release];
                  }
                  

                  谢谢

                  丹尼尔

                  推荐答案

                  我实际上是通过检查 blockBuffer 是否为 null 来解决这个问题,如果是则继续,问题是 ref 不是 null 但 blockBuffer 是所以这段代码修复了我的问题

                  I actually fixed this by checking that blockBuffer was null and continuing if it was, the problem was that ref was not null but the blockBuffer was so this code fixed my issue

                  -(void)doExportSong:(NSURL*)url toFileUrl:(NSString*)fileURL 
                  {
                      AVURLAsset *asset=[[[AVURLAsset alloc] initWithURL:url options:nil] autorelease];
                      AVAssetReader *reader=[[[AVAssetReader alloc] initWithAsset:asset error:nil] autorelease];
                      [reader setTimeRange:CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity)];
                      NSMutableArray *myOutputs =[[NSMutableArray alloc] init];
                      for(id track in [asset tracks])
                      {
                          AVAssetReaderTrackOutput *ot=[AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track outputSettings:nil];
                  
                          [myOutputs addObject:ot]; 
                          [reader addOutput:ot];
                      }
                      [reader startReading];
                      NSFileHandle *fileHandle ;
                      NSFileManager *fm=[NSFileManager defaultManager];
                      if(![fm fileExistsAtPath:fileURL])
                      {
                          [fm createFileAtPath:fileURL contents:[[[NSData alloc] init] autorelease] attributes:nil];
                      }
                      fileHandle=[NSFileHandle fileHandleForUpdatingAtPath:fileURL];    
                      [fileHandle seekToEndOfFile];
                  
                      AVAssetReaderOutput *output=[myOutputs objectAtIndex:0];
                  
                      int totalBuff=0;
                      BOOL one=TRUE;
                      while(TRUE)
                      {
                          CMSampleBufferRef ref=[output copyNextSampleBuffer];
                          // NSLog(@"%@",ref);
                          if(ref==NULL)
                              break;
                          //copy data to file
                          //read next one
                          AudioBufferList audioBufferList;
                          NSMutableData *data=[[NSMutableData alloc] init];
                          CMBlockBufferRef blockBuffer;
                          CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
                          // NSLog(@"%@",blockBuffer);
                  
                          if(blockBuffer==NULL)
                          {
                  
                                  [data release];
                                  continue;
                  
                          }
                          if(&audioBufferList==NULL)
                          {
                              [data release];
                              continue;
                          }
                  
                          for( int y=0; y<audioBufferList.mNumberBuffers; y++ )
                          {
                              AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
                              Float32 *frame = (Float32*)audioBuffer.mData;
                  
                  
                              [data appendBytes:frame length:audioBuffer.mDataByteSize];
                  
                  
                  
                          }
                  
                          totalBuff++;
                  
                          CFRelease(blockBuffer);
                          CFRelease(ref);
                          ref=NULL;
                          blockBuffer=NULL;
                          [fileHandle writeData:data];
                          [data release];
                      }
                  
                      [fileHandle closeFile];
                      [myOutputs release];  
                  }
                  

                  这篇关于从 AVAssetReaderOutput 读取数据时,iOS 5.0 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:实现 iOS Maps 风格的页面卷曲手势交互 下一篇:Apple 触摸图标未显示在主屏幕上

                  相关文章

                  最新文章

                      • <bdo id='iH8K1'></bdo><ul id='iH8K1'></ul>

                      <small id='iH8K1'></small><noframes id='iH8K1'>

                      <tfoot id='iH8K1'></tfoot>
                    1. <i id='iH8K1'><tr id='iH8K1'><dt id='iH8K1'><q id='iH8K1'><span id='iH8K1'><b id='iH8K1'><form id='iH8K1'><ins id='iH8K1'></ins><ul id='iH8K1'></ul><sub id='iH8K1'></sub></form><legend id='iH8K1'></legend><bdo id='iH8K1'><pre id='iH8K1'><center id='iH8K1'></center></pre></bdo></b><th id='iH8K1'></th></span></q></dt></tr></i><div id='iH8K1'><tfoot id='iH8K1'></tfoot><dl id='iH8K1'><fieldset id='iH8K1'></fieldset></dl></div>
                    2. <legend id='iH8K1'><style id='iH8K1'><dir id='iH8K1'><q id='iH8K1'></q></dir></style></legend>