rs / SDAVAssetExportSession

AVAssetExportSession drop-in replacement with customizable audio&video settings
MIT License
805 stars 212 forks source link

Crash while export #21

Open alexgarbarev opened 9 years ago

alexgarbarev commented 9 years ago

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

1)

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

2)

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

3)

*** 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?

axpence commented 9 years ago

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 <notifications@github.com

wrote:

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

1)

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

2)

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

3)

* 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.

alexgarbarev commented 9 years ago

@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)

longhongwei17 commented 7 years ago

@alexgarbarev How do you solve

alexgarbarev commented 7 years ago

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

exactspace commented 6 years ago

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.

aaronwardle commented 6 years ago

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

alexanderkhitev commented 5 years ago

Hi @aaronwardle any updates?

kyle5843 commented 5 years ago

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