3 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
4 * Copyright (C) 2010 Monty Montgomery
5 * Copyright (C) 2012-2014 Paolo Rampino
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 #ifndef __FILEFFMPEG_H__
24 #define __FILEFFMPEG_H__
28 #include "bcwindowbase.inc"
29 #include "bitspopup.inc"
33 #include "fileffmpeg.inc"
34 #include "indexfile.inc"
35 #include "mainprogress.inc"
47 class FileFFMPEG : public FileBase
52 FileFFMPEG(Asset *asset, File *file);
54 static void ff_lock(const char *cp=0);
55 static void ff_unlock();
57 static void set_options(char *cp, int len, const char *bp);
58 static void get_parameters(BC_WindowBase *parent_window,
59 Asset *asset, BC_WindowBase *&format_window,
60 int audio_options,int video_options, EDL *edl);
61 static int check_sig(Asset *asset);
62 int get_best_colormodel(int driver, int vstream);
63 int get_video_info(int track, int &pid, double &framerate,
64 int &width, int &height, char *title=0);
65 int get_audio_for_video(int vstream, int astream, int64_t &channel_mask);
66 static void get_info(char *path,char *text,int len);
67 int open_file(int rd,int wr);
68 int get_index(IndexFile *index_file, MainProgressBar *progress_bar);
70 int write_samples(double **buffer,int64_t len);
71 int write_frames(VFrame ***frames,int len);
72 int read_samples(double *buffer,int64_t len);
73 int read_frame(VFrame *frame);
74 int can_scale_input() { return 1; }
75 int64_t get_memory_usage(void);
76 int colormodel_supported(int colormodel);
77 static int get_best_colormodel(Asset *asset, int driver);
78 int select_video_stream(Asset *asset, int vstream);
79 int select_audio_stream(Asset *asset, int astream);
82 class FFMpegConfigNum : public BC_TumbleTextBox
85 FFMpegConfigNum(BC_Window *window, int x, int y,
86 char *title_text, int *output);
89 void create_objects();
90 int update_param(const char *param, const char *opts);
99 class FFMpegAudioNum : public FFMpegConfigNum
102 FFMpegAudioNum(BC_Window *window, int x, int y, char *title_text, int *output);
105 FFMPEGConfigAudio *window() { return (FFMPEGConfigAudio *)FFMpegConfigNum::window; }
108 class FFMpegAudioBitrate : public FFMpegAudioNum
111 FFMpegAudioBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
112 : FFMpegAudioNum(window, x, y, title_text, output) {}
116 class FFMpegAudioQuality : public FFMpegAudioNum
119 FFMpegAudioQuality(BC_Window *window, int x, int y, char *title_text, int *output)
120 : FFMpegAudioNum(window, x, y, title_text, output) {}
124 class FFMpegVideoNum : public FFMpegConfigNum
127 FFMpegVideoNum(BC_Window *window, int x, int y, char *title_text, int *output);
130 FFMPEGConfigVideo *window() { return (FFMPEGConfigVideo *)FFMpegConfigNum::window; }
133 class FFMpegVideoBitrate : public FFMpegVideoNum
136 FFMpegVideoBitrate(BC_Window *window, int x, int y, char *title_text, int *output)
137 : FFMpegVideoNum(window, x, y, title_text, output) {}
141 class FFMpegVideoQuality : public FFMpegVideoNum
144 FFMpegVideoQuality(BC_Window *window, int x, int y, char *title_text, int *output)
145 : FFMpegVideoNum(window, x, y, title_text, output) {}
149 class FFMpegPixFmtItems : public ArrayList<BC_ListBoxItem*>
152 FFMpegPixFmtItems() {}
153 ~FFMpegPixFmtItems() { remove_all_objects(); }
156 class FFMpegPixelFormat : public BC_PopupTextBox
159 FFMpegPixelFormat(FFMPEGConfigVideo *vid_config, int x, int y, int w, int list_h);
161 FFMPEGConfigVideo *vid_config;
162 FFMpegPixFmtItems pixfmts;
165 void update_formats();
168 class FFMpegSampleFormat : public BC_PopupTextBox
171 FFMpegSampleFormat(FFMPEGConfigAudio *aud_config, int x, int y, int w, int list_h);
173 FFMPEGConfigAudio *aud_config;
174 ArrayList<BC_ListBoxItem*> samplefmts;
177 void update_formats();
180 class FFMPEGConfigWindow : public BC_Window
183 FFMPEGConfigWindow(const char *title, BC_WindowBase *parent_window,
184 int x, int y, int w, int h, Asset *asset, EDL *edl);
185 ~FFMPEGConfigWindow();
186 virtual void read_options() = 0;
187 virtual void save_options() = 0;
188 void start(AVCodecContext *avctx);
189 void start(AVFormatContext *fmt_ctx);
191 BC_WindowBase *parent_window;
192 FFOptionsDialog *ff_options_dialog;
195 AVCodecContext *avctx;
196 AVFormatContext *fmt_ctx;
201 class FFMPEGConfigAudio : public FFMPEGConfigWindow
204 FFMPEGConfigAudio(BC_WindowBase *parent_window,
205 int x, int y, Asset *asset, EDL *edl);
206 ~FFMPEGConfigAudio();
208 void create_objects();
214 FFMpegSampleFormat *sample_format;
215 ArrayList<BC_ListBoxItem*> presets;
216 FFMPEGConfigAudioPopup *preset_popup;
217 FFMpegAudioBitrate *bitrate;
218 FFMpegAudioQuality *quality;
219 FFAudioOptions *audio_options;
220 BC_WindowBase *parent_window;
221 FFOptionsViewAudio *view_audio;
222 FFOptionsViewFormat *view_format;
225 class FFAudioOptions : public BC_ScrollTextBox
228 FFAudioOptions(FFMPEGConfigAudio *audio_popup,
229 int x, int y, int w, int rows, int size, char *text);
231 FFMPEGConfigAudio *audio_popup;
235 class FFMPEGConfigAudioPopup : public BC_PopupTextBox
238 FFMPEGConfigAudioPopup(FFMPEGConfigAudio *popup, int x, int y);
240 FFMPEGConfigAudio *popup;
243 class FFMPEGConfigVideo : public FFMPEGConfigWindow
246 FFMPEGConfigVideo(BC_WindowBase *parent_window,
247 int x, int y, Asset *asset, EDL *edl);
248 ~FFMPEGConfigVideo();
252 void create_objects();
256 FFMpegPixelFormat *pixel_format;
257 ArrayList<BC_ListBoxItem*> presets;
258 FFMPEGConfigVideoPopup *preset_popup;
259 BC_WindowBase *parent_window;
260 FFMpegVideoBitrate *bitrate;
261 FFMpegVideoQuality *quality;
262 FFVideoOptions *video_options;
263 FFOptionsViewVideo *view_video;
264 FFOptionsViewFormat *view_format;
267 class FFVideoOptions : public BC_ScrollTextBox
270 FFVideoOptions(FFMPEGConfigVideo *video_popup,
271 int x, int y, int w, int rows, int size, char *text);
273 FFMPEGConfigVideo *video_popup;
276 class FFMPEGConfigVideoPopup : public BC_PopupTextBox
279 FFMPEGConfigVideoPopup(FFMPEGConfigVideo *popup, int x, int y);
281 FFMPEGConfigVideo *popup;
284 class FFMPEGConfigFormat : public FFMPEGConfigWindow
287 FFMPEGConfigFormat(FFOptionsFormatViewDialog *view_dialog,
288 int x, int y, Asset *asset, EDL *edl);
289 ~FFMPEGConfigFormat();
294 void create_objects();
298 FFOptionsFormatViewDialog *view_dialog;
299 FFFormatOptions *format_options;
302 class FFFormatOptions : public BC_ScrollTextBox
305 FFFormatOptions(FFMPEGConfigFormat *format_popup,
306 int x, int y, int w, int rows, int size, char *text);
308 FFMPEGConfigFormat *format_popup;
312 class FFMPEGScanProgress : public Thread
315 IndexFile *index_file;
316 MainProgressBar *progress_bar;
317 char progress_title[BCTEXTLEN];
318 int64_t length, *position;
321 FFMPEGScanProgress(IndexFile *index_file, MainProgressBar *progress_bar,
322 const char *title, int64_t length, int64_t *position, int *canceled);
323 ~FFMPEGScanProgress();
328 class FFOptions_OptName : public BC_ListBoxItem {
332 FFOptions_OptName(FFOptions_Opt *opt, const char *nm);
333 ~FFOptions_OptName();
337 class FFOptions_OptValue : public BC_ListBoxItem {
342 void update(const char *v);
343 FFOptions_OptValue(FFOptions_Opt *opt);
346 class FFOptions_Opt {
350 FFOptions_OptName *item_name;
351 FFOptions_OptValue *item_value;
353 char *get(char *vp, int sz=-1);
354 void set(const char *val);
356 int scalar(double d, char *rp);
357 int ranges(char *rp);
358 int units(ArrayList<const char *> &opts);
359 const char *unit_name(int id);
363 FFOptions_Opt(FFOptions *options, const AVOption *opt, const char *nm);
367 class FFOptions : public ArrayList<FFOptions_Opt *>
372 FFOptionsWindow *win;
373 AVCodecContext *avctx;
376 void initialize(FFOptionsWindow *win, int kind);
377 static int cmpr(const void *a, const void *b);
382 class FFOptions_OptPanel : public BC_ListBox {
384 FFOptions_OptPanel(FFOptionsWindow *fwin, int x, int y, int w, int h);
385 ~FFOptions_OptPanel();
386 void create_objects();
387 int cursor_leave_event();
389 FFOptionsWindow *fwin;
390 ArrayList<BC_ListBoxItem*> items[2];
391 ArrayList<BC_ListBoxItem*> &opts;
392 ArrayList<BC_ListBoxItem*> &vals;
393 char tip_text[BCTEXTLEN];
395 int selection_changed();
397 void show_tip(const char *tip);
400 class FFOptionsKindItem : public BC_MenuItem
408 FFOptionsKindItem(FFOptionsKind *kind, const char *name, int idx);
409 ~FFOptionsKindItem();
412 class FFOptionsKind : public BC_PopupMenu
414 static const char *kinds[];
416 FFOptionsWindow *fwin;
419 void create_objects();
423 FFOptionsKind(FFOptionsWindow *fwin, int x, int y, int w);
427 class FFOptionsUnits : public BC_PopupMenu {
429 FFOptionsWindow *fwin;
431 FFOptionsUnits(FFOptionsWindow *fwin, int x, int y, int w);
436 class FFOptionsText : public BC_TextBox {
438 FFOptionsWindow *fwin;
440 FFOptionsText(FFOptionsWindow *fwin, int x, int y, int w);
445 class FFOptionsApply : public BC_GenericButton {
447 FFOptionsWindow *fwin;
449 FFOptionsApply(FFOptionsWindow *fwin, int x, int y);
454 class FFOptionsWindow : public BC_Window
457 FFOptionsWindow(FFOptionsDialog *dialog, int x, int y);
460 void create_objects();
461 void update(FFOptions_Opt *oip);
463 int resize_event(int w, int h);
465 FFOptionsDialog *dialog;
468 FFOptions_OptPanel *panel;
469 int panel_x, panel_y, panel_w, panel_h;
470 BC_Title *type, *range, *kind_title;
471 FFOptions_Opt *selected;
474 FFOptionsUnits *units;
476 FFOptionsApply *apply;
479 class FFOptionsDialog : public BC_DialogThread
482 FFOptionsDialog(FFMPEGConfigWindow *cfg_window);
484 virtual void update_options(const char *options) = 0;
486 void load_options(const char *bp, int len);
487 void store_options(char *cp, int len);
489 BC_Window* new_gui();
490 void handle_done_event(int result);
492 FFMPEGConfigWindow *cfg_window;
493 FFOptionsWindow *options_window;
494 AVDictionary *ff_opts;
498 class FFOptionsAudioDialog : public FFOptionsDialog
501 FFMPEGConfigAudio *aud_config;
502 void update_options(const char *options);
504 FFOptionsAudioDialog(FFMPEGConfigAudio *aud_config);
505 ~FFOptionsAudioDialog();
508 class FFOptionsVideoDialog : public FFOptionsDialog
511 FFMPEGConfigVideo *vid_config;
512 void update_options(const char *options);
514 FFOptionsVideoDialog(FFMPEGConfigVideo *vid_config);
515 ~FFOptionsVideoDialog();
518 class FFOptionsFormatDialog : public FFOptionsDialog
521 FFMPEGConfigFormat *fmt_config;
522 void update_options(const char *options);
524 FFOptionsFormatDialog(FFMPEGConfigFormat *fmt_config);
525 ~FFOptionsFormatDialog();
528 class FFOptionsViewAudio : public BC_GenericButton
531 FFOptionsViewAudio(FFMPEGConfigAudio *aud_config, int x, int y, const char *text);
532 ~FFOptionsViewAudio();
535 FFMPEGConfigAudio *aud_config;
536 AVCodecContext *avctx;
539 class FFOptionsViewVideo : public BC_GenericButton
542 FFOptionsViewVideo(FFMPEGConfigVideo *vid_config, int x, int y, const char *text);
543 ~FFOptionsViewVideo();
546 FFMPEGConfigVideo *vid_config;
547 AVCodecContext *avctx;
550 class FFOptionsViewFormat : public BC_GenericButton
553 FFOptionsViewFormat(FFMPEGConfigWindow *cfg_window,
554 EDL *edl, Asset *asset, int x, int y, const char *text);
555 ~FFOptionsViewFormat();
558 FFMPEGConfigWindow *cfg_window;
561 FFOptionsFormatViewDialog *format_dialog;
564 class FFOptionsFormatView : public BC_GenericButton
567 FFOptionsFormatView(FFMPEGConfigFormat *fmt_config, int x, int y, const char *text);
568 ~FFOptionsFormatView();
571 FFMPEGConfigFormat *fmt_config;
572 AVFormatContext *fmt_ctx;
575 class FFOptionsFormatViewDialog : public BC_DialogThread
578 FFOptionsFormatViewDialog(FFOptionsViewFormat *view_format, int wx, int wy);
579 ~FFOptionsFormatViewDialog();
580 BC_Window* new_gui();
581 void handle_done_event(int result);
583 FFOptionsViewFormat *view_format;
584 FFMPEGConfigFormat *cfg_window;