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"
29 #include "indexfile.inc"
31 #include "lame/lame.h"
32 #include "libzmpeg3.h"
33 #include "mainprogress.inc"
41 // Mpeg2enc prototypes
42 void mpeg2enc_init_buffers();
43 int mpeg2enc(int argc, char *argv[]);
44 void mpeg2enc_set_w(int width);
45 void mpeg2enc_set_h(int height);
46 void mpeg2enc_set_rate(double rate);
47 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
57 class FileMPEG : public FileBase
60 FileMPEG(Asset *asset, File *file);
63 friend class FileMPEGVideo;
65 static void get_parameters(BC_WindowBase *parent_window,
67 BC_WindowBase* &format_window,
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);
115 void to_streamchannel(int channel, int &stream_out, int &channel_out);
116 int reset_parameters_derived();
117 // File descriptor for decoder
120 // Thread for video encoder
121 FileMPEGVideo *video_out;
122 // Command line for video encoder
123 ArrayList<char*> vcommand_line;
124 void append_vcommand_line(const char *string);
128 int record_fd() { return recd_fd; }
130 // MJPEGtools encoder
133 Condition *next_frame_lock;
134 Condition *next_frame_done;
137 unsigned char *mjpeg_y;
138 unsigned char *mjpeg_u;
139 unsigned char *mjpeg_v;
140 char mjpeg_command[BCTEXTLEN];
143 static int skimming(void *vp, int track);
144 skim_fn skim_callback;
147 // toc scan commercial detection
148 static int toc_nail(void *vp, int track);
150 // Temporary for color conversion
153 unsigned char *twolame_temp, *twolame_out;
154 int twolame_allocation;
157 twolame_options *twopts;
162 int lame_output_allocation;
164 // Lame puts 0 before stream
167 lame_global_flags *lame_global;
172 class FileMPEGVideo : public Thread
175 FileMPEGVideo(FileMPEG *file);
183 class MPEGConfigAudioPopup;
187 class MPEGConfigAudio : public BC_Window
190 MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
193 void create_objects();
196 BC_WindowBase *parent_window;
197 MPEGABitrate *bitrate;
198 char string[BCTEXTLEN];
203 class MPEGLayer : public BC_PopupMenu
206 MPEGLayer(int x, int y, MPEGConfigAudio *gui);
207 void create_objects();
209 static int string_to_layer(char *string);
210 static char* layer_to_string(int derivative);
212 MPEGConfigAudio *gui;
215 class MPEGABitrate : public BC_PopupMenu
218 MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
220 void create_objects();
221 void set_layer(int layer);
224 static int string_to_bitrate(char *string);
225 static char* bitrate_to_string(char *string, int bitrate);
227 MPEGConfigAudio *gui;
232 class MPEGConfigVideo;
236 class MPEGPreset : public BC_PopupMenu
239 MPEGPreset(int x, int y, MPEGConfigVideo *gui);
240 void create_objects();
242 static int string_to_value(char *string);
243 static char* value_to_string(int value);
244 MPEGConfigVideo *gui;
247 class MPEGColorModel : public BC_PopupMenu
250 MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
251 void create_objects();
253 static int string_to_cmodel(char *string);
254 static char* cmodel_to_string(int cmodel);
256 MPEGConfigVideo *gui;
260 class MPEGDerivative : public BC_PopupMenu
263 MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
264 void create_objects();
266 static int string_to_derivative(char *string);
267 static char* derivative_to_string(int derivative);
269 MPEGConfigVideo *gui;
272 class MPEGBitrate : public BC_TextBox
275 MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
277 MPEGConfigVideo *gui;
280 class MPEGQuant : public BC_TumbleTextBox
283 MPEGQuant(int x, int y, MPEGConfigVideo *gui);
285 MPEGConfigVideo *gui;
288 class MPEGIFrameDistance : public BC_TumbleTextBox
291 MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
293 MPEGConfigVideo *gui;
296 class MPEGPFrameDistance : public BC_TumbleTextBox
299 MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
301 MPEGConfigVideo *gui;
304 class MPEGFixedBitrate : public BC_Radial
307 MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
309 MPEGConfigVideo *gui;
312 class MPEGFixedQuant : public BC_Radial
315 MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
317 MPEGConfigVideo *gui;
320 class MPEGSeqCodes : public BC_CheckBox
323 MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
325 MPEGConfigVideo *gui;
331 class MPEGConfigVideo : public BC_Window
334 MPEGConfigVideo(BC_WindowBase *parent_window,
338 void create_objects();
340 void delete_cmodel_objs();
342 void update_cmodel_objs();
344 BC_WindowBase *parent_window;
347 MPEGColorModel *cmodel;
348 MPEGDerivative *derivative;
349 MPEGBitrate *bitrate;
350 MPEGFixedBitrate *fixed_bitrate;
352 MPEGFixedQuant *fixed_quant;
353 MPEGIFrameDistance *iframe_distance;
354 MPEGPFrameDistance *pframe_distance;
355 BC_CheckBox *top_field_first;
356 BC_CheckBox *progressive;
357 BC_CheckBox *denoise;
358 BC_CheckBox *seq_codes;
360 ArrayList<BC_Title*> titles;
361 ArrayList<BC_SubWindow*> tools;