问题描述
我想打开一个现有的电影文件,并将此文件的每一帧导出为JPEG或TIFF等图像。我到现在为止已经到目前为止:
int main(int argc,char * argv []){
char filename [255]; //文件名ping。
OSErr e; //返回错误
FSSpec filespec; // QT文件规范
short filemovie; // QT电影句柄。
电影电影; // QT电影对象。
InitializeQTML(0);
EnterMovies();
//由于QT的Mac源码,必须将C-string filename
//转换为Pascal计数的字符串,然后使用它来创建一个filespec。
c2pstr(filename);
FSMakeFSSpec(0,0L,(ConstStr255Param)filename,& filespec);
OpenMovieFile(& filespec,& filemovie,fsRdPerm);
NewMovieFromFile(& movie,filemovie,nil,nil,newMovieActive,nil);
...
直到现在,它工作正常(我用 TimeValue movietime = GetMovieDuration(movie);
并打印),但现在我想要获取电影的每一帧并将其导出到一个文件(首先,稍后我只想保留数据在记忆中使用它,但我必须知道它是否真的有效,所以现在出口到一个图像文件是更好的)。
我该怎么做?我需要一个GWorld或PixMap吗?如何从电影文件中获取一个GWorld / PixMap,特别是每一帧?
编辑:我的平台是WinXP
作为一个开始,这篇关于电影出口商的文章应该几乎让你开始:
即使MacTech是Mac资源,所有描述的API函数应该是可以在QuickTime for Windows SDK中使用。
一旦我找到时间,我将一起拍下一些示例代码作为参考。
修改
请看本书摘录其他信息:
$ a $ b
QdHL-w8E&安培; SIG = A6OiGPRIV-xvdV7esJxTDUDG1Tk&安培; HL = EN&安培; EI = R1wvS8-uC9eGsAbo7-DDBw&安培; SA = X&安培; OI = book_result&安培; CT =导致&安培; resnum = 9&安培; VED = 0CBwQ6AEwCA#V = onepage&安培; Q = ConvertMovieToFile&安培; f = falserel =nofollow noreferrer> QuickTime工具包 - Google图书的基本电影播放和媒体类型
编辑2 - 高-Level方法:电影出口商
如果您需要完成的任务是从QuickTime Movie中提取所有视频帧,并将其转换为QuickTime API,如果使用电影导出器,则不需要执行任何低级别的操作。
以下示例代码可以提取并使用编程调用的电影导出对话框将QuickTime Movie中的所有视频帧转换为一组JPEG文件。
只需选择电影到图像序列在对话框的导出组合框中,选择您的想法点击选项的图像格式。
注意1:如果您需要以非交互方式执行此操作,只需让我知道。 >
注2:为了清楚起见,省略错误处理
#include电影.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();
//设置源路径的Core Foundation字符串(argv [1])包含要转换的文件的完整路径
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;
//使影片活动
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;
//获取电影文件的电影
NewMovieFromProperties(movie_prop_count,movie_props,0,0,& movie);
//调用转换对话框
ConvertMovieToFile(movie,0,0,0,'TVOD',0,0,flags,0);
//清理
DisposeMovie(电影);
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();
...
这篇关于从Movie-File(QuickTime-API)将每帧导出为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!