1 /* === S Y N F I G ========================================================= */
3 ** \brief bsd_mpeg1 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 ======================================================= */
36 #include <ETL/stringf>
44 /* === M A C R O S ========================================================= */
46 using namespace synfig;
50 /* === G L O B A L S ======================================================= */
52 const char bsd_mpeg1::Name[]="mpeg1";
53 const char bsd_mpeg1::Ext[]="mpg";
55 #define tmp_dir string("/tmp/")
57 /* === M E T H O D S ======================================================= */
59 #error This code has tmpfile vulnerabilites
62 bsd_mpeg1::New(const char *filename)
64 return new bsd_mpeg1(filename);
67 bsd_mpeg1::bsd_mpeg1(const char *Filename,
68 const synfig::TargetParam& /* params */)
71 passthru=ppm::New((tmp_dir+"temp.ppm").c_str());
76 bsd_mpeg1::~bsd_mpeg1()
81 cerr<<"Encoding "<<filename<<"with \"mpeg_encode\" utility..."<<endl;
82 if(system("mpeg_encode -float-dct -realquiet /tmp/temp.param")!=0)
84 cerr<<"Failed to encode "<<filename<<"with \"mpeg_encode\" utility"<<endl;
85 cerr<<"Are you sure it is installed?"<<endl;
90 bsd_mpeg1::set_rend_desc(RendDesc *given_desc)
96 paramfile=fopen((tmp_dir+"temp.param").c_str(),"wt");
97 int bitrate=150; // kbytes per second
98 int buffer_drift=50; // bitrate drift (in kbytes per second)
101 buffer_drift*=8*1024;
104 "PATTERN IBBPBBPBBPBBPBBP\n"
106 "BASE_FILE_FORMAT PPM\n"
109 "SLICES_PER_FRAME 1\n"
113 "PSEARCH_ALG LOGARITHMIC\n"
114 "BSEARCH_ALG CROSS2\n"
121 "REFERENCE_FRAME ORIGINAL\n"
123 // "BIT_RATE 1000000\n"
124 // "BUFFER_SIZE 327680\n"
126 ,filename.c_str(),bitrate,buffer_drift);
127 float fps=given_desc->get_frame_rate();
130 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
134 fprintf(paramfile,"FRAME_RATE 23.976\n");
135 given_desc->set_frame_rate(23.976);
137 if(fps>=24.0 && fps <25.0)
139 fprintf(paramfile,"FRAME_RATE 24\n");
140 given_desc->set_frame_rate(24);
142 if(fps>=25.0 && fps <29.97)
144 fprintf(paramfile,"FRAME_RATE 25\n");
145 given_desc->set_frame_rate(25);
147 if(fps>=29.97 && fps <30.0)
149 fprintf(paramfile,"FRAME_RATE 29.97\n");
150 given_desc->set_frame_rate(29.97);
152 if(fps>=29.97 && fps <30.0)
154 fprintf(paramfile,"FRAME_RATE 29.97\n");
155 given_desc->set_frame_rate(29.97);
157 if(fps>=30.0 && fps <50.0)
159 fprintf(paramfile,"FRAME_RATE 30\n");
160 given_desc->set_frame_rate(30.0);
162 if(fps>=50.0 && fps <59.94)
164 fprintf(paramfile,"FRAME_RATE 50\n");
165 given_desc->set_frame_rate(50);
169 fprintf(paramfile,"FRAME_RATE 59.94\n");
170 given_desc->set_frame_rate(59.94);
173 // Make sure that the width and height
174 // are multiples of 8
175 given_desc->set_w((given_desc->get_w()+4)/8*8);
176 given_desc->set_h((given_desc->get_h()+4)/8*8);
178 if(!passthru->set_rend_desc(given_desc))
185 "tmp/temp*.ppm [%04d-%04d]\n"
186 "END_INPUT\n",desc.get_frame_start(),desc.get_frame_end()-1);
195 bsd_mpeg1::end_frame()
197 passthru->end_frame();
201 bsd_mpeg1::start_frame(synfig::ProgressCallback *callback)
203 return passthru->start_frame(callback);
207 bsd_mpeg1::start_scanline(int scanline)
209 return passthru->start_scanline(scanline);
213 bsd_mpeg1::end_scanline(void)
215 return passthru->end_scanline();