Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grabbing frames from an rtsp stream



For a project I'm working on, I need to be able to grab all frames from
an rtsp video stream. This stream is produced by an Elphel 333 camera
<http://www.elphel.com>. The camera is reportedly able to produce 1
megapixel video at 30 fps...

As a first (naive...) approach I decided to use QTKit to try and capture
images as they come in. I play the stream in an off screen
NSWindow/QTMovieView, and register a callback on the Quicktime Movie
type to be notified when each frame is drawn. Then I grab the frame.

//  MovieDrawingCompleteProcPtr
OSErr movieDidDrawFrame(Movie theMovie, long refCon)
{
    NSLog(@"grab...");
    [(OTFrameGrabber *)refCon grab];
    NSLog(@"done");
    return noErr;
}

@implementation OTFrameGrabber

- (void)grab
{
    //  grab frame
    [self setGrabbedFrameTime:[[self movie] currentTime]];
    [self setGrabbedFrameImage:[[self movie] currentFrameImage]];
}

- (void)start
{
    //  setup offScreen window
    QTMovie *theMovie = [self movie];
    NSSize  movieSize = [[[theMovie movieAttributes]
valueForKey:QTMovieNaturalSizeAttribute] sizeValue];

    NSWindow *newWindow;
    newWindow = [[NSWindow alloc] initWithContentRect:(NSRect){
NSZeroPoint, movieSize } styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:NO];
    [newWindow setOneShot:YES];     //  don't need this?

    QTMovieView *movieView;
    movieView = [[QTMovieView alloc] initWithFrame:NSZeroRect];
    [movieView setMovie:theMovie];
    [movieView setControllerVisible:NO];
    [newWindow setContentView:[movieView autorelease]];
    [self setOffScreenWindow:[newWindow autorelease]];

    //  register callback and start
    SetMovieDrawingCompleteProc(
        [theMovie quickTimeMovie],
        movieDrawingCallWhenChanged,
        NewMovieDrawingCompleteUPP(movieDidDrawFrame),
        (long)self
    );
    [theMovie play];
}
...

@end

On my slow Powerbook I've been experimenting with an rtsp stream (160*120
pixel mp4) from the internet. When I'm not grabbing frames it runs at ~
20 fps. Grabbing a frame only takes 0.04 Seconds on average, so I was
expecting to grab @ ~10fps. In practice I only achieve around 2fps, so it
seems that grabbing frames somehow 'upsets' the playback of the stream.


On second thought, the problem may simply be that grabbing the frame makes the movie become out of sync with the stream, and re-syncing takes time.

The final product is going to run on a G5 @ 2.5 GHz with a GeForce 7800.
Also, I believe the rtsp stream from the camera will be mjpeg, not mp4.

I have a few questions:

- Am I taking the right approach to grabbing frames, could my Cocoa code
be improved?

- Could I improve performance by using Quicktime directly, instead of
using(/abusing) QTKit?

- Any pointers to other software or discussions on frame-grabbing would
be most welcome. I couldn't find Apple example code that relates to grabbing frames from a network stream, but maybe I didn't look in the right place.


TIA,

patrick

_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.