render config sample/pixel fmt, piped files, ffmpeg raw yuv/rgb
[goodguy/history.git] / cinelerra-5.1 / cinelerra / fileffmpeg.h
1 #ifndef __FILEFFMPEG_H__
2 #define __FILEFFMPEG_H__
3
4 #include "asset.inc"
5 #include "bcdialog.h"
6 #include "bcwindowbase.inc"
7 #include "bitspopup.inc"
8 #include "edl.inc"
9 #include "ffmpeg.h"
10 #include "filebase.h"
11 #include "fileffmpeg.inc"
12 #include "indexfile.inc"
13 #include "mainprogress.inc"
14 #include "mutex.h"
15 #include "thread.h"
16 #include "vframe.inc"
17
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23
24
25 class FileFFMPEG : public FileBase
26 {
27 public:
28         FFMPEG *ff;
29
30         FileFFMPEG(Asset *asset, File *file);
31         ~FileFFMPEG();
32         static void ff_lock(const char *cp=0);
33         static void ff_unlock();
34
35         static void set_options(char *cp, int len, const char *bp);
36         static void get_parameters(BC_WindowBase *parent_window,
37                 Asset *asset, BC_WindowBase *&format_window,
38                 int audio_options,int video_options, EDL *edl);
39         static int check_sig(Asset *asset);
40         int get_best_colormodel(int driver, int vstream);
41         int get_video_info(int track, int &pid, double &framerate,
42                 int &width, int &height, char *title=0);
43         int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
44         static void get_info(char *path,char *text,int len);
45         int open_file(int rd,int wr);
46         int get_index(IndexFile *index_file, MainProgressBar *progress_bar);
47         int close_file(void);
48         int write_samples(double **buffer,int64_t len);
49         int write_frames(VFrame ***frames,int len);
50         int read_samples(double *buffer,int64_t len);
51         int read_frame(VFrame *frame);
52         int can_scale_input() { return 1; }
53         int64_t get_memory_usage(void);
54         int colormodel_supported(int colormodel);
55         static int get_best_colormodel(Asset *asset, int driver);
56         int select_video_stream(Asset *asset, int vstream);
57         int select_audio_stream(Asset *asset, int astream);
58 };
59
60 class FFMpegConfigNum : public BC_TumbleTextBox
61 {
62 public:
63         FFMpegConfigNum(BC_Window *window, int x, int y,
64                 char *title_text, int *output);
65         ~FFMpegConfigNum();
66
67         void create_objects();
68         int update_param(const char *param, const char *opts);
69         int handle_event();
70         int *output;
71         BC_Window *window;
72         BC_Title *title;
73         char *title_text;
74         int x, y;
75 };
76
77 class FFMpegAudioNum : public FFMpegConfigNum
78 {
79 public:
80         FFMpegAudioNum(BC_Window *window, int x, int y, char *title_text, int *output);
81         ~FFMpegAudioNum() {}
82
83         FFMPEGConfigAudio *window() { return (FFMPEGConfigAudio *)FFMpegConfigNum::window; }
84 };
85
86 class FFMpegAudioBitrate : public FFMpegAudioNum
87 {
88 public:
89         FFMpegAudioBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
90           : FFMpegAudioNum(window, x, y, title_text, output) {}
91         int handle_event();
92 };
93
94 class FFMpegAudioQuality : public FFMpegAudioNum
95 {
96 public:
97         FFMpegAudioQuality(BC_Window *window, int x, int y, char *title_text, int *output)
98           : FFMpegAudioNum(window, x, y, title_text, output) {}
99         int handle_event();
100 };
101
102 class FFMpegVideoNum : public FFMpegConfigNum
103 {
104 public:
105         FFMpegVideoNum(BC_Window *window, int x, int y, char *title_text, int *output);
106         ~FFMpegVideoNum() {}
107
108         FFMPEGConfigVideo *window() { return (FFMPEGConfigVideo *)FFMpegConfigNum::window; }
109 };
110
111 class FFMpegVideoBitrate : public FFMpegVideoNum
112 {
113 public:
114         FFMpegVideoBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
115           : FFMpegVideoNum(window, x, y, title_text, output) {}
116         int handle_event();
117 };
118
119 class FFMpegVideoQuality : public FFMpegVideoNum
120 {
121 public:
122         FFMpegVideoQuality(BC_Window *window, int x, int y, char *title_text, int *output)
123           : FFMpegVideoNum(window, x, y, title_text, output) {}
124         int handle_event();
125 };
126
127 class FFMpegPixelFormat : public BC_PopupTextBox
128 {
129 public:
130         FFMpegPixelFormat(FFMPEGConfigVideo *vid_config, int x, int y, int w, int list_h);
131
132         FFMPEGConfigVideo *vid_config;
133         ArrayList<BC_ListBoxItem*> pixfmts;
134
135         int handle_event();
136         void update_formats();
137 };
138
139 class FFMpegSampleFormat : public BC_PopupTextBox
140 {
141 public:
142         FFMpegSampleFormat(FFMPEGConfigAudio *aud_config, int x, int y, int w, int list_h);
143
144         FFMPEGConfigAudio *aud_config;
145         ArrayList<BC_ListBoxItem*> samplefmts;
146
147         int handle_event();
148         void update_formats();
149 };
150
151 class FFMPEGConfigAudio : public BC_Window
152 {
153 public:
154         FFMPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset, EDL *edl);
155         ~FFMPEGConfigAudio();
156
157         void create_objects();
158         int close_event();
159         void load_options();
160
161         FFMpegSampleFormat *sample_format;
162         ArrayList<BC_ListBoxItem*> presets;
163         FFMPEGConfigAudioPopup *preset_popup;
164         FFMpegAudioBitrate *bitrate;
165         FFMpegAudioQuality *quality;
166         FFAudioOptions *audio_options;
167         BC_WindowBase *parent_window;
168         Asset *asset;
169         EDL *edl;
170         FFOptionsDialog *ff_options_dialog;
171 };
172
173 class FFAudioOptions : public BC_ScrollTextBox
174 {
175 public:
176         FFAudioOptions(FFMPEGConfigAudio *audio_popup,
177                 int x, int y, int w, int rows, int size, char *text);
178
179         FFMPEGConfigAudio *audio_popup;
180 };
181
182
183 class FFMPEGConfigAudioPopup : public BC_PopupTextBox
184 {
185 public:
186         FFMPEGConfigAudioPopup(FFMPEGConfigAudio *popup, int x, int y);
187         int handle_event();
188         FFMPEGConfigAudio *popup;
189 };
190
191
192 class FFMPEGConfigAudioToggle : public BC_CheckBox
193 {
194 public:
195         FFMPEGConfigAudioToggle(FFMPEGConfigAudio *popup,
196                 char *title_text, int x, int y, int *output);
197         int handle_event();
198         int *output;
199         FFMPEGConfigAudio *popup;
200 };
201
202 class FFMPEGConfigVideo : public BC_Window
203 {
204 public:
205         FFMPEGConfigVideo(BC_WindowBase *parent_window, Asset *asset, EDL *edl);
206         ~FFMPEGConfigVideo();
207
208         void create_objects();
209         int close_event();
210         void load_options();
211
212         FFMpegPixelFormat *pixel_format;
213         ArrayList<BC_ListBoxItem*> presets;
214         FFMPEGConfigVideoPopup *preset_popup;
215         BC_WindowBase *parent_window;
216         FFMpegVideoBitrate *bitrate;
217         FFMpegVideoQuality *quality;
218         FFVideoOptions *video_options;
219         Asset *asset;
220         EDL *edl;
221         FFOptionsDialog *ff_options_dialog;
222 };
223
224 class FFVideoOptions : public BC_ScrollTextBox
225 {
226 public:
227         FFVideoOptions(FFMPEGConfigVideo *video_popup,
228                 int x, int y, int w, int rows, int size, char *text);
229
230         FFMPEGConfigVideo *video_popup;
231 };
232
233 class FFMPEGConfigVideoPopup : public BC_PopupTextBox
234 {
235 public:
236         FFMPEGConfigVideoPopup(FFMPEGConfigVideo *popup, int x, int y);
237         int handle_event();
238         FFMPEGConfigVideo *popup;
239 };
240
241 class FFMPEGConfigVideoToggle : public BC_CheckBox
242 {
243 public:
244         FFMPEGConfigVideoToggle(FFMPEGConfigVideo *popup,
245                 char *title_text, int x, int y, int *output);
246         int handle_event();
247         int *output;
248         FFMPEGConfigVideo *popup;
249 };
250
251 class FFMPEGScanProgress : public Thread
252 {
253 public:
254         IndexFile *index_file;
255         MainProgressBar *progress_bar;
256         char progress_title[BCTEXTLEN];
257         int64_t length, *position;
258         int done, *canceled;
259
260         FFMPEGScanProgress(IndexFile *index_file, MainProgressBar *progress_bar,
261                 const char *title, int64_t length, int64_t *position, int *canceled);
262         ~FFMPEGScanProgress();
263         void run();
264 };
265
266
267 class FFOptions_OptName : public BC_ListBoxItem {
268 public:
269         FFOptions_Opt *opt;
270
271         FFOptions_OptName(FFOptions_Opt *opt, const char *nm);
272         ~FFOptions_OptName();
273
274 };
275
276 class FFOptions_OptValue : public BC_ListBoxItem {
277 public:
278         FFOptions_Opt *opt;
279
280         void update();
281         void update(const char *v);
282         FFOptions_OptValue(FFOptions_Opt *opt);
283 };
284
285 class FFOptions_Opt {
286 public:
287         FFOptions *options;
288         const AVOption *opt;
289         FFOptions_OptName *item_name;
290         FFOptions_OptValue *item_value;
291
292         char *get(char *vp, int sz=-1);
293         void set(const char *val);
294         int types(char *rp);
295         int scalar(double d, char *rp);
296         int ranges(char *rp);
297         int units(ArrayList<const char *> &opts);
298         const char *unit_name(int id);
299         int units(char *rp);
300         const char *tip();
301
302         FFOptions_Opt(FFOptions *options, const AVOption *opt, const char *nm);
303         ~FFOptions_Opt();
304 };
305
306 class FFOptions : public ArrayList<FFOptions_Opt *>
307 {
308 public:
309         FFOptions();
310         ~FFOptions();
311         FFOptionsWindow *win;
312         AVCodecContext *avctx;
313         const void *obj;
314
315         void initialize(FFOptionsWindow *win, int k);
316         static int cmpr(const void *a, const void *b);
317         int update();
318         void dump(FILE *fp);
319 };
320
321 class FFOptions_OptPanel : public BC_ListBox {
322 public:
323         FFOptions_OptPanel(FFOptionsWindow *fwin, int x, int y, int w, int h);
324         ~FFOptions_OptPanel();
325         void create_objects();
326         int cursor_leave_event();
327
328         FFOptionsWindow *fwin;
329         ArrayList<BC_ListBoxItem*> items[2];
330         ArrayList<BC_ListBoxItem*> &opts;
331         ArrayList<BC_ListBoxItem*> &vals;
332         char tip_text[BCTEXTLEN];
333
334         int selection_changed();
335         int update();
336         void show_tip(const char *tip);
337 };
338
339 class FFOptionsKindItem : public BC_MenuItem
340 {
341 public:
342         FFOptionsKind *kind;
343         int idx;
344         int handle_event();
345         void show_label();
346
347         FFOptionsKindItem(FFOptionsKind *kind, const char *name, int idx);
348         ~FFOptionsKindItem();
349 };
350
351 class FFOptionsKind : public BC_PopupMenu
352 {
353         static const char *kinds[];
354 public:
355         FFOptionsWindow *fwin;
356         int kind;
357
358         void create_objects();
359         int handle_event();
360         void set(int k);
361
362         FFOptionsKind(FFOptionsWindow *fwin, int x, int y, int w);
363         ~FFOptionsKind();
364 };
365
366 class FFOptionsUnits : public BC_PopupMenu {
367 public:
368         FFOptionsWindow *fwin;
369
370         FFOptionsUnits(FFOptionsWindow *fwin, int x, int y, int w);
371         ~FFOptionsUnits();
372         int handle_event();
373 };
374
375 class FFOptionsText : public BC_TextBox {
376 public:
377         FFOptionsWindow *fwin;
378
379         FFOptionsText(FFOptionsWindow *fwin, int x, int y, int w);
380         ~FFOptionsText();
381         int handle_event();
382 };
383
384 class FFOptionsApply : public BC_GenericButton {
385 public:
386         FFOptionsWindow *fwin;
387
388         FFOptionsApply(FFOptionsWindow *fwin, int x, int y);
389         ~FFOptionsApply();
390         int handle_event();
391 };
392
393 class FFOptionsWindow : public BC_Window
394 {
395 public:
396         FFOptionsWindow(FFOptionsDialog *dialog);
397         ~FFOptionsWindow();
398
399         void create_objects();
400         void update(FFOptions_Opt *oip);
401         void draw();
402         int resize_event(int w, int h);
403
404         FFOptionsDialog *dialog;
405         FFOptions options;
406
407         FFOptions_OptPanel *panel;
408         int panel_x, panel_y, panel_w, panel_h;
409         BC_Title *type, *range, *kind_title;
410         FFOptions_Opt *selected;
411
412         FFOptionsKind *kind;
413         FFOptionsUnits *units;
414         FFOptionsText *text;
415         FFOptionsApply *apply;
416 };
417
418 class FFOptionsDialog : public BC_DialogThread
419 {
420 public:
421         FFOptionsDialog();
422         ~FFOptionsDialog();
423         virtual void update_options(const char *options) = 0;
424
425         void load_options(const char *bp, int len);
426         void store_options(char *cp, int len);
427         void start(const char *format_name, const char *codec_name,
428                 AVCodec *codec, const char *options, int len);
429         BC_Window* new_gui();
430         void handle_done_event(int result);
431
432         FFOptionsWindow *options_window;
433         const char *format_name, *codec_name;
434         AVCodec *codec;
435         AVDictionary *ff_opts;
436         int ff_len;
437 };
438
439 class FFOptionsAudioDialog : public FFOptionsDialog
440 {
441 public:
442         FFMPEGConfigAudio *aud_config;
443         void update_options(const char *options);
444
445         FFOptionsAudioDialog(FFMPEGConfigAudio *aud_config);
446         ~FFOptionsAudioDialog();
447 };
448
449 class FFOptionsVideoDialog : public FFOptionsDialog
450 {
451 public:
452         FFMPEGConfigVideo *vid_config;
453         void update_options(const char *options);
454
455         FFOptionsVideoDialog(FFMPEGConfigVideo *vid_config);
456         ~FFOptionsVideoDialog();
457 };
458
459 class FFOptionsViewAudio: public BC_GenericButton
460 {
461 public:
462         FFOptionsViewAudio(FFMPEGConfigAudio *aud_config, int x, int y, const char *text);
463         ~FFOptionsViewAudio();
464
465         int handle_event();
466         FFMPEGConfigAudio *aud_config;
467 };
468
469 class FFOptionsViewVideo : public BC_GenericButton
470 {
471 public:
472         FFOptionsViewVideo(FFMPEGConfigVideo *vid_config, int x, int y, const char *text);
473         ~FFOptionsViewVideo();
474
475         int handle_event();
476         FFMPEGConfigVideo *vid_config;
477 };
478
479 #endif