BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

After motion detection recorded video distorted #2376

Closed Sunfocus closed 7 years ago

Sunfocus commented 7 years ago

I am recording video after detecting motion in front of camera. When i play recorded it looks like a histogram video with contrast black and blue.

-(void)stopRecoding:(GPUImageMovieWriter *)moveWriter{ dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSLog(@"Recording Stoped"); [videoCamera setAudioEncodingTarget:nil]; [filter removeTarget:moveWriter]; [moveWriter finishRecording];

    //remove all already existing files from document directory
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDirectoryPath=[paths firstObject];

    NSFileManager *fileManager=[NSFileManager defaultManager];

    NSError *error;

    NSArray *contents=[fileManager contentsOfDirectoryAtPath:documentDirectoryPath error:&error];

    if (error) {
        NSLog(@"Error:%@",error.description);
    }else if (contents.count){
        for (NSString *path in contents) {

            NSData *dataFromPath=[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:[documentDirectoryPath stringByAppendingPathComponent:path]]];
            NSError *localError;
            CGFloat removeSize=dataFromPath.length/1024;
            if (removeSize<100) {
                [fileManager removeItemAtPath:[documentDirectoryPath stringByAppendingPathComponent:path] error:&localError];
            }

            if ([path isEqualToString:[contents lastObject]]) {
                isVideoRecording=NO;
            }

        }
    }

});

}

Help me in this what's wrong in this code ?

BradLarson commented 7 years ago

Don't record the output of the motion detection filter. Record the output coming directly from the camera. The motion detection filter does internal pixel labeling for frame comparisons, and its output isn't intended to be used outside of the internal calculations it performs.

Sunfocus commented 7 years ago

Thanks for your update. Record the output coming directly from the camera ? how can i do that

Sunfocus commented 7 years ago

I need to capture video of 2-3 seconds after motion detection

Sunfocus commented 7 years ago

//output file movieFileOutput = [AVCaptureMovieFileOutput new];

Float64 TotalSeconds = 3;           //Total seconds
int32_t preferredTimeScale = 30;    //Frames per second
CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);   //<<SET MAX DURATION
movieFileOutput.maxRecordedDuration = maxDuration;
movieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;

//add output file
if ([videoCamera.captureSession canAddOutput:movieFileOutput]) {
    [videoCamera.captureSession addOutput:movieFileOutput];
}

When i try to add my outputSource.Camera screen is white.