1 /*! ========================================================================
4 ** $Id: mptr_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include <ETL/stringf>
32 #include "mptr_ffmpeg.h"
37 #include <ETL/stringf>
40 /* === M A C R O S ========================================================= */
42 using namespace synfig;
46 /* === G L O B A L S ======================================================= */
48 SYNFIG_IMPORTER_INIT(ffmpeg_mptr);
49 SYNFIG_IMPORTER_SET_NAME(ffmpeg_mptr,"ffmpeg");
50 SYNFIG_IMPORTER_SET_EXT(ffmpeg_mptr,"avi");
51 SYNFIG_IMPORTER_SET_VERSION(ffmpeg_mptr,"0.1");
52 SYNFIG_IMPORTER_SET_CVS_ID(ffmpeg_mptr,"$Id: mptr_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
54 /* === M E T H O D S ======================================================= */
57 ffmpeg_mptr::seek_to(int frame)
59 if(frame<cur_frame || !file)
68 command=strprintf("ffmpeg -i \"%s\" -an -f image2pipe -vcodec ppm -\n",filename.c_str());
70 file=popen(command.c_str(),"r");
74 cerr<<"Unable to open pipe to ffmpeg"<<endl;
80 while(cur_frame<frame-1)
82 cerr<<"Seeking to..."<<frame<<'('<<cur_frame<<')'<<endl;
90 ffmpeg_mptr::grab_frame(void)
94 cerr<<"unable to open "<<filename<<endl;
100 cookie[0]=fgetc(file);
101 cookie[1]=fgetc(file);
103 if(cookie[0]!='P' || cookie[1]!='6')
105 cerr<<"stream not in PPM format \""<<cookie[0]<<cookie[1]<<'"'<<endl;
110 fscanf(file,"%d %d\n",&w,&h);
111 fscanf(file,"%f",&divisor);
120 for(y=0;y<frame.get_h();y++)
121 for(x=0;x<frame.get_w();x++)
127 (float)(unsigned char)fgetc(file)/divisor,
128 (float)(unsigned char)fgetc(file)/divisor,
129 (float)(unsigned char)fgetc(file)/divisor,
132 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file));
133 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file));
134 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file));
146 ffmpeg_mptr::ffmpeg_mptr(const char *f)
148 #ifdef HAVE_TERMIOS_H
149 tcgetattr (0, &oldtty);
157 ffmpeg_mptr::~ffmpeg_mptr()
161 #ifdef HAVE_TERMIOS_H
162 tcsetattr(0,TCSANOW,&oldtty);
167 ffmpeg_mptr::get_frame(synfig::Surface &surface,Time time, synfig::ProgressCallback *)
169 int i=(int)(time*fps);