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; }

相关内容

热门资讯

微扑克wpk透视辅助!微扑克a... 微扑克wpk透视辅助!微扑克ai辅助会封号(透视)其实有挂是一款可以让一直输的玩家,快速成为一个“必...
wepower有外 挂!wep... wepower有外 挂!wepoke有机器人,wepoker好像真的有挂,微扑克教程(有挂揭秘);(...
我来教大家!哈灵棋牌有软件挂吗... 我来教大家!哈灵棋牌有软件挂吗(透明挂)一直是真的有挂(2026已更新)(哔哩哔哩)1、实时哈灵棋牌...
微扑克wpk透视辅助!德州微扑... 微扑克wpk透视辅助!德州微扑克外 挂是真的,微扑克辅助真的(原来真的是有挂)是一款可以让一直输的玩...
wepoke智能ai!wepo... wepoke智能ai!wepoke有机器人,WepoKe果然真的有挂,透明挂教程(有挂攻略)是一款可...
实测分享!胡乐麻将辅牌器怎么下... 您好,胡乐麻将辅牌器怎么下载这款游戏可以开挂的,确实是有挂的,需要了解加微【757446909】很多...
微扑克辅助器ios!微扑克到底... 微扑克辅助器ios!微扑克到底有辅助器,德州微扑克辅助透视(总是真的有挂)1、实时微扑克开挂更新:用...
2025新版教程!wepoke... 2025新版教程!wepoke真的(wepoke辅助插件)wEPOKE(一直真的有挂);(需添加指定...
推荐一款!永州扯胡子到底有没有... 推荐一款!永州扯胡子到底有没有外挂(透视辅助)原来是有挂(2021已更新)(哔哩哔哩)1、永州扯胡子...
微扑克全自动机器人!微扑克wp... 微扑克全自动机器人!微扑克wpk辅助存在,WPK一直存在有挂,黑科技教程(有挂实操)1、在微扑克ai...