7 // work around for __STDC_CONSTANT_MACROS
11 #include "bcwindowbase.h"
12 #include "bitspopup.h"
18 #include "fileffmpeg.h"
19 #include "filesystem.h"
20 #include "indexfile.h"
21 #include "interlacemodes.h"
23 #include "mainerror.h"
24 #include "mainprogress.h"
26 #include "preferences.h"
27 #include "videodevice.inc"
33 FileFFMPEG::FileFFMPEG(Asset *asset, File *file)
34 : FileBase(asset, file)
37 if(asset->format == FILE_UNKNOWN)
38 asset->format = FILE_FFMPEG;
41 FileFFMPEG::~FileFFMPEG()
47 FFMpegConfigNum::FFMpegConfigNum(BC_Window *window,
48 int x, int y, char *title_text, int *output)
49 : BC_TumbleTextBox(window, *output, -1, INT_MAX, xS(100), y, xS(100))
51 this->window = window;
52 this->x = x; this->y = y;
53 this->title_text = title_text;
54 this->output = output;
57 FFMpegConfigNum::~FFMpegConfigNum()
61 void FFMpegConfigNum::create_objects()
63 window->add_subwindow(title = new BC_Title(x, y, title_text));
64 BC_TumbleTextBox::create_objects();
67 int FFMpegConfigNum::update_param(const char *param, const char *opts)
70 if( !FFMPEG::get_ff_option(param, opts, value) ) {
71 if( (*output = atoi(value)) < 0 ) {
76 BC_TumbleTextBox::update((int64_t)*output);
81 int FFMpegConfigNum::handle_event()
83 *output = atoi(get_text());
87 FFMpegAudioNum::FFMpegAudioNum(BC_Window *window,
88 int x, int y, char *title_text, int *output)
89 : FFMpegConfigNum(window, x, y, title_text, output)
93 int FFMpegAudioBitrate::handle_event()
95 int ret = FFMpegAudioNum::handle_event();
96 Asset *asset = window()->asset;
97 if( asset->ff_audio_bitrate > 0 )
98 window()->quality->disable();
99 else if( !window()->quality->get_textbox()->is_hidden() )
100 window()->quality->enable();
104 int FFMpegAudioQuality::handle_event()
106 int ret = FFMpegAudioNum::handle_event();
107 Asset *asset = window()->asset;
108 if( asset->ff_audio_quality >= 0 )
109 window()->bitrate->disable();
110 else if( !window()->bitrate->get_textbox()->is_hidden() )
111 window()->bitrate->enable();
115 FFMpegVideoNum::FFMpegVideoNum(BC_Window *window,
116 int x, int y, char *title_text, int *output)
117 : FFMpegConfigNum(window, x, y, title_text, output)
121 int FFMpegVideoBitrate::handle_event()
123 int ret = FFMpegVideoNum::handle_event();
124 Asset *asset = window()->asset;
125 if( asset->ff_video_bitrate > 0 )
126 window()->quality->disable();
127 else if( !window()->quality->get_textbox()->is_hidden() )
128 window()->quality->enable();
132 int FFMpegVideoQuality::handle_event()
134 int ret = FFMpegVideoNum::handle_event();
135 Asset *asset = window()->asset;
136 if( asset->ff_video_quality >= 0 )
137 window()->bitrate->disable();
138 else if( !window()->bitrate->get_textbox()->is_hidden() )
139 window()->bitrate->enable();
143 FFMpegPixelFormat::FFMpegPixelFormat(FFMPEGConfigVideo *vid_config,
144 int x, int y, int w, int list_h)
145 : BC_PopupTextBox(vid_config, 0, 0, x, y, w, list_h)
147 this->vid_config = vid_config;
150 int FFMpegPixelFormat::handle_event()
152 strncpy(vid_config->asset->ff_pixel_format, get_text(),
153 sizeof(vid_config->asset->ff_pixel_format));
157 void FFMpegPixelFormat::update_formats()
159 pixfmts.remove_all_objects();
160 char video_codec[BCSTRLEN]; video_codec[0] = 0;
161 const char *vcodec = vid_config->asset->vcodec;
162 AVCodec *av_codec = !FFMPEG::get_codec(video_codec, "video", vcodec) ?
163 avcodec_find_encoder_by_name(video_codec) : 0;
164 const AVPixelFormat *pix_fmts = av_codec ? av_codec->pix_fmts : 0;
166 for( int i=0; pix_fmts[i]>=0; ++i ) {
167 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmts[i]);
168 if( desc ) pixfmts.append(new BC_ListBoxItem(desc->name));
171 update_list(&pixfmts);
174 FFMpegSampleFormat::FFMpegSampleFormat(FFMPEGConfigAudio *aud_config,
175 int x, int y, int w, int list_h)
176 : BC_PopupTextBox(aud_config, 0, 0, x, y, w, list_h)
178 this->aud_config = aud_config;
181 int FFMpegSampleFormat::handle_event()
183 strncpy(aud_config->asset->ff_sample_format, get_text(),
184 sizeof(aud_config->asset->ff_sample_format));
188 void FFMpegSampleFormat::update_formats()
190 samplefmts.remove_all_objects();
191 char audio_codec[BCSTRLEN]; audio_codec[0] = 0;
192 const char *acodec = aud_config->asset->acodec;
193 AVCodec *av_codec = !FFMPEG::get_codec(audio_codec, "audio", acodec) ?
194 avcodec_find_encoder_by_name(audio_codec) : 0;
195 const AVSampleFormat *sample_fmts = av_codec ? av_codec->sample_fmts : 0;
197 for( int i=0; sample_fmts[i]>=0; ++i ) {
198 const char *name = av_get_sample_fmt_name(sample_fmts[i]);
199 if( name ) samplefmts.append(new BC_ListBoxItem(name));
202 update_list(&samplefmts);
205 void FileFFMPEG::set_options(char *cp, int len, const char *bp)
207 char *ep = cp + len-2, ch = 0;
208 while( cp < ep && *bp != 0 ) { ch = *bp++; *cp++ = ch; }
209 if( ch != '\n' ) *cp++ = '\n';
213 void FileFFMPEG::get_parameters(BC_WindowBase *parent_window,
214 Asset *asset, BC_WindowBase *&format_window,
215 int audio_options, int video_options, EDL *edl)
217 Asset *ff_asset = new Asset();
218 ff_asset->copy_from(asset, 0);
220 parent_window->get_pop_cursor(wx, wy);
221 if( audio_options ) {
222 FFMPEGConfigAudio *window = new FFMPEGConfigAudio(parent_window,
223 wx, wy, ff_asset, edl);
224 format_window = window;
225 window->create_objects();
226 if( !window->run_window() ) {
227 asset->copy_from(ff_asset,0);
228 set_options(asset->ff_audio_options,
229 sizeof(asset->ff_audio_options),
230 window->audio_options->get_text());
234 else if( video_options ) {
235 FFMPEGConfigVideo *window = new FFMPEGConfigVideo(parent_window,
236 wx, wy, ff_asset, edl);
237 format_window = window;
238 window->create_objects();
239 if( !window->run_window() ) {
240 asset->copy_from(ff_asset,0);
241 set_options(asset->ff_video_options,
242 sizeof(asset->ff_video_options),
243 window->video_options->get_text());
247 ff_asset->remove_user();
250 int FileFFMPEG::check_sig(Asset *asset)
252 char *ptr = strstr(asset->path, ".pcm");
254 ptr = strstr(asset->path, ".raw");
258 int ret = !ffmpeg.init_decoder(asset->path) &&
259 !ffmpeg.open_decoder() ? 1 : 0;
263 void FileFFMPEG::get_info(char *path, char *text, int len)
267 cp += sprintf(cp, _("file path: %s\n"), path);
270 if( stat(path, &st) < 0 ) {
271 cp += sprintf(cp, _(" err: %s\n"), strerror(errno));
275 cp += sprintf(cp, _(" %jd bytes\n"), st.st_size);
277 if( !ret ) ret = ffmpeg.init_decoder(path);
278 if( !ret ) ret = ffmpeg.open_decoder();
280 cp += sprintf(cp, _("info:\n"));
281 ffmpeg.info(cp, len-(cp-text));
284 sprintf(cp, _("== open failed\n"));
287 int FileFFMPEG::get_video_info(int track, int &pid, double &framerate,
288 int &width, int &height, char *title)
291 pid = ff->ff_video_pid(track);
292 framerate = ff->ff_frame_rate(track);
293 width = ff->ff_video_width(track);
294 height = ff->ff_video_height(track);
295 if( title ) *title = 0;
299 int FileFFMPEG::get_audio_for_video(int vstream, int astream, int64_t &channel_mask)
302 return ff->ff_audio_for_video(vstream, astream, channel_mask);
305 int FileFFMPEG::select_video_stream(Asset *asset, int vstream)
307 if( !ff || !asset->video_data ) return 1;
308 asset->width = ff->ff_video_width(vstream);
309 asset->height = ff->ff_video_height(vstream);
310 if( (asset->video_length = ff->ff_video_frames(vstream)) < 2 )
311 asset->video_length = asset->video_length < 0 ? 0 : -1;
312 asset->frame_rate = ff->ff_frame_rate(vstream);
316 int FileFFMPEG::select_audio_stream(Asset *asset, int astream)
318 if( !ff || !asset->audio_data ) return 1;
319 asset->sample_rate = ff->ff_sample_rate(astream);
320 asset->audio_length = ff->ff_audio_samples(astream);
324 int FileFFMPEG::open_file(int rd, int wr)
328 ff = new FFMPEG(this);
331 result = ff->init_decoder(asset->path);
332 if( !result ) result = ff->open_decoder();
334 int audio_channels = ff->ff_total_audio_channels();
335 if( audio_channels > 0 ) {
336 asset->audio_data = 1;
337 asset->channels = audio_channels;
338 asset->sample_rate = ff->ff_sample_rate(0);
339 asset->audio_length = ff->ff_audio_samples(0);
340 strcpy(asset->acodec, ff->ff_audio_format(0));
342 int video_layers = ff->ff_total_video_layers();
343 if( video_layers > 0 ) {
344 asset->video_data = 1;
345 if( !asset->layers ) asset->layers = video_layers;
346 asset->actual_width = ff->ff_video_width(0);
347 asset->actual_height = ff->ff_video_height(0);
348 if( !asset->width ) asset->width = asset->actual_width;
349 if( !asset->height ) asset->height = asset->actual_height;
350 if( !asset->video_length &&
351 (asset->video_length = ff->ff_video_frames(0)) < 2 )
352 asset->video_length = asset->video_length < 0 ? 0 : -1;
353 if( !asset->frame_rate ) asset->frame_rate = ff->ff_frame_rate(0);
354 if( asset->ff_color_range < 0 )
355 asset->ff_color_range = ff->ff_color_range(0);
356 if( asset->ff_color_space < 0 )
357 asset->ff_color_space = ff->ff_color_space(0);
358 strcpy(asset->vcodec, ff->ff_video_codec(0));
360 IndexState *index_state = asset->index_state;
361 index_state->read_markers(file->preferences->index_directory, asset->path);
365 result = ff->init_encoder(asset->path);
366 // must be in this order or dvdauthor will fail
367 if( !result && asset->video_data )
368 result = ff->open_encoder("video", asset->vcodec);
369 if( !result && asset->audio_data )
370 result = ff->open_encoder("audio", asset->acodec);
375 int FileFFMPEG::close_file()
383 int FileFFMPEG::write_samples(double **buffer, int64_t len)
385 if( !ff || len < 0 ) return -1;
387 int ret = ff->encode(stream, buffer, len);
391 int FileFFMPEG::write_frames(VFrame ***frames, int len)
394 int ret = 0, layer = 0;
395 for(int i = 0; i < 1; i++) {
396 for(int j = 0; j < len && !ret; j++) {
397 VFrame *frame = frames[i][j];
398 ret = ff->encode(layer, frame);
405 int FileFFMPEG::read_samples(double *buffer, int64_t len)
407 if( !ff || len < 0 ) return -1;
408 int ch = file->current_channel;
409 int64_t pos = file->current_sample;
410 int ret = ff->decode(ch, pos, buffer, len);
411 if( ret > 0 ) return 0;
412 memset(buffer,0,len*sizeof(*buffer));
416 int FileFFMPEG::read_frame(VFrame *frame)
419 int layer = file->current_layer;
420 int64_t pos = asset->video_length >= 0 ? file->current_frame : 0;
421 int ret = ff->decode(layer, pos, frame);
422 frame->set_status(ret);
423 if( ret >= 0 ) return 0;
424 frame->clear_frame();
429 int64_t FileFFMPEG::get_memory_usage()
434 int FileFFMPEG::colormodel_supported(int colormodel)
440 int FileFFMPEG::get_best_colormodel(int driver, int vstream)
442 if( vstream < 0 ) vstream = 0;
443 int is_mpeg = !ff ? 0 : ff->ff_video_mpeg_color_range(vstream);
447 case PLAYBACK_X11_GL: return is_mpeg ? BC_YUV888 : BC_RGB888;
448 case PLAYBACK_X11_XV: return BC_YUV420P;
454 int FileFFMPEG::get_best_colormodel(Asset *asset, int driver)
457 // the direct X11 color model requires scaling in the codec
460 case PLAYBACK_X11_GL: return BC_RGB888;
461 case PLAYBACK_X11_XV: return BC_YUV420P;
468 FFMPEGConfigWindow::FFMPEGConfigWindow(const char *title,
469 BC_WindowBase *parent_window,
470 int x, int y, int w, int h,
471 Asset *asset, EDL *edl)
472 : BC_Window(title, x, y, w, h)
474 this->parent_window = parent_window;
479 ff_options_dialog = 0;
484 FFMPEGConfigWindow::~FFMPEGConfigWindow()
486 delete ff_options_dialog;
489 void FFMPEGConfigWindow::start(AVCodecContext *avctx)
492 ff_options_dialog->start();
495 void FFMPEGConfigWindow::start(AVFormatContext *fmt_ctx)
497 this->fmt_ctx = fmt_ctx;
498 ff_options_dialog->start();
503 FFMPEGConfigAudio::FFMPEGConfigAudio(BC_WindowBase *parent_window,
504 int x, int y, Asset *asset, EDL *edl)
505 : FFMPEGConfigWindow(_(PROGRAM_NAME ": Audio Preset"), parent_window, x, y,
506 xS(420), yS(420), asset, edl)
511 format_name = asset->fformat;
512 codec_name = asset->acodec;
515 FFMPEGConfigAudio::~FFMPEGConfigAudio()
517 lock_window("FFMPEGConfigAudio::~FFMPEGConfigAudio");
519 presets.remove_all_objects();
520 delete audio_options;
524 void FFMPEGConfigAudio::read_options()
526 const char *options = audio_options->get_text();
527 int options_len = strlen(options);
528 ff_options_dialog->load_options(options, options_len);
530 void FFMPEGConfigAudio::save_options()
532 char options[BCTEXTLEN];
533 ff_options_dialog->store_options(options, sizeof(options)-1);
534 audio_options->update(options);
537 void FFMPEGConfigAudio::load_options()
539 FFMPEG::load_audio_options(asset, edl);
542 void FFMPEGConfigAudio::create_objects()
544 int x = xS(10), y = yS(10);
545 lock_window("FFMPEGConfigAudio::create_objects");
548 char option_path[BCTEXTLEN];
549 FFMPEG::set_option_path(option_path, "audio");
550 fs.update(option_path);
551 int total_files = fs.total_files();
552 for(int i = 0; i < total_files; i++) {
553 const char *name = fs.get_entry(i)->get_name();
554 if( asset->fformat[0] != 0 ) {
555 const char *ext = strrchr(name,'.');
557 if( strcmp(asset->fformat, ++ext) ) continue;
559 presets.append(new BC_ListBoxItem(name));
562 if( asset->acodec[0] ) {
563 int k = presets.size();
564 while( --k >= 0 && strcmp(asset->acodec, presets[k]->get_text()) );
565 if( k < 0 ) asset->acodec[0] = 0;
568 if( !asset->acodec[0] && presets.size() > 0 )
569 strcpy(asset->acodec, presets[0]->get_text());
571 add_tool(new BC_Title(x, y, _("Preset:")));
573 preset_popup = new FFMPEGConfigAudioPopup(this, x, y);
574 preset_popup->create_objects();
577 bitrate = new FFMpegAudioBitrate(this, x, y, _("Bitrate:"), &asset->ff_audio_bitrate);
578 bitrate->create_objects();
579 bitrate->set_increment(1000);
580 bitrate->set_boundaries((int64_t)0, (int64_t)INT_MAX);
581 y += bitrate->get_h() + 5;
582 quality = new FFMpegAudioQuality(this, x, y, _("Quality:"), &asset->ff_audio_quality);
583 quality->create_objects();
584 quality->set_increment(1);
585 quality->set_boundaries((int64_t)-1, (int64_t)51);
586 y += quality->get_h() + yS(10);
588 add_subwindow(new BC_Title(x, y, _("Samples:")));
589 sample_format = new FFMpegSampleFormat(this, x+xS(90), y, xS(100), yS(120));
590 sample_format->create_objects();
591 if( asset->acodec[0] ) {
592 sample_format->update_formats();
593 if( !asset->ff_audio_options[0] )
596 if( !asset->ff_sample_format[0] ) strcpy(asset->ff_sample_format, _("None"));
597 sample_format->update(asset->ff_sample_format);
598 y += sample_format->get_h() + yS(10);
600 BC_Title *title = new BC_Title(x, y, _("Audio Options:"));
601 add_subwindow(title);
603 ff_options_dialog = new FFOptionsAudioDialog(this);
604 int x1 = x + title->get_w() + xS(8);
605 add_subwindow(view_audio = new FFOptionsViewAudio(this, x1, y, _("view")));
606 x1 += x + view_audio->get_w() + xS(20);
607 view_format = new FFOptionsViewFormat(this, edl, asset, x1, y, _("format"));
608 add_subwindow(view_format);
611 audio_options = new FFAudioOptions(this, x, y, get_w()-x-xS(20), 8,
612 sizeof(asset->ff_audio_options)-1, asset->ff_audio_options);
613 audio_options->create_objects();
614 add_subwindow(new BC_OKButton(this));
615 add_subwindow(new BC_CancelButton(this));
618 bitrate->update_param("cin_bitrate", asset->ff_audio_options);
619 quality->update_param("cin_quality", asset->ff_audio_options);
621 if( asset->ff_audio_bitrate > 0 ) quality->disable();
622 else if( asset->ff_audio_quality >= 0 ) bitrate->disable();
627 int FFMPEGConfigAudio::close_event()
633 FFAudioOptions::FFAudioOptions(FFMPEGConfigAudio *audio_popup,
634 int x, int y, int w, int rows, int size, char *text)
635 : BC_ScrollTextBox(audio_popup, x, y, w, rows, text, size)
637 this->audio_popup = audio_popup;
641 FFMPEGConfigAudioPopup::FFMPEGConfigAudioPopup(FFMPEGConfigAudio *popup, int x, int y)
642 : BC_PopupTextBox(popup, &popup->presets, popup->asset->acodec, x, y, xS(300), yS(300))
647 int FFMPEGConfigAudioPopup::handle_event()
649 strcpy(popup->asset->acodec, get_text());
650 popup->sample_format->update_formats();
651 Asset *asset = popup->asset;
652 asset->ff_audio_bitrate = 0; asset->ff_audio_quality = -1;
653 popup->load_options();
654 popup->audio_options->update(asset->ff_audio_options);
655 popup->audio_options->set_text_row(0);
657 popup->bitrate->update_param("cin_bitrate", asset->ff_audio_options);
658 popup->quality->update_param("cin_quality", asset->ff_audio_options);
659 popup->sample_format->update(asset->ff_sample_format);
665 FFMPEGConfigVideo::FFMPEGConfigVideo(BC_WindowBase *parent_window,
666 int x, int y, Asset *asset, EDL *edl)
667 : FFMPEGConfigWindow(_(PROGRAM_NAME ": Video Preset"), parent_window, x, y,
668 xS(420), yS(420), asset, edl)
672 format_name = asset->fformat;
673 codec_name = asset->vcodec;
680 FFMPEGConfigVideo::~FFMPEGConfigVideo()
682 lock_window("FFMPEGConfigVideo::~FFMPEGConfigVideo");
685 delete video_options;
686 presets.remove_all_objects();
690 void FFMPEGConfigVideo::read_options()
692 const char *options = video_options->get_text();
693 int options_len = strlen(options);
694 ff_options_dialog->load_options(options, options_len);
696 void FFMPEGConfigVideo::save_options()
698 char options[BCTEXTLEN];
699 ff_options_dialog->store_options(options, sizeof(options)-1);
700 video_options->update(options);
703 void FFMPEGConfigVideo::load_options()
705 FFMPEG::load_video_options(asset, edl);
708 void FFMPEGConfigVideo::create_objects()
710 int x = xS(10), y = yS(10);
711 lock_window("FFMPEGConfigVideo::create_objects");
713 add_subwindow(new BC_Title(x, y, _("Compression:")));
717 char option_path[BCTEXTLEN];
718 FFMPEG::set_option_path(option_path, "video");
719 fs.update(option_path);
720 int total_files = fs.total_files();
721 for(int i = 0; i < total_files; i++) {
722 const char *name = fs.get_entry(i)->get_name();
723 if( asset->fformat[0] != 0 ) {
724 const char *ext = strrchr(name,'.');
726 if( strcmp(asset->fformat, ++ext) ) continue;
728 presets.append(new BC_ListBoxItem(name));
731 if( asset->vcodec[0] ) {
732 int k = presets.size();
733 while( --k >= 0 && strcmp(asset->vcodec, presets[k]->get_text()) );
734 if( k < 0 ) asset->vcodec[0] = 0;
737 if( !asset->vcodec[0] && presets.size() > 0 )
738 strcpy(asset->vcodec, presets[0]->get_text());
740 preset_popup = new FFMPEGConfigVideoPopup(this, x, y);
741 preset_popup->create_objects();
743 if( asset->ff_video_bitrate > 0 && asset->ff_video_quality >= 0 ) {
744 asset->ff_video_bitrate = 0; asset->ff_video_quality = -1;
748 bitrate = new FFMpegVideoBitrate(this, x, y, _("Bitrate:"), &asset->ff_video_bitrate);
749 bitrate->create_objects();
750 bitrate->set_increment(100000);
751 bitrate->set_boundaries((int64_t)0, (int64_t)INT_MAX);
752 y += bitrate->get_h() + 5;
753 quality = new FFMpegVideoQuality(this, x, y, _("Quality:"), &asset->ff_video_quality);
754 quality->create_objects();
755 quality->set_increment(1);
756 quality->set_boundaries((int64_t)-1, (int64_t)51);
757 y += quality->get_h() + yS(10);
759 add_subwindow(new BC_Title(x, y, _("Pixels:")));
760 pixel_format = new FFMpegPixelFormat(this, x+xS(90), y, xS(100), yS(120));
761 pixel_format->create_objects();
762 if( asset->vcodec[0] ) {
763 pixel_format->update_formats();
764 if( !asset->ff_video_options[0] )
767 if( !asset->ff_pixel_format[0] ) strcpy(asset->ff_pixel_format, _("None"));
768 pixel_format->update(asset->ff_pixel_format);
769 y += pixel_format->get_h() + yS(10);
771 BC_Title *title = new BC_Title(x, y, _("Video Options:"));
772 add_subwindow(title);
774 ff_options_dialog = new FFOptionsVideoDialog(this);
775 int x1 = x + title->get_w() + 8;
776 add_subwindow(view_video = new FFOptionsViewVideo(this, x1, y, _("view")));
777 x1 += x + view_video->get_w() + xS(20);
778 view_format = new FFOptionsViewFormat(this, edl, asset, x1, y, _("format"));
779 add_subwindow(view_format);
782 video_options = new FFVideoOptions(this, x, y, get_w()-x-xS(20), 8,
783 sizeof(asset->ff_video_options)-1, asset->ff_video_options);
784 video_options->create_objects();
785 add_subwindow(new BC_OKButton(this));
786 add_subwindow(new BC_CancelButton(this));
789 bitrate->update_param("cin_bitrate", asset->ff_video_options);
790 quality->update_param("cin_quality", asset->ff_video_options);
792 if( asset->ff_video_bitrate > 0 ) quality->disable();
793 else if( asset->ff_video_quality >= 0 ) bitrate->disable();
797 int FFMPEGConfigVideo::close_event()
803 FFVideoOptions::FFVideoOptions(FFMPEGConfigVideo *video_popup,
804 int x, int y, int w, int rows, int size, char *text)
805 : BC_ScrollTextBox(video_popup, x, y, w, rows, text, size)
807 this->video_popup = video_popup;
811 FFMPEGConfigVideoPopup::FFMPEGConfigVideoPopup(FFMPEGConfigVideo *popup, int x, int y)
812 : BC_PopupTextBox(popup, &popup->presets, popup->asset->vcodec, x, y, xS(300), yS(300))
817 int FFMPEGConfigVideoPopup::handle_event()
819 strcpy(popup->asset->vcodec, get_text());
820 popup->pixel_format->update_formats();
821 Asset *asset = popup->asset;
822 asset->ff_video_bitrate = 0; asset->ff_video_quality = -1;
823 popup->load_options();
824 popup->video_options->update(asset->ff_video_options);
825 popup->video_options->set_text_row(0);
827 popup->bitrate->update_param("cin_bitrate", asset->ff_video_options);
828 popup->quality->update_param("cin_quality", asset->ff_video_options);
829 popup->pixel_format->update(asset->ff_pixel_format);
835 FFMPEGConfigFormat::FFMPEGConfigFormat(FFOptionsFormatViewDialog *view_dialog,
836 int x, int y, Asset *asset, EDL *edl)
837 : FFMPEGConfigWindow(_(PROGRAM_NAME ": Format Preset"),
838 view_dialog->view_format, x, y, xS(420), yS(300), asset, edl)
840 this->view_dialog = view_dialog;
842 format_name = asset->fformat;
846 FFMPEGConfigFormat::~FFMPEGConfigFormat()
848 lock_window("FFMPEGConfigFormat::~FFMPEGConfigFormat");
849 delete format_options;
853 void FFMPEGConfigFormat::read_options()
855 const char *options = format_options->get_text();
856 int options_len = strlen(options);
857 ff_options_dialog->load_options(options, options_len);
859 void FFMPEGConfigFormat::save_options()
861 char options[BCTEXTLEN];
862 ff_options_dialog->store_options(options, sizeof(options)-1);
863 format_options->update(options);
865 void FFMPEGConfigFormat::save_changes()
868 char *options = asset->ff_format_options;
869 int options_len = sizeof(asset->ff_format_options)-1;
870 ff_options_dialog->store_options(options, options_len);
873 void FFMPEGConfigFormat::load_options()
875 Asset *asset = view_dialog->view_format->asset;
876 EDL *edl = view_dialog->view_format->edl;
877 FFMPEG::load_format_options(asset, edl);
880 void FFMPEGConfigFormat::create_objects()
882 int x = xS(10), y = yS(10);
883 lock_window("FFMPEGConfigFormat::create_objects");
884 Asset *asset = view_dialog->view_format->asset;
886 add_subwindow(title = new BC_Title(x, y, _("Format:")));
887 int x1 = x + title->get_w() + 8;
888 add_subwindow(new BC_Title(x1, y, asset->fformat));
891 add_subwindow(title = new BC_Title(x, y, _("Format Options:")));
893 ff_options_dialog = new FFOptionsFormatDialog(this);
894 x1 = x + title->get_w() + 8;
895 add_subwindow(new FFOptionsFormatView(this, x1, y, _("view")));
898 format_options = new FFFormatOptions(this, x, y, get_w()-x-xS(20), 8,
899 sizeof(asset->ff_format_options)-1, asset->ff_format_options);
900 format_options->create_objects();
901 add_subwindow(new BC_OKButton(this));
902 add_subwindow(new BC_CancelButton(this));
907 int FFMPEGConfigFormat::close_event()
913 FFFormatOptions::FFFormatOptions(FFMPEGConfigFormat *format_popup,
914 int x, int y, int w, int rows, int size, char *text)
915 : BC_ScrollTextBox(format_popup, x, y, w, rows, text, size)
917 this->format_popup = format_popup;
922 FFMPEGScanProgress::FFMPEGScanProgress(IndexFile *index_file, MainProgressBar *progress_bar,
923 const char *title, int64_t length, int64_t *position, int *canceled)
926 this->index_file = index_file;
927 this->progress_bar = progress_bar;
928 strcpy(this->progress_title, title);
929 this->length = length;
930 this->position = position;
931 this->canceled = canceled;
936 FFMPEGScanProgress::~FFMPEGScanProgress()
943 void FFMPEGScanProgress::run()
946 if( progress_bar->update(*position) ) {
947 *canceled = done = 1;
950 index_file->redraw_edits(0);
955 int FileFFMPEG::get_index(IndexFile *index_file, MainProgressBar *progress_bar)
958 if( !file->preferences->ffmpeg_marker_indexes ) return 1;
960 IndexState *index_state = index_file->get_state();
961 if( index_state->index_status != INDEX_NOTTESTED ) return 0;
962 index_state->reset_index();
963 index_state->reset_markers();
964 index_state->index_status = INDEX_BUILDING;
966 for( int aidx=0; aidx<ff->ffaudio.size(); ++aidx ) {
967 FFAudioStream *aud = ff->ffaudio[aidx];
968 index_state->add_audio_stream(aud->channels, aud->length);
972 int64_t file_bytes = fs.get_size(ff->fmt_ctx->url);
973 char *index_path = index_file->index_filename;
976 int64_t scan_position = 0;
977 FFMPEGScanProgress *scan_progress = 0;
979 char progress_title[BCTEXTLEN];
980 sprintf(progress_title, _("Creating %s\n"), index_path);
981 progress_bar->update_title(progress_title, 1);
982 progress_bar->update_length(file_bytes);
983 scan_progress = new FFMPEGScanProgress(index_file,
984 progress_bar, progress_title, file_bytes,
985 &scan_position, &canceled);
988 index_state->index_bytes = file_bytes;
989 index_state->init_scan(file->preferences->index_size);
991 if( ff->scan(index_state, &scan_position, &canceled) || canceled ) {
992 index_state->reset_index();
993 index_state->reset_markers();
997 delete scan_progress;
998 if( canceled ) return 1;
1000 index_state->marker_status = MARKERS_READY;
1001 return index_state->create_index(index_path, asset);
1005 FFOptions_OptPanel::
1006 FFOptions_OptPanel(FFOptionsWindow *fwin, int x, int y, int w, int h)
1007 : BC_ListBox(x, y, w, h, LISTBOX_TEXT), opts(items[0]), vals(items[1])
1010 update(); // init col/wid/columns
1013 FFOptions_OptPanel::
1014 ~FFOptions_OptPanel()
1018 void FFOptions_OptPanel::create_objects()
1020 const char *cols[] = { _("option"), _("value"), };
1021 const int col1_w = xS(150);
1022 int wids[] = { col1_w, get_w()-col1_w };
1023 BC_ListBox::update(&items[0], &cols[0], &wids[0], sizeof(items)/sizeof(items[0]));
1026 int FFOptions_OptPanel::update()
1030 FFOptions &options = fwin->options;
1031 for( int i=0; i<options.size(); ++i ) {
1032 FFOptions_Opt *opt = options[i];
1033 opts.append(opt->item_name);
1034 vals.append(opt->item_value);
1040 int FFOptions_OptPanel::cursor_leave_event()
1047 FFOptions_OptName::FFOptions_OptName(FFOptions_Opt *opt, const char *nm)
1053 FFOptions_OptName::~FFOptions_OptName()
1057 FFOptions_OptValue::FFOptions_OptValue(FFOptions_Opt *opt)
1063 void FFOptions_OptValue::update()
1066 char val[BCTEXTLEN]; val[0] = 0;
1067 opt->get(val, sizeof(val));
1071 void FFOptions_OptValue::update(const char *v)
1076 FFOptions_Opt::FFOptions_Opt(FFOptions *options, const AVOption *opt, const char *nm)
1078 this->options = options;
1080 item_name = new FFOptions_OptName(this, nm);
1081 item_value = new FFOptions_OptValue(this);
1084 FFOptions_Opt::~FFOptions_Opt()
1090 char *FFOptions_Opt::get(char *vp, int sz)
1094 if( !opt ) return cp;
1096 void *obj = (void *)options->obj;
1098 if( av_opt_get(obj, opt->name, 0, &bp) >= 0 && bp != 0 ) {
1099 const char *val = (const char *)bp;
1100 if( opt->unit && *val ) {
1102 const char *uid = unit_name(id);
1103 if( uid ) val = uid;
1105 cp = sz >= 0 ? strncpy(vp,val,sz) : strcpy(vp, val);
1106 if( sz > 0 ) vp[sz-1] = 0;
1113 void FFOptions_Opt::set(const char *val)
1115 void *obj = (void *)options->obj;
1116 if( !obj || !opt ) return;
1117 av_opt_set(obj, opt->name, val, 0);
1121 FFOptionsKindItem::FFOptionsKindItem(FFOptionsKind *kind, const char *text, int idx)
1128 FFOptionsKindItem::~FFOptionsKindItem()
1132 int FFOptionsKindItem::handle_event()
1134 FFOptionsWindow *fwin = kind->fwin;
1135 FFOptions &options = fwin->options;
1136 options.initialize(fwin, idx);
1137 kind->set_text(get_text());
1142 const char *FFOptionsKind::kinds[] = {
1143 N_("codec"), // FF_KIND_CODEC
1144 N_("format"), // FF_KIND_FORMAT
1145 N_("ffmpeg"), // FF_KIND_FFMPEG
1149 FFOptionsKind(FFOptionsWindow *fwin, int x, int y, int w)
1150 : BC_PopupMenu(x, y, w, "")
1160 void FFOptionsKind::create_objects()
1162 add_item(new FFOptionsKindItem(this, _(kinds[FF_KIND_CODEC]), FF_KIND_CODEC));
1163 add_item(new FFOptionsKindItem(this, _(kinds[FF_KIND_FFMPEG]), FF_KIND_FFMPEG));
1166 int FFOptionsKind::handle_event()
1171 void FFOptionsKind::set(int k)
1174 set_text(_(kinds[k]));
1178 FFOptionsText(FFOptionsWindow *fwin, int x, int y, int w)
1179 : BC_TextBox(x, y, w, 1, (char *)"")
1189 int FFOptionsText::handle_event()
1195 FFOptionsUnits(FFOptionsWindow *fwin, int x, int y, int w)
1196 : BC_PopupMenu(x, y, w, "")
1206 int FFOptionsUnits::handle_event()
1208 const char *text = get_text();
1209 if( text && fwin->selected ) {
1210 fwin->selected->set(text);
1211 fwin->selected->item_value->update();
1212 av_dict_set(&fwin->dialog->ff_opts,
1213 fwin->selected->item_name->get_text(),
1214 fwin->selected->item_value->get_text(), 0);
1221 FFOptionsApply(FFOptionsWindow *fwin, int x, int y)
1222 : BC_GenericButton(x, y, _("Apply"))
1232 int FFOptionsApply::handle_event()
1234 const char *text = fwin->text->get_text();
1235 if( text && fwin->selected ) {
1236 fwin->selected->set(text);
1237 fwin->selected->item_value->update();
1238 av_dict_set(&fwin->dialog->ff_opts,
1239 fwin->selected->item_name->get_text(),
1240 fwin->selected->item_value->get_text(), 0);
1246 FFOptions::FFOptions()
1251 FFOptions::~FFOptions()
1253 remove_all_objects();
1256 int FFOptions::cmpr(const void *a, const void *b)
1258 FFOptions_Opt *ap = *(FFOptions_Opt **)a;
1259 FFOptions_Opt *bp = *(FFOptions_Opt **)b;
1260 const char *vap = ap->item_name->get_text();
1261 const char *vbp = bp->item_name->get_text();
1262 return strcmp(vap, vbp);
1265 void FFOptions::initialize(FFOptionsWindow *win, int kind)
1267 remove_all_objects();
1269 const void *obj = 0;
1272 obj = (const void *)win->dialog->cfg_window->avctx->priv_data;
1274 case FF_KIND_FFMPEG:
1275 obj = (const void *)win->dialog->cfg_window->avctx;
1277 case FF_KIND_FORMAT:
1278 obj = (const void *)win->dialog->cfg_window->fmt_ctx->priv_data;
1284 FFOptions &conf = *this;
1285 const AVOption *opt = 0;
1286 while( (opt=av_opt_next(obj, opt)) != 0 ) {
1287 if( opt->type == AV_OPT_TYPE_CONST ) continue;
1289 for( int i=0; !dupl && i<size(); ++i ) {
1290 FFOptions_Opt *fopt = conf[i];
1291 const AVOption *op = fopt->opt;
1292 if( op->offset != opt->offset ) continue;
1293 if( op->type != opt->type ) continue;
1295 if( strlen(op->name) < strlen(opt->name) )
1298 if( dupl ) continue;
1299 FFOptions_Opt *fopt = new FFOptions_Opt(this, opt, opt->name);
1301 AVDictionaryEntry *elem = av_dict_get(win->dialog->ff_opts,
1302 opt->name, 0, AV_DICT_IGNORE_SUFFIX);
1303 if( elem && elem->value ) fopt->set(elem->value);
1304 char val[BCTEXTLEN], *vp = fopt->get(val, sizeof(val));
1305 fopt->item_value->update(vp);
1307 qsort(&values[0],size(),sizeof(values[0]),cmpr);
1309 win->panel->update();
1310 win->panel->set_yposition(0);
1313 int FFOptions::update()
1316 FFOptions &conf = *this;
1318 for( int i=0; i<size(); ++i ) {
1319 FFOptions_Opt *fopt = conf[i];
1320 char val[BCTEXTLEN], *vp = fopt->get(val, sizeof(val));
1321 if( !vp || !strcmp(val, fopt->item_value->get_text()) ) continue;
1322 fopt->item_value->update(val);
1328 void FFOptions::dump(FILE *fp)
1331 const AVOption *opt = 0;
1332 FFOptions &conf = *this;
1334 while( (opt=av_opt_next(obj, opt)) != 0 ) {
1335 if( opt->type == AV_OPT_TYPE_CONST ) continue;
1337 while( --k >= 0 && strcmp(opt->name, conf[k]->opt->name) );
1338 if( k < 0 ) continue;
1339 FFOptions_Opt *fopt = conf[k];
1340 char val[BCTEXTLEN], *vp = fopt->get(val,sizeof(val));
1341 fprintf(fp, " %s:=%s", opt->name, vp);
1343 char unt[BCTEXTLEN], *up = unt;
1345 fprintf(fp, "%s", unt);
1352 void FFOptionsWindow::update(FFOptions_Opt *opt)
1354 if( selected != opt ) {
1355 if( selected ) selected->item_name->set_selected(0);
1357 if( selected ) selected->item_name->set_selected(1);
1359 clear_box(0,0, 0,panel->get_y());
1360 char str[BCTEXTLEN], *sp;
1362 if( opt ) opt->types(sp);
1365 if( opt ) opt->ranges(sp);
1367 while( units->total_items() ) units->del_item(0);
1368 char unit[BCSTRLEN]; strcpy(unit, "()");
1369 if( opt && opt->opt ) {
1370 ArrayList<const char *> names;
1372 if( opt->opt->unit ) {
1373 n = opt->units(names);
1374 if( n > 0 ) strcpy(unit,opt->opt->unit);
1376 for( int i=0; i<n; ++i )
1377 units->add_item(new BC_MenuItem(names[i], 0));
1379 units->set_text(unit);
1380 char val[BCTEXTLEN]; val[0] = 0;
1381 if( opt ) opt->get(val, sizeof(val));
1387 void FFOptions_OptPanel::show_tip(const char *tip)
1390 int len = strlen(tip);
1391 if( len > (int)sizeof(tip_text)-1 ) len = sizeof(tip_text)-1;
1392 strncpy(tip_text,tip,len);
1394 int line_limit = 60;
1395 int limit2 = line_limit/2;
1396 int limit4 = line_limit/4-2;
1397 char *cp = tip_text, *dp = cp+len;
1398 int n; char *bp, *ep, *pp, *sp;
1400 for( ep=cp; ep<dp && *ep!='\n'; ++ep );
1401 // target about half remaining line, constrain line_limit
1402 if( (n=(ep-1-cp)/2) < limit2 || n > line_limit )
1404 // search for last punct, last space before line_limit
1405 for( bp=cp, pp=sp=0; --n>=0 && cp<ep; ++cp ) {
1406 if( ispunct(*cp) && isspace(*(cp+1)) ) pp = cp;
1407 else if( isspace(*cp) ) sp = cp;
1411 // first, after punctuation
1412 if( pp && pp-bp >= limit4 )
1418 // last, on next space
1420 while( cp<dp && !isspace(*cp) ) ++cp;
1427 fwin->panel->set_tooltip(tip_text);
1428 fwin->panel->show_tooltip();
1431 int FFOptions_OptPanel::selection_changed()
1433 FFOptions_Opt *opt = 0;
1434 BC_ListBoxItem *item = get_selection(0, 0);
1436 FFOptions_OptName *opt_name = (FFOptions_OptName *)item;
1437 opt = opt_name->opt;
1440 if( opt ) show_tip(opt->tip());
1445 int FFOptions_Opt::types(char *rp)
1447 const char *cp = "";
1448 if( opt ) switch (opt->type) {
1449 case AV_OPT_TYPE_FLAGS: cp = N_("<flags>"); break;
1450 case AV_OPT_TYPE_INT: cp = N_("<int>"); break;
1451 case AV_OPT_TYPE_INT64: cp = N_("<int64>"); break;
1452 case AV_OPT_TYPE_DOUBLE: cp = N_("<double>"); break;
1453 case AV_OPT_TYPE_FLOAT: cp = N_("<float>"); break;
1454 case AV_OPT_TYPE_STRING: cp = N_("<string>"); break;
1455 case AV_OPT_TYPE_RATIONAL: cp = N_("<rational>"); break;
1456 case AV_OPT_TYPE_BINARY: cp = N_("<binary>"); break;
1457 case AV_OPT_TYPE_IMAGE_SIZE: cp = N_("<image_size>"); break;
1458 case AV_OPT_TYPE_VIDEO_RATE: cp = N_("<video_rate>"); break;
1459 case AV_OPT_TYPE_PIXEL_FMT: cp = N_("<pix_fmt>"); break;
1460 case AV_OPT_TYPE_SAMPLE_FMT: cp = N_("<sample_fmt>"); break;
1461 case AV_OPT_TYPE_DURATION: cp = N_("<duration>"); break;
1462 case AV_OPT_TYPE_COLOR: cp = N_("<color>"); break;
1463 case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = N_("<channel_layout>"); break;
1464 case AV_OPT_TYPE_BOOL: cp = N_("<bool>"); break;
1465 default: cp = N_("<undef>"); break;
1467 return sprintf(rp, "%s", _(cp));
1469 int FFOptions_Opt::scalar(double d, char *rp)
1472 if( d == INT_MAX ) cp = "INT_MAX";
1473 else if( d == INT_MIN ) cp = "INT_MIN";
1474 else if( d == UINT32_MAX ) cp = "UINT32_MAX";
1475 else if( d == (double)INT64_MAX ) cp = "I64_MAX";
1476 else if( d == INT64_MIN ) cp = "I64_MIN";
1477 else if( d == FLT_MAX ) cp = "FLT_MAX";
1478 else if( d == FLT_MIN ) cp = "FLT_MIN";
1479 else if( d == -FLT_MAX ) cp = "-FLT_MAX";
1480 else if( d == -FLT_MIN ) cp = "-FLT_MIN";
1481 else if( d == DBL_MAX ) cp = "DBL_MAX";
1482 else if( d == DBL_MIN ) cp = "DBL_MIN";
1483 else if( d == -DBL_MAX ) cp = "-DBL_MAX";
1484 else if( d == -DBL_MIN ) cp = "-DBL_MIN";
1485 else if( d == 0 ) cp = signbit(d) ? "-0" : "0";
1486 else if( isnan(d) ) cp = signbit(d) ? "-NAN" : "NAN";
1487 else if( isinf(d) ) cp = signbit(d) ? "-INF" : "INF";
1488 else return sprintf(rp, "%g", d);
1489 return sprintf(rp, "%s", cp);
1492 int FFOptions_Opt::ranges(char *rp)
1494 if( !opt ) return 0;
1495 void *obj = (void *)options->obj;
1496 if( !obj ) return 0;
1498 switch (opt->type) {
1499 case AV_OPT_TYPE_INT:
1500 case AV_OPT_TYPE_INT64:
1501 case AV_OPT_TYPE_DOUBLE:
1502 case AV_OPT_TYPE_FLOAT: break;
1505 AVOptionRanges *r = 0;
1507 if( av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) < 0 ) return 0;
1508 for( int i=0; i<r->nb_ranges; ++i ) {
1509 cp += sprintf(cp, " ("); cp += scalar(r->range[i]->value_min, cp);
1510 cp += sprintf(cp, ".."); cp += scalar(r->range[i]->value_max, cp);
1511 cp += sprintf(cp, ")");
1513 av_opt_freep_ranges(&r);
1517 int FFOptions_Opt::units(ArrayList<const char *> &names)
1519 if( !opt || !opt->unit ) return 0;
1520 const void *obj = options->obj;
1521 if( !obj ) return 0;
1523 ArrayList<const AVOption *> opts;
1524 const AVOption *opt = NULL;
1525 while( (opt=av_opt_next(obj, opt)) != 0 ) {
1526 if( !opt->unit ) continue;
1527 if( opt->type != AV_OPT_TYPE_CONST ) continue;
1528 if( strcmp(this->opt->unit, opt->unit) ) continue;
1529 int i = opts.size();
1531 if( opts[i]->default_val.i64 != opt->default_val.i64 ) continue;
1532 if( strlen(opts[i]->name) < strlen(opt->name) ) opts[i] = opt;
1535 if( i >= 0 ) continue;
1539 for( int i=0; i<opts.size(); ++i )
1540 names.append(opts[i]->name);
1542 return names.size();
1545 int FFOptions_Opt::units(char *rp)
1547 ArrayList<const char *> names;
1548 int n = units(names);
1551 cp += sprintf(cp, " [%s:", this->opt->unit);
1552 for( int i=0; i<n; ++i )
1553 cp += sprintf(cp, " %s", names[i]);
1554 cp += sprintf(cp, "]:");
1558 const char *FFOptions_Opt::unit_name(int id)
1560 if( !opt || !opt->unit ) return 0;
1561 const void *obj = options->obj;
1562 if( !obj ) return 0;
1564 const char *ret = 0;
1565 const AVOption *opt = NULL;
1566 while( (opt=av_opt_next(obj, opt)) != 0 ) {
1567 if( !opt->unit ) continue;
1568 if( opt->type != AV_OPT_TYPE_CONST ) continue;
1569 if( strcmp(this->opt->unit, opt->unit) ) continue;
1570 if( opt->default_val.i64 != id ) continue;
1571 if( !ret ) { ret = opt->name; continue; }
1572 if( strlen(ret) < strlen(opt->name) ) ret = opt->name;
1578 const char *FFOptions_Opt::tip()
1580 return !opt ? 0 : opt->help;
1584 FFOptionsWindow::FFOptionsWindow(FFOptionsDialog *dialog, int x, int y)
1585 : BC_Window(_(PROGRAM_NAME ": Options"), x, y, xS(640), yS(400))
1587 this->dialog = dialog;
1592 FFOptionsWindow::~FFOptionsWindow()
1596 void FFOptionsWindow::create_objects()
1598 int xs8 = xS(8), xs10 = xS(10);
1600 lock_window("FFOptionsWindow::create_objects");
1602 const char *format_name = dialog->cfg_window->format_name;
1603 const char *codec_name = dialog->cfg_window->codec_name;
1604 int x0 = xs10, y0 = ys10;
1606 add_subwindow(title = new BC_Title(x, y, _("Format: ")));
1607 x += title->get_w();
1608 add_subwindow(new BC_Title(x, y, format_name));
1611 add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
1612 x += title->get_w();
1613 add_subwindow(new BC_Title(x, y, codec_name));
1615 x = x0; y += title->get_h() + ys10; y0 = y;
1616 add_subwindow(title = new BC_Title(x, y, _("Type: ")));
1617 x += title->get_w() + xs8;
1618 add_subwindow(type = new BC_Title(x, y, (char *)""));
1620 add_subwindow(title = new BC_Title(x, y, _("Range: ")));
1621 x += title->get_w() + xs8;
1622 add_subwindow(range = new BC_Title(x, y, (char *)""));
1624 x = x0; y += title->get_h() + ys10;
1625 add_subwindow(units = new FFOptionsUnits(this, x, y, xS(120)));
1626 x += units->get_w() + xs8;
1627 int x1 = get_w() - BC_GenericButton::calculate_w(this, _("Apply")) - xs8;
1628 add_subwindow(text = new FFOptionsText(this, x, y, x1-x - xs8));
1629 add_subwindow(apply = new FFOptionsApply(this, x1, y));
1630 y += units->get_h() + ys10;
1632 add_subwindow(kind = new FFOptionsKind(this, x1, y0, apply->get_w()));
1633 kind->create_objects();
1634 const char *kind_text = _("Kind:");
1635 x1 -= BC_Title::calculate_w(this, kind_text) + xs8;
1636 add_subwindow(kind_title = new BC_Title(x1, y0, kind_text));
1639 panel_x = x0; panel_y = y0;
1640 panel_w = get_w()-xs10 - panel_x;
1641 panel_h = get_h()-ys10 - panel_y - BC_OKButton::calculate_h();
1642 panel = new FFOptions_OptPanel(this, panel_x, panel_y, panel_w, panel_h);
1643 add_subwindow(panel);
1644 add_subwindow(new BC_OKButton(this));
1645 add_subwindow(new BC_CancelButton(this));
1646 panel->create_objects();
1647 int k = codec_name ? FF_KIND_CODEC : FF_KIND_FORMAT;
1648 options.initialize(this, k);
1656 void FFOptionsWindow::draw()
1661 int FFOptionsWindow::resize_event(int w, int h)
1663 int xs8 = xS(8), xs10 = xS(10);
1666 int x0 = w - xs8 - kind->get_w();
1667 int y0 = kind->get_y();
1668 kind->reposition_window(x0, y0);
1669 x0 -= kind_title->get_w() + xs8;
1670 kind_title->reposition_window(x0, y0);
1672 int x1 = get_w() - apply->get_w() - xs8;
1673 int y1 = units->get_y();
1674 apply->reposition_window(x1, y1);
1675 int x0 = units->get_x() + units->get_w() + xs8;
1676 int y0 = units->get_y();
1677 text->reposition_window(x0,y0, x1-x0-xs8);
1678 panel_w = get_w()-xs10 - panel_x;
1679 panel_h = get_h()-ys10 - panel_y - BC_OKButton::calculate_h();
1680 panel->reposition_window(panel_x,panel_y, panel_w, panel_h);
1684 FFOptionsDialog::FFOptionsDialog(FFMPEGConfigWindow *cfg_window)
1687 this->cfg_window = cfg_window;
1692 FFOptionsDialog::~FFOptionsDialog()
1695 av_dict_free(&ff_opts);
1698 void FFOptionsDialog::load_options(const char *bp, int len)
1700 av_dict_free(&ff_opts);
1701 char line[BCTEXTLEN];
1702 char key[BCSTRLEN], val[BCTEXTLEN];
1703 const char *dp = bp + len-1;
1705 while( bp < dp && *bp != 0 ) {
1707 char *cp = line, *ep = cp+sizeof(line)-1;
1708 while( *bp && cp<ep && (*cp=*bp++)!='\n' ) ++cp;
1710 if( line[0] == '#' ) {
1711 sprintf(key,"#%d", no);
1712 av_dict_set(&ff_opts, key, line, 0);
1715 if( line[0] == '\n' ) continue;
1716 if( FFMPEG::scan_option_line(line, key, val) ) continue;
1717 av_dict_set(&ff_opts, key, val, 0);
1721 void FFOptionsDialog::store_options(char *cp, int len)
1723 char *ep = cp + len-1;
1724 AVDictionaryEntry *elem = 0;
1725 while( (elem=av_dict_get(ff_opts, "", elem, AV_DICT_IGNORE_SUFFIX)) != 0 ) {
1726 if( elem->key[0] == '#' ) {
1727 cp += snprintf(cp,ep-cp, "%s\n", elem->value);
1730 cp += snprintf(cp,ep-cp, "%s=%s\n", elem->key, elem->value);
1736 void FFOptionsDialog::start()
1738 if( options_window ) {
1739 options_window->lock_window("FFOptionsDialog::start");
1740 options_window->raise_window();
1741 options_window->unlock_window();
1744 cfg_window->get_pop_cursor(wx, wy);
1745 cfg_window->read_options();
1746 BC_DialogThread::start();
1749 BC_Window* FFOptionsDialog::new_gui()
1751 options_window = new FFOptionsWindow(this, wx, wy);
1752 options_window->create_objects();
1753 return options_window;
1756 void FFOptionsDialog::handle_done_event(int result)
1759 cfg_window->lock_window("FFMPEGConfigFormat::save_options");
1760 cfg_window->save_options();
1761 cfg_window->unlock_window();
1766 FFOptionsAudioDialog::FFOptionsAudioDialog(FFMPEGConfigAudio *aud_config)
1767 : FFOptionsDialog(aud_config)
1769 this->aud_config = aud_config;
1772 FFOptionsAudioDialog::~FFOptionsAudioDialog()
1777 void FFOptionsAudioDialog::update_options(const char *options)
1779 aud_config->lock_window("FFOptionsAudioDialog::update_options");
1780 aud_config->audio_options->update(options);
1781 aud_config->unlock_window();
1784 FFOptionsVideoDialog::FFOptionsVideoDialog(FFMPEGConfigVideo *vid_config)
1785 : FFOptionsDialog(vid_config)
1787 this->vid_config = vid_config;
1790 FFOptionsVideoDialog::~FFOptionsVideoDialog()
1795 void FFOptionsVideoDialog::update_options(const char *options)
1797 vid_config->lock_window("FFOptionsVideoDialog::update_options");
1798 vid_config->video_options->update(options);
1799 vid_config->unlock_window();
1802 FFOptionsFormatDialog::FFOptionsFormatDialog(FFMPEGConfigFormat *fmt_config)
1803 : FFOptionsDialog(fmt_config)
1805 this->fmt_config = fmt_config;
1808 FFOptionsFormatDialog::~FFOptionsFormatDialog()
1813 void FFOptionsFormatDialog::update_options(const char *options)
1815 fmt_config->lock_window("FFOptionsFormatDialog::update_options");
1816 fmt_config->format_options->update(options);
1817 fmt_config->unlock_window();
1821 FFOptionsViewAudio::FFOptionsViewAudio(FFMPEGConfigAudio *aud_config,
1822 int x, int y, const char *text)
1823 : BC_GenericButton(x, y, text)
1825 this->aud_config = aud_config;
1829 FFOptionsViewAudio::~FFOptionsViewAudio()
1831 avcodec_free_context(&avctx);
1834 int FFOptionsViewAudio::handle_event()
1837 Asset *asset = aud_config->asset;
1838 const char *name = asset->acodec;
1839 char audio_format[BCSTRLEN]; audio_format[0] = 0;
1840 char audio_codec[BCSTRLEN]; audio_codec[0] = 0;
1841 AVCodec *codec = !ret &&
1842 !FFMPEG::get_format(audio_format, "audio", name) &&
1843 !FFMPEG::get_codec(audio_codec, "audio", name) ?
1844 avcodec_find_encoder_by_name(audio_codec) : 0;
1845 if( !ret && !codec ) {
1846 eprintf(_("no codec named: %s: %s"), name, audio_codec);
1849 avcodec_free_context(&avctx);
1850 if( !ret && !(avctx = avcodec_alloc_context3(codec)) ) {
1851 eprintf(_("no codec context: %s: %s"), name, audio_codec);
1855 aud_config->start(avctx);
1859 FFOptionsViewVideo::FFOptionsViewVideo(FFMPEGConfigVideo *vid_config,
1860 int x, int y, const char *text)
1861 : BC_GenericButton(x, y, text)
1863 this->vid_config = vid_config;
1867 FFOptionsViewVideo::~FFOptionsViewVideo()
1869 avcodec_free_context(&avctx);
1872 int FFOptionsViewVideo::handle_event()
1875 Asset *asset = vid_config->asset;
1876 const char *name = asset->vcodec;
1877 char video_format[BCSTRLEN]; video_format[0] = 0;
1878 char video_codec[BCSTRLEN]; video_codec[0] = 0;
1879 AVCodec *codec = !ret &&
1880 !FFMPEG::get_format(video_format, "video", name) &&
1881 !FFMPEG::get_codec(video_codec, "video", name) ?
1882 avcodec_find_encoder_by_name(video_codec) : 0;
1883 if( !ret && !codec ) {
1884 eprintf(_("no codec named: %s: %s"), name, video_codec);
1887 avcodec_free_context(&avctx);
1888 if( !ret && !(avctx = avcodec_alloc_context3(codec)) ) {
1889 eprintf(_("no codec context: %s: %s"), name, video_codec);
1894 vid_config->start(avctx);
1898 FFOptionsViewFormat::FFOptionsViewFormat(FFMPEGConfigWindow *cfg_window,
1899 EDL *edl, Asset *asset, int x, int y, const char *text)
1900 : BC_GenericButton(x, y, text)
1902 this->cfg_window = cfg_window;
1904 this->asset = asset;
1908 FFOptionsViewFormat::~FFOptionsViewFormat()
1910 delete format_dialog;
1913 int FFOptionsViewFormat::handle_event()
1915 delete format_dialog;
1917 get_pop_cursor(wx, wy);
1918 format_dialog = new FFOptionsFormatViewDialog(this, wx, wy);
1919 format_dialog->start();
1924 FFOptionsFormatView::FFOptionsFormatView(FFMPEGConfigFormat *fmt_config,
1925 int x, int y, const char *text)
1926 : BC_GenericButton(x, y, text)
1928 this->fmt_config = fmt_config;
1932 FFOptionsFormatView::~FFOptionsFormatView()
1934 avformat_free_context(fmt_ctx);
1937 int FFOptionsFormatView::handle_event()
1939 Asset *asset = fmt_config->asset;
1940 char *format_name = asset->fformat;
1941 avformat_free_context(fmt_ctx); fmt_ctx = 0;
1942 int ret = avformat_alloc_output_context2(&fmt_ctx, 0, format_name, 0);
1943 if( ret || !fmt_ctx ) {
1944 eprintf(_("no format named: %s"), format_name);
1948 fmt_config->start(fmt_ctx);
1952 FFOptionsFormatViewDialog::FFOptionsFormatViewDialog(FFOptionsViewFormat *view_format,
1955 this->view_format = view_format;
1961 FFOptionsFormatViewDialog::~FFOptionsFormatViewDialog()
1966 BC_Window *FFOptionsFormatViewDialog::new_gui()
1968 cfg_window = new FFMPEGConfigFormat(this, wx, wy,
1969 view_format->asset, view_format->edl);
1970 cfg_window->create_objects();
1971 cfg_window->read_options();
1975 void FFOptionsFormatViewDialog::handle_done_event(int result)
1978 cfg_window->save_changes();