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
26 #include "bitspopup.inc"
27 #include "condition.inc"
31 #include "indexfile.inc"
33 #include "lame/lame.h"
34 #include "libzmpeg3.h"
35 #include "mainprogress.inc"
43 // Mpeg2enc prototypes
44 void mpeg2enc_init_buffers();
45 int mpeg2enc(int argc, char *argv[]);
46 void mpeg2enc_set_w(int width);
47 void mpeg2enc_set_h(int height);
48 void mpeg2enc_set_rate(double rate);
49 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
59 class FileMPEG : public FileBase
62 FileMPEG(Asset *asset, File *file);
65 friend class FileMPEGVideo;
67 static void get_parameters(BC_WindowBase *parent_window,
68 Asset *asset, BC_WindowBase* &format_window,
69 int audio_options, int video_options, EDL *edl);
71 static int check_sig(Asset *asset);
73 // Get extra info for info dialog.
74 static void get_info(char *title_path, char *path, char *text, int len);
75 int open_file(int rd, int wr);
77 int create_toc(char *toc_path);
78 int get_index(IndexFile *index_file, MainProgressBar *progress_bar);
80 int set_video_position(int64_t x);
81 int set_audio_position(int64_t x);
82 int write_samples(double **buffer,
84 int write_frames(VFrame ***frames, int len);
86 int read_frame(VFrame *frame);
87 int read_samples(double *buffer, int64_t len);
89 int64_t get_memory_usage();
90 int set_program(int no);
91 int get_cell_time(int no, double &time);
92 int get_system_time(int64_t &tm);
93 int get_video_pid(int track);
94 int get_video_info(int track, int &pid, double &framerate,
95 int &width, int &height, char *title=0);
96 int select_video_stream(Asset *asset, int vstream);
97 int select_audio_stream(Asset *asset, int astream);
98 int get_thumbnail(int stream,
99 int64_t &position, unsigned char *&thumbnail, int &ww, int &hh);
100 int set_skimming(int track, int skim, skim_fn fn, void *vp);
101 int skim_video(int track, void *vp, skim_fn fn);
102 int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
104 // Direct copy routines
105 static int get_best_colormodel(Asset *asset, int driver);
106 int colormodel_supported(int colormodel);
107 // zmpeg3<->BC colormodels
108 static int zmpeg3_cmdl(int colormodel);
109 static int bc_colormodel(int cmdl);
110 static const char *zmpeg3_cmdl_name(int cmdl);
111 // This file can copy frames directly from the asset
112 int can_copy_from(Asset *asset, int64_t position);
113 int can_scale_input() { return 1; }
116 void to_streamchannel(int channel, int &stream_out, int &channel_out);
117 int reset_parameters_derived();
118 // File descriptor for decoder
121 // Thread for video encoder
122 FileMPEGVideo *video_out;
123 // Command line for video encoder
124 ArrayList<char*> vcommand_line;
125 void append_vcommand_line(const char *string);
129 int record_fd() { return recd_fd; }
131 // MJPEGtools encoder
134 Condition *next_frame_lock;
135 Condition *next_frame_done;
138 unsigned char *mjpeg_y;
139 unsigned char *mjpeg_u;
140 unsigned char *mjpeg_v;
141 char mjpeg_command[BCTEXTLEN];
144 static int skimming(void *vp, int track);
145 skim_fn skim_callback;
148 // toc scan commercial detection
149 static int toc_nail(void *vp, int track);
151 // Temporary for color conversion
154 unsigned char *twolame_temp, *twolame_out;
155 int twolame_allocation;
158 twolame_options *twopts;
163 int lame_output_allocation;
165 // Lame puts 0 before stream
168 lame_global_flags *lame_global;
173 class FileMPEGVideo : public Thread
176 FileMPEGVideo(FileMPEG *file);
184 class MPEGConfigAudioPopup;
188 class MPEGConfigAudio : public BC_Window
191 MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
194 void create_objects();
197 BC_WindowBase *parent_window;
198 MPEGABitrate *bitrate;
199 char string[BCTEXTLEN];
204 class MPEGLayer : public BC_PopupMenu
207 MPEGLayer(int x, int y, MPEGConfigAudio *gui);
208 void create_objects();
210 static int string_to_layer(char *string);
211 static char* layer_to_string(int derivative);
213 MPEGConfigAudio *gui;
216 class MPEGABitrate : public BC_PopupMenu
219 MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
221 void create_objects();
222 void set_layer(int layer);
225 static int string_to_bitrate(char *string);
226 static char* bitrate_to_string(char *string, int bitrate);
228 MPEGConfigAudio *gui;
233 class MPEGConfigVideo;
237 class MPEGPreset : public BC_PopupMenu
240 MPEGPreset(int x, int y, MPEGConfigVideo *gui);
241 void create_objects();
243 static int string_to_value(char *string);
244 static char* value_to_string(int value);
245 MPEGConfigVideo *gui;
248 class MPEGColorModel : public BC_PopupMenu
251 MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
252 void create_objects();
254 static int string_to_cmodel(char *string);
255 static char* cmodel_to_string(int cmodel);
257 MPEGConfigVideo *gui;
261 class MPEGDerivative : public BC_PopupMenu
264 MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
265 void create_objects();
267 static int string_to_derivative(char *string);
268 static char* derivative_to_string(int derivative);
270 MPEGConfigVideo *gui;
273 class MPEGBitrate : public BC_TextBox
276 MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
278 MPEGConfigVideo *gui;
281 class MPEGQuant : public BC_TumbleTextBox
284 MPEGQuant(int x, int y, MPEGConfigVideo *gui);
286 MPEGConfigVideo *gui;
289 class MPEGIFrameDistance : public BC_TumbleTextBox
292 MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
294 MPEGConfigVideo *gui;
297 class MPEGPFrameDistance : public BC_TumbleTextBox
300 MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
302 MPEGConfigVideo *gui;
305 class MPEGFixedBitrate : public BC_Radial
308 MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
310 MPEGConfigVideo *gui;
313 class MPEGFixedQuant : public BC_Radial
316 MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
318 MPEGConfigVideo *gui;
321 class MPEGSeqCodes : public BC_CheckBox
324 MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
326 MPEGConfigVideo *gui;
332 class MPEGConfigVideo : public BC_Window
335 MPEGConfigVideo(BC_WindowBase *parent_window,
339 void create_objects();
341 void delete_cmodel_objs();
343 void update_cmodel_objs();
345 BC_WindowBase *parent_window;
348 MPEGColorModel *cmodel;
349 MPEGDerivative *derivative;
350 MPEGBitrate *bitrate;
351 MPEGFixedBitrate *fixed_bitrate;
353 MPEGFixedQuant *fixed_quant;
354 MPEGIFrameDistance *iframe_distance;
355 MPEGPFrameDistance *pframe_distance;
356 BC_CheckBox *top_field_first;
357 BC_CheckBox *progressive;
358 BC_CheckBox *denoise;
359 BC_CheckBox *seq_codes;
361 ArrayList<BC_Title*> titles;
362 ArrayList<BC_SubWindow*> tools;