I'm currently using AVAssetWriter
to generate a Quicktime mov. The video track is generated correctly. Now I'd like to add a "garbage" mp4a audio track. The audio can just be white noise. What I'm mainly concerned with is the mov file containing both video and audio tracks.
How do I setup a CMSampleBufferRef
that just contains white noise in mp4a format? Here's what I've tried so far:
CMSampleBufferRef garbageAudioSampleBuffer = NULL;
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = 4;
audioFormat.mBytesPerFrame = 4;
CMAudioFormatDescriptionRef audioFormatDescrip = NULL;
CMAudioFormatDescriptionCreate(kCFAllocatorDefault,
&audioFormat,
0,
NULL,
0,
NULL,
NULL,
&audioFormatDescrip
);
CMSampleBufferCreate(kCFAllocatorDefault,
NULL,
YES,
NULL,
NULL,
NULL, // audioFormatDescrip,
0,
0,
NULL,
0,
NULL,
&garbageAudioSampleBuffer
);
if(myAVAssetAudioWriterInput isReadyForMoreMediaData)
[myAVAssetAudioWriterInput appendSampleBuffer:garbageAudioSampleBuffer];
When NULL
is passed for the audioFormatDescrip the mov file is generated successfully but contains only a video track (and no audio track). When I actually pass audioFormatDescrip the mov file seems to be corrupted. I probably have to actually pass some samples but I'm not sure how.
Note: I've verified that appendSampleBuffer
returns YES
(for brevity I omitted that code).