ios - Performance issues with AVAssetWriterInput (audio) and single-core devices -


i'm having strange performance issue avassetwriterinput on single-core devices iphone 3gs , iphone 4. basically, have avassetwriter 2 avassetwriterinputs, 1 video , 1 audio. roughly, looks like:

avassetwriter * assetwriter = [[avassetwriter alloc] initwithurl:videourl                                                         filetype:avfiletypempeg4                                                            error:&error]; videowriterinput = [avassetwriterinput assetwriterinputwithmediatype:avmediatypevideo                                                       outputsettings:videosettings];  videowriterinput.expectsmediadatainrealtime = yes;  nsdictionary * audiosettings = [nsdictionary dictionarywithobjectsandkeys:                                     [nsnumber numberwithint:kaudioformatmpeg4aac],      avformatidkey,                                     [nsnumber numberwithint:64000],                     avencoderbitratekey,                                     [nsnumber numberwithint:2],                         avnumberofchannelskey,                                     [nsnumber numberwithint:44100],                     avsampleratekey,                                     currentchannellayoutdata,                           avchannellayoutkey,                                     nil]; audiowriterinput = [avassetwriterinput assetwriterinputwithmediatype:avmediatypeaudio                                                       outputsettings:audiosettings]; audiowriterinput.expectsmediadatainrealtime = yes;   [assetwriter addinput:videowriterinput]; [assetwriter addinput:audiowriterinput]; 

there's avassetwriterinputpixelbufferadaptor in there left out brevity's sake. create 1 serial dispatch queue use both video , audio writing. when new video frame, dispatch job onto serial queue, , when new audio bytes, dispatch job same serial queue. way, of audio writing code doesn't happen on audio callback thread (which otherwise slow down high-priority audio thread).

i'm able write video audio , performs fine on dual-core devices. however, on single core devices, find there's noticeable stutter on device's display every 500-700ms. i've tracked down culprit following:

if ([audiowriterinput isreadyformoremediadata]) {     if (![audiowriterinput appendsamplebuffer:samplebuffer])     {        nslog(@"couldn't append audio sample buffer: %d", numaudiocallbacks_);     } } 

if comment out appendsamplebuffer audiowriterinput, no audio gets written, there's no stutter in actual display either. it's weird because of happening off of main thread. cpu/gpu times per frame on order of 4-5 ms, it's not cpu/gpu bottlenecked.

another clue/curiosity: when write audio buffers, saw-tooth memory graph following:

sawtooth

it seems me audiowriterinput queueing buffers , writing/releasing them.

one last hint seems stuttering less severe when record mono instead of stereo. unfortunately, sounds come in stereo, when that, sound wrong. either way, stuttering doesn't go away it's not valid solution, might hint @ fact stereo takes more resources handle.

does have ideas on why writing audio avassetinputwriter causes entire app stutter? these devices have 1 core threads run on that, seems strange main thread should stutter when cpu load low.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -