Reading video frame-by-frame under iOS
I’m looking for a way to retrieve the individual frames of a video using iOS API.
I tried using AVAssetImageGenerator but it seems to only provide frame to the nearest second which is a bit too rough for my usage.
From what I understand of the documentation, a pipeline of AVAssetReader, AVAssetReaderOutput and CMSampleBufferGetImageBuffer I should be able to do something but I’m stuck with a CVImageBufferRef. With this I’m looking for a way to get a CGImageRef or a UIImage but haven’t found it.
Real-time is not needed and the more I can stick to provided API the better.
Thanks a lot!
Based on this site: http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation and this question: how to convert a CVImageBufferRef to UIImage I’m nearing on a solution. Problem, the AVAssetReader stops reading after the first
copyNextSampleBuffer without giving me anything (the sampleBuffer is NULL).
The video is readable by MPMoviePlayerController. I don’t understand what’s wrong.
- Auto Focus and Auto Exposure in AVFoundation on Custom Camera Layer
- How do I record a maker note or user comment in EXIF?
- Animate AVPlayerLayer videoGravity property
- Fast switching between videos using AVFoundation
- Send headers with AVPlayer request in iOS
- Using Swift with AVPlayer, how do you add and remove a video via code?
3 Solutions Collect From Internet About “Reading video frame-by-frame under iOS”
The two links above actually answer my question and the empty
copyNextBufferSample is an issue with iOS SDK 5.0b3, it works on the device.
AVAssetImageGenerator has very loose default tolerances for the exact frame time that is grabbed. It has two properties that determine the tolerance:
requestedTimeToleranceAfter. These tolerances default to
kCMTimePositiveInfinity, so if you want exact times, set them to
kCMTimeZero to get exact frames.
(It may take longer to grab the exact frames than approximate frames, but you state that realtime is not an issue.)
Use AVReaderWriter. Though its an OS X Apple sample code, AVFoundation is available on both platforms with little changes.
- UIButton Doesn't allow UIScrollView to scroll
- iOS swift remove elements of an array from another array
- When to use Core Data's NSMainQueueConcurrencyType?
- Xcode 5- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- Difference between retain] and init]
- Storing authentication tokens on iOS – NSUserDefaults vs Keychain?
- “End-of-central-directory signature not found.” when installing Xcode 8 beta xip file
- how to add elements to tableview on scrolling iphone?
- Core Bluetooth State Preservation and Restoration Not Working, Can't relaunch app into background
- What does the ^ operator do to a BOOL?
- How do I detect a dual core CPU on iOS?
- Custom AlertView With Background
- Force Touch animation freezes if gently touched
- How do I submit an app to the App Store using Xcode 4.3 or Application Loader
- Build Cocoa application Bundle with private dylib/framework