1 /*! ========================================================================
4 ** $Id: mptr_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
30 #include <ETL/stringf>
31 #include "mptr_ffmpeg.h"
36 #include <ETL/stringf>
39 /* === M A C R O S ========================================================= */
41 using namespace sinfg;
45 /* === G L O B A L S ======================================================= */
47 SINFG_IMPORTER_INIT(ffmpeg_mptr);
48 SINFG_IMPORTER_SET_NAME(ffmpeg_mptr,"ffmpeg");
49 SINFG_IMPORTER_SET_EXT(ffmpeg_mptr,"avi");
50 SINFG_IMPORTER_SET_VERSION(ffmpeg_mptr,"0.1");
51 SINFG_IMPORTER_SET_CVS_ID(ffmpeg_mptr,"$Id: mptr_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
53 /* === M E T H O D S ======================================================= */
56 ffmpeg_mptr::seek_to(int frame)
58 if(frame<cur_frame || !file)
67 command=strprintf("ffmpeg -i \"%s\" -an -f ppmpipe -\n",filename.c_str());
69 file=popen(command.c_str(),"r");
73 cerr<<"Unable to open pipe to ffmpeg"<<endl;
79 while(cur_frame<frame-1)
81 cerr<<"Seeking to..."<<frame<<'('<<cur_frame<<')'<<endl;
89 ffmpeg_mptr::grab_frame(void)
93 cerr<<"unable to open "<<filename<<endl;
99 cookie[0]=fgetc(file);
100 cookie[1]=fgetc(file);
102 if(cookie[0]!='P' || cookie[1]!='6')
104 cerr<<"stream not in PPM format \""<<cookie[0]<<cookie[1]<<'"'<<endl;
109 fscanf(file,"%d %d\n",&w,&h);
110 fscanf(file,"%f",&divisor);
119 for(y=0;y<frame.get_h();y++)
120 for(x=0;x<frame.get_w();x++)
126 (float)(unsigned char)fgetc(file)/divisor,
127 (float)(unsigned char)fgetc(file)/divisor,
128 (float)(unsigned char)fgetc(file)/divisor,
131 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file));
132 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file));
133 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file));
145 ffmpeg_mptr::ffmpeg_mptr(const char *f)
147 #ifdef HAVE_TERMIOS_H
148 tcgetattr (0, &oldtty);
156 ffmpeg_mptr::~ffmpeg_mptr()
160 #ifdef HAVE_TERMIOS_H
161 tcsetattr(0,TCSANOW,&oldtty);
166 ffmpeg_mptr::get_frame(sinfg::Surface &surface,Time time, sinfg::ProgressCallback *)
168 int i=(int)(time*fps);