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);
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);
112 static const char *strtocompression(char *string);
113 static const char *compressiontostr(char *string);
117 void to_streamchannel(int channel, int &stream_out, int &channel_out);
118 int reset_parameters_derived();
119 // File descriptor for decoder
122 // Thread for video encoder
123 FileMPEGVideo *video_out;
124 // Command line for video encoder
125 ArrayList<char*> vcommand_line;
126 void append_vcommand_line(const char *string);
130 int record_fd() { return recd_fd; }
132 // MJPEGtools encoder
135 Condition *next_frame_lock;
136 Condition *next_frame_done;
139 unsigned char *mjpeg_y;
140 unsigned char *mjpeg_u;
141 unsigned char *mjpeg_v;
142 char mjpeg_command[BCTEXTLEN];
145 static int skimming(void *vp, int track);
146 skim_fn skim_callback;
149 // toc scan commercial detection
150 static int toc_nail(void *vp, int track);
152 // Temporary for color conversion
155 unsigned char *twolame_temp, *twolame_out;
156 int twolame_allocation;
159 twolame_options *twopts;
164 int lame_output_allocation;
166 // Lame puts 0 before stream
169 lame_global_flags *lame_global;
174 class FileMPEGVideo : public Thread
177 FileMPEGVideo(FileMPEG *file);
185 class MPEGConfigAudioPopup;
189 class MPEGConfigAudio : public BC_Window
192 MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
195 void create_objects();
198 BC_WindowBase *parent_window;
199 MPEGABitrate *bitrate;
200 char string[BCTEXTLEN];
205 class MPEGLayer : public BC_PopupMenu
208 MPEGLayer(int x, int y, MPEGConfigAudio *gui);
209 void create_objects();
211 static int string_to_layer(char *string);
212 static char* layer_to_string(int derivative);
214 MPEGConfigAudio *gui;
217 class MPEGABitrate : public BC_PopupMenu
220 MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
222 void create_objects();
223 void set_layer(int layer);
226 static int string_to_bitrate(char *string);
227 static char* bitrate_to_string(char *string, int bitrate);
229 MPEGConfigAudio *gui;
234 class MPEGConfigVideo;
238 class MPEGPreset : public BC_PopupMenu
241 MPEGPreset(int x, int y, MPEGConfigVideo *gui);
242 void create_objects();
244 static int string_to_value(char *string);
245 static char* value_to_string(int value);
246 MPEGConfigVideo *gui;
249 class MPEGColorModel : public BC_PopupMenu
252 MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
253 void create_objects();
255 static int string_to_cmodel(char *string);
256 static char* cmodel_to_string(int cmodel);
258 MPEGConfigVideo *gui;
262 class MPEGDerivative : public BC_PopupMenu
265 MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
266 void create_objects();
268 static int string_to_derivative(char *string);
269 static char* derivative_to_string(int derivative);
271 MPEGConfigVideo *gui;
274 class MPEGBitrate : public BC_TextBox
277 MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
279 MPEGConfigVideo *gui;
282 class MPEGQuant : public BC_TumbleTextBox
285 MPEGQuant(int x, int y, MPEGConfigVideo *gui);
287 MPEGConfigVideo *gui;
290 class MPEGIFrameDistance : public BC_TumbleTextBox
293 MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
295 MPEGConfigVideo *gui;
298 class MPEGPFrameDistance : public BC_TumbleTextBox
301 MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
303 MPEGConfigVideo *gui;
306 class MPEGFixedBitrate : public BC_Radial
309 MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
311 MPEGConfigVideo *gui;
314 class MPEGFixedQuant : public BC_Radial
317 MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
319 MPEGConfigVideo *gui;
322 class MPEGSeqCodes : public BC_CheckBox
325 MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
327 MPEGConfigVideo *gui;
333 class MPEGConfigVideo : public BC_Window
336 MPEGConfigVideo(BC_WindowBase *parent_window,
340 void create_objects();
342 void delete_cmodel_objs();
344 void update_cmodel_objs();
346 BC_WindowBase *parent_window;
349 MPEGColorModel *cmodel;
350 MPEGDerivative *derivative;
351 MPEGBitrate *bitrate;
352 MPEGFixedBitrate *fixed_bitrate;
354 MPEGFixedQuant *fixed_quant;
355 MPEGIFrameDistance *iframe_distance;
356 MPEGPFrameDistance *pframe_distance;
357 BC_CheckBox *top_field_first;
358 BC_CheckBox *progressive;
359 BC_CheckBox *denoise;
360 BC_CheckBox *seq_codes;
362 ArrayList<BC_Title*> titles;
363 ArrayList<BC_SubWindow*> tools;