7 #include "edlsession.h"
12 #include "mainerror.h"
15 #include "mwindowgui.h"
17 #include "pluginset.h"
25 #include <sys/statfs.h>
29 #define BD_1920x1080_2997i 0
30 #define BD_1920x1080_2500i 1
31 #define BD_1920x1080_2400p 2
32 #define BD_1920x1080_23976p 3
33 #define BD_1280x720_5997p 4
34 #define BD_1280x720_5000p 5
35 #define BD_1280x720_23976p 6
36 #define BD_1280x720_2400p 7
37 #define BD_720x576_2500i 8
38 #define BD_720x480_2997i 9
40 static struct bd_format {
45 { "1920x1080 29.97i", 1920,1080, 29.97 },
46 { "1920x1080 25i", 1920,1080, 25 },
47 { "1920x1080 24p", 1920,1080, 24 },
48 { "1920x1080 23.976p", 1920,1080, 23.976 },
49 { "1280x720 59.97p", 1280,720, 59.97 },
50 { "1280x720 50p", 1280,720, 50 },
51 { "1280x720 23.976p", 1280,720, 23.976 },
52 { "1280x720 24p", 1280,720, 24 },
53 { "720x576 25i (PAL)", 720,576, 25 },
54 { "720x480 29.97i (NTSC)", 720,480, 29.97 },
57 const int64_t CreateBD_Thread::BD_SIZE = 25000000000;
58 const int CreateBD_Thread::BD_STREAMS = 1;
59 const int CreateBD_Thread::BD_WIDTH = 1920;
60 const int CreateBD_Thread::BD_HEIGHT = 1080;
61 const double CreateBD_Thread::BD_ASPECT_WIDTH = 4.;
62 const double CreateBD_Thread::BD_ASPECT_HEIGHT = 3.;
63 const double CreateBD_Thread::BD_WIDE_ASPECT_WIDTH = 16.;
64 const double CreateBD_Thread::BD_WIDE_ASPECT_HEIGHT = 9.;
65 const double CreateBD_Thread::BD_FRAMERATE = 24000. / 1001.;
66 //const int CreateBD_Thread::BD_MAX_BITRATE = 40000000;
67 const int CreateBD_Thread::BD_MAX_BITRATE = 8000000;
68 const int CreateBD_Thread::BD_CHANNELS = 2;
69 const int CreateBD_Thread::BD_WIDE_CHANNELS = 6;
70 const double CreateBD_Thread::BD_SAMPLERATE = 48000;
71 const double CreateBD_Thread::BD_KAUDIO_RATE = 224;
74 CreateBD_MenuItem::CreateBD_MenuItem(MWindow *mwindow)
75 : BC_MenuItem(_("BD Render..."), _("Ctrl-d"), 'd')
78 this->mwindow = mwindow;
81 int CreateBD_MenuItem::handle_event()
83 mwindow->create_bd->start();
88 CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
91 this->mwindow = mwindow;
93 this->use_deinterlace = 0;
95 this->use_histogram = 0;
96 this->use_inverse_telecine = 0;
97 this->use_wide_audio = 0;
98 this->use_wide_aspect = 0;
99 this->use_resize_tracks = 0;
100 this->use_label_chapters = 0;
102 this->bd_size = BD_SIZE;
103 this->bd_width = BD_WIDTH;
104 this->bd_height = BD_HEIGHT;
105 this->bd_aspect_width = BD_ASPECT_WIDTH;
106 this->bd_aspect_height = BD_ASPECT_HEIGHT;
107 this->bd_framerate = BD_FRAMERATE;
108 this->bd_samplerate = BD_SAMPLERATE;
109 this->bd_max_bitrate = BD_MAX_BITRATE;
110 this->bd_kaudio_rate = BD_KAUDIO_RATE;
111 this->max_w = this->max_h = 0;
114 CreateBD_Thread::~CreateBD_Thread()
119 int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs,
120 const char *tmp_path, const char *asset_title)
122 EDL *edl = mwindow->edl;
123 if( !edl || !edl->session ) {
125 sprintf(msg, _("No EDL/Session"));
126 MainError::show_error(msg);
129 EDLSession *session = edl->session;
131 double total_length = edl->tracks->total_length();
132 if( total_length <= 0 ) {
134 sprintf(msg, _("No content: %s"), asset_title);
135 MainError::show_error(msg);
139 char asset_dir[BCTEXTLEN];
140 sprintf(asset_dir, "%s/%s", tmp_path, asset_title);
142 if( mkdir(asset_dir, 0777) ) {
143 char err[BCTEXTLEN], msg[BCTEXTLEN];
144 strerror_r(errno, err, sizeof(err));
145 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
146 MainError::show_error(msg);
150 double old_samplerate = session->sample_rate;
151 double old_framerate = session->frame_rate;
153 session->video_channels = BD_STREAMS;
154 session->video_tracks = BD_STREAMS;
155 session->frame_rate = bd_framerate;
156 session->output_w = bd_width;
157 session->output_h = bd_height;
158 session->aspect_w = bd_aspect_width;
159 session->aspect_h = bd_aspect_height;
160 session->sample_rate = bd_samplerate;
161 session->audio_channels = session->audio_tracks =
162 use_wide_audio ? BD_WIDE_CHANNELS : BD_CHANNELS;
164 char script_filename[BCTEXTLEN];
165 sprintf(script_filename, "%s/bd.sh", asset_dir);
166 int fd = open(script_filename, O_WRONLY+O_CREAT+O_TRUNC, 0755);
167 FILE *fp = fdopen(fd, "w");
169 char err[BCTEXTLEN], msg[BCTEXTLEN];
170 strerror_r(errno, err, sizeof(err));
171 sprintf(msg, _("Unable to save: %s\n-- %s"), script_filename, err);
172 MainError::show_error(msg);
175 char exe_path[BCTEXTLEN];
176 get_exe_path(exe_path);
177 fprintf(fp,"#!/bin/bash -ex\n");
178 fprintf(fp,"PATH=$PATH:%s\n",exe_path);
179 fprintf(fp,"mkdir -p $1/udfs\n");
180 fprintf(fp,"sz=`du -sb $1/bd.m2ts | sed -e 's/[ \t].*//'`\n");
181 fprintf(fp,"blks=$((sz/2048 + 4096))\n");
182 fprintf(fp,"mkudffs $1/bd.udfs $blks\n");
183 fprintf(fp,"mount -o loop $1/bd.udfs $1/udfs\n");
184 fprintf(fp,"bdwrite $1/udfs $1/bd.m2ts\n");
185 fprintf(fp,"umount $1/udfs\n");
186 fprintf(fp,"echo To burn bluray, load writable media and run:\n");
187 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/bd=$1/bd.udfs\n");
191 if( use_wide_audio ) {
192 session->audio_channels = session->audio_tracks = BD_WIDE_CHANNELS;
193 session->achannel_positions[0] = 90;
194 session->achannel_positions[1] = 150;
195 session->achannel_positions[2] = 30;
196 session->achannel_positions[3] = 210;
197 session->achannel_positions[4] = 330;
198 session->achannel_positions[5] = 270;
199 if( edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
200 mwindow->remap_audio(MWindow::AUDIO_1_TO_1);
203 session->audio_channels = session->audio_tracks = BD_CHANNELS;
204 session->achannel_positions[0] = 180;
205 session->achannel_positions[1] = 0;
206 if( edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
207 mwindow->remap_audio(MWindow::AUDIO_5_1_TO_2);
210 double new_samplerate = session->sample_rate;
211 double new_framerate = session->frame_rate;
213 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
214 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
216 int64_t aud_size = ((bd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
217 int64_t vid_size = bd_size*0.96 - aud_size;
218 int64_t vid_bitrate = (vid_size * 8) / total_length;
219 vid_bitrate /= 1000; vid_bitrate *= 1000;
220 if( vid_bitrate > bd_max_bitrate ) vid_bitrate = bd_max_bitrate;
222 char xml_filename[BCTEXTLEN];
223 sprintf(xml_filename, "%s/bd.xml", asset_dir);
225 edl->save_xml(&xml_file, xml_filename, 0, 0);
226 xml_file.terminate_string();
227 if( xml_file.write_to_file(xml_filename) ) {
229 sprintf(msg, _("Unable to save: %s"), xml_filename);
230 MainError::show_error(msg);
234 BatchRenderJob *job = new BatchRenderJob(mwindow->preferences);
236 strcpy(&job->edl_path[0], xml_filename);
237 Asset *asset = job->asset;
239 asset->layers = BD_STREAMS;
240 asset->frame_rate = session->frame_rate;
241 asset->width = session->output_w;
242 asset->height = session->output_h;
243 asset->aspect_ratio = session->aspect_w / session->aspect_h;
245 char option_path[BCTEXTLEN];
246 sprintf(&asset->path[0],"%s/bd.m2ts", asset_dir);
247 asset->format = FILE_FFMPEG;
248 strcpy(asset->fformat, "m2ts");
250 asset->audio_data = 1;
251 strcpy(asset->acodec, "bluray.m2ts");
252 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
253 FFMPEG::load_options(option_path, asset->ff_audio_options,
254 sizeof(asset->ff_audio_options));
255 asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
257 asset->video_data = 1;
258 strcpy(asset->vcodec, "bluray.m2ts");
259 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
260 FFMPEG::load_options(option_path, asset->ff_video_options,
261 sizeof(asset->ff_video_options));
262 asset->ff_video_bitrate = vid_bitrate;
263 asset->ff_video_quality = 0;
265 job = new BatchRenderJob(mwindow->preferences);
267 job->edl_path[0] = '@';
268 strcpy(&job->edl_path[1], script_filename);
269 strcpy(&job->asset->path[0], asset_dir);
274 void CreateBD_Thread::handle_close_event(int result)
277 mwindow->batch_render->load_defaults(mwindow->defaults);
278 mwindow->undo->update_undo_before();
279 KeyFrame keyframe; char data[BCTEXTLEN];
280 if( use_deinterlace ) {
281 sprintf(data,"<DEINTERLACE MODE=1>");
282 keyframe.set_data(data);
283 insert_video_plugin("Deinterlace", &keyframe);
285 if( use_inverse_telecine ) {
286 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
287 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
288 keyframe.set_data(data);
289 insert_video_plugin("Inverse Telecine", &keyframe);
292 sprintf(data,"<SCALE TYPE=%d X_FACTOR=%f Y_FACTOR=%f "
293 "WIDTH=%d HEIGHT=%d CONSTRAIN=0>",
294 max_w >= bd_width || max_h >= bd_height ? 1 : 0,
295 max_w > 0 ? (double)bd_width/max_w : 1,
296 max_h > 0 ? (double)bd_height/max_h : 1,
297 bd_width, bd_height);
298 keyframe.set_data(data);
299 insert_video_plugin("Scale", &keyframe);
301 if( use_resize_tracks )
303 if( use_histogram ) {
305 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
306 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
307 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
308 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
309 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
310 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
311 "<POINTS><POINT X=6.0e-02 Y=0>"
312 "<POINT X=9.4e-01 Y=1></POINTS>");
314 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
315 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
316 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
317 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
318 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
319 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
322 keyframe.set_data(data);
323 insert_video_plugin("Histogram", &keyframe);
325 mwindow->batch_render->reset();
326 create_bd_jobs(&mwindow->batch_render->jobs, tmp_path, asset_title);
327 mwindow->save_backup();
328 mwindow->undo->update_undo_after(_("create bd"), LOAD_ALL);
329 mwindow->resync_guis();
330 mwindow->batch_render->handle_close_event(0);
331 mwindow->batch_render->start();
334 BC_Window* CreateBD_Thread::new_gui()
336 memset(tmp_path,0,sizeof(tmp_path));
337 strcpy(tmp_path,"/tmp");
338 memset(asset_title,0,sizeof(asset_title));
339 time_t dt; time(&dt);
340 struct tm dtm; localtime_r(&dt, &dtm);
341 sprintf(asset_title, "bd_%02d%02d%02d-%02d%02d%02d",
342 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
343 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
347 use_inverse_telecine = 0;
350 use_resize_tracks = 0;
351 use_label_chapters = 0;
352 use_standard = BD_1920x1080_2997i;
356 bd_height = BD_HEIGHT;
357 bd_aspect_width = BD_ASPECT_WIDTH;
358 bd_aspect_height = BD_ASPECT_HEIGHT;
359 bd_framerate = BD_FRAMERATE;
360 bd_samplerate = BD_SAMPLERATE;
361 bd_max_bitrate = BD_MAX_BITRATE;
362 bd_kaudio_rate = BD_KAUDIO_RATE;
363 max_w = 0; max_h = 0;
365 int has_standard = -1;
367 EDLSession *session = mwindow->edl->session;
368 // match the session to any known standard
369 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
370 if( !EQUIV(session->frame_rate, bd_formats[i].framerate) ) continue;
371 if( session->output_w != bd_formats[i].w ) continue;
372 if( session->output_h != bd_formats[i].h ) continue;
373 has_standard = i; break;
376 use_standard = has_standard >= 0 ? has_standard : BD_1920x1080_2400p;
379 int scr_x = mwindow->gui->get_screen_x(0, -1);
380 int scr_w = mwindow->gui->get_screen_w(0, -1);
381 int scr_h = mwindow->gui->get_screen_h(0, -1);
382 int w = 500, h = 280;
383 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
385 gui = new CreateBD_GUI(this, x, y, w, h);
386 gui->create_objects();
391 CreateBD_OK::CreateBD_OK(CreateBD_GUI *gui, int x, int y)
395 set_tooltip(_("end setup, start batch render"));
398 CreateBD_OK::~CreateBD_OK()
402 int CreateBD_OK::button_press_event()
404 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
411 int CreateBD_OK::keypress_event()
417 CreateBD_Cancel::CreateBD_Cancel(CreateBD_GUI *gui, int x, int y)
418 : BC_CancelButton(x, y)
423 CreateBD_Cancel::~CreateBD_Cancel()
427 int CreateBD_Cancel::button_press_event()
429 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
437 CreateBD_DiskSpace::CreateBD_DiskSpace(CreateBD_GUI *gui, int x, int y)
438 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
443 CreateBD_DiskSpace::~CreateBD_DiskSpace()
447 int64_t CreateBD_DiskSpace::tmp_path_space()
449 const char *path = gui->tmp_path->get_text();
450 if( access(path,R_OK+W_OK) ) return 0;
452 if( statfs(path, &sfs) ) return 0;
453 return (int64_t)sfs.f_bsize * sfs.f_bfree;
456 void CreateBD_DiskSpace::update()
458 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
459 int64_t disk_space = tmp_path_space();
460 double media_size = 100e9, msz = 0, m = 1;
462 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
463 int i = sizeof(suffix)/sizeof(suffix[0]);
464 while( --i >= 0 && strcmp(sfx, suffix[i]) );
465 while( --i >= 0 ) m *= 1000;
466 media_size = msz * m;
468 int color = disk_space < media_size*2 ? RED : GREEN;
470 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
471 char text[BCTEXTLEN];
472 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
473 gui->disk_space->BC_Title::update(text);
474 gui->disk_space->set_color(color);
477 CreateBD_TmpPath::CreateBD_TmpPath(CreateBD_GUI *gui, int x, int y, int w)
478 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
479 gui->thread->tmp_path, 1, MEDIUMFONT)
484 CreateBD_TmpPath::~CreateBD_TmpPath()
488 int CreateBD_TmpPath::handle_event()
490 gui->disk_space->update();
495 CreateBD_AssetTitle::CreateBD_AssetTitle(CreateBD_GUI *gui, int x, int y, int w)
496 : BC_TextBox(x, y, w, 1, 0, gui->thread->asset_title, 1, MEDIUMFONT)
501 CreateBD_AssetTitle::~CreateBD_AssetTitle()
506 CreateBD_Deinterlace::CreateBD_Deinterlace(CreateBD_GUI *gui, int x, int y)
507 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
512 CreateBD_Deinterlace::~CreateBD_Deinterlace()
516 int CreateBD_Deinterlace::handle_event()
519 gui->need_inverse_telecine->set_value(0);
520 gui->thread->use_inverse_telecine = 0;
522 return BC_CheckBox::handle_event();
526 CreateBD_InverseTelecine::CreateBD_InverseTelecine(CreateBD_GUI *gui, int x, int y)
527 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
532 CreateBD_InverseTelecine::~CreateBD_InverseTelecine()
536 int CreateBD_InverseTelecine::handle_event()
539 gui->need_deinterlace->set_value(0);
540 gui->thread->use_deinterlace = 0;
542 return BC_CheckBox::handle_event();
546 CreateBD_Scale::CreateBD_Scale(CreateBD_GUI *gui, int x, int y)
547 : BC_CheckBox(x, y, &gui->thread->use_scale, _("Scale"))
552 CreateBD_Scale::~CreateBD_Scale()
557 CreateBD_ResizeTracks::CreateBD_ResizeTracks(CreateBD_GUI *gui, int x, int y)
558 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
563 CreateBD_ResizeTracks::~CreateBD_ResizeTracks()
568 CreateBD_Histogram::CreateBD_Histogram(CreateBD_GUI *gui, int x, int y)
569 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
574 CreateBD_Histogram::~CreateBD_Histogram()
578 CreateBD_LabelChapters::CreateBD_LabelChapters(CreateBD_GUI *gui, int x, int y)
579 : BC_CheckBox(x, y, &gui->thread->use_label_chapters, _("Chapters at Labels"))
584 CreateBD_LabelChapters::~CreateBD_LabelChapters()
588 CreateBD_WideAudio::CreateBD_WideAudio(CreateBD_GUI *gui, int x, int y)
589 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
594 CreateBD_WideAudio::~CreateBD_WideAudio()
598 CreateBD_WideAspect::CreateBD_WideAspect(CreateBD_GUI *gui, int x, int y)
599 : BC_CheckBox(x, y, &gui->thread->use_wide_aspect, _("Aspect 16x9"))
604 CreateBD_WideAspect::~CreateBD_WideAspect()
610 CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
611 : BC_Window(_(PROGRAM_NAME ": Create BD"), x, y, w, h, 50, 50, 1, 0, 1)
613 this->thread = thread;
614 at_x = at_y = tmp_x = tmp_y = 0;
615 ok_x = ok_y = ok_w = ok_h = 0;
616 cancel_x = cancel_y = cancel_w = cancel_h = 0;
620 need_deinterlace = 0;
621 need_inverse_telecine = 0;
623 need_resize_tracks = 0;
626 need_wide_aspect = 0;
627 need_label_chapters = 0;
632 CreateBD_GUI::~CreateBD_GUI()
636 void CreateBD_GUI::create_objects()
638 lock_window("CreateBD_GUI::create_objects");
639 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + 5;
640 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
641 int x = padx/2, y = pady/2;
642 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
643 add_subwindow(title);
644 at_x = x + title->get_w(); at_y = y;
645 asset_title = new CreateBD_AssetTitle(this, at_x, at_y, get_w()-at_x-10);
646 add_subwindow(asset_title);
647 y += title->get_h() + pady/2;
648 title = new BC_Title(x, y, _("tmp path:"), MEDIUMFONT, YELLOW);
649 add_subwindow(title);
650 tmp_x = x + title->get_w(); tmp_y = y;
651 tmp_path = new CreateBD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-10);
652 add_subwindow(tmp_path);
653 y += title->get_h() + pady/2;
654 disk_space = new CreateBD_DiskSpace(this, x, y);
655 add_subwindow(disk_space);
656 int x0 = get_w() - 170;
657 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
658 add_subwindow(title);
659 x0 += title->get_w() + padx;
660 media_size = new CreateBD_MediaSize(this, x0, y);
661 media_size->create_objects();
662 media_sizes.append(new BC_ListBoxItem("25GB"));
663 media_sizes.append(new BC_ListBoxItem("50GB"));
664 media_size->update_list(&media_sizes);
665 media_size->update(media_sizes[0]->get_text());
666 disk_space->update();
668 y += disk_space->get_h() + pady/2;
669 title = new BC_Title(x0, y, _("Format:"), MEDIUMFONT, YELLOW);
670 add_subwindow(title);
671 x0 += title->get_w() + padx;
672 standard = new CreateBD_Format(this, x0, y);
673 add_subwindow(standard);
674 standard->create_objects();
675 y += standard->get_h() + pady/2;
676 need_deinterlace = new CreateBD_Deinterlace(this, x, y);
677 add_subwindow(need_deinterlace);
678 int x1 = x + 150, x2 = x1 + 150;
679 need_inverse_telecine = new CreateBD_InverseTelecine(this, x1, y);
680 add_subwindow(need_inverse_telecine);
681 y += need_deinterlace->get_h() + pady/2;
682 need_scale = new CreateBD_Scale(this, x, y);
683 add_subwindow(need_scale);
684 need_wide_audio = new CreateBD_WideAudio(this, x1, y);
685 add_subwindow(need_wide_audio);
686 need_resize_tracks = new CreateBD_ResizeTracks(this, x2, y);
687 add_subwindow(need_resize_tracks);
688 y += need_scale->get_h() + pady/2;
689 need_histogram = new CreateBD_Histogram(this, x, y);
690 add_subwindow(need_histogram);
691 need_wide_aspect = new CreateBD_WideAspect(this, x1, y);
692 add_subwindow(need_wide_aspect);
693 // need_label_chapters = new CreateBD_LabelChapters(this, x2, y);
694 // add_subwindow(need_label_chapters);
695 ok_w = BC_OKButton::calculate_w();
696 ok_h = BC_OKButton::calculate_h();
698 ok_y = get_h() - ok_h - 10;
699 ok = new CreateBD_OK(this, ok_x, ok_y);
701 cancel_w = BC_CancelButton::calculate_w();
702 cancel_h = BC_CancelButton::calculate_h();
703 cancel_x = get_w() - cancel_w - 10,
704 cancel_y = get_h() - cancel_h - 10;
705 cancel = new CreateBD_Cancel(this, cancel_x, cancel_y);
706 add_subwindow(cancel);
711 int CreateBD_GUI::resize_event(int w, int h)
713 asset_title->reposition_window(at_x, at_y, get_w()-at_x-10);
714 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-10);
715 ok_y = h - ok_h - 10;
716 ok->reposition_window(ok_x, ok_y);
717 cancel_x = w - cancel_w - 10,
718 cancel_y = h - cancel_h - 10;
719 cancel->reposition_window(cancel_x, cancel_y);
723 int CreateBD_GUI::translation_event()
728 int CreateBD_GUI::close_event()
734 void CreateBD_GUI::update()
736 need_deinterlace->set_value(thread->use_deinterlace);
737 need_inverse_telecine->set_value(thread->use_inverse_telecine);
738 need_scale->set_value(thread->use_scale);
739 need_resize_tracks->set_value(thread->use_resize_tracks);
740 need_histogram->set_value(thread->use_histogram);
741 need_wide_audio->set_value(thread->use_wide_audio);
742 need_wide_aspect->set_value(thread->use_wide_aspect);
743 // need_label_chapters->set_value(thread->use_label_chapters);
746 int CreateBD_Thread::
747 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
749 Tracks *tracks = mwindow->edl->tracks;
750 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
751 if( vtrk->data_type != TRACK_VIDEO ) continue;
752 if( !vtrk->record ) continue;
753 vtrk->expand_view = 1;
754 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
755 vtrk->plugin_set.append(plugin_set);
756 Edits *edits = vtrk->edits;
757 for( Edit *edit=edits->first; edit; edit=edit->next ) {
758 plugin_set->insert_plugin(_(title),
759 edit->startproject, edit->length,
760 PLUGIN_STANDALONE, 0, default_keyframe, 0);
767 int CreateBD_Thread::
770 Tracks *tracks = mwindow->edl->tracks;
771 int trk_w = max_w, trk_h = max_h;
772 if( trk_w < bd_width ) trk_w = bd_width;
773 if( trk_h < bd_height ) trk_h = bd_height;
774 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
775 if( vtrk->data_type != TRACK_VIDEO ) continue;
776 if( !vtrk->record ) continue;
777 vtrk->track_w = trk_w;
778 vtrk->track_h = trk_h;
783 int CreateBD_Thread::
786 // reset only probed options
789 use_resize_tracks = 0;
792 use_label_chapters = 0;
794 if( !mwindow->edl ) return 1;
796 bd_width = bd_formats[use_standard].w;
797 bd_height = bd_formats[use_standard].h;
798 bd_framerate = bd_formats[use_standard].framerate;
800 Tracks *tracks = mwindow->edl->tracks;
801 max_w = 0; max_h = 0;
802 int has_deinterlace = 0, has_scale = 0;
803 for( Track *trk=tracks->first; trk; trk=trk->next ) {
804 if( !trk->record ) continue;
805 Edits *edits = trk->edits;
806 switch( trk->data_type ) {
808 for( Edit *edit=edits->first; edit; edit=edit->next ) {
809 if( edit->silence() ) continue;
810 Indexable *indexable = edit->get_source();
811 int w = indexable->get_w();
812 if( w > max_w ) max_w = w;
813 if( w != bd_width ) use_scale = 1;
814 int h = indexable->get_h();
815 if( h > max_h ) max_h = h;
816 if( h != bd_height ) use_scale = 1;
818 for( int i=0; i<trk->plugin_set.size(); ++i ) {
819 for(Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
821 plugin = (Plugin*)plugin->next) {
822 if( !strcmp(plugin->title, _("Deinterlace")) )
824 if( !strcmp(plugin->title, _("Auto Scale")) ||
825 !strcmp(plugin->title, _("Scale")) )
835 if( max_w != bd_width ) use_resize_tracks = 1;
836 if( max_h != bd_height ) use_resize_tracks = 1;
838 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
839 if( !trk->record ) continue;
840 switch( trk->data_type ) {
842 if( trk->track_w != max_w ) use_resize_tracks = 1;
843 if( trk->track_h != max_h ) use_resize_tracks = 1;
847 if( !has_deinterlace && max_h > 2*bd_height ) use_deinterlace = 1;
848 // Labels *labels = mwindow->edl->labels;
849 // use_label_chapters = labels && labels->first ? 1 : 0;
851 MWindow::create_aspect_ratio(aw, ah, max_w, max_h);
852 if( aw == BD_WIDE_ASPECT_WIDTH && ah == BD_WIDE_ASPECT_HEIGHT )
854 bd_aspect_width = use_wide_aspect ? BD_WIDE_ASPECT_WIDTH : BD_ASPECT_WIDTH;
855 bd_aspect_height = use_wide_aspect ? BD_WIDE_ASPECT_HEIGHT : BD_ASPECT_HEIGHT;
857 if( tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
864 CreateBD_FormatItem::CreateBD_FormatItem(CreateBD_Format *popup,
865 int standard, const char *name)
869 this->standard = standard;
872 CreateBD_FormatItem::~CreateBD_FormatItem()
876 int CreateBD_FormatItem::handle_event()
878 popup->set_text(get_text());
879 popup->gui->thread->use_standard = standard;
880 return popup->handle_event();
884 CreateBD_Format::CreateBD_Format(CreateBD_GUI *gui, int x, int y)
885 : BC_PopupMenu(x, y, 180, bd_formats[gui->thread->use_standard].name, 1)
890 CreateBD_Format::~CreateBD_Format()
894 void CreateBD_Format::create_objects()
896 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
897 add_item(new CreateBD_FormatItem(this, i, bd_formats[i].name));
901 int CreateBD_Format::handle_event()
903 gui->thread->option_presets();
908 CreateBD_MediaSize::CreateBD_MediaSize(CreateBD_GUI *gui, int x, int y)
909 : BC_PopupTextBox(gui, 0, 0, x, y, 70,50)
914 CreateBD_MediaSize::~CreateBD_MediaSize()
918 int CreateBD_MediaSize::handle_event()
920 gui->disk_space->update();