4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "bitspopup.inc"
26 #include "condition.inc"
30 #include "lame/lame.h"
31 #include "libzmpeg3.h"
39 // Mpeg2enc prototypes
40 void mpeg2enc_init_buffers();
41 int mpeg2enc(int argc, char *argv[]);
42 void mpeg2enc_set_w(int width);
43 void mpeg2enc_set_h(int height);
44 void mpeg2enc_set_rate(double rate);
45 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
55 class FileMPEG : public FileBase
58 FileMPEG(Asset *asset, File *file);
61 friend class FileMPEGVideo;
63 static void get_parameters(BC_WindowBase *parent_window,
65 BC_WindowBase* &format_window,
69 static int check_sig(Asset *asset);
71 // Get extra info for info dialog.
72 static void get_info(char *title_path, char *path, char *text, int len);
73 int open_file(int rd, int wr);
78 int get_index(char *index_path);
79 int set_video_position(int64_t x);
80 int set_audio_position(int64_t x);
81 int write_samples(double **buffer,
83 int write_frames(VFrame ***frames, int len);
85 int read_frame(VFrame *frame);
86 int read_samples(double *buffer, int64_t len);
88 int64_t get_memory_usage();
89 int set_program(int no);
90 int get_cell_time(int no, double &time);
91 int get_system_time(int64_t &tm);
92 int get_video_pid(int track);
93 int get_video_info(int track, int &pid, double &framerate,
94 int &width, int &height, char *title=0);
95 int select_video_stream(Asset *asset, int vstream);
96 int select_audio_stream(Asset *asset, int astream);
97 int get_thumbnail(int stream,
98 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh);
99 int set_skimming(int track, int skim, skim_fn fn, void *vp);
100 int skim_video(int track, void *vp, skim_fn fn);
101 int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
103 // Direct copy routines
104 static int get_best_colormodel(Asset *asset, int driver);
105 int colormodel_supported(int colormodel);
106 // zmpeg3<->BC colormodels
107 static int zmpeg3_cmdl(int colormodel);
108 static int bc_colormodel(int cmdl);
109 static const char *zmpeg3_cmdl_name(int cmdl);
110 // This file can copy frames directly from the asset
111 int can_copy_from(Asset *asset, int64_t position);
114 void to_streamchannel(int channel, int &stream_out, int &channel_out);
115 int reset_parameters_derived();
116 // File descriptor for decoder
119 // Thread for video encoder
120 FileMPEGVideo *video_out;
121 // Command line for video encoder
122 ArrayList<char*> vcommand_line;
123 void append_vcommand_line(const char *string);
127 int record_fd() { return recd_fd; }
129 // MJPEGtools encoder
132 Condition *next_frame_lock;
133 Condition *next_frame_done;
136 unsigned char *mjpeg_y;
137 unsigned char *mjpeg_u;
138 unsigned char *mjpeg_v;
139 char mjpeg_command[BCTEXTLEN];
142 static int skimming(void *vp, int track);
143 skim_fn skim_callback;
146 // toc scan commercial detection
147 static int toc_nail(void *vp, int track);
149 // Temporary for color conversion
152 unsigned char *twolame_temp, *twolame_out;
153 int twolame_allocation;
156 twolame_options *twopts;
161 int lame_output_allocation;
163 // Lame puts 0 before stream
166 lame_global_flags *lame_global;
171 class FileMPEGVideo : public Thread
174 FileMPEGVideo(FileMPEG *file);
182 class MPEGConfigAudioPopup;
186 class MPEGConfigAudio : public BC_Window
189 MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
192 void create_objects();
195 BC_WindowBase *parent_window;
196 MPEGABitrate *bitrate;
197 char string[BCTEXTLEN];
202 class MPEGLayer : public BC_PopupMenu
205 MPEGLayer(int x, int y, MPEGConfigAudio *gui);
206 void create_objects();
208 static int string_to_layer(char *string);
209 static char* layer_to_string(int derivative);
211 MPEGConfigAudio *gui;
214 class MPEGABitrate : public BC_PopupMenu
217 MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
219 void create_objects();
220 void set_layer(int layer);
223 static int string_to_bitrate(char *string);
224 static char* bitrate_to_string(char *string, int bitrate);
226 MPEGConfigAudio *gui;
231 class MPEGConfigVideo;
235 class MPEGPreset : public BC_PopupMenu
238 MPEGPreset(int x, int y, MPEGConfigVideo *gui);
239 void create_objects();
241 static int string_to_value(char *string);
242 static char* value_to_string(int value);
243 MPEGConfigVideo *gui;
246 class MPEGColorModel : public BC_PopupMenu
249 MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
250 void create_objects();
252 static int string_to_cmodel(char *string);
253 static char* cmodel_to_string(int cmodel);
255 MPEGConfigVideo *gui;
259 class MPEGDerivative : public BC_PopupMenu
262 MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
263 void create_objects();
265 static int string_to_derivative(char *string);
266 static char* derivative_to_string(int derivative);
268 MPEGConfigVideo *gui;
271 class MPEGBitrate : public BC_TextBox
274 MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
276 MPEGConfigVideo *gui;
279 class MPEGQuant : public BC_TumbleTextBox
282 MPEGQuant(int x, int y, MPEGConfigVideo *gui);
284 MPEGConfigVideo *gui;
287 class MPEGIFrameDistance : public BC_TumbleTextBox
290 MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
292 MPEGConfigVideo *gui;
295 class MPEGPFrameDistance : public BC_TumbleTextBox
298 MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
300 MPEGConfigVideo *gui;
303 class MPEGFixedBitrate : public BC_Radial
306 MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
308 MPEGConfigVideo *gui;
311 class MPEGFixedQuant : public BC_Radial
314 MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
316 MPEGConfigVideo *gui;
319 class MPEGSeqCodes : public BC_CheckBox
322 MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
324 MPEGConfigVideo *gui;
330 class MPEGConfigVideo : public BC_Window
333 MPEGConfigVideo(BC_WindowBase *parent_window,
337 void create_objects();
339 void delete_cmodel_objs();
341 void update_cmodel_objs();
343 BC_WindowBase *parent_window;
346 MPEGColorModel *cmodel;
347 MPEGDerivative *derivative;
348 MPEGBitrate *bitrate;
349 MPEGFixedBitrate *fixed_bitrate;
351 MPEGFixedQuant *fixed_quant;
352 MPEGIFrameDistance *iframe_distance;
353 MPEGPFrameDistance *pframe_distance;
354 BC_CheckBox *top_field_first;
355 BC_CheckBox *progressive;
356 BC_CheckBox *denoise;
357 BC_CheckBox *seq_codes;
359 ArrayList<BC_Title*> titles;
360 ArrayList<BC_SubWindow*> tools;