render config sample/pixel fmt, piped files, ffmpeg raw yuv/rgb
[goodguy/history.git] / cinelerra-5.1 / cinelerra / filempeg.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef FILEMPEG_H
23 #define FILEMPEG_H
24
25 #include "bitspopup.inc"
26 #include "condition.inc"
27 #include "edl.inc"
28 #include "file.inc"
29 #include "filebase.h"
30 #include "indexfile.inc"
31 #include "twolame.h"
32 #include "lame/lame.h"
33 #include "libzmpeg3.h"
34 #include "mainprogress.inc"
35 #include "thread.h"
36
37
38 extern "C"
39 {
40
41
42 // Mpeg2enc prototypes
43 void mpeg2enc_init_buffers();
44 int mpeg2enc(int argc, char *argv[]);
45 void mpeg2enc_set_w(int width);
46 void mpeg2enc_set_h(int height);
47 void mpeg2enc_set_rate(double rate);
48 void mpeg2enc_set_input_buffers(int eof, char *y, char *u, char *v);
49
50
51
52
53
54 }
55
56 class FileMPEGVideo;
57
58 class FileMPEG : public FileBase
59 {
60 public:
61         FileMPEG(Asset *asset, File *file);
62         ~FileMPEG();
63
64         friend class FileMPEGVideo;
65
66         static void get_parameters(BC_WindowBase *parent_window,
67                 Asset *asset, BC_WindowBase* &format_window,
68                 int audio_options, int video_options, EDL *edl);
69
70         static int check_sig(Asset *asset);
71
72 // Get extra info for info dialog.
73         static void get_info(char *title_path, char *path, char *text, int len);
74         int open_file(int rd, int wr);
75         int close_file();
76         int create_toc(char *toc_path);
77         int get_index(IndexFile *index_file, MainProgressBar *progress_bar);
78
79         int set_video_position(int64_t x);
80         int set_audio_position(int64_t x);
81         int write_samples(double **buffer,
82                         int64_t len);
83         int write_frames(VFrame ***frames, int len);
84
85         int read_frame(VFrame *frame);
86         int read_samples(double *buffer, int64_t len);
87
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);
102
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         int can_scale_input() { return 1; }
113
114 private:
115         void to_streamchannel(int channel, int &stream_out, int &channel_out);
116         int reset_parameters_derived();
117 // File descriptor for decoder
118         mpeg3_t *fd;
119
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);
125
126 // DVB capture
127         int recd_fd;
128         int record_fd() { return recd_fd; }
129
130 // MJPEGtools encoder
131         FILE *mjpeg_out;
132         int mjpeg_error;
133         Condition *next_frame_lock;
134         Condition *next_frame_done;
135         int mjpeg_eof;
136         int wrote_header;
137         unsigned char *mjpeg_y;
138         unsigned char *mjpeg_u;
139         unsigned char *mjpeg_v;
140         char mjpeg_command[BCTEXTLEN];
141
142 // skimmer
143         static int skimming(void *vp, int track);
144         skim_fn skim_callback;
145         void *skim_data;
146         int skim_result;
147 // toc scan commercial detection
148         static int toc_nail(void *vp, int track);
149
150 // Temporary for color conversion
151         VFrame *temp_frame;
152
153         unsigned char *twolame_temp, *twolame_out;
154         int twolame_allocation;
155         int twolame_result;
156         FILE *twofp;
157         twolame_options *twopts;
158
159         float *lame_temp[2];
160         int lame_allocation;
161         char *lame_output;
162         int lame_output_allocation;
163         FILE *lame_fd;
164 // Lame puts 0 before stream
165         int lame_started;
166
167         lame_global_flags *lame_global;
168         double *weight;
169 };
170
171
172 class FileMPEGVideo : public Thread
173 {
174 public:
175         FileMPEGVideo(FileMPEG *file);
176         ~FileMPEGVideo();
177
178         void run();
179
180         FileMPEG *file;
181 };
182
183 class MPEGConfigAudioPopup;
184 class MPEGABitrate;
185
186
187 class MPEGConfigAudio : public BC_Window
188 {
189 public:
190         MPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset);
191         ~MPEGConfigAudio();
192
193         void create_objects();
194         int close_event();
195
196         BC_WindowBase *parent_window;
197         MPEGABitrate *bitrate;
198         char string[BCTEXTLEN];
199         Asset *asset;
200 };
201
202
203 class MPEGLayer : public BC_PopupMenu
204 {
205 public:
206         MPEGLayer(int x, int y, MPEGConfigAudio *gui);
207         void create_objects();
208         int handle_event();
209         static int string_to_layer(char *string);
210         static char* layer_to_string(int derivative);
211
212         MPEGConfigAudio *gui;
213 };
214
215 class MPEGABitrate : public BC_PopupMenu
216 {
217 public:
218         MPEGABitrate(int x, int y, MPEGConfigAudio *gui);
219
220         void create_objects();
221         void set_layer(int layer);
222
223         int handle_event();
224         static int string_to_bitrate(char *string);
225         static char* bitrate_to_string(char *string, int bitrate);
226
227         MPEGConfigAudio *gui;
228 };
229
230
231
232 class MPEGConfigVideo;
233
234
235
236 class MPEGPreset : public BC_PopupMenu
237 {
238 public:
239         MPEGPreset(int x, int y, MPEGConfigVideo *gui);
240         void create_objects();
241         int handle_event();
242         static int string_to_value(char *string);
243         static char* value_to_string(int value);
244         MPEGConfigVideo *gui;
245 };
246
247 class MPEGColorModel : public BC_PopupMenu
248 {
249 public:
250         MPEGColorModel(int x, int y, MPEGConfigVideo *gui);
251         void create_objects();
252         int handle_event();
253         static int string_to_cmodel(char *string);
254         static char* cmodel_to_string(int cmodel);
255
256         MPEGConfigVideo *gui;
257 };
258
259
260 class MPEGDerivative : public BC_PopupMenu
261 {
262 public:
263         MPEGDerivative(int x, int y, MPEGConfigVideo *gui);
264         void create_objects();
265         int handle_event();
266         static int string_to_derivative(char *string);
267         static char* derivative_to_string(int derivative);
268
269         MPEGConfigVideo *gui;
270 };
271
272 class MPEGBitrate : public BC_TextBox
273 {
274 public:
275         MPEGBitrate(int x, int y, MPEGConfigVideo *gui);
276         int handle_event();
277         MPEGConfigVideo *gui;
278 };
279
280 class MPEGQuant : public BC_TumbleTextBox
281 {
282 public:
283         MPEGQuant(int x, int y, MPEGConfigVideo *gui);
284         int handle_event();
285         MPEGConfigVideo *gui;
286 };
287
288 class MPEGIFrameDistance : public BC_TumbleTextBox
289 {
290 public:
291         MPEGIFrameDistance(int x, int y, MPEGConfigVideo *gui);
292         int handle_event();
293         MPEGConfigVideo *gui;
294 };
295
296 class MPEGPFrameDistance : public BC_TumbleTextBox
297 {
298 public:
299         MPEGPFrameDistance(int x, int y, MPEGConfigVideo *gui);
300         int handle_event();
301         MPEGConfigVideo *gui;
302 };
303
304 class MPEGFixedBitrate : public BC_Radial
305 {
306 public:
307         MPEGFixedBitrate(int x, int y, MPEGConfigVideo *gui);
308         int handle_event();
309         MPEGConfigVideo *gui;
310 };
311
312 class MPEGFixedQuant : public BC_Radial
313 {
314 public:
315         MPEGFixedQuant(int x, int y, MPEGConfigVideo *gui);
316         int handle_event();
317         MPEGConfigVideo *gui;
318 };
319
320 class MPEGSeqCodes : public BC_CheckBox
321 {
322 public:
323         MPEGSeqCodes(int x, int y, MPEGConfigVideo *gui);
324         int handle_event();
325         MPEGConfigVideo *gui;
326 };
327
328
329
330
331 class MPEGConfigVideo : public BC_Window
332 {
333 public:
334         MPEGConfigVideo(BC_WindowBase *parent_window,
335                 Asset *asset);
336         ~MPEGConfigVideo();
337
338         void create_objects();
339         int close_event();
340         void delete_cmodel_objs();
341         void reset_cmodel();
342         void update_cmodel_objs();
343
344         BC_WindowBase *parent_window;
345         Asset *asset;
346         MPEGPreset *preset;
347         MPEGColorModel *cmodel;
348         MPEGDerivative *derivative;
349         MPEGBitrate *bitrate;
350         MPEGFixedBitrate *fixed_bitrate;
351         MPEGQuant *quant;
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;
359
360         ArrayList<BC_Title*> titles;
361         ArrayList<BC_SubWindow*> tools;
362 };
363
364
365 #endif