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 ======================================================= */
60 bsd_mpeg1::New(const char *filename)
62 return new bsd_mpeg1(filename);
65 bsd_mpeg1::bsd_mpeg1(const char *Filename)
68 passthru=ppm::New((tmp_dir+"temp.ppm").c_str());
73 bsd_mpeg1::~bsd_mpeg1()
78 cerr<<"Encoding "<<filename<<"with \"mpeg_encode\" utility..."<<endl;
79 if(system("mpeg_encode -float-dct -realquiet /tmp/temp.param")!=0)
81 cerr<<"Failed to encode "<<filename<<"with \"mpeg_encode\" utility"<<endl;
82 cerr<<"Are you sure it is installed?"<<endl;
87 bsd_mpeg1::set_rend_desc(RendDesc *given_desc)
93 paramfile=fopen((tmp_dir+"temp.param").c_str(),"wt");
94 int bitrate=150; // kbytes per second
95 int buffer_drift=50; // bitrate drift (in kbytes per second)
101 "PATTERN IBBPBBPBBPBBPBBP\n"
103 "BASE_FILE_FORMAT PPM\n"
106 "SLICES_PER_FRAME 1\n"
110 "PSEARCH_ALG LOGARITHMIC\n"
111 "BSEARCH_ALG CROSS2\n"
118 "REFERENCE_FRAME ORIGINAL\n"
120 // "BIT_RATE 1000000\n"
121 // "BUFFER_SIZE 327680\n"
123 ,filename.c_str(),bitrate,buffer_drift);
124 float fps=given_desc->get_frame_rate();
127 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
131 fprintf(paramfile,"FRAME_RATE 23.976\n");
132 given_desc->set_frame_rate(23.976);
134 if(fps>=24.0 && fps <25.0)
136 fprintf(paramfile,"FRAME_RATE 24\n");
137 given_desc->set_frame_rate(24);
139 if(fps>=25.0 && fps <29.97)
141 fprintf(paramfile,"FRAME_RATE 25\n");
142 given_desc->set_frame_rate(25);
144 if(fps>=29.97 && fps <30.0)
146 fprintf(paramfile,"FRAME_RATE 29.97\n");
147 given_desc->set_frame_rate(29.97);
149 if(fps>=29.97 && fps <30.0)
151 fprintf(paramfile,"FRAME_RATE 29.97\n");
152 given_desc->set_frame_rate(29.97);
154 if(fps>=30.0 && fps <50.0)
156 fprintf(paramfile,"FRAME_RATE 30\n");
157 given_desc->set_frame_rate(30.0);
159 if(fps>=50.0 && fps <59.94)
161 fprintf(paramfile,"FRAME_RATE 50\n");
162 given_desc->set_frame_rate(50);
166 fprintf(paramfile,"FRAME_RATE 59.94\n");
167 given_desc->set_frame_rate(59.94);
170 // Make sure that the width and height
171 // are multiples of 8
172 given_desc->set_w((given_desc->get_w()+4)/8*8);
173 given_desc->set_h((given_desc->get_h()+4)/8*8);
175 if(!passthru->set_rend_desc(given_desc))
182 "tmp/temp*.ppm [%04d-%04d]\n"
183 "END_INPUT\n",desc.get_frame_start(),desc.get_frame_end()-1);
192 bsd_mpeg1::end_frame()
194 passthru->end_frame();
198 bsd_mpeg1::start_frame(synfig::ProgressCallback *callback)
200 return passthru->start_frame(callback);
204 bsd_mpeg1::start_scanline(int scanline)
206 return passthru->start_scanline(scanline);
210 bsd_mpeg1::end_scanline(void)
212 return passthru->end_scanline();