1 /*! ========================================================================
3 ** bsd_mpeg1 Target Module
4 ** $Id: trgt_mpg.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
32 #include <ETL/stringf>
40 /* === M A C R O S ========================================================= */
42 using namespace sinfg;
46 /* === G L O B A L S ======================================================= */
48 const char bsd_mpeg1::Name[]="mpeg1";
49 const char bsd_mpeg1::Ext[]="mpg";
51 #define tmp_dir string("/tmp/")
53 /* === M E T H O D S ======================================================= */
56 bsd_mpeg1::New(const char *filename)
58 return new bsd_mpeg1(filename);
61 bsd_mpeg1::bsd_mpeg1(const char *Filename)
64 passthru=ppm::New((tmp_dir+"temp.ppm").c_str());
69 bsd_mpeg1::~bsd_mpeg1()
74 cerr<<"Encoding "<<filename<<"with \"mpeg_encode\" utility..."<<endl;
75 if(system("mpeg_encode -float-dct -realquiet /tmp/temp.param")!=0)
77 cerr<<"Failed to encode "<<filename<<"with \"mpeg_encode\" utility"<<endl;
78 cerr<<"Are you sure it is installed?"<<endl;
83 bsd_mpeg1::set_rend_desc(RendDesc *given_desc)
89 paramfile=fopen((tmp_dir+"temp.param").c_str(),"wt");
90 int bitrate=150; // kbytes per second
91 int buffer_drift=50; // bitrate drift (in kbytes per second)
97 "PATTERN IBBPBBPBBPBBPBBP\n"
99 "BASE_FILE_FORMAT PPM\n"
102 "SLICES_PER_FRAME 1\n"
106 "PSEARCH_ALG LOGARITHMIC\n"
107 "BSEARCH_ALG CROSS2\n"
114 "REFERENCE_FRAME ORIGINAL\n"
116 // "BIT_RATE 1000000\n"
117 // "BUFFER_SIZE 327680\n"
119 ,filename.c_str(),bitrate,buffer_drift);
120 float fps=given_desc->get_frame_rate();
123 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
127 fprintf(paramfile,"FRAME_RATE 23.976\n");
128 given_desc->set_frame_rate(23.976);
130 if(fps>=24.0 && fps <25.0)
132 fprintf(paramfile,"FRAME_RATE 24\n");
133 given_desc->set_frame_rate(24);
135 if(fps>=25.0 && fps <29.97)
137 fprintf(paramfile,"FRAME_RATE 25\n");
138 given_desc->set_frame_rate(25);
140 if(fps>=29.97 && fps <30.0)
142 fprintf(paramfile,"FRAME_RATE 29.97\n");
143 given_desc->set_frame_rate(29.97);
145 if(fps>=29.97 && fps <30.0)
147 fprintf(paramfile,"FRAME_RATE 29.97\n");
148 given_desc->set_frame_rate(29.97);
150 if(fps>=30.0 && fps <50.0)
152 fprintf(paramfile,"FRAME_RATE 30\n");
153 given_desc->set_frame_rate(30.0);
155 if(fps>=50.0 && fps <59.94)
157 fprintf(paramfile,"FRAME_RATE 50\n");
158 given_desc->set_frame_rate(50);
162 fprintf(paramfile,"FRAME_RATE 59.94\n");
163 given_desc->set_frame_rate(59.94);
166 // Make sure that the width and height
167 // are multiples of 8
168 given_desc->set_w((given_desc->get_w()+4)/8*8);
169 given_desc->set_h((given_desc->get_h()+4)/8*8);
171 if(!passthru->set_rend_desc(given_desc))
178 "tmp/temp*.ppm [%04d-%04d]\n"
179 "END_INPUT\n",desc.get_frame_start(),desc.get_frame_end()-1);
188 bsd_mpeg1::end_frame()
190 passthru->end_frame();
194 bsd_mpeg1::start_frame(sinfg::ProgressCallback *callback)
196 return passthru->start_frame(callback);
200 bsd_mpeg1::start_scanline(int scanline)
202 return passthru->start_scanline(scanline);
206 bsd_mpeg1::end_scanline(void)
208 return passthru->end_scanline();