1 /* === S Y N F I G ========================================================= */
2 /*! \file mptr_ffmpeg.cpp
3 ** \brief ppm Target Module
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include <ETL/stringf>
33 #include "mptr_ffmpeg.h"
38 #include <ETL/stringf>
41 /* === M A C R O S ========================================================= */
43 using namespace synfig;
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_IMPORTER_INIT(ffmpeg_mptr);
50 SYNFIG_IMPORTER_SET_NAME(ffmpeg_mptr,"ffmpeg");
51 SYNFIG_IMPORTER_SET_EXT(ffmpeg_mptr,"avi");
52 SYNFIG_IMPORTER_SET_VERSION(ffmpeg_mptr,"0.1");
53 SYNFIG_IMPORTER_SET_CVS_ID(ffmpeg_mptr,"$Id: mptr_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
55 /* === M E T H O D S ======================================================= */
58 ffmpeg_mptr::seek_to(int frame)
60 if(frame<cur_frame || !file)
69 command=strprintf("ffmpeg -i \"%s\" -an -f image2pipe -vcodec ppm -\n",filename.c_str());
71 file=popen(command.c_str(),"r");
75 cerr<<"Unable to open pipe to ffmpeg"<<endl;
81 while(cur_frame<frame-1)
83 cerr<<"Seeking to..."<<frame<<'('<<cur_frame<<')'<<endl;
91 ffmpeg_mptr::grab_frame(void)
95 cerr<<"unable to open "<<filename<<endl;
101 cookie[0]=fgetc(file);
102 cookie[1]=fgetc(file);
104 if(cookie[0]!='P' || cookie[1]!='6')
106 cerr<<"stream not in PPM format \""<<cookie[0]<<cookie[1]<<'"'<<endl;
111 fscanf(file,"%d %d\n",&w,&h);
112 fscanf(file,"%f",&divisor);
121 for(y=0;y<frame.get_h();y++)
122 for(x=0;x<frame.get_w();x++)
128 (float)(unsigned char)fgetc(file)/divisor,
129 (float)(unsigned char)fgetc(file)/divisor,
130 (float)(unsigned char)fgetc(file)/divisor,
133 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file));
134 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file));
135 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file));
147 ffmpeg_mptr::ffmpeg_mptr(const char *f)
149 #ifdef HAVE_TERMIOS_H
150 tcgetattr (0, &oldtty);
158 ffmpeg_mptr::~ffmpeg_mptr()
162 #ifdef HAVE_TERMIOS_H
163 tcsetattr(0,TCSANOW,&oldtty);
168 ffmpeg_mptr::get_frame(synfig::Surface &surface,Time time, synfig::ProgressCallback *)
170 int i=(int)(time*fps);