将每个帧作为来自电影文件(QuickTime-API)的图像导出 [英] Export every frame as image from a Movie-File (QuickTime-API)
问题描述
我想打开一个现有的电影文件,并将此文件的每一帧导出为JPEG或TIFF等图像。我到目前为止:
int main(int argc,char * argv []){
char filename [255]; //文件名ping。
OSErr e; //错误返回。
FSSpec filespec; // QT文件规范
short filemovie; // QT电影句柄。
电影电影; // QT movieobject。
InitializeQTML(0);
EnterMovies();
//因为QT的Mac起源,必须将C字符串文件名
//转换为Pascal计数字符串,然后使用它来创建文件规范。
c2pstr(filename);
FSMakeFSSpec(0,0L,(ConstStr255Param)filename,& filespec);
OpenMovieFile(& filespec,& filemovie,fsRdPerm);
NewMovieFromFile(& movie,filemovie,nil,nil,newMovieActive,nil);
...
直到现在它工作正常> TIMEVALUE movietime = GetMovieDuration(电影); 并打印),但现在我想这部电影的每一帧,并将其导出到一个文件中(为先,以后我只是想保持数据在内存中使用它,但我必须知道如果它真的工作,所以导出到一个图像文件是更好的现在)。
我该怎么做?我需要一个GWorld或PixMap?
作为开始,这篇关于电影出口商的文章应该几乎让你开始:
http://www.mactech.com /articles/mactech/Vol.16/16.05/May00QTToolkit/index.html
尽管MACTECH是Mac的资源,所有的描述API函数应该可用在Windows版本的QuickTime SDK为好。
我会在这里,只要我觉得在一起的时候拍一些示例代码,自己作为一个参考。
编辑
有关详情,请参阅此书摘录:
QuickTime工具包 - Google图书的基本电影播放和媒体类型
编辑2 - 高级方法:电影出口商
如果你需要做到的是从一个QuickTime影片提取所有的视频帧,并将它们转换成由你赢得了QuickTime的API支持的另一种格式吨有采取任何低级别的动作无论如何,如果使用的电影出口商
下面的示例代码允许提取和转换所有的视频帧从QuickTime影片来,铁,一堆用编程调用影片导出对话框JPEG文件。
只要选择的电影图像序列的中 选项,选择对话框的导出组合框,然后选择所需的图片格式。
注意2:错误处理已被省略为了清楚起见
#includeMovies.h
#includeQTML.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];
电影电影;
//初始化QuickTime API
InitializeQTML(0);
EnterMovies();
//设置核心基础字符串源路径(的argv [1])包含对MOV文件的完整路径转换
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我们的电影文件的电影
NewMovieFromProperties(movie_prop_count,movie_props,0,0,& movie);
//调用转换对话框
ConvertMovieToFile(movie,0,0,0,'TVOD',0,0,flags,0);
//清理
DisposeMovie(movie);
CFRelease(cfpath);
ExitMovies();
TerminateQTML();
...
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* argv[]) {
char filename[255]; // Filename to ping.
OSErr e; // Error return.
FSSpec filespec; // QT file specification
short filemovie; // QT movie handle.
Movie movie; // QT movie "object".
InitializeQTML(0);
EnterMovies();
// Because of QT's Mac origin, must convert C-string filename
// to Pascal counted string, then use that to make a filespec.
c2pstr(filename);
FSMakeFSSpec(0, 0L, (ConstStr255Param)filename, &filespec);
OpenMovieFile(&filespec, &filemovie, fsRdPerm);
NewMovieFromFile(&movie, filemovie, nil, nil, newMovieActive, nil);
...
Until now it works fine (I tested with TimeValue movietime = GetMovieDuration(movie);
and print it), but now I want to get every frame of the movie and export it to a file (for first, later i just want to keep the data in memory to work with it, but i have to know if it really works, so export to an image-file is better for now).
How do I do that? Do I need a GWorld or a PixMap? How do I get a GWorld/PixMap from a Movie-File, especially each frame of it?
edit: My Platform is WinXP
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();
...
这篇关于将每个帧作为来自电影文件(QuickTime-API)的图像导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!