Giter Club home page Giter Club logo

llsimplecamera's Introduction

LLSimpleCamera: A simple customizable camera - video recorder control

Screenshot

LLSimpleCamera is a library for creating a customized camera - video recorder screens similar to snapchat's. You don't have to present the camera in a new view controller.

You can also use my LLVideoEditor library to easily edit recorded videos.

###LLSimpleCamera:###

  • lets you easily capture photos and record videos
  • handles the position and flash of the camera
  • hides the nitty gritty details from the developer
  • doesn't have to be presented in a new modal view controller, simply can be embedded inside any of your VCs. (like Snapchat)

###Version 5.0 notes:###

  • Better recording API
  • Improved reliability

###Version 4.2 notes:### New features:

  • zoom feature
  • white balance configuration
  • attaching to view controller improved

###Version 4.1 notes:### Merged some PRs:

  • camera mirroring option
  • implementation of *- (instancetype)initWithCoder:(NSCoder )aDecoder

###Version 4.0 notes:### Thanks to the open source community, recently I have merged about 10 PR's to make this library much better and reliable. Also I did some cleanups which contains some breaking changes (sorry for that). Therefore I'm incrementing the major version.

Install

pod 'LLSimpleCamera', '~> 4.1'

Example usage

Initialize the LLSimpleCamera

CGRect screenRect = [[UIScreen mainScreen] bounds];

// create camera with standard settings
self.camera = [[LLSimpleCamera alloc] init];

// camera with video recording capability
self.camera =  [[LLSimpleCamera alloc] initWithVideoEnabled:YES];

// camera with precise quality, position and video parameters.
self.camera = [[LLSimpleCamera alloc] initWithQuality:AVCaptureSessionPresetHigh
                                             position:LLCameraPositionRear
                                         videoEnabled:YES];
// attach to the view
[self.camera attachToViewController:self withFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];

To capture a photo:

// capture
[self.camera capture:^(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error) {
    if(!error) {    
        // we should stop the camera, since we don't need it anymore. We will open a new vc.
        // this very important, otherwise you may experience memory crashes
        [camera stop];
            
        // show the image
        ImageViewController *imageVC = [[ImageViewController alloc] initWithImage:image];
        [self presentViewController:imageVC animated:NO completion:nil];
       }
}];

To start recording a video:

// start recording
NSURL *outputURL = [[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"test1"] URLByAppendingPathExtension:@"mov"];
[self.camera startRecordingWithOutputUrl:outputURL didRecord:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
    VideoViewController *vc = [[VideoViewController alloc] initWithVideoUrl:outputFileUrl];
    [self.navigationController pushViewController:vc animated:YES];
}];

To stop recording the video:

[self.camera stopRecording];

Changing the focus layer and animation:

- (void)alterFocusBox:(CALayer *)layer animation:(CAAnimation *)animation;

Adding the camera controls

You have to add your own camera controls (flash, camera switch etc). Simply add the controls to the view where LLSimpleCamera is attached to. You can see a full camera example in the example project. Download and try it on your device.

Stopping and restarting the camera

You should never forget to stop the camera either after the capture block is triggered, or inside somewhere -viewWillDisappear of the parent controller to make sure that the app doesn't use the camera when it is not needed. You can call -start() to reuse the camera. So it may be good idea to to place -start() inside -viewWillAppear or in another relevant method.

Contact

Ömer Faruk Gül

Personal Site

[email protected]

Version History

Version 3.0.0

  • added video recording capability
  • class is heavily refactored

Version 2.2.0

  • camera permissions are supported, if the permission is not given by the user, onError will be triggered.
  • camera flash methods are altered. Now you have to call - (BOOL)updateFlashMode:(CameraFlash)cameraFlash;
  • cameraFlash and cameraPosition property names are simplified to: flash and position.
  • added support for device orientation in case your vc orientation is locked but you want to use the device orientation no matter what.

Version 2.1.1

  • freezing the screen just after the photo is taken for better user experience.

Version 2.1.0

  • added an extra parameter exactSeenImage:(BOOL)exactSeenImage to -capture method to easily get the exact seen image on the screen instead of the raw uncropped image. The default value is NO.
  • fixed an orientation bug inside capture method.

Version 2.0.0

Some significant changes have been made at both internal structure and api.

  • added tap to focus feature (it is fully customizable, if you don't like the default layer and animation)
  • removed delegates and added blocks
  • interface is significantly improved

Version 1.1.1

  • fixed a potential crash scenario if -stop() is called multiple times

Version 1.1.0

  • fixed a problem that sometimes caused a crash after capturing a photo.
  • improved code structure, didChangeDevice delegate is now also triggered for the first default device.

llsimplecamera's People

Contributors

bluesuedesw avatar djbe avatar hapiben avatar haritonbatkov avatar htdahms avatar kylebrowning avatar leenabeena avatar leoneparise avatar liyalin avatar llinardos avatar mklb avatar omergul avatar roshannindrai avatar sachinkesiraju avatar siong1987 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

llsimplecamera's Issues

Failed to stop recording

When I'm using LLSimpleCamera for recording videos, once I pressed on recording button and then I pressed it again to stop the video. But can't stop recording. I think

self.camera.isRecording

doesn't get initialized to true after start recording.

Quick flash of photo in opposite orientation

When using LLSimpleCamera (the example project or my own implementation of it) after capturing a photo I see a quick flash of the image in the opposite orientation before the imageViewController shows up. So if the device is in portrait mode when I take the photo, I very quickly see a flash of that image in landscape mode and then it goes into portrait again when the imageviewcontroller.

In my implementation, when I dismiss the imageviewcontroller followed by the camera one I see that sideways flash again quick.
Not sure if you're seeing the same thing.

Photo Aspect Ratio

Is there any way to effect the aspect ratio of the photo? I find that the photos show up at the same aspect ratio as the entire screen, rather than the normal 4:3 (I think) iOS aspect ratio. Any help?

No zooming option

Please add zooming option for better experience on video recording

setOnError on Swift

Does anyone know how to set onError on Swift? I know in Objective-C, you can do:

[self.camera setOnError:^(LLSimpleCamera *camera, NSError *error) {
    // Something
}];

but on Swift, I don't have access to setOnError. I tried doing:

self.camera.onError = ({(camera : LLSimpleCamera!, error : NSError!) -> Void! in 
    // Something
})

but I would get an error. I just started working with Swift so this might be a syntax issue. Thanks for the great library and for the help!

Background music pauses when camera is launched and photo is taken.

I just started using the framework and I noticed that soundcloud's music stops playing. I tried using this line of code that I searched for all over Google and Stackoverflow and found this line of code [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; supposedly used to keep all forms of audio playing but it does not seem to be working.

Bug in the zoom feature

Hey,
I just pulled the latest commit on the zoom feature, and my app crashed.
Apparently, effectiveScale took a value it should not have:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[AVCaptureVideoDevice rampToVideoZoomFactor:rate:] - the passed videoZoomFactor 1.089863 out-of-range [1, activeFormat.videoMaxZoomFactor]'

That error is one that line/
[_videoCaptureDevice rampToVideoZoomFactor:_effectiveScale withRate:10];
at the end of file LLSimpleCamera.m

I tried to put
[_videoCaptureDevice rampToVideoZoomFactor:_effectiveScale < _videoCaptureDevice.activeFormat.videoMaxZoomFactor ? _effectiveScale : _videoCaptureDevice.activeFormat.videoMaxZoomFactor withRate:10];
instead, but still I cannot zoom in.
Do I need to do anything else than pull the last commit, since _zoomEnabled is already set to YES ?

Orientation flipped upside down

I have three orientation enabled in my view controller: both landscape and portrait orientation.

When I flip my phone from the right to the left landscape (and vice versa) the cameraview is sometimes flipped upside down.

Square

How can wee get a square photo (Instagram)?
Or maybe add an "edit" step as in camera app?

Feature request: Pause/resume recording

Kayıt yaparken, kayıdı pause moduna alıp, ardından tekrar resume edebilmek ve bunların aynı dosyada toplanıp çıktısı verilirse büyük bir eksiği kapanmış olur library'nin.

Mirror

@omergul123 When using the back camera(both image and video) it gets mirrored.. Can you take a look at this?

This is my LLSimpleCamera.m file from Pod: http://pastebin.com/ytZk2Ti6

preview frame

  • (void)attachToViewController:(UIViewController *)vc withFrame:(CGRect)frame {
    [vc.view addSubview:self.view];
    [vc addChildViewController:self];
    [self didMoveToParentViewController:vc];

    vc.view.frame = frame;
    }

this function set preview frame . but last row is set ParentVC.view frame

Torch/flash not working (iOS 8)

Hello guys.

I couldn't make flash/torch work on iOS 8.
I tried to turn the flash on in both my own project and LLSimpleCamera's example and it didn't work neither.

I tried to workaround as well but I didn't got any success.

Anybody notice that?

Thanks.

Video capture

I wanted to know if it's possible to configure the camera to not only capture image but video as well. Is it possible? Is there any tutorial that you can recommend me?

Thank you very much.

Enabling auto-flash mode

What is the proper procedure to change the flash mode, specifically to auto-flash mode?

Attempted to use updateFlashMode with CameraFlashAuto immediately following start, but the session is not yet created and the mode is not changed.

How can this reliably be accomplished? Is there a completion block where I could place the updateFlashMode call?

Zoom Out

Hi, Thanks for sharing,

Rear camera is seems like zoomed.
I checked with native iphone cam (with fasten the phone) from same distance in square mode. And native cam view angle is more wide. Is there any zoom value?

Thanks

Front Cam Video Recorder

Hello,

I have a small problem I don't know if anyone else is experiencing this, but when I try to record a video using front camera the frame of the result/output video size differs from the frame given, also the completion of the stopRecording function doesn't get called which is the even bigger problem
[self.camera stopRecording:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
NSLog(@"here");
}];

Anyone has any idea what's wrong here?

Thank you

Cannot focus camera

Hello,

I am Using some overlays that are on a scrollView ontop of the camera view. (Like snapchat where you have camera controls then can scroll up to see other controls like settings and stuff).
Because of this, my cameraView does not recognize any taps because the overlays and scrollView pick them all up.

Would you be able to make those control methods public so I can call them manually?
focusAtPoint
showFocusBox

Orientation not working properly

If I don't have useDeviceOrientation set to YES, orientation is always flipped the wrong way.

If I do set it to YES, the output video is always landscape.

Image rotation issue in iOS 9 or later

Hello,

Your camera sample is really helpful.

and you have used that orientation classes for fixing images, but when we have checked that it is having multiple issue and than main issue we faced is, its never changing image orientation and its always changes imageview orientation.

Kindly help if you can,

Thanks
Jankar

camera.capture throws AVFoundationErrorDomain Code=-11800 "The operation could not be completed"

I can see the camera on the screen, but when I call the following:

self.camera!.capture({ (camera:LLSimpleCamera!, photo:UIImage!, metadata:[NSObject : AnyObject]!, error:NSError!) -> Void in

                    if(error != nil)
                    {
                        println(error)
                    }

I get the output:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x171066540 {NSUnderlyingError=0x174641230 "The operation couldn’t be completed. (OSStatus error -16800.)", NSLocalizedFailureReason=An unknown error occurred (-16800), NSLocalizedDescription=The operation could not be completed}

Any idea what might be happening?

saving photo asset with metadata?

Hello, is it possible to enable saving photo metadata with this VC, eg. geo location? I see a pointer to metadata Dictionary in the capture method, but I'm not sure what to do with this data exactly.

Close a session & start another one leads to display the last state for every shoot

Hi guys great library & easy to use thank you 👍

The problem appear when close the camera session & restart another one, when trying to capture a photo the last state of the previous camera session will appear every capture shoot for a while before display the captured photo

You can replicate the problem by add [camera stop] to the existing sample in viewWillDisappear

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.camera stop];
}

How to solve & thanks in advance :)

Video recording is not working

Hello,

I tried your code and photo capturing is working perfectly. But when I tried capture video then first time it capture perfect but when I tried to capture it second time then It is not capturing video.

Then I run your code without changing single line, I got same scenario. First time video capture works, but when I stop debugging and again start then video capturing is not working.

what I found was,When I click button for recording video it goes to "if(!self.camera.isRecording) " condition and when I press same button for stoping video it goes to "else condition" and that is fine.
But when I run app second time then It always go to "if(!self.camera.isRecording) " condition. It is not going in "else" condition.

if(!self.camera.isRecording) {
//always come here after I run the app for first time. every time it goes to this condition
[self.camera startRecordingWithOutputUrl:outputURL];
}
else {
[self.camera stopRecording:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
}];
}

I found this error : Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x165c36b0 {NSLocalizedRecoverySuggestion=Try saving again., AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Save, NSUnderlyingError=0x16514ca0 "The operation couldn’t be completed. (OSStatus error -12672.)"}

I am running your code in iOS 7.1.2 with iPhone4

So How to solve this ?

Now working only Photo mode if permission to microphone not given

So here is the use case. For example i want to use it only for making photo. I added it to test project and if i'm not giving permission to use microphone but gave for using camera the screen became black(In my opinion the sound is not needed when you make photos). But make photo button still appears and focus rectangle is still working when you tap on screen.

Square framed video?

For photos you just re-size camera's frame and that's it.
But for video that method does not work.

Images turn out way too dark

I am taking pictures with LLSimpleCamera
This is my setup:

fullsizerender

Now I did two pictures.
The first turns out to be ok:

92b58a0c-2-0

But the second one is way too dark and has a shift in color towards blue. Even though the image looks OK on the screen when taking it.

92b58a0c-2-1

Internal reference #37

self.interfaceOrientation is deprecated on iOS 8

Hello there,

In LLSimpleCamera.h, self.interfaceOrientation is deprecated. Does changing it from self.interfaceOrientation to [[UIApplication sharedApplication].statusBarOrientation]; works?

stackoverflow thread for more detail.

Just for your info, I am currently testing out LLSimpleCamera on Xcode 7 GM.

Thank you!

Embed controller crash

Hello,

There is a problem with embedding controller. No default values being set, I believe it can be fixed in few lines of code.

We need to add initWithCoder:

-(instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        [self setupWithQuality:AVCaptureSessionPresetHigh
                      position:LLCameraPositionRear
                  videoEnabled:YES];
    }
    return self;
}

And change initWithQuality:

- (instancetype)initWithQuality:(NSString *)quality position:(LLCameraPosition)position videoEnabled:(BOOL)videoEnabled
{
    self = [super initWithNibName:nil bundle:nil];
    if(self) {
        [self setupWithQuality:quality position videoEnabled:videoEnabled];
    }

    return self;
}

- (void) setupWithQuality:(NSString *)quality
                 position:(LLCameraPosition)position
             videoEnabled:(BOOL)videoEnabled {
    _cameraQuality = quality;
    _position = position;
    _fixOrientationAfterCapture = NO;
    _tapToFocus = YES;
    _useDeviceOrientation = NO;
    _flash = LLCameraFlashOff;
    _videoEnabled = videoEnabled;
    _recording = NO;   
}

Swift

Could you make this swift compatible aswell?

Camera freeze

Hello, great code and App, easy to understand and to make changes. I just added a selfie flash to your code and works grate for me, i can help you with that if you need, by the way. I tried to use the app when i make a call and the screen got freeze, i don't know why but if i change the SessionPreset to AVCaptureSessionPresetPhoto works fine, but i can't make videos. Do you know why the screen freeze when i use the AVCaptureSessionPresetHigh and i open the app when im calling?

Camera display orientation issue

In the example project, if I select to enable all orientations, the camera display properly flips. If present homeViewController within my app, the orientations are behaving strangely. After the first orientation change the axis are all messed up. I am assuming this isn't a bug in your library, but any hints as to what might be different about my project that could be causing this to happen?

camera.startRecordingWithOutputUrl doesn't call delegate

I am using the example on the front page, and when I do camera.startRecordingWithOutputUrl,
The delegate method didStartRecording never gets called. didFinishRecording does get called, but didStart never gets called. Any ideas?

MultipleShot

Hi Omer,
I found your contact thanks to cocoacontrol.com, using your pod “LLSimpleCamera”.
This pod is very useful for me because it is very simple and I added exposure controls.
Now I would like add multiple shots but all that I have tried, doesn’t work.
Have you got some advice to me ?
Thank you very much
Filippo

Flash stays on even after starting a new session

My CameraCaptureVC comes up, I snap a picture, it goes to the ImageViewVC. I decide to retake the picture, then I snap the picture and the camera returns that its state is "LLCameraFlashOff" but flashes. Then if I try to toggle the flash button but it still always flashes. Any ideas why this may be happening? Thanks

Auto Focus

Is there is any way to show auto focus on Camera for photo?

Feature request : Pinch to zoom

Hi guy,

I am not familiar with best practices to include pinch to zoom to this awesome controller.
If you have some advice, I am ready to take this in charge.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.