Kickflip / kickflip-ios-sdk

Kickflip iOS SDK
http://kickflip.io
Apache License 2.0
346 stars 143 forks source link

AssetWritterInput Code=-11800 "The operation could not be completed #43

Open omarojo opened 8 years ago

omarojo commented 8 years ago

Im trying to substitute the CMSamplebuffer that comes out of the native camera in the method - (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

with my own generated CMSampleBufferRef that I build out of a GPUImage output. But I get an error when the kickflip AssetWriterInput tries to appendBuffer

writer error Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x133a94f60 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed}

//THS IS MY CODE

broadcastOutputTarget = [[GPUImageRawDataOutput alloc] initWithImageSize:CGSizeMake(1920, 1080) resultsInBGRAFormat:YES];
        [filterChain.output addTarget:broadcastOutputTarget];
        self.streamImage = [[UIImage alloc] init];
        __block ToyViewController *safeSelf = self;

        __weak GPUImageRawDataOutput *weakRawOutput = broadcastOutputTarget;
        [broadcastOutputTarget setNewFrameAvailableBlock:^{
            GLubyte *outputBytes = [weakRawOutput rawBytesForImage];
            NSInteger bytesPerRow = [weakRawOutput bytesPerRowInOutput];

            CVPixelBufferRef pixelBuffer = NULL;
            OSStatus result = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
                                                           1920,
                                                           1080,
                                                           kCVPixelFormatType_32BGRA,
                                                           outputBytes,
                                                           bytesPerRow, nil, nil, nil,
                                                           &pixelBuffer);

            CMVideoFormatDescriptionRef videoInfo = NULL;
            result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBuffer, &videoInfo);

            CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid;
            timingInfo.duration = frameDuration;
            timingInfo.presentationTimeStamp = nextPTS;

            //NSLog(@"TIME: %f", CMTimeGetSeconds(timingInfo.presentationTimeStamp));

            CMSampleBufferRef sampleBuffer = NULL;
            result = CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault,
                                                        pixelBuffer,
                                                        true, NULL, NULL,
                                                        videoInfo,
                                                        &timingInfo,
                                                        &sampleBuffer);
            NSLog(@"BUFFER : %@", sampleBuffer);
            //THIS IS WHERE I SEND THE BUFFER TO THE ENCODER
           ** [safeSelf.broadCastRecorder captureGenerateVideoOutput:sampleBuffer];**
            //Increment presentation time
            nextPTS = CMTimeAdd(frameDuration, nextPTS);
            // release the copy of the sample buffer we made
            CFRelease(sampleBuffer);
}];

And my custom captureGenerateVideoOutput:CMSampleBufferRef method that I integrated in my Recorder class. that is pretty much a clone of the KFRecorder.h/m

-(void) captureGenerateVideoOutput:(CMSampleBufferRef)sampleBuffer{
    if (!_hasScreenshot) {
        UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
        NSString *path = [self.hlsWriter.directoryPath stringByAppendingPathComponent:@"thumb.jpg"];
        NSData *imageData = UIImageJPEGRepresentation(image, 0.7);
        [imageData writeToFile:path atomically:NO];
        _hasScreenshot = YES;
    }
    if(_h264Encoder)
        [_h264Encoder encodeSampleBuffer:sampleBuffer];

}
jonasandero commented 7 years ago

Did you ever figure this one out? I am frustrated over having the same problem.

omarojo commented 7 years ago

Dont use their service, not worth it. You should try Red5Pro its way more supported and with more features.

On Feb 8, 2017, 1:53 PM -0800, jonasandero notifications@github.com, wrote:

Did you ever figure this one out? I am frustrated over having the same problem.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub (https://github.com/Kickflip/kickflip-ios-sdk/issues/43#issuecomment-278473695), or mute the thread (https://github.com/notifications/unsubscribe-auth/AA8vweMVp7DLS-a3CximRr1KFj_IUw6mks5rajlPgaJpZM4GTbaD).