1 /* === S Y N F I G ========================================================= */
2 /*! \file mptr_ffmpeg.cpp
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include <ETL/stringf>
35 #include "mptr_ffmpeg.h"
37 #include <sys/types.h>
43 #include <ETL/stringf>
46 /* === M A C R O S ========================================================= */
48 using namespace synfig;
52 /* === G L O B A L S ======================================================= */
54 SYNFIG_IMPORTER_INIT(ffmpeg_mptr);
55 SYNFIG_IMPORTER_SET_NAME(ffmpeg_mptr,"ffmpeg");
56 SYNFIG_IMPORTER_SET_EXT(ffmpeg_mptr,"avi");
57 SYNFIG_IMPORTER_SET_VERSION(ffmpeg_mptr,"0.1");
58 SYNFIG_IMPORTER_SET_CVS_ID(ffmpeg_mptr,"$Id$");
60 /* === M E T H O D S ======================================================= */
63 ffmpeg_mptr::seek_to(int frame)
65 if(frame<cur_frame || !file)
71 waitpid(pid,&status,0);
77 cerr<<"Unable to open pipe to ffmpeg"<<endl;
84 cerr<<"Unable to open pipe to ffmpeg"<<endl;
90 // Close pipein, not needed
92 // Dup pipein to stdout
93 if( dup2( p[1], STDOUT_FILENO ) == -1 ){
94 cerr<<"Unable to open pipe to ffmpeg"<<endl;
97 // Close the unneeded pipein
99 execlp("ffmpeg", "ffmpeg", "-i", filename.c_str(), "-an", "-f", "image2pipe", "-vcodec", "ppm", "-", (const char *)NULL);
100 // We should never reach here unless the exec failed
101 cerr<<"Unable to open pipe to ffmpeg"<<endl;
105 // Close pipeout, not needed
107 // Save pipeout to file handle, will write to it later
108 file = fdopen(p[0], "wb");
113 cerr<<"Unable to open pipe to ffmpeg"<<endl;
119 while(cur_frame<frame-1)
121 cerr<<"Seeking to..."<<frame<<'('<<cur_frame<<')'<<endl;
129 ffmpeg_mptr::grab_frame(void)
133 cerr<<"unable to open "<<filename<<endl;
139 cookie[0]=fgetc(file);
140 cookie[1]=fgetc(file);
142 if(cookie[0]!='P' || cookie[1]!='6')
144 cerr<<"stream not in PPM format \""<<cookie[0]<<cookie[1]<<'"'<<endl;
149 fscanf(file,"%d %d\n",&w,&h);
150 fscanf(file,"%f",&divisor);
159 for(y=0;y<frame.get_h();y++)
160 for(x=0;x<frame.get_w();x++)
166 (float)(unsigned char)fgetc(file)/divisor,
167 (float)(unsigned char)fgetc(file)/divisor,
168 (float)(unsigned char)fgetc(file)/divisor,
171 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file));
172 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file));
173 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file));
185 ffmpeg_mptr::ffmpeg_mptr(const char *f)
188 #ifdef HAVE_TERMIOS_H
189 tcgetattr (0, &oldtty);
197 ffmpeg_mptr::~ffmpeg_mptr()
203 waitpid(pid,&status,0);
205 #ifdef HAVE_TERMIOS_H
206 tcsetattr(0,TCSANOW,&oldtty);
211 ffmpeg_mptr::get_frame(synfig::Surface &surface,Time time, synfig::ProgressCallback *)
213 int i=(int)(time*fps);