How do I pause video at the exact moment I capture a photo? - iphone

I am using AVFoundation to display a Video in my UIView via an AVCaptureVideoPreviewOverlay.
I then use AVStillImageOutput's -captureStillImageAsynchronouslyFromConnection: to capture a still Image from the Video with the AVCaptureSessionPresetPhoto preset.
I am freezing the video using AVCaptureSession's -stopRunning in the -captureStillImageAsynchronouslyFromConnection completion block mentioned earlier. However, it's too late and the video has continued running while the still image is taken, so the freeze is a second or two later. When I display the image there is a jump.
How can I freeze the video at the exact moment the photo is taken?

Almost a year later...Your approach is all wrong. Instead of trying to pause the video at the precise moment that the image is captured why don't you pause the video and then capture that paused image. To a user it makes no difference, to a developer you don't have to worry about exact precision.
To reiterate my idea, if you pause a video and flash white visual and play a click the user will think you have just captured that frame regardless if you are or not. Actually, you could consider pausing video the same as capturing an image without saving it.

Related

Android: Custom video recording app and its quality

I followed the tutorial to create a basic video recorder using the button ("Capture" & "Stop")
Generally it works well but I noticed that if we tap too rapidly on the button to toggle between "Capture to Stop" or from "Stop to Capture", the app stop responding and crashes.
May I know the reason(s) why and how can we solve this issue?
My guess is that it takes time for the app to start the processes of Capture/Stop respectively, and by rapidly tapping the button, the respective processes are force to stop?
Also, I notice the quality of my video recorder is not as good as the default Camera App that comes with Android. (The custom video recorder seems to capture videos of darker and dimmer quality)
Can this issue be solve by adjusting the Camera parameters?
(For e.g. adjust the exposure compensation?)

How do I detect when the flash for the AVCaptureDevice has finished and still image capture has begun?

I am making a pretty simple/standard camera app that uses a AVCaptureVideoPreviewLayer. When the user presses a button, I call captureStillImageAsynchronouslyFromConnection on the AVCaptureStillImageOutput to capture an image. At the time that I capture the image, I animate a simple white UIView over the preview layer as an indication to the user that a photo is being captured, and hide it again after the image capture is complete.
My problem is that when the camera flash is on, I don't want to display the white view immediately because the photo capture doesn't actually happen until after the flash has gone off. Is there a way to determine that the flash has finished or that the image capture has actually begun? Perhaps via KVO, NSNotificationCenter, or something?
Try using KVO on the capturingStillImage property of AVCaptureStillImageOutput.
The documentation reads like that may be what you need.

Capture video without displaying the actual video feed

So I have an application that can currently capture video with the front facing iphone camera and then do some processing on the video feed real-time. What I'm trying to do, however, is make this process run in the background and put other controls onscreen. So for example, say I'd like to run the camera and process the image feed, but I want the user to see a black screen with some buttons on it. Any ideas on how to do this?
Just so we get terminology right, by "in the background", you mean running the camera capture while your application is in the foreground, but not displaying the actual video feed. This is possible, but I wanted to make clear that if you move your whole application into the background you will not have access to the camera then.
There are a few ways to do this, but the one that I've spent the most time with is grabbing frames of video (or photos) via AV Foundation. Using an AVCaptureDevice and AVCaptureSession, you can grab the frames of video and route them to an encoder for saving to disk or for processing using your own custom code. None of this requires the camera feed to be displayed onscreen, so you can put up whatever interface you like and do this video recording or photo capture without any onscreen indication.
I would caution that you should make it explicit to your users what you are doing, so that you do not run the risk of violating someone's privacy. Apple does not react kindly to those who do this (for good reason).
I encapsulate a lot of this within my open source GPUImage video and photo processing framework, so you could look at the code for the GPUImageVideoCamera class there to see how I configure the capture inputs. I hand the video frames off to OpenGL ES for the application of filters and other processing operations, but you could ignore that portion of it if you just wanted to do your own encoding or processing.
Heres an exemple code from Apple's doc:
http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html
there is also the way to customize the camera interface.

Playing a real time video stream from iPhone camera on a 20 second delay

I am trying to see if it is possible to record a video from the iPhone's camera and write this to a file. I then want the video to start playing on the screen a set time after. This all needs to happen continuously. For example, I want the video on the screen to always be 20 seconds behind what the camera is recording.
Some background:
I have a friend who is a coach and would like for his players to be able to see their last play. This could be accomplished by a feed going to a TV from an iPad always 20 seconds behind what is recorded. This needs to continually run until practice is over. (I would connect the iPad to the TV either with a cable or AirPlay to an Apple TV). The video would never need to be saved and should just be discarded after playing.
Is this even possible with the APIs AVFoundation offers? Will the iPhone let you write to a file and read from a file at the same time to accomplish this? Any other better way to accomplish this?
Thanks for your time.
Instead of writing to a file, how about saving your frames in a circular buffer big enough to hold X seconds of video?
The way I would start to do this would be to look at what's provided in AVCaptureVideoDataOutput and its delegate methods (where you can get the frame data from).

How to play a video slowly for marking

I am Creating application for coaching. I struck with the marking on video. So I choose ffmpeg for converting video to image frame. That make me time delay as well as memory issues. I need to provide the user play the video slowly as frame by frame. Is there any other way to do that with out image conversion. V1 Golf did that process very quick manner. Please help me.
I would try converting video frame in separate thread and I would extract a few frames ahead as images in the background when user gets into 'slow motion mode'.
Here is example for one frame, so you should be quick with others: Video frame capture by NSOperation.
This should reduce delays and frames could be converted while user is eye-consuming subsequent frames.