8 #include "edlsession.h"
13 #include "mainerror.h"
16 #include "mwindowgui.h"
18 #include "pluginset.h"
27 #include <sys/statfs.h>
31 #define DVD_PAL_16x9 1
32 #define DVD_NTSC_4x3 2
33 #define DVD_NTSC_16x9 3
35 #define DVD_NORM_PAL 0
36 #define DVD_NORM_NTSC 1
38 #define DVD_ASPECT_4x3 0
39 #define DVD_ASPECT_16x9 1
41 static struct dvd_norm {
46 { "PAL", 720,576, 25 },
47 { "NTSC", 720,480, 29.97 },
50 static struct dvd_aspect {
59 static struct dvd_format {
62 { DVD_NORM_PAL, DVD_ASPECT_4x3, },
63 { DVD_NORM_PAL, DVD_ASPECT_16x9, },
64 { DVD_NORM_NTSC, DVD_ASPECT_4x3, },
65 { DVD_NORM_NTSC, DVD_ASPECT_16x9, },
68 const int64_t CreateDVD_Thread::DVD_SIZE = 4700000000;
69 const int CreateDVD_Thread::DVD_STREAMS = 1;
70 const int CreateDVD_Thread::DVD_WIDTH = 720;
71 const int CreateDVD_Thread::DVD_HEIGHT = 480;
72 const double CreateDVD_Thread::DVD_ASPECT_WIDTH = 4.;
73 const double CreateDVD_Thread::DVD_ASPECT_HEIGHT = 3.;
74 const double CreateDVD_Thread::DVD_WIDE_ASPECT_WIDTH = 16.;
75 const double CreateDVD_Thread::DVD_WIDE_ASPECT_HEIGHT = 9.;
76 const double CreateDVD_Thread::DVD_FRAMERATE = 30000. / 1001.;
77 const int CreateDVD_Thread::DVD_MAX_BITRATE = 8000000;
78 const int CreateDVD_Thread::DVD_CHANNELS = 2;
79 const int CreateDVD_Thread::DVD_WIDE_CHANNELS = 6;
80 const double CreateDVD_Thread::DVD_SAMPLERATE = 48000;
81 const double CreateDVD_Thread::DVD_KAUDIO_RATE = 224;
84 CreateDVD_MenuItem::CreateDVD_MenuItem(MWindow *mwindow)
85 : BC_MenuItem(_("DVD Render..."), _("Shift-D"), 'D')
88 this->mwindow = mwindow;
91 int CreateDVD_MenuItem::handle_event()
93 mwindow->create_dvd->start();
98 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
101 this->mwindow = mwindow;
103 this->use_deinterlace = 0;
105 this->use_histogram = 0;
106 this->use_inverse_telecine = 0;
107 this->use_wide_audio = 0;
108 this->use_ffmpeg = 0;
109 this->use_resize_tracks = 0;
110 this->use_label_chapters = 0;
112 this->dvd_size = DVD_SIZE;
113 this->dvd_width = DVD_WIDTH;
114 this->dvd_height = DVD_HEIGHT;
115 this->dvd_aspect_width = DVD_ASPECT_WIDTH;
116 this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
117 this->dvd_framerate = DVD_FRAMERATE;
118 this->dvd_samplerate = DVD_SAMPLERATE;
119 this->dvd_max_bitrate = DVD_MAX_BITRATE;
120 this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
121 this->max_w = this->max_h = 0;
124 CreateDVD_Thread::~CreateDVD_Thread()
129 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
131 EDL *edl = mwindow->edl;
132 if( !edl || !edl->session ) {
134 sprintf(msg, _("No EDL/Session"));
135 MainError::show_error(msg);
138 EDLSession *session = edl->session;
140 double total_length = edl->tracks->total_length();
141 if( total_length <= 0 ) {
143 sprintf(msg, _("No content: %s"), asset_title);
144 MainError::show_error(msg);
148 if( mkdir(asset_dir, 0777) ) {
149 char err[BCTEXTLEN], msg[BCTEXTLEN];
150 strerror_r(errno, err, sizeof(err));
151 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
152 MainError::show_error(msg);
156 double old_samplerate = session->sample_rate;
157 double old_framerate = session->frame_rate;
159 session->video_channels = DVD_STREAMS;
160 session->video_tracks = DVD_STREAMS;
161 session->frame_rate = dvd_framerate;
162 session->output_w = dvd_width;
163 session->output_h = dvd_height;
164 session->aspect_w = dvd_aspect_width;
165 session->aspect_h = dvd_aspect_height;
166 session->sample_rate = dvd_samplerate;
167 session->audio_channels = session->audio_tracks =
168 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
170 char script_filename[BCTEXTLEN];
171 sprintf(script_filename, "%s/dvd.sh", asset_dir);
172 int fd = open(script_filename, O_WRONLY+O_CREAT+O_TRUNC, 0755);
173 FILE *fp = fdopen(fd, "w");
175 char err[BCTEXTLEN], msg[BCTEXTLEN];
176 strerror_r(errno, err, sizeof(err));
177 sprintf(msg, _("Unable to save: %s\n-- %s"), script_filename, err);
178 MainError::show_error(msg);
181 fprintf(fp,"#!/bin/bash\n");
182 fprintf(fp,"echo \"running %s\" $# $*\n", script_filename);
184 const char *exec_path = File::get_cinlib_path();
185 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
187 fprintf(fp,"mplex -f 8 -o $1/dvd.mpg $1/dvd.m2v $1/dvd.ac3\n");
190 fprintf(fp,"rm -rf $1/iso\n");
191 fprintf(fp,"mkdir -p $1/iso\n");
193 // dvdauthor ver 0.7.0 requires this to work
194 int norm = dvd_formats[use_standard].norm;
195 const char *name = dvd_norms[norm].name;
196 fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
197 fprintf(fp,"dvdauthor -x - <<eof\n");
198 fprintf(fp,"<dvdauthor dest=\"$1/iso\">\n");
199 fprintf(fp," <vmgm>\n");
200 fprintf(fp," <fpc> jump title 1; </fpc>\n");
201 fprintf(fp," </vmgm>\n");
202 fprintf(fp," <titleset>\n");
203 fprintf(fp," <titles>\n");
204 char std[BCSTRLEN], *cp = std;
205 for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
207 fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
208 std, (int)session->aspect_w, (int)session->aspect_h,
209 session->output_w, session->output_h);
210 fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
211 fprintf(fp," <pgc>\n");
212 fprintf(fp," <vob file=\"$1/dvd.mpg\" chapters=\"");
213 if( use_label_chapters && edl->labels ) {
214 Label *label = edl->labels->first;
216 int secs = label->position;
217 int mins = secs / 60;
218 int frms = (label->position-secs) * session->frame_rate;
219 fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
220 if( (label=label->next) != 0 ) fprintf(fp, ",");
225 for( int secs=0 ; secs<total_length; secs+=10*60 ) {
227 fprintf(fp,"%d:%02d:00,", mins/60, mins%60);
229 fprintf(fp,"%d:%02d:00", mins/60, mins%60);
231 fprintf(fp,"\"/>\n");
232 fprintf(fp," </pgc>\n");
233 fprintf(fp," </titles>\n");
234 fprintf(fp," </titleset>\n");
235 fprintf(fp,"</dvdauthor>\n");
238 fprintf(fp,"echo To burn dvd, load blank media and run:\n");
239 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $1/iso\n");
240 fprintf(fp,"kill $$\n");
244 if( use_wide_audio ) {
245 session->audio_channels = session->audio_tracks = DVD_WIDE_CHANNELS;
246 session->achannel_positions[0] = 90;
247 session->achannel_positions[1] = 150;
248 session->achannel_positions[2] = 30;
249 session->achannel_positions[3] = 210;
250 session->achannel_positions[4] = 330;
251 session->achannel_positions[5] = 270;
252 if( edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
253 mwindow->remap_audio(MWindow::AUDIO_1_TO_1);
256 session->audio_channels = session->audio_tracks = DVD_CHANNELS;
257 session->achannel_positions[0] = 180;
258 session->achannel_positions[1] = 0;
259 if( edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
260 mwindow->remap_audio(MWindow::AUDIO_5_1_TO_2);
263 double new_samplerate = session->sample_rate;
264 double new_framerate = session->frame_rate;
266 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
267 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
269 int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
270 int64_t vid_size = dvd_size*0.96 - aud_size;
271 int64_t vid_bitrate = (vid_size * 8) / total_length;
272 vid_bitrate /= 1000; vid_bitrate *= 1000;
273 if( vid_bitrate > dvd_max_bitrate )
274 vid_bitrate = dvd_max_bitrate;
276 char xml_filename[BCTEXTLEN];
277 sprintf(xml_filename, "%s/dvd.xml", asset_dir);
279 edl->save_xml(&xml_file, xml_filename, 0, 0);
280 xml_file.terminate_string();
281 if( xml_file.write_to_file(xml_filename) ) {
283 sprintf(msg, _("Unable to save: %s"), xml_filename);
284 MainError::show_error(msg);
288 BatchRenderJob *job = new BatchRenderJob(mwindow->preferences);
290 strcpy(&job->edl_path[0], xml_filename);
291 Asset *asset = job->asset;
293 asset->layers = DVD_STREAMS;
294 asset->frame_rate = session->frame_rate;
295 asset->width = session->output_w;
296 asset->height = session->output_h;
297 asset->aspect_ratio = session->aspect_w / session->aspect_h;
300 char option_path[BCTEXTLEN];
301 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
302 asset->format = FILE_FFMPEG;
303 strcpy(asset->fformat, "dvd");
305 asset->audio_data = 1;
306 strcpy(asset->acodec, "dvd.dvd");
307 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
308 FFMPEG::load_options(option_path, asset->ff_audio_options,
309 sizeof(asset->ff_audio_options));
310 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
312 asset->video_data = 1;
313 strcpy(asset->vcodec, "dvd.dvd");
314 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
315 FFMPEG::load_options(option_path, asset->ff_video_options,
316 sizeof(asset->ff_video_options));
317 asset->ff_video_bitrate = vid_bitrate;
318 asset->ff_video_quality = -1;
321 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
322 asset->video_data = 1;
323 asset->format = FILE_VMPEG;
324 asset->vmpeg_cmodel = BC_YUV420P;
325 asset->vmpeg_fix_bitrate = 1;
326 asset->vmpeg_bitrate = vid_bitrate;
327 asset->vmpeg_quantization = 15;
328 asset->vmpeg_iframe_distance = 15;
329 asset->vmpeg_progressive = 0;
330 asset->vmpeg_denoise = 0;
331 asset->vmpeg_seq_codes = 0;
332 asset->vmpeg_derivative = 2;
333 asset->vmpeg_preset = 8;
334 asset->vmpeg_field_order = 0;
335 asset->vmpeg_pframe_distance = 0;
336 job = new BatchRenderJob(mwindow->preferences);
338 strcpy(&job->edl_path[0], xml_filename);
341 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
342 asset->audio_data = 1;
343 asset->format = FILE_AC3;
344 asset->channels = session->audio_channels;
345 asset->sample_rate = session->sample_rate;
347 asset->byte_order = 0;
351 asset->ac3_bitrate = dvd_kaudio_rate;
354 job = new BatchRenderJob(mwindow->preferences);
356 job->edl_path[0] = '@';
357 strcpy(&job->edl_path[1], script_filename);
358 strcpy(&job->asset->path[0], asset_dir);
363 void CreateDVD_Thread::handle_close_event(int result)
366 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
367 mwindow->batch_render->load_defaults(mwindow->defaults);
368 mwindow->undo->update_undo_before();
369 KeyFrame keyframe; char data[BCTEXTLEN];
370 if( use_deinterlace ) {
371 sprintf(data,"<DEINTERLACE MODE=1>");
372 keyframe.set_data(data);
373 insert_video_plugin("Deinterlace", &keyframe);
375 if( use_inverse_telecine ) {
376 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
377 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
378 keyframe.set_data(data);
379 insert_video_plugin("Inverse Telecine", &keyframe);
381 if( use_scale != Rescale::none ) {
382 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
384 Tracks *tracks = mwindow->edl->tracks;
385 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
386 if( vtrk->data_type != TRACK_VIDEO ) continue;
387 if( !vtrk->record ) continue;
388 vtrk->expand_view = 1;
389 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
390 vtrk->plugin_set.append(plugin_set);
391 Edits *edits = vtrk->edits;
392 for( Edit *edit=edits->first; edit; edit=edit->next ) {
393 Indexable *indexable = edit->get_source();
394 if( !indexable ) continue;
395 Rescale in(indexable);
396 Rescale out(dvd_width, dvd_height, dvd_aspect);
397 float src_w, src_h, dst_w, dst_h;
398 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
399 sprintf(data,"<SCALERATIO TYPE=%d"
400 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
401 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
402 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
403 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
404 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
405 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
406 keyframe.set_data(data);
407 plugin_set->insert_plugin(_("Scale Ratio"),
408 edit->startproject, edit->length,
409 PLUGIN_STANDALONE, 0, &keyframe, 0);
415 if( use_resize_tracks )
417 if( use_histogram ) {
419 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
420 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
421 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
422 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
423 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
424 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
425 "<POINTS><POINT X=6.0e-02 Y=0>"
426 "<POINT X=9.4e-01 Y=1></POINTS>");
428 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
429 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
430 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
431 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
432 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
433 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
436 keyframe.set_data(data);
437 insert_video_plugin("Histogram", &keyframe);
439 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
440 sprintf(asset_dir, "%s/%s", tmp_path, asset_title);
441 sprintf(jobs_path, "%s/dvd.jobs", asset_dir);
442 mwindow->batch_render->reset(jobs_path);
443 int ret = create_dvd_jobs(&mwindow->batch_render->jobs, asset_dir);
444 mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
445 mwindow->resync_guis();
447 mwindow->batch_render->save_jobs();
448 mwindow->batch_render->start();
451 BC_Window* CreateDVD_Thread::new_gui()
453 strcpy(tmp_path,"/tmp");
454 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
455 memset(asset_title,0,sizeof(asset_title));
456 time_t dt; time(&dt);
457 struct tm dtm; localtime_r(&dt, &dtm);
458 sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
459 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
460 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
462 use_scale = Rescale::none;
464 use_inverse_telecine = 0;
467 use_resize_tracks = 0;
468 use_label_chapters = 0;
469 use_standard = DVD_NTSC_4x3;
472 dvd_width = DVD_WIDTH;
473 dvd_height = DVD_HEIGHT;
474 dvd_aspect_width = DVD_ASPECT_WIDTH;
475 dvd_aspect_height = DVD_ASPECT_HEIGHT;
476 dvd_framerate = DVD_FRAMERATE;
477 dvd_samplerate = DVD_SAMPLERATE;
478 dvd_max_bitrate = DVD_MAX_BITRATE;
479 dvd_kaudio_rate = DVD_KAUDIO_RATE;
480 max_w = 0; max_h = 0;
482 int has_standard = -1;
484 EDLSession *session = mwindow->edl->session;
485 double framerate = session->frame_rate;
486 double aspect_ratio = session->aspect_h > 0 ?
487 session->aspect_w / session->aspect_h > 0 : 1;
488 int output_w = session->output_w, output_h = session->output_h;
489 // match the session to any known standard
490 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
491 int norm = dvd_formats[i].norm;
492 if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
493 if( output_w != dvd_norms[norm].w ) continue;
494 if( output_h != dvd_norms[norm].h ) continue;
495 int aspect = dvd_formats[i].aspect;
496 double dvd_aspect_ratio =
497 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
498 if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
499 has_standard = i; break;
501 if( has_standard < 0 ) {
502 // or use the default standard
503 if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
504 else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
507 if( has_standard >= 0 )
508 use_standard = has_standard;
511 int scr_x = mwindow->gui->get_screen_x(0, -1);
512 int scr_w = mwindow->gui->get_screen_w(0, -1);
513 int scr_h = mwindow->gui->get_screen_h(0, -1);
514 int w = 520, h = 280;
515 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
517 gui = new CreateDVD_GUI(this, x, y, w, h);
518 gui->create_objects();
523 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
527 set_tooltip(_("end setup, start batch render"));
530 CreateDVD_OK::~CreateDVD_OK()
534 int CreateDVD_OK::button_press_event()
536 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
543 int CreateDVD_OK::keypress_event()
549 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
550 : BC_CancelButton(x, y)
555 CreateDVD_Cancel::~CreateDVD_Cancel()
559 int CreateDVD_Cancel::button_press_event()
561 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
569 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
570 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
575 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
579 int64_t CreateDVD_DiskSpace::tmp_path_space()
581 const char *path = gui->thread->tmp_path;
582 if( access(path,R_OK+W_OK) ) return 0;
584 if( statfs(path, &sfs) ) return 0;
585 return (int64_t)sfs.f_bsize * sfs.f_bfree;
588 void CreateDVD_DiskSpace::update()
590 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
591 int64_t disk_space = tmp_path_space();
592 double media_size = 15e9, msz = 0, m = 1;
594 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
595 int i = sizeof(suffix)/sizeof(suffix[0]);
596 while( --i >= 0 && strcmp(sfx, suffix[i]) );
597 while( --i >= 0 ) m *= 1000;
598 media_size = msz * m;
600 m = gui->thread->use_ffmpeg ? 2 : 3;
601 int color = disk_space < media_size*m ? RED : GREEN;
603 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
604 char text[BCTEXTLEN];
605 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
606 gui->disk_space->BC_Title::update(text);
607 gui->disk_space->set_color(color);
610 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
611 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
612 gui->thread->tmp_path, 1, MEDIUMFONT)
617 CreateDVD_TmpPath::~CreateDVD_TmpPath()
621 int CreateDVD_TmpPath::handle_event()
624 gui->disk_space->update();
629 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
630 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
631 gui->thread->asset_title, 1, MEDIUMFONT)
636 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
640 int CreateDVD_AssetTitle::handle_event()
647 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
648 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
653 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
657 int CreateDVD_Deinterlace::handle_event()
660 gui->need_inverse_telecine->set_value(0);
661 gui->thread->use_inverse_telecine = 0;
663 return BC_CheckBox::handle_event();
667 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
668 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
673 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
677 int CreateDVD_InverseTelecine::handle_event()
680 gui->need_deinterlace->set_value(0);
681 gui->thread->use_deinterlace = 0;
683 return BC_CheckBox::handle_event();
687 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
688 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
693 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
698 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
699 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
704 CreateDVD_Histogram::~CreateDVD_Histogram()
708 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
709 : BC_CheckBox(x, y, &gui->thread->use_label_chapters, _("Chapters at Labels"))
714 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
718 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
719 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
724 CreateDVD_WideAudio::~CreateDVD_WideAudio()
728 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
729 : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
734 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
741 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
742 : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, 50, 50, 1, 0, 1)
744 this->thread = thread;
745 at_x = at_y = tmp_x = tmp_y = 0;
746 ok_x = ok_y = ok_w = ok_h = 0;
747 cancel_x = cancel_y = cancel_w = cancel_h = 0;
754 need_deinterlace = 0;
755 need_inverse_telecine = 0;
756 need_resize_tracks = 0;
759 need_label_chapters = 0;
764 CreateDVD_GUI::~CreateDVD_GUI()
768 void CreateDVD_GUI::create_objects()
770 lock_window("CreateDVD_GUI::create_objects");
771 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + 5;
772 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
773 int x = padx/2, y = pady/2;
774 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
775 add_subwindow(title);
776 at_x = x + title->get_w(); at_y = y;
777 asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-10);
778 add_subwindow(asset_title);
779 y += title->get_h() + pady/2;
780 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
781 add_subwindow(title);
782 tmp_x = x + title->get_w(); tmp_y = y;
783 tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-35);
784 add_subwindow(tmp_path);
785 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
786 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
787 _("Work path"), _("Select a Work directory:"), 1);
788 add_subwindow(btmp_path);
789 y += title->get_h() + pady/2;
790 disk_space = new CreateDVD_DiskSpace(this, x, y);
791 add_subwindow(disk_space);
792 int x0 = get_w() - 170;
793 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
794 add_subwindow(title);
795 int x1 = x0+title->get_w()+padx;
796 media_size = new CreateDVD_MediaSize(this, x1, y);
797 media_size->create_objects();
798 media_sizes.append(new BC_ListBoxItem("4.7GB"));
799 media_sizes.append(new BC_ListBoxItem("8.3GB"));
800 media_size->update_list(&media_sizes);
801 media_size->update(media_sizes[0]->get_text());
802 disk_space->update();
803 y += disk_space->get_h() + pady/2;
804 title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
805 add_subwindow(title);
806 standard = new CreateDVD_Format(this, title->get_w() + padx, y);
807 add_subwindow(standard);
808 standard->create_objects();
810 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
811 add_subwindow(title);
812 x1 = x0+title->get_w()+padx;
813 scale = new CreateDVD_Scale(this, x1, y);
814 add_subwindow(scale);
815 scale->create_objects();
816 y += standard->get_h() + pady/2;
817 need_deinterlace = new CreateDVD_Deinterlace(this, x, y);
818 add_subwindow(need_deinterlace);
821 need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
822 add_subwindow(need_inverse_telecine);
823 need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x2, y);
824 add_subwindow(need_use_ffmpeg);
825 y += need_deinterlace->get_h() + pady/2;
826 need_histogram = new CreateDVD_Histogram(this, x, y);
827 add_subwindow(need_histogram);
828 need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
829 add_subwindow(need_wide_audio);
830 need_resize_tracks = new CreateDVD_ResizeTracks(this, x2, y);
831 add_subwindow(need_resize_tracks);
832 y += need_histogram->get_h() + pady/2;
833 need_label_chapters = new CreateDVD_LabelChapters(this, x1, y);
834 add_subwindow(need_label_chapters);
835 ok_w = BC_OKButton::calculate_w();
836 ok_h = BC_OKButton::calculate_h();
838 ok_y = get_h() - ok_h - 10;
839 ok = new CreateDVD_OK(this, ok_x, ok_y);
841 cancel_w = BC_CancelButton::calculate_w();
842 cancel_h = BC_CancelButton::calculate_h();
843 cancel_x = get_w() - cancel_w - 10,
844 cancel_y = get_h() - cancel_h - 10;
845 cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
846 add_subwindow(cancel);
851 int CreateDVD_GUI::resize_event(int w, int h)
853 asset_title->reposition_window(at_x, at_y, get_w()-at_x-10);
854 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-35);
855 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
856 ok_y = h - ok_h - 10;
857 ok->reposition_window(ok_x, ok_y);
858 cancel_x = w - cancel_w - 10,
859 cancel_y = h - cancel_h - 10;
860 cancel->reposition_window(cancel_x, cancel_y);
864 int CreateDVD_GUI::translation_event()
869 int CreateDVD_GUI::close_event()
875 void CreateDVD_GUI::update()
877 scale->set_value(thread->use_scale);
878 need_deinterlace->set_value(thread->use_deinterlace);
879 need_inverse_telecine->set_value(thread->use_inverse_telecine);
880 need_use_ffmpeg->set_value(thread->use_ffmpeg);
881 need_resize_tracks->set_value(thread->use_resize_tracks);
882 need_histogram->set_value(thread->use_histogram);
883 need_wide_audio->set_value(thread->use_wide_audio);
884 need_label_chapters->set_value(thread->use_label_chapters);
887 int CreateDVD_Thread::
888 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
890 Tracks *tracks = mwindow->edl->tracks;
891 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
892 if( vtrk->data_type != TRACK_VIDEO ) continue;
893 if( !vtrk->record ) continue;
894 vtrk->expand_view = 1;
895 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
896 vtrk->plugin_set.append(plugin_set);
897 Edits *edits = vtrk->edits;
898 for( Edit *edit=edits->first; edit; edit=edit->next ) {
899 plugin_set->insert_plugin(_(title),
900 edit->startproject, edit->length,
901 PLUGIN_STANDALONE, 0, default_keyframe, 0);
908 int CreateDVD_Thread::
911 Tracks *tracks = mwindow->edl->tracks;
912 int trk_w = max_w, trk_h = max_h;
913 if( trk_w < dvd_width ) trk_w = dvd_width;
914 if( trk_h < dvd_height ) trk_h = dvd_height;
915 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
916 if( vtrk->data_type != TRACK_VIDEO ) continue;
917 if( !vtrk->record ) continue;
918 vtrk->track_w = trk_w;
919 vtrk->track_h = trk_h;
924 int CreateDVD_Thread::
927 // reset only probed options
929 use_scale = Rescale::none;
930 use_resize_tracks = 0;
932 use_label_chapters = 0;
934 if( !mwindow->edl ) return 1;
936 int norm = dvd_formats[use_standard].norm;
937 dvd_width = dvd_norms[norm].w;
938 dvd_height = dvd_norms[norm].h;
939 dvd_framerate = dvd_norms[norm].framerate;
940 int aspect = dvd_formats[use_standard].aspect;
941 dvd_aspect_width = dvd_aspects[aspect].w;
942 dvd_aspect_height = dvd_aspects[aspect].h;
943 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
945 Tracks *tracks = mwindow->edl->tracks;
946 max_w = 0; max_h = 0;
947 int has_deinterlace = 0, has_scale = 0;
948 for( Track *trk=tracks->first; trk; trk=trk->next ) {
949 if( !trk->record ) continue;
950 Edits *edits = trk->edits;
951 switch( trk->data_type ) {
953 for( Edit *edit=edits->first; edit; edit=edit->next ) {
954 if( edit->silence() ) continue;
955 Indexable *indexable = edit->get_source();
956 int w = indexable->get_w();
957 if( w > max_w ) max_w = w;
958 if( w != dvd_width ) use_scale = Rescale::scaled;
959 int h = indexable->get_h();
960 if( h > max_h ) max_h = h;
961 if( h != dvd_height ) use_scale = Rescale::scaled;
963 MWindow::create_aspect_ratio(aw, ah, w, h);
964 double aspect = ah > 0 ? aw / ah : 1;
965 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
967 for( int i=0; i<trk->plugin_set.size(); ++i ) {
968 for(Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
970 plugin = (Plugin*)plugin->next) {
971 if( !strcmp(plugin->title, _("Deinterlace")) )
973 if( !strcmp(plugin->title, _("Auto Scale")) ||
974 !strcmp(plugin->title, _("Scale Ratio")) ||
975 !strcmp(plugin->title, _("Scale")) )
983 use_scale = Rescale::none;
984 if( use_scale != Rescale::none ) {
985 if( max_w != dvd_width ) use_resize_tracks = 1;
986 if( max_h != dvd_height ) use_resize_tracks = 1;
988 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
989 if( !trk->record ) continue;
990 switch( trk->data_type ) {
992 if( trk->track_w != max_w ) use_resize_tracks = 1;
993 if( trk->track_h != max_h ) use_resize_tracks = 1;
997 if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
998 Labels *labels = mwindow->edl->labels;
999 use_label_chapters = labels && labels->first ? 1 : 0;
1001 if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
1009 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
1010 int standard, const char *text)
1013 this->popup = popup;
1014 this->standard = standard;
1017 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1021 int CreateDVD_FormatItem::handle_event()
1023 popup->set_text(get_text());
1024 popup->gui->thread->use_standard = standard;
1025 return popup->handle_event();
1029 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1030 : BC_PopupMenu(x, y, 180, "", 1)
1035 CreateDVD_Format::~CreateDVD_Format()
1039 void CreateDVD_Format::create_objects()
1041 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1042 int norm = dvd_formats[i].norm;
1043 int aspect = dvd_formats[i].aspect;
1044 char item_text[BCTEXTLEN];
1045 sprintf(item_text,"%4s (%5.2f) %dx%d",
1046 dvd_norms[norm].name, dvd_norms[norm].framerate,
1047 dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1048 add_item(new CreateDVD_FormatItem(this, i, item_text));
1050 set_value(gui->thread->use_standard);
1053 int CreateDVD_Format::handle_event()
1055 gui->thread->option_presets();
1061 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1062 int scale, const char *text)
1065 this->popup = popup;
1066 this->scale = scale;
1069 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1073 int CreateDVD_ScaleItem::handle_event()
1075 popup->gui->thread->use_scale = scale;
1076 popup->set_value(scale);
1077 return popup->handle_event();
1081 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1082 : BC_PopupMenu(x, y, 100, "", 1)
1087 CreateDVD_Scale::~CreateDVD_Scale()
1091 void CreateDVD_Scale::create_objects()
1094 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1095 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1097 set_value(gui->thread->use_scale);
1100 int CreateDVD_Scale::handle_event()
1107 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1108 : BC_PopupTextBox(gui, 0, 0, x, y, 70,50)
1113 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1117 int CreateDVD_MediaSize::handle_event()
1119 gui->disk_space->update();