8 #include "edlsession.h"
13 #include "mainerror.h"
16 #include "mwindowgui.h"
18 #include "pluginset.h"
19 #include "preferences.h"
28 #include <sys/statfs.h>
32 #define DVD_PAL_16x9 1
33 #define DVD_NTSC_4x3 2
34 #define DVD_NTSC_16x9 3
36 #define DVD_NORM_PAL 0
37 #define DVD_NORM_NTSC 1
39 #define DVD_ASPECT_4x3 0
40 #define DVD_ASPECT_16x9 1
42 static struct dvd_norm {
47 { "PAL", 720,576, 25 },
48 { "NTSC", 720,480, 29.97 },
51 static struct dvd_aspect {
60 static struct dvd_format {
63 { DVD_NORM_PAL, DVD_ASPECT_4x3, },
64 { DVD_NORM_PAL, DVD_ASPECT_16x9, },
65 { DVD_NORM_NTSC, DVD_ASPECT_4x3, },
66 { DVD_NORM_NTSC, DVD_ASPECT_16x9, },
69 const int64_t CreateDVD_Thread::DVD_SIZE = 4700000000;
70 const int CreateDVD_Thread::DVD_STREAMS = 1;
71 const int CreateDVD_Thread::DVD_WIDTH = 720;
72 const int CreateDVD_Thread::DVD_HEIGHT = 480;
73 const double CreateDVD_Thread::DVD_ASPECT_WIDTH = 4.;
74 const double CreateDVD_Thread::DVD_ASPECT_HEIGHT = 3.;
75 const double CreateDVD_Thread::DVD_WIDE_ASPECT_WIDTH = 16.;
76 const double CreateDVD_Thread::DVD_WIDE_ASPECT_HEIGHT = 9.;
77 const double CreateDVD_Thread::DVD_FRAMERATE = 30000. / 1001.;
78 const int CreateDVD_Thread::DVD_MAX_BITRATE = 8000000;
79 const int CreateDVD_Thread::DVD_CHANNELS = 2;
80 const int CreateDVD_Thread::DVD_WIDE_CHANNELS = 6;
81 const double CreateDVD_Thread::DVD_SAMPLERATE = 48000;
82 const double CreateDVD_Thread::DVD_KAUDIO_RATE = 224;
85 CreateDVD_MenuItem::CreateDVD_MenuItem(MWindow *mwindow)
86 : BC_MenuItem(_("DVD Render..."), _("Alt-d"), 'd')
89 this->mwindow = mwindow;
92 int CreateDVD_MenuItem::handle_event()
94 mwindow->create_dvd->start();
99 DVD_BatchRenderJob::DVD_BatchRenderJob(Preferences *preferences,
100 int labeled, int farmed, int standard, int muxed)
101 : BatchRenderJob("DVD_JOB", preferences, labeled, farmed)
103 this->standard = standard;
111 void DVD_BatchRenderJob::copy_from(DVD_BatchRenderJob *src)
113 standard = src->standard;
115 BatchRenderJob::copy_from(src);
118 DVD_BatchRenderJob *DVD_BatchRenderJob::copy()
120 DVD_BatchRenderJob *t = new DVD_BatchRenderJob(preferences,
121 labeled, farmed, standard, muxed);
126 void DVD_BatchRenderJob::load(FileXML *file)
128 standard = file->tag.get_property("STANDARD", standard);
129 muxed = file->tag.get_property("MUXED", muxed);
130 BatchRenderJob::load(file);
133 void DVD_BatchRenderJob::save(FileXML *file)
135 file->tag.set_property("STANDARD", standard);
136 file->tag.set_property("MUXED", muxed);
137 BatchRenderJob::save(file);
140 void DVD_BatchRenderJob::create_chapter(double pos)
142 fprintf(fp,"%s", !chapter++? "\" chapters=\"" : ",");
143 int secs = pos, mins = secs/60;
144 int frms = (pos-secs) * edl->session->frame_rate;
145 fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
148 char *DVD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
150 char script[BCTEXTLEN];
151 strcpy(script, edl_path);
154 char *bp = strrchr(script,'/');
157 strcpy(bp, "/dvd.sh");
158 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
161 fp = fdopen(fd, "w");
163 char err[BCTEXTLEN], msg[BCTEXTLEN];
164 strerror_r(errno, err, sizeof(err));
165 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
166 MainError::show_error(msg);
170 fprintf(fp,"#!/bin/bash\n");
171 fprintf(fp,"sdir=`dirname $0`\n");
172 fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
173 fprintf(fp,"echo \"running %s\"\n", script);
175 const char *exec_path = File::get_cinlib_path();
176 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
177 int file_seq = farmed || labeled ? 1 : 0;
180 fprintf(fp, "cat > $dir/dvd.m2v $dir/dvd.m2v[0-9]*\n");
181 fprintf(fp, "mplex -M -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
185 fprintf(fp, "mplex -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
187 fprintf(fp,"rm -rf $dir/iso\n");
188 fprintf(fp,"mkdir -p $dir/iso\n");
190 // dvdauthor ver 0.7.0 requires this to work
191 int norm = dvd_formats[standard].norm;
192 const char *name = dvd_norms[norm].name;
193 fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
194 fprintf(fp,"dvdauthor -x - <<eof\n");
195 fprintf(fp,"<dvdauthor dest=\"$dir/iso\">\n");
196 fprintf(fp," <vmgm>\n");
197 fprintf(fp," <fpc> jump title 1; </fpc>\n");
198 fprintf(fp," </vmgm>\n");
199 fprintf(fp," <titleset>\n");
200 fprintf(fp," <titles>\n");
201 char std[BCSTRLEN], *cp = std;
202 for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
204 EDLSession *session = edl->session;
205 fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
206 std, (int)session->aspect_w, (int)session->aspect_h,
207 session->output_w, session->output_h);
208 fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
209 fprintf(fp," <pgc>\n");
210 int total_idxbls = !file_seq ? 1 : idxbls->size();
213 double total_length = edl->tracks->total_length();
214 Label *label = edl->labels->first;
215 for( int i=0; i<total_idxbls; ++i ) {
216 Indexable *idxbl = idxbls->get(i);
217 double video_length = idxbl->have_video() && idxbl->get_frame_rate() > 0 ?
218 (double)idxbl->get_video_frames() / idxbl->get_frame_rate() : 0 ;
219 double audio_length = idxbl->have_audio() && idxbl->get_sample_rate() > 0 ?
220 (double)idxbl->get_audio_samples() / idxbl->get_sample_rate() : 0 ;
221 double length = idxbl->have_video() && idxbl->have_audio() ?
222 bmin(video_length, audio_length) :
223 idxbl->have_video() ? video_length :
224 idxbl->have_audio() ? audio_length : 0;
225 fprintf(fp," <vob file=\"%s", !file_seq ? "$dir/dvd.mpg" : idxbl->path);
227 double vob_end = i+1>=total_idxbls ? total_length : vob_pos + length;
229 while( label && label->position < vob_end ) {
230 create_chapter(label->position - vob_pos);
235 while( secs < vob_end ) {
236 create_chapter(secs - vob_pos);
237 secs += 10*60; // ch every 10 minutes
240 fprintf(fp,"\"/>\n");
243 fprintf(fp," </pgc>\n");
244 fprintf(fp," </titles>\n");
245 fprintf(fp," </titleset>\n");
246 fprintf(fp,"</dvdauthor>\n");
249 fprintf(fp,"echo To burn dvd, load blank media and run:\n");
250 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $dir/iso\n");
251 fprintf(fp,"kill $$\n");
254 return cstrdup(script);
258 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
261 this->mwindow = mwindow;
263 this->use_deinterlace = 0;
265 this->use_histogram = 0;
266 this->use_inverse_telecine = 0;
267 this->use_wide_audio = 0;
268 this->use_ffmpeg = 0;
269 this->use_resize_tracks = 0;
270 this->use_labeled = 0;
271 this->use_farmed = 0;
273 this->dvd_size = DVD_SIZE;
274 this->dvd_width = DVD_WIDTH;
275 this->dvd_height = DVD_HEIGHT;
276 this->dvd_aspect_width = DVD_ASPECT_WIDTH;
277 this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
278 this->dvd_framerate = DVD_FRAMERATE;
279 this->dvd_samplerate = DVD_SAMPLERATE;
280 this->dvd_max_bitrate = DVD_MAX_BITRATE;
281 this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
282 this->max_w = this->max_h = 0;
285 CreateDVD_Thread::~CreateDVD_Thread()
290 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
292 EDL *edl = mwindow->edl;
293 if( !edl || !edl->session ) {
295 sprintf(msg, _("No EDL/Session"));
296 MainError::show_error(msg);
299 EDLSession *session = edl->session;
300 double total_length = edl->tracks->total_length();
301 if( total_length <= 0 ) {
303 sprintf(msg, _("No content: %s"), asset_title);
304 MainError::show_error(msg);
308 if( mkdir(asset_dir, 0777) ) {
309 char err[BCTEXTLEN], msg[BCTEXTLEN];
310 strerror_r(errno, err, sizeof(err));
311 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
312 MainError::show_error(msg);
316 double old_samplerate = session->sample_rate;
317 double old_framerate = session->frame_rate;
319 session->video_channels = DVD_STREAMS;
320 session->video_tracks = DVD_STREAMS;
321 session->frame_rate = dvd_framerate;
322 session->output_w = dvd_width;
323 session->output_h = dvd_height;
324 session->aspect_w = dvd_aspect_width;
325 session->aspect_h = dvd_aspect_height;
326 session->sample_rate = dvd_samplerate;
327 session->audio_channels = session->audio_tracks =
328 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
330 session->audio_channels = session->audio_tracks =
331 !use_wide_audio ? DVD_CHANNELS : DVD_WIDE_CHANNELS;
332 for( int i=0; i<MAX_CHANNELS; ++i )
333 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
334 int audio_mapping = edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS &&
335 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
336 mwindow->remap_audio(audio_mapping);
338 double new_samplerate = session->sample_rate;
339 double new_framerate = session->frame_rate;
342 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
343 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
345 int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
346 int64_t vid_size = dvd_size*0.96 - aud_size;
347 int64_t vid_bitrate = (vid_size * 8) / total_length;
348 vid_bitrate /= 1000; vid_bitrate *= 1000;
349 if( vid_bitrate > dvd_max_bitrate )
350 vid_bitrate = dvd_max_bitrate;
352 char xml_filename[BCTEXTLEN];
353 sprintf(xml_filename, "%s/dvd.xml", asset_dir);
355 edl->save_xml(&xml_file, xml_filename);
356 xml_file.terminate_string();
357 if( xml_file.write_to_file(xml_filename) ) {
359 sprintf(msg, _("Unable to save: %s"), xml_filename);
360 MainError::show_error(msg);
364 BatchRenderJob *job = new DVD_BatchRenderJob(mwindow->preferences,
365 use_labeled, use_farmed, use_standard, 0);// use_ffmpeg);
367 strcpy(&job->edl_path[0], xml_filename);
368 Asset *asset = job->asset;
370 asset->layers = DVD_STREAMS;
371 asset->frame_rate = session->frame_rate;
372 asset->width = session->output_w;
373 asset->height = session->output_h;
374 asset->aspect_ratio = session->aspect_w / session->aspect_h;
377 char option_path[BCTEXTLEN];
378 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
379 asset->format = FILE_FFMPEG;
380 strcpy(asset->fformat, "dvd");
381 // if there are many renderfarm jobs, then there are small audio fragments of
382 // silence that are used at the end of a render to fill the last audio "block".
383 // this extra data gradually skews the audio/video sync. Therefore, the audio
384 // is not rendered muxed for ffmpeg, and is remuxed as with mjpeg rendering.
385 // since this audio is in one file, the only fragment is at the end and is ok.
387 asset->audio_data = 1;
388 asset->channels = session->audio_channels;
389 asset->sample_rate = session->sample_rate;
390 strcpy(asset->acodec, "dvd.dvd");
391 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
392 FFMPEG::load_options(option_path, asset->ff_audio_options,
393 sizeof(asset->ff_audio_options));
394 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
396 asset->video_data = 1;
397 strcpy(asset->vcodec, "dvd.dvd");
398 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
399 FFMPEG::load_options(option_path, asset->ff_video_options,
400 sizeof(asset->ff_video_options));
401 asset->ff_video_bitrate = vid_bitrate;
402 asset->ff_video_quality = -1;
403 use_farmed = job->farmed;
405 asset->video_data = 1;
406 strcpy(asset->vcodec, "raw.dvd");
407 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
408 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
409 FFMPEG::load_options(option_path, asset->ff_video_options,
410 sizeof(asset->ff_video_options));
411 asset->ff_video_bitrate = vid_bitrate;
412 asset->ff_video_quality = -1;
413 use_farmed = job->farmed;
415 job = new BatchRenderJob(mwindow->preferences, 0, 0);
417 strcpy(&job->edl_path[0], xml_filename);
419 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
420 asset->format = FILE_AC3;
421 asset->audio_data = 1;
422 asset->channels = session->audio_channels;
423 asset->sample_rate = session->sample_rate;
424 asset->ac3_bitrate = dvd_kaudio_rate;
428 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
429 asset->video_data = 1;
430 asset->format = FILE_VMPEG;
431 asset->vmpeg_cmodel = BC_YUV420P;
432 asset->vmpeg_fix_bitrate = 1;
433 asset->vmpeg_bitrate = vid_bitrate;
434 asset->vmpeg_quantization = 15;
435 asset->vmpeg_iframe_distance = 15;
436 asset->vmpeg_progressive = 0;
437 asset->vmpeg_denoise = 0;
438 asset->vmpeg_seq_codes = 0;
439 asset->vmpeg_derivative = 2;
440 asset->vmpeg_preset = 8;
441 asset->vmpeg_field_order = 0;
442 asset->vmpeg_pframe_distance = 0;
443 use_farmed = job->farmed;
444 job = new BatchRenderJob(mwindow->preferences, 0, 0);
446 strcpy(&job->edl_path[0], xml_filename);
449 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
450 asset->audio_data = 1;
451 asset->format = FILE_AC3;
452 asset->channels = session->audio_channels;
453 asset->sample_rate = session->sample_rate;
455 asset->byte_order = 0;
459 asset->ac3_bitrate = dvd_kaudio_rate;
465 void CreateDVD_Thread::handle_close_event(int result)
468 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
469 mwindow->batch_render->load_defaults(mwindow->defaults);
470 mwindow->undo->update_undo_before();
471 KeyFrame keyframe; char data[BCTEXTLEN];
472 if( use_deinterlace ) {
473 sprintf(data,"<DEINTERLACE MODE=1>");
474 keyframe.set_data(data);
475 insert_video_plugin("Deinterlace", &keyframe);
477 if( use_inverse_telecine ) {
478 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
479 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
480 keyframe.set_data(data);
481 insert_video_plugin("Inverse Telecine", &keyframe);
483 if( use_scale != Rescale::none ) {
484 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
486 Tracks *tracks = mwindow->edl->tracks;
487 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
488 if( vtrk->data_type != TRACK_VIDEO ) continue;
489 if( !vtrk->is_armed() ) continue;
490 vtrk->expand_view = 1;
491 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
492 vtrk->plugin_set.append(plugin_set);
493 Edits *edits = vtrk->edits;
494 for( Edit *edit=edits->first; edit; edit=edit->next ) {
495 Indexable *indexable = edit->get_source();
496 if( !indexable ) continue;
497 Rescale in(indexable);
498 Rescale out(dvd_width, dvd_height, dvd_aspect);
499 float src_w, src_h, dst_w, dst_h;
500 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
501 sprintf(data,"<SCALERATIO TYPE=%d"
502 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
503 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
504 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
505 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
506 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
507 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
508 keyframe.set_data(data);
509 plugin_set->insert_plugin(_("Scale Ratio"),
510 edit->startproject, edit->length,
511 PLUGIN_STANDALONE, 0, &keyframe, 0);
517 if( use_resize_tracks )
519 if( use_histogram ) {
521 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
522 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
523 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
524 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
525 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
526 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
527 "<POINTS><POINT X=6.0e-02 Y=0>"
528 "<POINT X=9.4e-01 Y=1></POINTS>");
530 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
531 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
532 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
533 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
534 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
535 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
538 keyframe.set_data(data);
539 insert_video_plugin("Histogram", &keyframe);
541 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
542 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
543 snprintf(jobs_path, sizeof(jobs_path), "%s/dvd.jobs", asset_dir);
544 mwindow->batch_render->reset(jobs_path);
545 int ret = create_dvd_jobs(&mwindow->batch_render->jobs, asset_dir);
546 mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
547 mwindow->resync_guis();
549 mwindow->batch_render->save_jobs();
550 mwindow->batch_render->start(-use_farmed, -use_labeled);
553 BC_Window* CreateDVD_Thread::new_gui()
555 strcpy(tmp_path,"/tmp");
556 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
557 memset(asset_title,0,sizeof(asset_title));
558 time_t dt; time(&dt);
559 struct tm dtm; localtime_r(&dt, &dtm);
560 sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
561 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
562 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
564 use_scale = Rescale::none;
566 use_inverse_telecine = 0;
569 use_resize_tracks = 0;
572 use_standard = DVD_NTSC_4x3;
575 dvd_width = DVD_WIDTH;
576 dvd_height = DVD_HEIGHT;
577 dvd_aspect_width = DVD_ASPECT_WIDTH;
578 dvd_aspect_height = DVD_ASPECT_HEIGHT;
579 dvd_framerate = DVD_FRAMERATE;
580 dvd_samplerate = DVD_SAMPLERATE;
581 dvd_max_bitrate = DVD_MAX_BITRATE;
582 dvd_kaudio_rate = DVD_KAUDIO_RATE;
583 max_w = 0; max_h = 0;
585 int has_standard = -1;
587 EDLSession *session = mwindow->edl->session;
588 double framerate = session->frame_rate;
589 double aspect_ratio = session->aspect_h > 0 ?
590 session->aspect_w / session->aspect_h > 0 : 1;
591 int output_w = session->output_w, output_h = session->output_h;
592 // match the session to any known standard
593 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
594 int norm = dvd_formats[i].norm;
595 if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
596 if( output_w != dvd_norms[norm].w ) continue;
597 if( output_h != dvd_norms[norm].h ) continue;
598 int aspect = dvd_formats[i].aspect;
599 double dvd_aspect_ratio =
600 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
601 if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
602 has_standard = i; break;
604 if( has_standard < 0 ) {
605 // or use the default standard
606 if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
607 else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
610 if( has_standard >= 0 )
611 use_standard = has_standard;
614 int scr_x = mwindow->gui->get_screen_x(0, -1);
615 int scr_w = mwindow->gui->get_screen_w(0, -1);
616 int scr_h = mwindow->gui->get_screen_h(0, -1);
617 int w = xS(560), h = yS(280);
618 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
620 gui = new CreateDVD_GUI(this, x, y, w, h);
621 gui->create_objects();
626 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
630 set_tooltip(_("end setup, start batch render"));
633 CreateDVD_OK::~CreateDVD_OK()
637 int CreateDVD_OK::button_press_event()
639 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
646 int CreateDVD_OK::keypress_event()
648 return context_help_check_and_show();
652 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
653 : BC_CancelButton(x, y)
658 CreateDVD_Cancel::~CreateDVD_Cancel()
662 int CreateDVD_Cancel::button_press_event()
664 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
672 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
673 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
678 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
682 int64_t CreateDVD_DiskSpace::tmp_path_space()
684 const char *path = gui->thread->tmp_path;
685 if( access(path,R_OK+W_OK) ) return 0;
687 if( statfs(path, &sfs) ) return 0;
688 return (int64_t)sfs.f_bsize * sfs.f_bfree;
691 void CreateDVD_DiskSpace::update()
693 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
694 int64_t disk_space = tmp_path_space();
695 double media_size = 15e9, msz = 0, m = 1;
697 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
698 int i = sizeof(suffix)/sizeof(suffix[0]);
699 while( --i >= 0 && strcmp(sfx, suffix[i]) );
700 while( --i >= 0 ) m *= 1000;
701 media_size = msz * m;
703 m = gui->thread->use_ffmpeg ? 2 : 3;
704 int color = disk_space < media_size*m ? RED : GREEN;
706 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
707 char text[BCTEXTLEN];
708 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
709 gui->disk_space->BC_Title::update(text);
710 gui->disk_space->set_color(color);
713 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
714 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
715 gui->thread->tmp_path, 1, MEDIUMFONT)
720 CreateDVD_TmpPath::~CreateDVD_TmpPath()
724 int CreateDVD_TmpPath::handle_event()
727 gui->disk_space->update();
732 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
733 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
734 gui->thread->asset_title, 1, MEDIUMFONT)
739 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
743 int CreateDVD_AssetTitle::handle_event()
750 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
751 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
756 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
760 int CreateDVD_Deinterlace::handle_event()
763 gui->need_inverse_telecine->set_value(0);
764 gui->thread->use_inverse_telecine = 0;
766 return BC_CheckBox::handle_event();
770 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
771 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
776 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
780 int CreateDVD_InverseTelecine::handle_event()
783 gui->need_deinterlace->set_value(0);
784 gui->thread->use_deinterlace = 0;
786 return BC_CheckBox::handle_event();
790 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
791 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
796 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
801 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
802 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
807 CreateDVD_Histogram::~CreateDVD_Histogram()
811 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
812 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
817 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
821 CreateDVD_UseRenderFarm::CreateDVD_UseRenderFarm(CreateDVD_GUI *gui, int x, int y)
822 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
827 CreateDVD_UseRenderFarm::~CreateDVD_UseRenderFarm()
831 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
832 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
837 CreateDVD_WideAudio::~CreateDVD_WideAudio()
841 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
842 : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
847 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
854 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
855 : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
857 this->thread = thread;
858 at_x = at_y = tmp_x = tmp_y = 0;
859 ok_x = ok_y = ok_w = ok_h = 0;
860 cancel_x = cancel_y = cancel_w = cancel_h = 0;
867 need_deinterlace = 0;
868 need_inverse_telecine = 0;
869 need_resize_tracks = 0;
876 // *** CONTEXT_HELP ***
877 context_help_set_keyword("DVD and Bluray Creation");
880 CreateDVD_GUI::~CreateDVD_GUI()
884 void CreateDVD_GUI::create_objects()
886 int xs10 = xS(10), xs35 = xS(35), xs170 = xS(170);
887 int ys5 = yS(5), ys10 = yS(10);
888 lock_window("CreateDVD_GUI::create_objects");
889 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
890 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
891 int x = padx/2, y = pady/2;
892 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
893 add_subwindow(title);
894 at_x = x + title->get_w(); at_y = y;
895 asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
896 add_subwindow(asset_title);
897 y += title->get_h() + pady/2;
898 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
899 add_subwindow(title);
900 tmp_x = x + title->get_w(); tmp_y = y;
901 tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-xs35);
902 add_subwindow(tmp_path);
903 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
904 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
905 _("Work path"), _("Select a Work directory:"), 1);
906 add_subwindow(btmp_path);
907 y += title->get_h() + pady/2;
908 disk_space = new CreateDVD_DiskSpace(this, x, y);
909 add_subwindow(disk_space);
910 int x0 = get_w() - xs170;
911 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
912 add_subwindow(title);
913 int x1 = x0+title->get_w()+padx;
914 media_size = new CreateDVD_MediaSize(this, x1, y);
915 media_size->create_objects();
916 media_sizes.append(new BC_ListBoxItem("4.7GB"));
917 media_sizes.append(new BC_ListBoxItem("8.3GB"));
918 media_size->update_list(&media_sizes);
919 media_size->update(media_sizes[0]->get_text());
920 disk_space->update();
921 y += disk_space->get_h() + pady/2;
922 title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
923 add_subwindow(title);
924 standard = new CreateDVD_Format(this, title->get_w() + padx, y);
925 add_subwindow(standard);
926 standard->create_objects();
928 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
929 add_subwindow(title);
930 x1 = x0+title->get_w()+padx;
931 scale = new CreateDVD_Scale(this, x1, y);
932 add_subwindow(scale);
933 scale->create_objects();
934 y += standard->get_h() + pady/2;
936 need_deinterlace = new CreateDVD_Deinterlace(this, x1, y);
937 add_subwindow(need_deinterlace);
938 y += need_deinterlace->get_h() + pady/2;
939 need_histogram = new CreateDVD_Histogram(this, x, y);
940 add_subwindow(need_histogram);
942 need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
943 add_subwindow(need_inverse_telecine);
944 y += need_inverse_telecine->get_h() + pady/2;
945 need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
946 add_subwindow(need_wide_audio);
947 y += need_wide_audio->get_h() + pady/2;
948 need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x1, y);
949 add_subwindow(need_use_ffmpeg);
950 y += need_use_ffmpeg->get_h() + pady/2;
951 need_resize_tracks = new CreateDVD_ResizeTracks(this, x1, y);
952 add_subwindow(need_resize_tracks);
954 need_labeled = new CreateDVD_LabelChapters(this, x1, y);
955 add_subwindow(need_labeled);
956 y += need_labeled->get_h() + pady/2;
957 need_farmed = new CreateDVD_UseRenderFarm(this, x1, y);
958 add_subwindow(need_farmed);
959 ok_w = BC_OKButton::calculate_w();
960 ok_h = BC_OKButton::calculate_h();
962 ok_y = get_h() - ok_h - ys10;
963 ok = new CreateDVD_OK(this, ok_x, ok_y);
965 cancel_w = BC_CancelButton::calculate_w();
966 cancel_h = BC_CancelButton::calculate_h();
967 cancel_x = get_w() - cancel_w - xs10,
968 cancel_y = get_h() - cancel_h - ys10;
969 cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
970 add_subwindow(cancel);
975 int CreateDVD_GUI::resize_event(int w, int h)
977 int xs10 = xS(10), xs35 = xS(35);
979 asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
980 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-xs35);
981 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
982 ok_y = h - ok_h - ys10;
983 ok->reposition_window(ok_x, ok_y);
984 cancel_x = w - cancel_w - xs10,
985 cancel_y = h - cancel_h - ys10;
986 cancel->reposition_window(cancel_x, cancel_y);
990 int CreateDVD_GUI::translation_event()
995 int CreateDVD_GUI::close_event()
1001 void CreateDVD_GUI::update()
1003 scale->set_value(thread->use_scale);
1004 need_deinterlace->set_value(thread->use_deinterlace);
1005 need_inverse_telecine->set_value(thread->use_inverse_telecine);
1006 need_use_ffmpeg->set_value(thread->use_ffmpeg);
1007 need_resize_tracks->set_value(thread->use_resize_tracks);
1008 need_histogram->set_value(thread->use_histogram);
1009 need_wide_audio->set_value(thread->use_wide_audio);
1010 need_labeled->set_value(thread->use_labeled);
1011 need_farmed->set_value(thread->use_farmed);
1014 int CreateDVD_Thread::
1015 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
1017 Tracks *tracks = mwindow->edl->tracks;
1018 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1019 if( vtrk->data_type != TRACK_VIDEO ) continue;
1020 if( !vtrk->is_armed() ) continue;
1021 vtrk->expand_view = 1;
1022 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
1023 vtrk->plugin_set.append(plugin_set);
1024 Edits *edits = vtrk->edits;
1025 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1026 plugin_set->insert_plugin(_(title),
1027 edit->startproject, edit->length,
1028 PLUGIN_STANDALONE, 0, default_keyframe, 0);
1035 int CreateDVD_Thread::
1038 Tracks *tracks = mwindow->edl->tracks;
1039 int trk_w = max_w, trk_h = max_h;
1040 if( trk_w < dvd_width ) trk_w = dvd_width;
1041 if( trk_h < dvd_height ) trk_h = dvd_height;
1042 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1043 if( vtrk->data_type != TRACK_VIDEO ) continue;
1044 if( !vtrk->is_armed() ) continue;
1045 vtrk->track_w = trk_w;
1046 vtrk->track_h = trk_h;
1051 int CreateDVD_Thread::
1054 // reset only probed options
1055 use_deinterlace = 0;
1056 use_scale = Rescale::none;
1057 use_resize_tracks = 0;
1062 if( !mwindow->edl ) return 1;
1064 int norm = dvd_formats[use_standard].norm;
1065 dvd_width = dvd_norms[norm].w;
1066 dvd_height = dvd_norms[norm].h;
1067 dvd_framerate = dvd_norms[norm].framerate;
1068 int aspect = dvd_formats[use_standard].aspect;
1069 dvd_aspect_width = dvd_aspects[aspect].w;
1070 dvd_aspect_height = dvd_aspects[aspect].h;
1071 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
1073 Tracks *tracks = mwindow->edl->tracks;
1074 max_w = 0; max_h = 0;
1075 int has_deinterlace = 0, has_scale = 0;
1076 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1077 if( !trk->is_armed() ) continue;
1078 Edits *edits = trk->edits;
1079 switch( trk->data_type ) {
1081 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1082 if( edit->silence() ) continue;
1083 Indexable *indexable = edit->get_source();
1084 int w = indexable->get_w();
1085 if( w > max_w ) max_w = w;
1086 if( w != dvd_width ) use_scale = Rescale::scaled;
1087 int h = indexable->get_h();
1088 if( h > max_h ) max_h = h;
1089 if( h != dvd_height ) use_scale = Rescale::scaled;
1091 MWindow::create_aspect_ratio(aw, ah, w, h);
1092 double aspect = ah > 0 ? aw / ah : 1;
1093 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
1095 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1096 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1097 plugin; plugin=(Plugin*)plugin->next ) {
1098 if( !strcmp(plugin->title, "Deinterlace") )
1099 has_deinterlace = 1;
1100 if( !strcmp(plugin->title, "Auto Scale") ||
1101 !strcmp(plugin->title, "Scale Ratio") ||
1102 !strcmp(plugin->title, "Scale") )
1110 use_scale = Rescale::none;
1111 if( use_scale != Rescale::none ) {
1112 if( max_w != dvd_width ) use_resize_tracks = 1;
1113 if( max_h != dvd_height ) use_resize_tracks = 1;
1115 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1116 if( !trk->is_armed() ) continue;
1117 switch( trk->data_type ) {
1119 if( trk->track_w != max_w ) use_resize_tracks = 1;
1120 if( trk->track_h != max_h ) use_resize_tracks = 1;
1124 if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
1125 Labels *labels = mwindow->edl->labels;
1126 use_labeled = labels && labels->first ? 1 : 0;
1128 if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
1131 use_farmed = mwindow->preferences->use_renderfarm;
1137 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
1138 int standard, const char *text)
1141 this->popup = popup;
1142 this->standard = standard;
1145 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1149 int CreateDVD_FormatItem::handle_event()
1151 popup->set_text(get_text());
1152 popup->gui->thread->use_standard = standard;
1153 return popup->handle_event();
1157 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1158 : BC_PopupMenu(x, y, xS(180), "", 1)
1163 CreateDVD_Format::~CreateDVD_Format()
1167 void CreateDVD_Format::create_objects()
1169 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1170 int norm = dvd_formats[i].norm;
1171 int aspect = dvd_formats[i].aspect;
1172 char item_text[BCTEXTLEN];
1173 sprintf(item_text,"%4s (%5.2f) %dx%d",
1174 dvd_norms[norm].name, dvd_norms[norm].framerate,
1175 dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1176 add_item(new CreateDVD_FormatItem(this, i, item_text));
1178 set_value(gui->thread->use_standard);
1181 int CreateDVD_Format::handle_event()
1183 gui->thread->option_presets();
1189 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1190 int scale, const char *text)
1193 this->popup = popup;
1194 this->scale = scale;
1197 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1201 int CreateDVD_ScaleItem::handle_event()
1203 popup->gui->thread->use_scale = scale;
1204 popup->set_value(scale);
1205 return popup->handle_event();
1209 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1210 : BC_PopupMenu(x, y, xS(140), "", 1)
1215 CreateDVD_Scale::~CreateDVD_Scale()
1219 void CreateDVD_Scale::create_objects()
1222 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1223 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1225 set_value(gui->thread->use_scale);
1228 int CreateDVD_Scale::handle_event()
1235 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1236 : BC_PopupTextBox(gui, 0, 0, x, y, xS(70), 50)
1241 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1245 int CreateDVD_MediaSize::handle_event()
1247 gui->disk_space->update();