I have a function that is supposed to re-encode a video to a manageable bitrate on iphone/ipad. Here it is: *UPDATED WORKING CODE, NOW WITH AUDIO! :) *
-copyNextSampleBuffer is returning a CMSampleBufferRef with +1 retain (copy methods do that). This means you must release the object. Since you're not doing so, you're going to leak a copy every pass through your while() loop.
Additionally, you're running that loop tightly without managing an autorelease pool. If there are objects being autoreleased in any of the routines you're calling, they will not be released until the autorelease pool above you drains. Since your while() loop duration is based on input, it's a good candidate for adding a manual autorelease pool.
One other thing to consider: because you're running this synchronously with a while() loop, you'll block the thread and possibly spin unnecessarily over your continue condition several times. AVAssetWriterInput provides an alternative mechanism to use libdispatch to process data asynchronously as resources become available: -requestMediaDataWhenReadyOnQueue:usingBlock: