Domanda

I am troubleshooting a problem with my application that worked fine in iOS6, but when I upgraded to XCode 5 and iOS7 the AVAssetWriter quit writing video data to a file in the tmp directory. I am using AVFoundation with an AVCaptureSession to capture the video. The output file is created when the recording begins, but it is never loaded with any video data. The finishWritingWithCompletionHandler runs without any errors and calls its completion handler as expected.

Does anyone know if I need to do anything different with iOS7 that was not needed in iOS6? I have not been successful finding anything in the documentation.

Here is some more information...

Temporary file location: /var/mobile/Applications/[App ID]/tmp/[TempFileName].MOV

Video Sample Buffer Size: 1

Audio Sample Buffer Size: 1024

Any help will be greatly appreciated.

È stato utile?

Soluzione 2

I discovered what the problem is. First I wrongly blamed the AVAssetWriter object. It was working correctly. The actual problem came from AVPlayerItem. I was using AVPlayerItem to determine the duration of the video. No matter what I tried it always returned a duration of zero which kept my video compilation getting called. Therefore to fix the problem I instead used AVAssetItem to get the video duration and that fixed my problem. I will probably report this to Apple as a bug in the AVPlayerItem object.

Altri suggerimenti

I've had the exact same scenario, also only over iOS 7.
On my case the problem turned to be actually a corrupted video file that was captured using same app.

The problem was that after done capturing with AVAssetWriter, I was calling 'finishWriting' on background thread and accessing the media immediately, before writing was done.

Solved it using 'finishWritingWithCompletionHandler:' and accessing file only after writing done (callback from the completion handler). Remember to dispatch back to main thread because handler called from a background thread.

Hope it helps

avishic was right. Before iOS 7, I didn't have to include assetWriter finishWritingWithCompletionHandler, but now it will leave the file unusable if you don't. Here is some code to illustrate:

[assetWriterInput requestMediaDataWhenReadyOnQueue:mediaInputQueue
                                                usingBlock:
^{
    CMSampleBufferRef nextBuffer;
    while (assetWriterInput.readyForMoreMediaData)
    {
        nextBuffer = [assetReaderOutput copyNextSampleBuffer];
        if (nextBuffer) {
            //...
        }
        else {
            [assetWriterInput markAsFinished];
            [assetReader cancelReading];
            [assetWriter finishWritingWithCompletionHandler:^{
                //notify your other code that the file is ready
               }];
            return;
        }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top