7 #include "edlsession.h"
12 #include "mainerror.h"
15 #include "mwindowgui.h"
17 #include "pluginset.h"
26 #include <sys/statfs.h>
30 #define DVD_PAL_16x9 1
31 #define DVD_NTSC_4x3 2
32 #define DVD_NTSC_16x9 3
34 #define DVD_NORM_PAL 0
35 #define DVD_NORM_NTSC 1
37 #define DVD_ASPECT_4x3 0
38 #define DVD_ASPECT_16x9 1
40 static struct dvd_norm {
45 { "PAL", 720,576, 25 },
46 { "NTSC", 720,480, 29.97 },
49 static struct dvd_aspect {
58 static struct dvd_format {
61 { DVD_NORM_PAL, DVD_ASPECT_4x3, },
62 { DVD_NORM_PAL, DVD_ASPECT_16x9, },
63 { DVD_NORM_NTSC, DVD_ASPECT_4x3, },
64 { DVD_NORM_NTSC, DVD_ASPECT_16x9, },
67 const int64_t CreateDVD_Thread::DVD_SIZE = 4700000000;
68 const int CreateDVD_Thread::DVD_STREAMS = 1;
69 const int CreateDVD_Thread::DVD_WIDTH = 720;
70 const int CreateDVD_Thread::DVD_HEIGHT = 480;
71 const double CreateDVD_Thread::DVD_ASPECT_WIDTH = 4.;
72 const double CreateDVD_Thread::DVD_ASPECT_HEIGHT = 3.;
73 const double CreateDVD_Thread::DVD_WIDE_ASPECT_WIDTH = 16.;
74 const double CreateDVD_Thread::DVD_WIDE_ASPECT_HEIGHT = 9.;
75 const double CreateDVD_Thread::DVD_FRAMERATE = 30000. / 1001.;
76 const int CreateDVD_Thread::DVD_MAX_BITRATE = 8000000;
77 const int CreateDVD_Thread::DVD_CHANNELS = 2;
78 const int CreateDVD_Thread::DVD_WIDE_CHANNELS = 6;
79 const double CreateDVD_Thread::DVD_SAMPLERATE = 48000;
80 const double CreateDVD_Thread::DVD_KAUDIO_RATE = 224;
83 CreateDVD_MenuItem::CreateDVD_MenuItem(MWindow *mwindow)
84 : BC_MenuItem(_("DVD Render..."), _("Shift-D"), 'D')
87 this->mwindow = mwindow;
90 int CreateDVD_MenuItem::handle_event()
92 mwindow->create_dvd->start();
97 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
100 this->mwindow = mwindow;
102 this->use_deinterlace = 0;
104 this->use_histogram = 0;
105 this->use_inverse_telecine = 0;
106 this->use_wide_audio = 0;
107 this->use_ffmpeg = 0;
108 this->use_resize_tracks = 0;
109 this->use_label_chapters = 0;
111 this->dvd_size = DVD_SIZE;
112 this->dvd_width = DVD_WIDTH;
113 this->dvd_height = DVD_HEIGHT;
114 this->dvd_aspect_width = DVD_ASPECT_WIDTH;
115 this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
116 this->dvd_framerate = DVD_FRAMERATE;
117 this->dvd_samplerate = DVD_SAMPLERATE;
118 this->dvd_max_bitrate = DVD_MAX_BITRATE;
119 this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
120 this->max_w = this->max_h = 0;
123 CreateDVD_Thread::~CreateDVD_Thread()
128 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs,
129 const char *tmp_path, const char *asset_title)
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 char asset_dir[BCTEXTLEN];
149 sprintf(asset_dir, "%s/%s", tmp_path, asset_title);
151 if( mkdir(asset_dir, 0777) ) {
152 char err[BCTEXTLEN], msg[BCTEXTLEN];
153 strerror_r(errno, err, sizeof(err));
154 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
155 MainError::show_error(msg);
159 double old_samplerate = session->sample_rate;
160 double old_framerate = session->frame_rate;
162 session->video_channels = DVD_STREAMS;
163 session->video_tracks = DVD_STREAMS;
164 session->frame_rate = dvd_framerate;
165 session->output_w = dvd_width;
166 session->output_h = dvd_height;
167 session->aspect_w = dvd_aspect_width;
168 session->aspect_h = dvd_aspect_height;
169 session->sample_rate = dvd_samplerate;
170 session->audio_channels = session->audio_tracks =
171 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
173 char script_filename[BCTEXTLEN];
174 sprintf(script_filename, "%s/dvd.sh", asset_dir);
175 int fd = open(script_filename, O_WRONLY+O_CREAT+O_TRUNC, 0755);
176 FILE *fp = fdopen(fd, "w");
178 char err[BCTEXTLEN], msg[BCTEXTLEN];
179 strerror_r(errno, err, sizeof(err));
180 sprintf(msg, _("Unable to save: %s\n-- %s"), script_filename, err);
181 MainError::show_error(msg);
184 fprintf(fp,"#!/bin/bash\n");
185 fprintf(fp,"echo \"running %s\" $# $*\n", script_filename);
187 const char *exec_path = File::get_cinlib_path();
188 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
190 fprintf(fp,"mplex -f 8 -o $1/dvd.mpg $1/dvd.m2v $1/dvd.ac3\n");
193 fprintf(fp,"rm -rf $1/iso\n");
194 fprintf(fp,"mkdir -p $1/iso\n");
196 // dvdauthor ver 0.7.0 requires this to work
197 int norm = dvd_formats[use_standard].norm;
198 const char *name = dvd_norms[norm].name;
199 fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
200 fprintf(fp,"dvdauthor -x - <<eof\n");
201 fprintf(fp,"<dvdauthor dest=\"$1/iso\">\n");
202 fprintf(fp," <vmgm>\n");
203 fprintf(fp," <fpc> jump title 1; </fpc>\n");
204 fprintf(fp," </vmgm>\n");
205 fprintf(fp," <titleset>\n");
206 fprintf(fp," <titles>\n");
207 char std[BCSTRLEN], *cp = std;
208 for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
210 fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
211 std, (int)session->aspect_w, (int)session->aspect_h,
212 session->output_w, session->output_h);
213 fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
214 fprintf(fp," <pgc>\n");
215 fprintf(fp," <vob file=\"$1/dvd.mpg\" chapters=\"");
216 if( use_label_chapters && edl->labels ) {
217 Label *label = edl->labels->first;
219 int secs = label->position;
220 int mins = secs / 60;
221 int frms = (label->position-secs) * session->frame_rate;
222 fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
223 if( (label=label->next) != 0 ) fprintf(fp, ",");
228 for( int secs=0 ; secs<total_length; secs+=10*60 ) {
230 fprintf(fp,"%d:%02d:00,", mins/60, mins%60);
232 fprintf(fp,"%d:%02d:00", mins/60, mins%60);
234 fprintf(fp,"\"/>\n");
235 fprintf(fp," </pgc>\n");
236 fprintf(fp," </titles>\n");
237 fprintf(fp," </titleset>\n");
238 fprintf(fp,"</dvdauthor>\n");
241 fprintf(fp,"echo To burn dvd, load blank media and run:\n");
242 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $1/iso\n");
246 if( use_wide_audio ) {
247 session->audio_channels = session->audio_tracks = DVD_WIDE_CHANNELS;
248 session->achannel_positions[0] = 90;
249 session->achannel_positions[1] = 150;
250 session->achannel_positions[2] = 30;
251 session->achannel_positions[3] = 210;
252 session->achannel_positions[4] = 330;
253 session->achannel_positions[5] = 270;
254 if( edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
255 mwindow->remap_audio(MWindow::AUDIO_1_TO_1);
258 session->audio_channels = session->audio_tracks = DVD_CHANNELS;
259 session->achannel_positions[0] = 180;
260 session->achannel_positions[1] = 0;
261 if( edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
262 mwindow->remap_audio(MWindow::AUDIO_5_1_TO_2);
265 double new_samplerate = session->sample_rate;
266 double new_framerate = session->frame_rate;
268 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
269 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
271 int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
272 int64_t vid_size = dvd_size*0.96 - aud_size;
273 int64_t vid_bitrate = (vid_size * 8) / total_length;
274 vid_bitrate /= 1000; vid_bitrate *= 1000;
275 if( vid_bitrate > dvd_max_bitrate )
276 vid_bitrate = dvd_max_bitrate;
278 char xml_filename[BCTEXTLEN];
279 sprintf(xml_filename, "%s/dvd.xml", asset_dir);
281 edl->save_xml(&xml_file, xml_filename, 0, 0);
282 xml_file.terminate_string();
283 if( xml_file.write_to_file(xml_filename) ) {
285 sprintf(msg, _("Unable to save: %s"), xml_filename);
286 MainError::show_error(msg);
290 BatchRenderJob *job = new BatchRenderJob(mwindow->preferences);
292 strcpy(&job->edl_path[0], xml_filename);
293 Asset *asset = job->asset;
295 asset->layers = DVD_STREAMS;
296 asset->frame_rate = session->frame_rate;
297 asset->width = session->output_w;
298 asset->height = session->output_h;
299 asset->aspect_ratio = session->aspect_w / session->aspect_h;
302 char option_path[BCTEXTLEN];
303 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
304 asset->format = FILE_FFMPEG;
305 strcpy(asset->fformat, "dvd");
307 asset->audio_data = 1;
308 strcpy(asset->acodec, "dvd.dvd");
309 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
310 FFMPEG::load_options(option_path, asset->ff_audio_options,
311 sizeof(asset->ff_audio_options));
312 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
314 asset->video_data = 1;
315 strcpy(asset->vcodec, "dvd.dvd");
316 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
317 FFMPEG::load_options(option_path, asset->ff_video_options,
318 sizeof(asset->ff_video_options));
319 asset->ff_video_bitrate = vid_bitrate;
320 asset->ff_video_quality = 0;
323 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
324 asset->video_data = 1;
325 asset->format = FILE_VMPEG;
326 asset->vmpeg_cmodel = BC_YUV420P;
327 asset->vmpeg_fix_bitrate = 1;
328 asset->vmpeg_bitrate = vid_bitrate;
329 asset->vmpeg_quantization = 15;
330 asset->vmpeg_iframe_distance = 15;
331 asset->vmpeg_progressive = 0;
332 asset->vmpeg_denoise = 0;
333 asset->vmpeg_seq_codes = 0;
334 asset->vmpeg_derivative = 2;
335 asset->vmpeg_preset = 8;
336 asset->vmpeg_field_order = 0;
337 asset->vmpeg_pframe_distance = 0;
338 job = new BatchRenderJob(mwindow->preferences);
340 strcpy(&job->edl_path[0], xml_filename);
343 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
344 asset->audio_data = 1;
345 asset->format = FILE_AC3;
346 asset->channels = session->audio_channels;
347 asset->sample_rate = session->sample_rate;
349 asset->byte_order = 0;
353 asset->ac3_bitrate = dvd_kaudio_rate;
356 job = new BatchRenderJob(mwindow->preferences);
358 job->edl_path[0] = '@';
359 strcpy(&job->edl_path[1], script_filename);
360 strcpy(&job->asset->path[0], asset_dir);
365 void CreateDVD_Thread::handle_close_event(int result)
368 mwindow->batch_render->load_defaults(mwindow->defaults);
369 mwindow->undo->update_undo_before();
370 KeyFrame keyframe; char data[BCTEXTLEN];
371 if( use_deinterlace ) {
372 sprintf(data,"<DEINTERLACE MODE=1>");
373 keyframe.set_data(data);
374 insert_video_plugin("Deinterlace", &keyframe);
376 if( use_inverse_telecine ) {
377 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
378 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
379 keyframe.set_data(data);
380 insert_video_plugin("Inverse Telecine", &keyframe);
382 if( use_scale != Rescale::none ) {
383 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
385 Tracks *tracks = mwindow->edl->tracks;
386 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
387 if( vtrk->data_type != TRACK_VIDEO ) continue;
388 if( !vtrk->record ) continue;
389 vtrk->expand_view = 1;
390 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
391 vtrk->plugin_set.append(plugin_set);
392 Edits *edits = vtrk->edits;
393 for( Edit *edit=edits->first; edit; edit=edit->next ) {
394 Indexable *indexable = edit->get_source();
395 if( !indexable ) continue;
396 Rescale in(indexable);
397 Rescale out(dvd_width, dvd_height, dvd_aspect);
398 float src_w, src_h, dst_w, dst_h;
399 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
400 sprintf(data,"<SCALERATIO TYPE=%d"
401 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
402 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
403 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
404 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
405 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
406 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
407 keyframe.set_data(data);
408 plugin_set->insert_plugin(_("Scale Ratio"),
409 edit->startproject, edit->length,
410 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 mwindow->batch_render->reset(1);
440 create_dvd_jobs(&mwindow->batch_render->jobs, tmp_path, asset_title);
441 mwindow->save_backup();
442 mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
443 mwindow->resync_guis();
444 mwindow->batch_render->handle_close_event(0);
445 mwindow->batch_render->start();
448 BC_Window* CreateDVD_Thread::new_gui()
450 memset(tmp_path,0,sizeof(tmp_path));
451 strcpy(tmp_path,"/tmp");
452 memset(asset_title,0,sizeof(asset_title));
453 time_t dt; time(&dt);
454 struct tm dtm; localtime_r(&dt, &dtm);
455 sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
456 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
457 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
459 use_scale = Rescale::none;
461 use_inverse_telecine = 0;
464 use_resize_tracks = 0;
465 use_label_chapters = 0;
466 use_standard = DVD_NTSC_4x3;
469 dvd_width = DVD_WIDTH;
470 dvd_height = DVD_HEIGHT;
471 dvd_aspect_width = DVD_ASPECT_WIDTH;
472 dvd_aspect_height = DVD_ASPECT_HEIGHT;
473 dvd_framerate = DVD_FRAMERATE;
474 dvd_samplerate = DVD_SAMPLERATE;
475 dvd_max_bitrate = DVD_MAX_BITRATE;
476 dvd_kaudio_rate = DVD_KAUDIO_RATE;
477 max_w = 0; max_h = 0;
479 int has_standard = -1;
481 EDLSession *session = mwindow->edl->session;
482 double framerate = session->frame_rate;
483 double aspect_ratio = session->aspect_h > 0 ?
484 session->aspect_w / session->aspect_h > 0 : 1;
485 int output_w = session->output_w, output_h = session->output_h;
486 // match the session to any known standard
487 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
488 int norm = dvd_formats[i].norm;
489 if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
490 if( output_w != dvd_norms[norm].w ) continue;
491 if( output_h != dvd_norms[norm].h ) continue;
492 int aspect = dvd_formats[i].aspect;
493 double dvd_aspect_ratio =
494 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
495 if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
496 has_standard = i; break;
498 if( has_standard < 0 ) {
499 // or use the default standard
500 if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
501 else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
504 if( has_standard >= 0 )
505 use_standard = has_standard;
508 int scr_x = mwindow->gui->get_screen_x(0, -1);
509 int scr_w = mwindow->gui->get_screen_w(0, -1);
510 int scr_h = mwindow->gui->get_screen_h(0, -1);
511 int w = 520, h = 280;
512 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
514 gui = new CreateDVD_GUI(this, x, y, w, h);
515 gui->create_objects();
520 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
524 set_tooltip(_("end setup, start batch render"));
527 CreateDVD_OK::~CreateDVD_OK()
531 int CreateDVD_OK::button_press_event()
533 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
540 int CreateDVD_OK::keypress_event()
546 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
547 : BC_CancelButton(x, y)
552 CreateDVD_Cancel::~CreateDVD_Cancel()
556 int CreateDVD_Cancel::button_press_event()
558 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
566 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
567 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
572 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
576 int64_t CreateDVD_DiskSpace::tmp_path_space()
578 const char *path = gui->tmp_path->get_text();
579 if( access(path,R_OK+W_OK) ) return 0;
581 if( statfs(path, &sfs) ) return 0;
582 return (int64_t)sfs.f_bsize * sfs.f_bfree;
585 void CreateDVD_DiskSpace::update()
587 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
588 int64_t disk_space = tmp_path_space();
589 double media_size = 15e9, msz = 0, m = 1;
591 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
592 int i = sizeof(suffix)/sizeof(suffix[0]);
593 while( --i >= 0 && strcmp(sfx, suffix[i]) );
594 while( --i >= 0 ) m *= 1000;
595 media_size = msz * m;
597 m = gui->thread->use_ffmpeg ? 2 : 3;
598 int color = disk_space < media_size*m ? RED : GREEN;
600 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
601 char text[BCTEXTLEN];
602 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
603 gui->disk_space->BC_Title::update(text);
604 gui->disk_space->set_color(color);
607 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
608 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
609 gui->thread->tmp_path, 1, MEDIUMFONT)
614 CreateDVD_TmpPath::~CreateDVD_TmpPath()
618 int CreateDVD_TmpPath::handle_event()
620 gui->disk_space->update();
625 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
626 : BC_TextBox(x, y, w, 1, 0, gui->thread->asset_title, 1, MEDIUMFONT)
631 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
636 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
637 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
642 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
646 int CreateDVD_Deinterlace::handle_event()
649 gui->need_inverse_telecine->set_value(0);
650 gui->thread->use_inverse_telecine = 0;
652 return BC_CheckBox::handle_event();
656 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
657 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
662 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
666 int CreateDVD_InverseTelecine::handle_event()
669 gui->need_deinterlace->set_value(0);
670 gui->thread->use_deinterlace = 0;
672 return BC_CheckBox::handle_event();
676 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
677 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
682 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
687 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
688 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
693 CreateDVD_Histogram::~CreateDVD_Histogram()
697 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
698 : BC_CheckBox(x, y, &gui->thread->use_label_chapters, _("Chapters at Labels"))
703 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
707 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
708 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
713 CreateDVD_WideAudio::~CreateDVD_WideAudio()
717 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
718 : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
723 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
730 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
731 : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, 50, 50, 1, 0, 1)
733 this->thread = thread;
734 at_x = at_y = tmp_x = tmp_y = 0;
735 ok_x = ok_y = ok_w = ok_h = 0;
736 cancel_x = cancel_y = cancel_w = cancel_h = 0;
743 need_deinterlace = 0;
744 need_inverse_telecine = 0;
745 need_resize_tracks = 0;
748 need_label_chapters = 0;
753 CreateDVD_GUI::~CreateDVD_GUI()
757 void CreateDVD_GUI::create_objects()
759 lock_window("CreateDVD_GUI::create_objects");
760 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + 5;
761 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
762 int x = padx/2, y = pady/2;
763 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
764 add_subwindow(title);
765 at_x = x + title->get_w(); at_y = y;
766 asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-10);
767 add_subwindow(asset_title);
768 y += title->get_h() + pady/2;
769 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
770 add_subwindow(title);
771 tmp_x = x + title->get_w(); tmp_y = y;
772 tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-35);
773 add_subwindow(tmp_path);
774 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
775 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
776 _("Work path"), _("Select a Work directory:"), 1);
777 add_subwindow(btmp_path);
778 y += title->get_h() + pady/2;
779 disk_space = new CreateDVD_DiskSpace(this, x, y);
780 add_subwindow(disk_space);
781 int x0 = get_w() - 170;
782 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
783 add_subwindow(title);
784 int x1 = x0+title->get_w()+padx;
785 media_size = new CreateDVD_MediaSize(this, x1, y);
786 media_size->create_objects();
787 media_sizes.append(new BC_ListBoxItem("4.7GB"));
788 media_sizes.append(new BC_ListBoxItem("8.3GB"));
789 media_size->update_list(&media_sizes);
790 media_size->update(media_sizes[0]->get_text());
791 disk_space->update();
792 y += disk_space->get_h() + pady/2;
793 title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
794 add_subwindow(title);
795 standard = new CreateDVD_Format(this, title->get_w() + padx, y);
796 add_subwindow(standard);
797 standard->create_objects();
799 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
800 add_subwindow(title);
801 x1 = x0+title->get_w()+padx;
802 scale = new CreateDVD_Scale(this, x1, y);
803 add_subwindow(scale);
804 scale->create_objects();
805 y += standard->get_h() + pady/2;
806 need_deinterlace = new CreateDVD_Deinterlace(this, x, y);
807 add_subwindow(need_deinterlace);
810 need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
811 add_subwindow(need_inverse_telecine);
812 need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x2, y);
813 add_subwindow(need_use_ffmpeg);
814 y += need_deinterlace->get_h() + pady/2;
815 need_histogram = new CreateDVD_Histogram(this, x, y);
816 add_subwindow(need_histogram);
817 need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
818 add_subwindow(need_wide_audio);
819 need_resize_tracks = new CreateDVD_ResizeTracks(this, x2, y);
820 add_subwindow(need_resize_tracks);
821 y += need_histogram->get_h() + pady/2;
822 need_label_chapters = new CreateDVD_LabelChapters(this, x1, y);
823 add_subwindow(need_label_chapters);
824 ok_w = BC_OKButton::calculate_w();
825 ok_h = BC_OKButton::calculate_h();
827 ok_y = get_h() - ok_h - 10;
828 ok = new CreateDVD_OK(this, ok_x, ok_y);
830 cancel_w = BC_CancelButton::calculate_w();
831 cancel_h = BC_CancelButton::calculate_h();
832 cancel_x = get_w() - cancel_w - 10,
833 cancel_y = get_h() - cancel_h - 10;
834 cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
835 add_subwindow(cancel);
840 int CreateDVD_GUI::resize_event(int w, int h)
842 asset_title->reposition_window(at_x, at_y, get_w()-at_x-10);
843 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-35);
844 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
845 ok_y = h - ok_h - 10;
846 ok->reposition_window(ok_x, ok_y);
847 cancel_x = w - cancel_w - 10,
848 cancel_y = h - cancel_h - 10;
849 cancel->reposition_window(cancel_x, cancel_y);
853 int CreateDVD_GUI::translation_event()
858 int CreateDVD_GUI::close_event()
864 void CreateDVD_GUI::update()
866 scale->set_value(thread->use_scale);
867 need_deinterlace->set_value(thread->use_deinterlace);
868 need_inverse_telecine->set_value(thread->use_inverse_telecine);
869 need_use_ffmpeg->set_value(thread->use_ffmpeg);
870 need_resize_tracks->set_value(thread->use_resize_tracks);
871 need_histogram->set_value(thread->use_histogram);
872 need_wide_audio->set_value(thread->use_wide_audio);
873 need_label_chapters->set_value(thread->use_label_chapters);
876 int CreateDVD_Thread::
877 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
879 Tracks *tracks = mwindow->edl->tracks;
880 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
881 if( vtrk->data_type != TRACK_VIDEO ) continue;
882 if( !vtrk->record ) continue;
883 vtrk->expand_view = 1;
884 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
885 vtrk->plugin_set.append(plugin_set);
886 Edits *edits = vtrk->edits;
887 for( Edit *edit=edits->first; edit; edit=edit->next ) {
888 plugin_set->insert_plugin(_(title),
889 edit->startproject, edit->length,
890 PLUGIN_STANDALONE, 0, default_keyframe, 0);
896 int CreateDVD_Thread::
899 Tracks *tracks = mwindow->edl->tracks;
900 int trk_w = max_w, trk_h = max_h;
901 if( trk_w < dvd_width ) trk_w = dvd_width;
902 if( trk_h < dvd_height ) trk_h = dvd_height;
903 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
904 if( vtrk->data_type != TRACK_VIDEO ) continue;
905 if( !vtrk->record ) continue;
906 vtrk->track_w = trk_w;
907 vtrk->track_h = trk_h;
912 int CreateDVD_Thread::
915 // reset only probed options
917 use_scale = Rescale::none;
918 use_resize_tracks = 0;
920 use_label_chapters = 0;
922 if( !mwindow->edl ) return 1;
924 int norm = dvd_formats[use_standard].norm;
925 dvd_width = dvd_norms[norm].w;
926 dvd_height = dvd_norms[norm].h;
927 dvd_framerate = dvd_norms[norm].framerate;
928 int aspect = dvd_formats[use_standard].aspect;
929 dvd_aspect_width = dvd_aspects[aspect].w;
930 dvd_aspect_height = dvd_aspects[aspect].h;
931 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
933 Tracks *tracks = mwindow->edl->tracks;
934 max_w = 0; max_h = 0;
935 int has_deinterlace = 0, has_scale = 0;
936 for( Track *trk=tracks->first; trk; trk=trk->next ) {
937 if( !trk->record ) continue;
938 Edits *edits = trk->edits;
939 switch( trk->data_type ) {
941 for( Edit *edit=edits->first; edit; edit=edit->next ) {
942 if( edit->silence() ) continue;
943 Indexable *indexable = edit->get_source();
944 int w = indexable->get_w();
945 if( w > max_w ) max_w = w;
946 if( w != dvd_width ) use_scale = Rescale::scaled;
947 int h = indexable->get_h();
948 if( h > max_h ) max_h = h;
949 if( h != dvd_height ) use_scale = Rescale::scaled;
951 MWindow::create_aspect_ratio(aw, ah, w, h);
952 double aspect = ah > 0 ? aw / ah : 1;
953 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
955 for( int i=0; i<trk->plugin_set.size(); ++i ) {
956 for(Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
958 plugin = (Plugin*)plugin->next) {
959 if( !strcmp(plugin->title, _("Deinterlace")) )
961 if( !strcmp(plugin->title, _("Auto Scale")) ||
962 !strcmp(plugin->title, _("Scale Ratio")) ||
963 !strcmp(plugin->title, _("Scale")) )
971 use_scale = Rescale::none;
972 if( use_scale != Rescale::none ) {
973 if( max_w != dvd_width ) use_resize_tracks = 1;
974 if( max_h != dvd_height ) use_resize_tracks = 1;
976 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
977 if( !trk->record ) continue;
978 switch( trk->data_type ) {
980 if( trk->track_w != max_w ) use_resize_tracks = 1;
981 if( trk->track_h != max_h ) use_resize_tracks = 1;
985 if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
986 Labels *labels = mwindow->edl->labels;
987 use_label_chapters = labels && labels->first ? 1 : 0;
989 if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
997 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
998 int standard, const char *text)
1001 this->popup = popup;
1002 this->standard = standard;
1005 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1009 int CreateDVD_FormatItem::handle_event()
1011 popup->set_text(get_text());
1012 popup->gui->thread->use_standard = standard;
1013 return popup->handle_event();
1017 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1018 : BC_PopupMenu(x, y, 180, "", 1)
1023 CreateDVD_Format::~CreateDVD_Format()
1027 void CreateDVD_Format::create_objects()
1029 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1030 int norm = dvd_formats[i].norm;
1031 int aspect = dvd_formats[i].aspect;
1032 char item_text[BCTEXTLEN];
1033 sprintf(item_text,"%4s (%5.2f) %dx%d",
1034 dvd_norms[norm].name, dvd_norms[norm].framerate,
1035 dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1036 add_item(new CreateDVD_FormatItem(this, i, item_text));
1038 set_value(gui->thread->use_standard);
1041 int CreateDVD_Format::handle_event()
1043 gui->thread->option_presets();
1049 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1050 int scale, const char *text)
1053 this->popup = popup;
1054 this->scale = scale;
1057 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1061 int CreateDVD_ScaleItem::handle_event()
1063 popup->gui->thread->use_scale = scale;
1064 popup->set_value(scale);
1065 return popup->handle_event();
1069 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1070 : BC_PopupMenu(x, y, 100, "", 1)
1075 CreateDVD_Scale::~CreateDVD_Scale()
1079 void CreateDVD_Scale::create_objects()
1082 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1083 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1085 set_value(gui->thread->use_scale);
1088 int CreateDVD_Scale::handle_event()
1095 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1096 : BC_PopupTextBox(gui, 0, 0, x, y, 70,50)
1101 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1105 int CreateDVD_MediaSize::handle_event()
1107 gui->disk_space->update();