SDAVAssetExportSession icon indicating copy to clipboard operation
SDAVAssetExportSession copied to clipboard

Crash while export

Open alexgarbarev opened this issue 10 years ago • 8 comments

Hello, This project is great (y), but I faced with few crashes on my application:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** 
-[AVAssetWriterInput appendSampleBuffer:] Must start a session (using -[AVAssetWriter startSessionAtSourceTime:) before appending sample buffers'
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '***
 -[AVAssetWriterInput markAsFinished] Cannot call method when status is 0'
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** 
-[AVAssetReader initWithAsset:error:] invalid parameter not satisfying: asset != ((void *)0)'

Config is:

    SDAVAssetExportSession *session = [[SDAVAssetExportSession alloc] initWithAsset:composition];
    session.videoComposition = videoMix;
    session.audioMix = audioMix;
    session.videoSettings = @{
        AVVideoCodecKey : AVVideoCodecH264,
        AVVideoWidthKey : @640,
        AVVideoHeightKey : @640,
        AVVideoCompressionPropertiesKey : @{
            AVVideoAverageBitRateKey : @2000000,
            AVVideoProfileLevelKey : AVVideoProfileLevelH264Baseline31,
        }
    };
    session.audioSettings = @{
        AVFormatIDKey : @(kAudioFormatMPEG4AAC),
        AVNumberOfChannelsKey : @2,
        AVSampleRateKey : @44100,
        AVEncoderBitRateKey : @64000,
    };

    session.outputURL = [[NSURL alloc] initFileURLWithPath:outPath];
    session.outputFileType = AVFileTypeMPEG4;
    session.shouldOptimizeForNetworkUse = YES;

Plus I'm using custom videoComposition and audioMix

They happens rarely - hard to reproduce, but.. any thoughts why this happens? Recommendations?

alexgarbarev avatar Feb 10 '15 18:02 alexgarbarev

I had a similar issue that rarely occurred and nearly drove me mad. Turns out it was due to the rare case that input video had 0 audio tracks. (Think of 4x video filmed in an iOS device, for example. Apple removes the audio tracks from the video asset).

On Tue, Feb 10, 2015 at 11:00 AM, Aleksey Garbarev <[email protected]

wrote:

Hello, This project is great (y), but I faced with few crashes on my application:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '* -[AVAssetWriterInput appendSampleBuffer:] Must start a session (using -[AVAssetWriter startSessionAtSourceTime:) before appending sample buffers'

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '* -[AVAssetWriterInput markAsFinished] Cannot call method when status is 0'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVAssetReader initWithAsset:error:] invalid parameter not satisfying: asset != ((void *)0)'

Config is:

SDAVAssetExportSession *session = [[SDAVAssetExportSession alloc] initWithAsset:composition];
session.videoComposition = videoMix;
session.audioMix = audioMix;
session.videoSettings = @{
    AVVideoCodecKey : AVVideoCodecH264,
    AVVideoWidthKey : @640,
    AVVideoHeightKey : @640,
    AVVideoCompressionPropertiesKey : @{
        AVVideoAverageBitRateKey : @2000000,
        AVVideoProfileLevelKey : AVVideoProfileLevelH264Baseline31,
    }
};
session.audioSettings = @{
    AVFormatIDKey : @(kAudioFormatMPEG4AAC),
    AVNumberOfChannelsKey : @2,
    AVSampleRateKey : @44100,
    AVEncoderBitRateKey : @64000,
};

session.outputURL = [[NSURL alloc] initFileURLWithPath:outPath];
session.outputFileType = AVFileTypeMPEG4;
session.shouldOptimizeForNetworkUse = YES;

Plus I'm using custom videoComposition and audioMix

They happens rarely - hard to reproduce, but.. any thoughts why this happens? Recommendations?

— Reply to this email directly or view it on GitHub https://github.com/rs/SDAVAssetExportSession/issues/21.

axpence avatar Feb 11 '15 17:02 axpence

@axpence Thanks for response I figured out that crash 3 was my fault - (AVAsset was nil). But others are still here. Let's see If I can found the reason..

Also I have AVPlayer which plays my composition, videoComposition and audioMix at same time during export. (Could it is be a reason? Probably not)

alexgarbarev avatar Feb 12 '15 10:02 alexgarbarev

@alexgarbarev How do you solve

longhongwei17 avatar Apr 26 '17 09:04 longhongwei17

@longhongwei17 solved my removing that library from my project and using standard AVAssetExportSession.

alexgarbarev avatar Apr 26 '17 09:04 alexgarbarev

I'm also having the issue (using Swift 4) that happens maybe 1/20 times. I can barely find any info online about it. It crashes when I end the recording. It shows nothing in my code where it crashed, except in assembler in "libsystem_kernel.dylib`__pthread_kill:", but it appears that it crashes on endSession(atSourceTime:). I'm also already using AVAssetExportSession.

exactspace avatar Oct 24 '18 15:10 exactspace

Did anyone find a solution for this? @alexgarbarev did was it a big job to swap out and use the standard AVAssetExportSession?

aaronwardle avatar Oct 28 '18 19:10 aaronwardle

Hi @aaronwardle any updates?

alexanderkhitev avatar Jan 06 '19 14:01 alexanderkhitev

Check the AVAssetWriterStatus before call "appendSampleBuffer:(CMSampleBufferRef)sampleBuffer". Sometimes the session will be cancel / failed by system.

kyle5843 avatar Mar 13 '19 11:03 kyle5843