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..."), _("Shift-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,"dir=`dirname $0`\n");
172 fprintf(fp,"echo \"running %s\"\n", script);
174 const char *exec_path = File::get_cinlib_path();
175 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
176 int file_seq = farmed || labeled ? 1 : 0;
179 fprintf(fp, "cat > $dir/dvd.m2v $dir/dvd.m2v0*\n");
180 fprintf(fp, "mplex -M -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
184 fprintf(fp, "mplex -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
186 fprintf(fp,"rm -rf $dir/iso\n");
187 fprintf(fp,"mkdir -p $dir/iso\n");
189 // dvdauthor ver 0.7.0 requires this to work
190 int norm = dvd_formats[standard].norm;
191 const char *name = dvd_norms[norm].name;
192 fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
193 fprintf(fp,"dvdauthor -x - <<eof\n");
194 fprintf(fp,"<dvdauthor dest=\"$dir/iso\">\n");
195 fprintf(fp," <vmgm>\n");
196 fprintf(fp," <fpc> jump title 1; </fpc>\n");
197 fprintf(fp," </vmgm>\n");
198 fprintf(fp," <titleset>\n");
199 fprintf(fp," <titles>\n");
200 char std[BCSTRLEN], *cp = std;
201 for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
203 EDLSession *session = edl->session;
204 fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
205 std, (int)session->aspect_w, (int)session->aspect_h,
206 session->output_w, session->output_h);
207 fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
208 fprintf(fp," <pgc>\n");
209 int total_idxbls = !file_seq ? 1 : idxbls->size();
212 double total_length = edl->tracks->total_length();
213 Label *label = edl->labels->first;
214 for( int i=0; i<total_idxbls; ++i ) {
215 Indexable *idxbl = idxbls->get(i);
216 double video_length = idxbl->have_video() && idxbl->get_frame_rate() > 0 ?
217 (double)idxbl->get_video_frames() / idxbl->get_frame_rate() : 0 ;
218 double audio_length = idxbl->have_audio() && idxbl->get_sample_rate() > 0 ?
219 (double)idxbl->get_audio_samples() / idxbl->get_sample_rate() : 0 ;
220 double length = idxbl->have_video() && idxbl->have_audio() ?
221 bmin(video_length, audio_length) :
222 idxbl->have_video() ? video_length :
223 idxbl->have_audio() ? audio_length : 0;
224 fprintf(fp," <vob file=\"%s", !file_seq ? "dvd.mpg" : idxbl->path);
226 double vob_end = i+1>=total_idxbls ? total_length : vob_pos + length;
228 while( label && label->position < vob_end ) {
229 create_chapter(label->position - vob_pos);
234 while( secs < vob_end ) {
235 create_chapter(secs - vob_pos);
236 secs += 10*60; // ch every 10 minutes
239 fprintf(fp,"\"/>\n");
242 fprintf(fp," </pgc>\n");
243 fprintf(fp," </titles>\n");
244 fprintf(fp," </titleset>\n");
245 fprintf(fp,"</dvdauthor>\n");
248 fprintf(fp,"echo To burn dvd, load blank media and run:\n");
249 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $dir/iso\n");
250 fprintf(fp,"kill $$\n");
253 return cstrdup(script);
257 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
260 this->mwindow = mwindow;
262 this->use_deinterlace = 0;
264 this->use_histogram = 0;
265 this->use_inverse_telecine = 0;
266 this->use_wide_audio = 0;
267 this->use_ffmpeg = 0;
268 this->use_resize_tracks = 0;
269 this->use_labeled = 0;
270 this->use_farmed = 0;
272 this->dvd_size = DVD_SIZE;
273 this->dvd_width = DVD_WIDTH;
274 this->dvd_height = DVD_HEIGHT;
275 this->dvd_aspect_width = DVD_ASPECT_WIDTH;
276 this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
277 this->dvd_framerate = DVD_FRAMERATE;
278 this->dvd_samplerate = DVD_SAMPLERATE;
279 this->dvd_max_bitrate = DVD_MAX_BITRATE;
280 this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
281 this->max_w = this->max_h = 0;
284 CreateDVD_Thread::~CreateDVD_Thread()
289 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
291 EDL *edl = mwindow->edl;
292 if( !edl || !edl->session ) {
294 sprintf(msg, _("No EDL/Session"));
295 MainError::show_error(msg);
298 EDLSession *session = edl->session;
299 double total_length = edl->tracks->total_length();
300 if( total_length <= 0 ) {
302 sprintf(msg, _("No content: %s"), asset_title);
303 MainError::show_error(msg);
307 if( mkdir(asset_dir, 0777) ) {
308 char err[BCTEXTLEN], msg[BCTEXTLEN];
309 strerror_r(errno, err, sizeof(err));
310 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
311 MainError::show_error(msg);
315 double old_samplerate = session->sample_rate;
316 double old_framerate = session->frame_rate;
318 session->video_channels = DVD_STREAMS;
319 session->video_tracks = DVD_STREAMS;
320 session->frame_rate = dvd_framerate;
321 session->output_w = dvd_width;
322 session->output_h = dvd_height;
323 session->aspect_w = dvd_aspect_width;
324 session->aspect_h = dvd_aspect_height;
325 session->sample_rate = dvd_samplerate;
326 session->audio_channels = session->audio_tracks =
327 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
329 session->audio_channels = session->audio_tracks =
330 !use_wide_audio ? DVD_CHANNELS : DVD_WIDE_CHANNELS;
331 for( int i=0; i<MAX_CHANNELS; ++i )
332 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
333 int audio_mapping = edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS &&
334 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
335 mwindow->remap_audio(audio_mapping);
337 double new_samplerate = session->sample_rate;
338 double new_framerate = session->frame_rate;
341 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
342 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
344 int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
345 int64_t vid_size = dvd_size*0.96 - aud_size;
346 int64_t vid_bitrate = (vid_size * 8) / total_length;
347 vid_bitrate /= 1000; vid_bitrate *= 1000;
348 if( vid_bitrate > dvd_max_bitrate )
349 vid_bitrate = dvd_max_bitrate;
351 char xml_filename[BCTEXTLEN];
352 sprintf(xml_filename, "%s/dvd.xml", asset_dir);
354 edl->save_xml(&xml_file, xml_filename);
355 xml_file.terminate_string();
356 if( xml_file.write_to_file(xml_filename) ) {
358 sprintf(msg, _("Unable to save: %s"), xml_filename);
359 MainError::show_error(msg);
363 BatchRenderJob *job = new DVD_BatchRenderJob(mwindow->preferences,
364 use_labeled, use_farmed, use_standard, use_ffmpeg);
366 strcpy(&job->edl_path[0], xml_filename);
367 Asset *asset = job->asset;
369 asset->layers = DVD_STREAMS;
370 asset->frame_rate = session->frame_rate;
371 asset->width = session->output_w;
372 asset->height = session->output_h;
373 asset->aspect_ratio = session->aspect_w / session->aspect_h;
376 char option_path[BCTEXTLEN];
377 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
378 asset->format = FILE_FFMPEG;
379 strcpy(asset->fformat, "dvd");
381 asset->audio_data = 1;
382 asset->channels = session->audio_channels;
383 asset->sample_rate = session->sample_rate;
384 strcpy(asset->acodec, "dvd.dvd");
385 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
386 FFMPEG::load_options(option_path, asset->ff_audio_options,
387 sizeof(asset->ff_audio_options));
388 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
390 asset->video_data = 1;
391 strcpy(asset->vcodec, "dvd.dvd");
392 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
393 FFMPEG::load_options(option_path, asset->ff_video_options,
394 sizeof(asset->ff_video_options));
395 asset->ff_video_bitrate = vid_bitrate;
396 asset->ff_video_quality = -1;
397 use_farmed = job->farmed;
400 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
401 asset->video_data = 1;
402 asset->format = FILE_VMPEG;
403 asset->vmpeg_cmodel = BC_YUV420P;
404 asset->vmpeg_fix_bitrate = 1;
405 asset->vmpeg_bitrate = vid_bitrate;
406 asset->vmpeg_quantization = 15;
407 asset->vmpeg_iframe_distance = 15;
408 asset->vmpeg_progressive = 0;
409 asset->vmpeg_denoise = 0;
410 asset->vmpeg_seq_codes = 0;
411 asset->vmpeg_derivative = 2;
412 asset->vmpeg_preset = 8;
413 asset->vmpeg_field_order = 0;
414 asset->vmpeg_pframe_distance = 0;
415 use_farmed = job->farmed;
416 job = new BatchRenderJob(mwindow->preferences, 0, 0);
418 strcpy(&job->edl_path[0], xml_filename);
421 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
422 asset->audio_data = 1;
423 asset->format = FILE_AC3;
424 asset->channels = session->audio_channels;
425 asset->sample_rate = session->sample_rate;
427 asset->byte_order = 0;
431 asset->ac3_bitrate = dvd_kaudio_rate;
437 void CreateDVD_Thread::handle_close_event(int result)
440 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
441 mwindow->batch_render->load_defaults(mwindow->defaults);
442 mwindow->undo->update_undo_before();
443 KeyFrame keyframe; char data[BCTEXTLEN];
444 if( use_deinterlace ) {
445 sprintf(data,"<DEINTERLACE MODE=1>");
446 keyframe.set_data(data);
447 insert_video_plugin("Deinterlace", &keyframe);
449 if( use_inverse_telecine ) {
450 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
451 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
452 keyframe.set_data(data);
453 insert_video_plugin("Inverse Telecine", &keyframe);
455 if( use_scale != Rescale::none ) {
456 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
458 Tracks *tracks = mwindow->edl->tracks;
459 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
460 if( vtrk->data_type != TRACK_VIDEO ) continue;
461 if( !vtrk->record ) continue;
462 vtrk->expand_view = 1;
463 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
464 vtrk->plugin_set.append(plugin_set);
465 Edits *edits = vtrk->edits;
466 for( Edit *edit=edits->first; edit; edit=edit->next ) {
467 Indexable *indexable = edit->get_source();
468 if( !indexable ) continue;
469 Rescale in(indexable);
470 Rescale out(dvd_width, dvd_height, dvd_aspect);
471 float src_w, src_h, dst_w, dst_h;
472 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
473 sprintf(data,"<SCALERATIO TYPE=%d"
474 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
475 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
476 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
477 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
478 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
479 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
480 keyframe.set_data(data);
481 plugin_set->insert_plugin(_("Scale Ratio"),
482 edit->startproject, edit->length,
483 PLUGIN_STANDALONE, 0, &keyframe, 0);
489 if( use_resize_tracks )
491 if( use_histogram ) {
493 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
494 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
495 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
496 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
497 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
498 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
499 "<POINTS><POINT X=6.0e-02 Y=0>"
500 "<POINT X=9.4e-01 Y=1></POINTS>");
502 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
503 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
504 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
505 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
506 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
507 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
510 keyframe.set_data(data);
511 insert_video_plugin("Histogram", &keyframe);
513 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
514 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
515 snprintf(jobs_path, sizeof(jobs_path), "%s/dvd.jobs", asset_dir);
516 mwindow->batch_render->reset(jobs_path);
517 int ret = create_dvd_jobs(&mwindow->batch_render->jobs, asset_dir);
518 mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
519 mwindow->resync_guis();
521 mwindow->batch_render->save_jobs();
522 mwindow->batch_render->start(-use_farmed, -use_labeled);
525 BC_Window* CreateDVD_Thread::new_gui()
527 strcpy(tmp_path,"/tmp");
528 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
529 memset(asset_title,0,sizeof(asset_title));
530 time_t dt; time(&dt);
531 struct tm dtm; localtime_r(&dt, &dtm);
532 sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
533 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
534 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
536 use_scale = Rescale::none;
538 use_inverse_telecine = 0;
541 use_resize_tracks = 0;
544 use_standard = DVD_NTSC_4x3;
547 dvd_width = DVD_WIDTH;
548 dvd_height = DVD_HEIGHT;
549 dvd_aspect_width = DVD_ASPECT_WIDTH;
550 dvd_aspect_height = DVD_ASPECT_HEIGHT;
551 dvd_framerate = DVD_FRAMERATE;
552 dvd_samplerate = DVD_SAMPLERATE;
553 dvd_max_bitrate = DVD_MAX_BITRATE;
554 dvd_kaudio_rate = DVD_KAUDIO_RATE;
555 max_w = 0; max_h = 0;
557 int has_standard = -1;
559 EDLSession *session = mwindow->edl->session;
560 double framerate = session->frame_rate;
561 double aspect_ratio = session->aspect_h > 0 ?
562 session->aspect_w / session->aspect_h > 0 : 1;
563 int output_w = session->output_w, output_h = session->output_h;
564 // match the session to any known standard
565 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
566 int norm = dvd_formats[i].norm;
567 if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
568 if( output_w != dvd_norms[norm].w ) continue;
569 if( output_h != dvd_norms[norm].h ) continue;
570 int aspect = dvd_formats[i].aspect;
571 double dvd_aspect_ratio =
572 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
573 if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
574 has_standard = i; break;
576 if( has_standard < 0 ) {
577 // or use the default standard
578 if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
579 else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
582 if( has_standard >= 0 )
583 use_standard = has_standard;
586 int scr_x = mwindow->gui->get_screen_x(0, -1);
587 int scr_w = mwindow->gui->get_screen_w(0, -1);
588 int scr_h = mwindow->gui->get_screen_h(0, -1);
589 int w = 520, h = 280;
590 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
592 gui = new CreateDVD_GUI(this, x, y, w, h);
593 gui->create_objects();
598 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
602 set_tooltip(_("end setup, start batch render"));
605 CreateDVD_OK::~CreateDVD_OK()
609 int CreateDVD_OK::button_press_event()
611 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
618 int CreateDVD_OK::keypress_event()
624 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
625 : BC_CancelButton(x, y)
630 CreateDVD_Cancel::~CreateDVD_Cancel()
634 int CreateDVD_Cancel::button_press_event()
636 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
644 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
645 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
650 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
654 int64_t CreateDVD_DiskSpace::tmp_path_space()
656 const char *path = gui->thread->tmp_path;
657 if( access(path,R_OK+W_OK) ) return 0;
659 if( statfs(path, &sfs) ) return 0;
660 return (int64_t)sfs.f_bsize * sfs.f_bfree;
663 void CreateDVD_DiskSpace::update()
665 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
666 int64_t disk_space = tmp_path_space();
667 double media_size = 15e9, msz = 0, m = 1;
669 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
670 int i = sizeof(suffix)/sizeof(suffix[0]);
671 while( --i >= 0 && strcmp(sfx, suffix[i]) );
672 while( --i >= 0 ) m *= 1000;
673 media_size = msz * m;
675 m = gui->thread->use_ffmpeg ? 2 : 3;
676 int color = disk_space < media_size*m ? RED : GREEN;
678 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
679 char text[BCTEXTLEN];
680 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
681 gui->disk_space->BC_Title::update(text);
682 gui->disk_space->set_color(color);
685 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
686 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
687 gui->thread->tmp_path, 1, MEDIUMFONT)
692 CreateDVD_TmpPath::~CreateDVD_TmpPath()
696 int CreateDVD_TmpPath::handle_event()
699 gui->disk_space->update();
704 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
705 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
706 gui->thread->asset_title, 1, MEDIUMFONT)
711 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
715 int CreateDVD_AssetTitle::handle_event()
722 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
723 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
728 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
732 int CreateDVD_Deinterlace::handle_event()
735 gui->need_inverse_telecine->set_value(0);
736 gui->thread->use_inverse_telecine = 0;
738 return BC_CheckBox::handle_event();
742 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
743 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
748 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
752 int CreateDVD_InverseTelecine::handle_event()
755 gui->need_deinterlace->set_value(0);
756 gui->thread->use_deinterlace = 0;
758 return BC_CheckBox::handle_event();
762 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
763 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
768 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
773 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
774 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
779 CreateDVD_Histogram::~CreateDVD_Histogram()
783 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
784 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
789 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
793 CreateDVD_UseRenderFarm::CreateDVD_UseRenderFarm(CreateDVD_GUI *gui, int x, int y)
794 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
799 CreateDVD_UseRenderFarm::~CreateDVD_UseRenderFarm()
803 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
804 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
809 CreateDVD_WideAudio::~CreateDVD_WideAudio()
813 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
814 : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
819 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
826 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
827 : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, 50, 50, 1, 0, 1)
829 this->thread = thread;
830 at_x = at_y = tmp_x = tmp_y = 0;
831 ok_x = ok_y = ok_w = ok_h = 0;
832 cancel_x = cancel_y = cancel_w = cancel_h = 0;
839 need_deinterlace = 0;
840 need_inverse_telecine = 0;
841 need_resize_tracks = 0;
850 CreateDVD_GUI::~CreateDVD_GUI()
854 void CreateDVD_GUI::create_objects()
856 lock_window("CreateDVD_GUI::create_objects");
857 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + 5;
858 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
859 int x = padx/2, y = pady/2;
860 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
861 add_subwindow(title);
862 at_x = x + title->get_w(); at_y = y;
863 asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-10);
864 add_subwindow(asset_title);
865 y += title->get_h() + pady/2;
866 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
867 add_subwindow(title);
868 tmp_x = x + title->get_w(); tmp_y = y;
869 tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-35);
870 add_subwindow(tmp_path);
871 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
872 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
873 _("Work path"), _("Select a Work directory:"), 1);
874 add_subwindow(btmp_path);
875 y += title->get_h() + pady/2;
876 disk_space = new CreateDVD_DiskSpace(this, x, y);
877 add_subwindow(disk_space);
878 int x0 = get_w() - 170;
879 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
880 add_subwindow(title);
881 int x1 = x0+title->get_w()+padx;
882 media_size = new CreateDVD_MediaSize(this, x1, y);
883 media_size->create_objects();
884 media_sizes.append(new BC_ListBoxItem("4.7GB"));
885 media_sizes.append(new BC_ListBoxItem("8.3GB"));
886 media_size->update_list(&media_sizes);
887 media_size->update(media_sizes[0]->get_text());
888 disk_space->update();
889 y += disk_space->get_h() + pady/2;
890 title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
891 add_subwindow(title);
892 standard = new CreateDVD_Format(this, title->get_w() + padx, y);
893 add_subwindow(standard);
894 standard->create_objects();
896 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
897 add_subwindow(title);
898 x1 = x0+title->get_w()+padx;
899 scale = new CreateDVD_Scale(this, x1, y);
900 add_subwindow(scale);
901 scale->create_objects();
902 y += standard->get_h() + pady/2;
904 need_deinterlace = new CreateDVD_Deinterlace(this, x1, y);
905 add_subwindow(need_deinterlace);
906 y += need_deinterlace->get_h() + pady/2;
907 need_histogram = new CreateDVD_Histogram(this, x, y);
908 add_subwindow(need_histogram);
910 need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
911 add_subwindow(need_inverse_telecine);
912 y += need_inverse_telecine->get_h() + pady/2;
913 need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
914 add_subwindow(need_wide_audio);
915 y += need_wide_audio->get_h() + pady/2;
916 need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x1, y);
917 add_subwindow(need_use_ffmpeg);
918 y += need_use_ffmpeg->get_h() + pady/2;
919 need_resize_tracks = new CreateDVD_ResizeTracks(this, x1, y);
920 add_subwindow(need_resize_tracks);
922 need_labeled = new CreateDVD_LabelChapters(this, x1, y);
923 add_subwindow(need_labeled);
924 y += need_labeled->get_h() + pady/2;
925 need_farmed = new CreateDVD_UseRenderFarm(this, x1, y);
926 add_subwindow(need_farmed);
927 ok_w = BC_OKButton::calculate_w();
928 ok_h = BC_OKButton::calculate_h();
930 ok_y = get_h() - ok_h - 10;
931 ok = new CreateDVD_OK(this, ok_x, ok_y);
933 cancel_w = BC_CancelButton::calculate_w();
934 cancel_h = BC_CancelButton::calculate_h();
935 cancel_x = get_w() - cancel_w - 10,
936 cancel_y = get_h() - cancel_h - 10;
937 cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
938 add_subwindow(cancel);
943 int CreateDVD_GUI::resize_event(int w, int h)
945 asset_title->reposition_window(at_x, at_y, get_w()-at_x-10);
946 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-35);
947 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
948 ok_y = h - ok_h - 10;
949 ok->reposition_window(ok_x, ok_y);
950 cancel_x = w - cancel_w - 10,
951 cancel_y = h - cancel_h - 10;
952 cancel->reposition_window(cancel_x, cancel_y);
956 int CreateDVD_GUI::translation_event()
961 int CreateDVD_GUI::close_event()
967 void CreateDVD_GUI::update()
969 scale->set_value(thread->use_scale);
970 need_deinterlace->set_value(thread->use_deinterlace);
971 need_inverse_telecine->set_value(thread->use_inverse_telecine);
972 need_use_ffmpeg->set_value(thread->use_ffmpeg);
973 need_resize_tracks->set_value(thread->use_resize_tracks);
974 need_histogram->set_value(thread->use_histogram);
975 need_wide_audio->set_value(thread->use_wide_audio);
976 need_labeled->set_value(thread->use_labeled);
977 need_farmed->set_value(thread->use_farmed);
980 int CreateDVD_Thread::
981 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
983 Tracks *tracks = mwindow->edl->tracks;
984 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
985 if( vtrk->data_type != TRACK_VIDEO ) continue;
986 if( !vtrk->record ) continue;
987 vtrk->expand_view = 1;
988 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
989 vtrk->plugin_set.append(plugin_set);
990 Edits *edits = vtrk->edits;
991 for( Edit *edit=edits->first; edit; edit=edit->next ) {
992 plugin_set->insert_plugin(_(title),
993 edit->startproject, edit->length,
994 PLUGIN_STANDALONE, 0, default_keyframe, 0);
1001 int CreateDVD_Thread::
1004 Tracks *tracks = mwindow->edl->tracks;
1005 int trk_w = max_w, trk_h = max_h;
1006 if( trk_w < dvd_width ) trk_w = dvd_width;
1007 if( trk_h < dvd_height ) trk_h = dvd_height;
1008 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1009 if( vtrk->data_type != TRACK_VIDEO ) continue;
1010 if( !vtrk->record ) continue;
1011 vtrk->track_w = trk_w;
1012 vtrk->track_h = trk_h;
1017 int CreateDVD_Thread::
1020 // reset only probed options
1021 use_deinterlace = 0;
1022 use_scale = Rescale::none;
1023 use_resize_tracks = 0;
1028 if( !mwindow->edl ) return 1;
1030 int norm = dvd_formats[use_standard].norm;
1031 dvd_width = dvd_norms[norm].w;
1032 dvd_height = dvd_norms[norm].h;
1033 dvd_framerate = dvd_norms[norm].framerate;
1034 int aspect = dvd_formats[use_standard].aspect;
1035 dvd_aspect_width = dvd_aspects[aspect].w;
1036 dvd_aspect_height = dvd_aspects[aspect].h;
1037 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
1039 Tracks *tracks = mwindow->edl->tracks;
1040 max_w = 0; max_h = 0;
1041 int has_deinterlace = 0, has_scale = 0;
1042 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1043 if( !trk->record ) continue;
1044 Edits *edits = trk->edits;
1045 switch( trk->data_type ) {
1047 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1048 if( edit->silence() ) continue;
1049 Indexable *indexable = edit->get_source();
1050 int w = indexable->get_w();
1051 if( w > max_w ) max_w = w;
1052 if( w != dvd_width ) use_scale = Rescale::scaled;
1053 int h = indexable->get_h();
1054 if( h > max_h ) max_h = h;
1055 if( h != dvd_height ) use_scale = Rescale::scaled;
1057 MWindow::create_aspect_ratio(aw, ah, w, h);
1058 double aspect = ah > 0 ? aw / ah : 1;
1059 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
1061 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1062 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1063 plugin; plugin=(Plugin*)plugin->next ) {
1064 if( !strcmp(plugin->title, "Deinterlace") )
1065 has_deinterlace = 1;
1066 if( !strcmp(plugin->title, "Auto Scale") ||
1067 !strcmp(plugin->title, "Scale Ratio") ||
1068 !strcmp(plugin->title, "Scale") )
1076 use_scale = Rescale::none;
1077 if( use_scale != Rescale::none ) {
1078 if( max_w != dvd_width ) use_resize_tracks = 1;
1079 if( max_h != dvd_height ) use_resize_tracks = 1;
1081 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1082 if( !trk->record ) continue;
1083 switch( trk->data_type ) {
1085 if( trk->track_w != max_w ) use_resize_tracks = 1;
1086 if( trk->track_h != max_h ) use_resize_tracks = 1;
1090 if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
1091 Labels *labels = mwindow->edl->labels;
1092 use_labeled = labels && labels->first ? 1 : 0;
1094 if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
1097 use_farmed = mwindow->preferences->use_renderfarm;
1103 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
1104 int standard, const char *text)
1107 this->popup = popup;
1108 this->standard = standard;
1111 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1115 int CreateDVD_FormatItem::handle_event()
1117 popup->set_text(get_text());
1118 popup->gui->thread->use_standard = standard;
1119 return popup->handle_event();
1123 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1124 : BC_PopupMenu(x, y, 180, "", 1)
1129 CreateDVD_Format::~CreateDVD_Format()
1133 void CreateDVD_Format::create_objects()
1135 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1136 int norm = dvd_formats[i].norm;
1137 int aspect = dvd_formats[i].aspect;
1138 char item_text[BCTEXTLEN];
1139 sprintf(item_text,"%4s (%5.2f) %dx%d",
1140 dvd_norms[norm].name, dvd_norms[norm].framerate,
1141 dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1142 add_item(new CreateDVD_FormatItem(this, i, item_text));
1144 set_value(gui->thread->use_standard);
1147 int CreateDVD_Format::handle_event()
1149 gui->thread->option_presets();
1155 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1156 int scale, const char *text)
1159 this->popup = popup;
1160 this->scale = scale;
1163 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1167 int CreateDVD_ScaleItem::handle_event()
1169 popup->gui->thread->use_scale = scale;
1170 popup->set_value(scale);
1171 return popup->handle_event();
1175 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1176 : BC_PopupMenu(x, y, 100, "", 1)
1181 CreateDVD_Scale::~CreateDVD_Scale()
1185 void CreateDVD_Scale::create_objects()
1188 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1189 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1191 set_value(gui->thread->use_scale);
1194 int CreateDVD_Scale::handle_event()
1201 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1202 : BC_PopupTextBox(gui, 0, 0, x, y, 70,50)
1207 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1211 int CreateDVD_MediaSize::handle_event()
1213 gui->disk_space->update();