Export every frame as image from a Movie-File (QuickTime-API)

后端 未结 4 565
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 12:10

I want to open an existing Movie-File and export every frame of this file to an image like JPEG or TIFF. I got so far until now:

int main(int argc, char* a         


        
4条回答
  •  情话喂你
    2021-01-07 12:57

    As a beginning, this article on Movie exporters should pretty much get you started:

    http://www.mactech.com/articles/mactech/Vol.16/16.05/May00QTToolkit/index.html

    Even though MacTech is a Mac resource, all described API functions should be available in the QuickTime for Windows SDK as well.

    I will slap some sample code together myself as a reference here as soon as I find the time.

    Edit

    See this book excerpt for additional info:

    QuickTime Toolkit - Basic Movie Playback and Media Types @ Google Books

    Edit 2 - The High-Level Approach: Movie Exporters

    If all you need to accomplish is to extract all video frames from a QuickTime Movie and convert them to another format supported by the QuickTime API you won't have to take any low-level actions whatsoever if using a Movie Exporter.

    The below sample code allows to extract and convert all video frames from a QuickTime Movie to, f.e., a bunch of JPEG files using a programmatically invoked Movie Export Dialog.

    Just select Movie to Image Sequence in the Export combo box of the dialog and select your desired image format by hitting Options.

    Note 1: If you need to do this non-interactively, just let me know.

    Note 2: error handling has been omitted for clarity

    #include "Movies.h"
    #include "QTML.h"
    #pragma comment (lib, "QTMLClient.lib")
    

    ...

    int  flags                  = createMovieFileDeleteCurFile 
        | showUserSettingsDialog 
        | movieToFileOnlyExport;
    ItemCount  movie_prop_count = 0;
    CFStringRef  cfpath         = 0;
    Boolean  bool_true          = true; 
    QTNewMoviePropertyElement  movie_props[ 2 ];
    Movie  movie;
    
    // initialize QuickTime API
    InitializeQTML( 0 );
    EnterMovies();
    
    // set up Core Foundation string for source path (argv[ 1 ]) contains the full path to the MOV file to convert
    cfpath = CFStringCreateWithCString( 0, argv[ 1 ], kCFStringEncodingASCII );
    movie_props[movie_prop_count].propClass        = kQTPropertyClass_DataLocation;
    movie_props[movie_prop_count].propID           = kQTDataLocationPropertyID_CFStringNativePath;
    movie_props[movie_prop_count].propValueSize    = sizeof(cfpath);
    movie_props[movie_prop_count].propValueAddress = (void*)&cfpath;            
    movie_props[movie_prop_count].propStatus       = 0;
    ++movie_prop_count;
    
    // make Movie active
    movie_props[movie_prop_count].propClass        = kQTPropertyClass_NewMovieProperty;
    movie_props[movie_prop_count].propID           = kQTNewMoviePropertyID_Active;
    movie_props[movie_prop_count].propValueSize    = sizeof(bool_true);
    movie_props[movie_prop_count].propValueAddress = &bool_true;
    movie_props[movie_prop_count].propStatus       = 0;
    ++movie_prop_count;
    
    // aquire Movie for our Movie file
    NewMovieFromProperties( movie_prop_count, movie_props, 0, 0, &movie );
    
    // invoke conversion dialog
    ConvertMovieToFile( movie, 0, 0, 0, 'TVOD', 0, 0, flags, 0 );
    
    // clean up
    DisposeMovie( movie );
    CFRelease( cfpath );
    
    ExitMovies();
    TerminateQTML();
    

    ...

提交回复
热议问题