Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

wpf - Windows的QuickTime视频采集器示例(QuickTime video grabber example for Windows)

Do you know some working example of how to grab frames from video using QuickTime on Windows?

(您知道如何在Windows上使用QuickTime从视频中获取帧的一些可行示例吗?)

I need to play the video in memory and access every rendered frame pixel by pixel.

(我需要在内存中播放视频并逐像素访问每个渲染的帧。)

My app is WPF calling dll code from C++ library.

(我的应用程序是WPF从C ++库调用dll代码。)

I have some old code using SetMovieDrawingCompleteProc and accessing the rendered frames using GetGWorldPixMap.

(我有一些使用SetMovieDrawingCompleteProc的旧代码,并使用GetGWorldPixMap访问渲染的帧。)

But there are some memory leaks and also the code stops working sometimes by unhanded exception inside Quicktime - and I can't make it work correctly.

(但是有一些内存泄漏,并且代码有时会由于Quicktime内意外的异常而停止工作-我无法使其正常工作。)

This is the grab code:

(这是抓取代码:)

    CGrafPtr pOldWorld = nil;
    GDHandle pOldHandle = nil;
    GetGWorld(&pOldWorld, &pOldHandle);
    SetGWorld(m_offscreenWorld, NULL);

    PixMapHandle pixMapHandle = GetGWorldPixMap(m_offscreenWorld);

    SetGWorld(pOldWorld, pOldHandle);

    if (!LockPixels(pixMapHandle))
        return;

    UCHAR *pixBaseAddr = (UCHAR*)GetPixBaseAddr(pixMapHandle);

    // handle pixels...

    UnlockPixels(pixMapHandle);

    SetGWorld(pOldWorld, pOldHandle);

This is how I open the movie:

(这是我打开电影的方式:)

    qtErr = FSMakeFSSpec(0, 0, macFullPath, &m_sfFile);
    if (qtErr != noErr)
        throw "Can't convert filename to mac file struct";

    qtErr = OpenMovieFile(&m_sfFile, &theFile, fsRdPerm);
    if (qtErr != noErr)
        throw "Can't open file";


    qtErr = NewMovieFromFile(&m_movie, theFile, nil, nil, 0, nil);
    if (qtErr != noErr)
    {
        m_movie = nil;
        throw "Can't make new movie";
    }

    qtErr = CloseMovieFile(theFile);
    if (qtErr != noErr)
        throw "Can't close movie";

    SetMovieActive(m_movie, true);

    GetMovieBox(m_movie, &m_movieRect);

    qtErr = QTNewGWorld(
        &m_offscreenWorld, k32BGRAPixelFormat, &m_movieRect,
        NULL, NULL, NULL);
    if (qtErr != noErr)
        throw "Can't create off screen world";

    CGrafPtr pOldWorld = nil;
    GDHandle pOldHandle = nil;
    GetGWorld(&pOldWorld, &pOldHandle);
    SetGWorld(m_offscreenWorld, NULL);

    SetMovieGWorld(m_movie, m_offscreenWorld, NULL);

    SetGWorld(pOldWorld, pOldHandle);

    m_movieController = NewMovieController(m_movie,
        &m_movieRect, mcNotVisible | mcScaleMovieToFit | mcTopLeftMovie);
    if (m_movieController == nil)
        throw "Can't get movie controller";

    SetMovieDrawingCompleteProc(
        m_movie, movieDrawingCallWhenChanged,
        pContext->drawCompleteFunc, (long)this);

Before you any suggestions of using DirectShow, DirectX, some Windows media stuff - no, I can't use it, since I need precise speed control of the video (and no, it's not working well in these technologies).

(在您对使用DirectShow,DirectX和某些Windows媒体的任何建议之前-不,我不能使用它,因为我需要精确的视频速度控制(不,在这些技术中它不能很好地工作)。)

  ask by Michal Pokluda translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...