1 /*! ========================================================================
4 ** $Id: trgt_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 ======================================================= */
33 #include <ETL/stringf>
34 #include "trgt_ffmpeg.h"
42 /* === M A C R O S ========================================================= */
44 using namespace synfig;
48 /* === G L O B A L S ======================================================= */
50 SYNFIG_TARGET_INIT(ffmpeg_trgt);
51 SYNFIG_TARGET_SET_NAME(ffmpeg_trgt,"ffmpeg");
52 SYNFIG_TARGET_SET_EXT(ffmpeg_trgt,"mpg");
53 SYNFIG_TARGET_SET_VERSION(ffmpeg_trgt,"0.1");
54 SYNFIG_TARGET_SET_CVS_ID(ffmpeg_trgt,"$Id: trgt_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
56 /* === M E T H O D S ======================================================= */
58 ffmpeg_trgt::ffmpeg_trgt(const char *Filename)
68 ffmpeg_trgt::~ffmpeg_trgt()
78 delete [] color_buffer;
82 ffmpeg_trgt::set_rend_desc(RendDesc *given_desc)
84 //given_desc->set_pixel_format(PF_RGB);
86 // Make sure that the width and height
88 given_desc->set_w((given_desc->get_w()+4)/8*8);
89 given_desc->set_h((given_desc->get_h()+4)/8*8);
93 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
94 float fps=given_desc->get_frame_rate();
96 given_desc->set_frame_rate(23.976);
97 if(fps>=24.0 && fps <25.0)
98 given_desc->set_frame_rate(24);
99 if(fps>=25.0 && fps <29.97)
100 given_desc->set_frame_rate(25);
101 if(fps>=29.97 && fps <30.0)
102 given_desc->set_frame_rate(29.97);
103 if(fps>=29.97 && fps <30.0)
104 given_desc->set_frame_rate(29.97);
105 if(fps>=30.0 && fps <50.0)
106 given_desc->set_frame_rate(30.0);
107 if(fps>=50.0 && fps <59.94)
108 given_desc->set_frame_rate(50);
110 given_desc->set_frame_rate(59.94);
121 imagecount=desc.get_frame_start();
122 if(desc.get_frame_end()-desc.get_frame_start()>0)
126 command=strprintf("ffmpeg -f image2pipe -vcodec ppm -an -r %f -i pipe: -loop -hq -title \"%s\" -vcodec mpeg1video -y \"%s\"\n",desc.get_frame_rate(),get_canvas()->get_name().c_str(),filename.c_str());
128 file=popen(command.c_str(),"w");
134 synfig::error(_("Unable to open pipe to ffmpeg"));
142 ffmpeg_trgt::end_frame()
144 //fprintf(file, " ");
150 ffmpeg_trgt::start_frame(synfig::ProgressCallback *callback)
152 int w=desc.get_w(),h=desc.get_h();
157 fprintf(file, "P6\n");
158 fprintf(file, "%d %d\n", w, h);
159 fprintf(file, "%d\n", 255);
162 buffer=new unsigned char[3*w];
163 delete [] color_buffer;
164 color_buffer=new Color[w];
170 ffmpeg_trgt::start_scanline(int scanline)
176 ffmpeg_trgt::end_scanline()
181 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
183 if(!fwrite(buffer,1,desc.get_w()*3,file))