4

How can I implement a delegate that is triggered for every frame in a locally stored video? I tried AVCaptureVideoDataOutputSampleBufferDelegate but it isn't working for locally stored videos. Is there any other to do this, or can I use a virtual AVCaptureDevice?

brainray
  • 12,512
  • 11
  • 67
  • 116
umirza47
  • 940
  • 2
  • 10
  • 21

2 Answers2

1

AVCapture__ methods are all meant for camera-type things, which a movie file on disk most certainly is not.

I suspect what you are really looking for is something like the "AVPlayerItemVideoOutput" class, which came in with iOS 6.0.

While it has a delegate protocol, I haven't yet used this new object or protocol and I don't know if the delegate methods such as "outputSequenceWasFlushed" will actually be useful for your purposes). One thing about the AVPlayerItemVideoOutput class is that it like you can get at the pixel buffer for those items (i.e. which, for movies, would be frames).

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • The AVPlayerItemVideoOutput only provide us pixel buffer at certain CMTime. I want that for every frame it throughs or triggers a method that which return pixel data of that frame. Somewhat exactly like captureOutputSampleBuffer. Would you provide me any working code sample, that may help me for better understanding? – umirza47 Oct 03 '12 at 07:01
  • I haven't used this new class yet and I didn't see anything obvious when I checked Apple's sample code archive. [I do see a potentially useful related question here on StackOverflow](http://stackoverflow.com/questions/10232072/cant-have-avassetimagegenerator-give-me-all-the-frames-of-a-movie), which shows how to get each and every frame of a movie file. Maybe that might help you out? – Michael Dautermann Oct 03 '12 at 07:05
0

You might take a look on these: https://ar.qualcomm.at/support_file/download/iOS/videoplayback%20sample%20app/vuforia-videoplayback-ios-1-0-2.zip

It implement something like you want it. It relies on an AVAssetReader you can use the AVAssetReaderOutput -> copyNextSampleBuffer method.

You can setup a timer for every frame played based on the frame rate of the video asset, in the timer you can retrieve the aforementioned CMSampleBufferRef retrieved by copyNextSampleBuffer , also it's available from iOS4.x

lalfonso
  • 33
  • 1
  • 5