1 /* === S Y N F I G ========================================================= */
2 /*! \file trgt_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 ======================================================= */
34 #include <ETL/stringf>
35 #include "trgt_ffmpeg.h"
43 /* === M A C R O S ========================================================= */
45 using namespace synfig;
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_TARGET_INIT(ffmpeg_trgt);
52 SYNFIG_TARGET_SET_NAME(ffmpeg_trgt,"ffmpeg");
53 SYNFIG_TARGET_SET_EXT(ffmpeg_trgt,"mpg");
54 SYNFIG_TARGET_SET_VERSION(ffmpeg_trgt,"0.1");
55 SYNFIG_TARGET_SET_CVS_ID(ffmpeg_trgt,"$Id: trgt_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
57 /* === M E T H O D S ======================================================= */
59 ffmpeg_trgt::ffmpeg_trgt(const char *Filename)
69 ffmpeg_trgt::~ffmpeg_trgt()
79 delete [] color_buffer;
83 ffmpeg_trgt::set_rend_desc(RendDesc *given_desc)
85 //given_desc->set_pixel_format(PF_RGB);
87 // Make sure that the width and height
89 given_desc->set_w((given_desc->get_w()+4)/8*8);
90 given_desc->set_h((given_desc->get_h()+4)/8*8);
94 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
95 float fps=given_desc->get_frame_rate();
97 given_desc->set_frame_rate(23.976);
98 if(fps>=24.0 && fps <25.0)
99 given_desc->set_frame_rate(24);
100 if(fps>=25.0 && fps <29.97)
101 given_desc->set_frame_rate(25);
102 if(fps>=29.97 && fps <30.0)
103 given_desc->set_frame_rate(29.97);
104 if(fps>=29.97 && fps <30.0)
105 given_desc->set_frame_rate(29.97);
106 if(fps>=30.0 && fps <50.0)
107 given_desc->set_frame_rate(30.0);
108 if(fps>=50.0 && fps <59.94)
109 given_desc->set_frame_rate(50);
111 given_desc->set_frame_rate(59.94);
122 imagecount=desc.get_frame_start();
123 if(desc.get_frame_end()-desc.get_frame_start()>0)
127 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());
129 file=popen(command.c_str(),"w");
135 synfig::error(_("Unable to open pipe to ffmpeg"));
143 ffmpeg_trgt::end_frame()
145 //fprintf(file, " ");
151 ffmpeg_trgt::start_frame(synfig::ProgressCallback *callback)
153 int w=desc.get_w(),h=desc.get_h();
158 fprintf(file, "P6\n");
159 fprintf(file, "%d %d\n", w, h);
160 fprintf(file, "%d\n", 255);
163 buffer=new unsigned char[3*w];
164 delete [] color_buffer;
165 color_buffer=new Color[w];
171 ffmpeg_trgt::start_scanline(int scanline)
177 ffmpeg_trgt::end_scanline()
182 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
184 if(!fwrite(buffer,1,desc.get_w()*3,file))