AVAssetWriterInput-CapturedAudio缺少足够的视频帧。
创始人
2024-11-12 20:30:19
0

在输入视频帧之前,为AVAssetWriterInput添加一个空的CMSampleBuffer,以确保捕获的音频数据和视频帧都能与完整的持续时间对应。

示例代码:

//定义一些变量 AVAssetWriterInput *videoInput; AVAssetWriterInput *audioInput; AVAssetWriter *writer; CMTime videoTime; CMSampleBufferRef emptySampleBuffer; CMTime audioStartTime; CMTime videoStartTime;

//初始化AVAssetWriter和输入流 //...

//为videoInput设置一个初始时间戳 videoStartTime = CMTimeMake(0, videoTrack.naturalTimeScale); [videoInput setMediaTimeScale:videoTrack.naturalTimeScale]; [videoInput setMediaTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)]; [writer startWriting]; [writer startSessionAtSourceTime:videoStartTime];

//添加一个空的CMSampleBuffer //该样本缓冲区保证视频帧和音频数据都能与持续时间相对应 emptySampleBuffer = [self createEmptySampleBufferForAudioTrack:audioTrack atTime:audioStartTime]; if ([audioInput isReadyForMoreMediaData]) { [audioInput appendSampleBuffer:emptySampleBuffer]; }

//添加视频帧和音频数据 //...

//创建一个空的CMSampleBuffer

  • (CMSampleBufferRef)createEmptySampleBufferForAudioTrack:(AVAssetTrack *)audioTrack atTime:(CMTime)time { CMSampleBufferRef sampleBuffer = NULL; CMBlockBufferRef blockBuffer = NULL;

    OSStatus status = CMBlockBufferCreateEmpty(kCFAllocatorDefault, 0, kCMBlockBufferAssureMemoryNowFlag, &blockBuffer); if (status != noErr) { NSLog(@"Error creating empty CMSampleBuffer for audio: %d", status); return NULL; }

    AudioStreamBasicDescription audioFormat = *(audioTrack.formatDescriptions[0]); CMSampleTimingInfo timingInfo = {.duration = kCMTimeInvalid, .presentationTimeStamp = time, .decodeTimeStamp = kCMTimeInvalid};

    CMSampleBufferCreate(kCFAllocatorDefault, blockBuffer, true, NULL, NULL, audioTrack.formatDescriptionsCount, 1, &timingInfo, 0, NULL, &sampleBuffer); CFRelease(blockBuffer);

    return sampleBuffer; }

相关内容

热门资讯

透视最新!aapoker俱乐部... 透视最新!aapoker俱乐部靠谱吗(透视)透视脚本下载(本来有挂)1、打开软件启动之后找到中间准星...
透视安卓版!德普之星的辅助工具... 透视安卓版!德普之星的辅助工具介绍(透视)透视辅助软件下载(总是是真的有挂)1、德普之星的辅助工具介...
透视规律!aapoker怎么选... 透视规律!aapoker怎么选牌(透视)真的假的(总是是真的有挂)1)aapoker怎么选牌辅助挂:...
透视了解!德普之星怎么开辅助(... 透视了解!德普之星怎么开辅助(透视)的辅助工具介绍(果然是真的有挂)1、全新机制【德普之星怎么开辅助...
透视数据!aa poker辅助... 透视数据!aa poker辅助(透视)插件下载(总是有挂);1、进入游戏-大厅左侧-新手福利-激活码...
透视免费!德普之星私人局透视(... 透视免费!德普之星私人局透视(透视)透视辅助软件(真是存在有挂)1、每一步都需要思考,不同水平的挑战...
透视游戏!aapoker免费透... 透视游戏!aapoker免费透视脚本(透视)透视方法(好像是有挂)1、任何aapoker免费透视脚本...
透视数据!德普之星透视软件免费... 透视数据!德普之星透视软件免费入口官网(透视)私人局辅助器(都是有挂)德普之星透视软件免费入口官网辅...
透视新版!aapoker怎么设... 透视新版!aapoker怎么设置抽水(透视)真的假的(其实有挂)1.aapoker怎么设置抽水 ai...
透视新版!德普之星透视辅助(透... 透视新版!德普之星透视辅助(透视)透视挂(都是是有挂)1、完成德普之星透视辅助的残局,帮助玩家取得所...