3 * Copyright (C) 2016-2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include "dvdcreate.h"
28 #include "edlsession.h"
33 #include "mainerror.h"
36 #include "mwindowgui.h"
38 #include "pluginset.h"
39 #include "preferences.h"
47 #if !defined(__FreeBSD__)
49 #if !defined(__NetBSD__)
50 #include <sys/statfs.h>
53 #include <sys/param.h>
54 #include <sys/mount.h>
57 #if defined(__NetBSD__)
58 #include <sys/statvfs.h>
60 #define statfs statvfs
65 #define DVD_PAL_16x9 1
66 #define DVD_NTSC_4x3 2
67 #define DVD_NTSC_16x9 3
69 #define DVD_NORM_PAL 0
70 #define DVD_NORM_NTSC 1
72 #define DVD_ASPECT_4x3 0
73 #define DVD_ASPECT_16x9 1
75 static struct dvd_norm {
80 { "PAL", 720,576, 25 },
81 { "NTSC", 720,480, 29.97 },
84 static struct dvd_aspect {
93 static struct dvd_format {
96 { DVD_NORM_PAL, DVD_ASPECT_4x3, },
97 { DVD_NORM_PAL, DVD_ASPECT_16x9, },
98 { DVD_NORM_NTSC, DVD_ASPECT_4x3, },
99 { DVD_NORM_NTSC, DVD_ASPECT_16x9, },
102 const int64_t CreateDVD_Thread::DVD_SIZE = 4700000000;
103 const int CreateDVD_Thread::DVD_STREAMS = 1;
104 const int CreateDVD_Thread::DVD_WIDTH = 720;
105 const int CreateDVD_Thread::DVD_HEIGHT = 480;
106 const double CreateDVD_Thread::DVD_ASPECT_WIDTH = 4.;
107 const double CreateDVD_Thread::DVD_ASPECT_HEIGHT = 3.;
108 const double CreateDVD_Thread::DVD_WIDE_ASPECT_WIDTH = 16.;
109 const double CreateDVD_Thread::DVD_WIDE_ASPECT_HEIGHT = 9.;
110 const double CreateDVD_Thread::DVD_FRAMERATE = 30000. / 1001.;
111 const int CreateDVD_Thread::DVD_MAX_BITRATE = 8000000;
112 const int CreateDVD_Thread::DVD_CHANNELS = 2;
113 const int CreateDVD_Thread::DVD_WIDE_CHANNELS = 6;
114 const double CreateDVD_Thread::DVD_SAMPLERATE = 48000;
115 const double CreateDVD_Thread::DVD_KAUDIO_RATE = 224;
118 CreateDVD_MenuItem::CreateDVD_MenuItem(MWindow *mwindow)
119 : BC_MenuItem(_("DVD Render..."), _("Alt-d"), 'd')
122 this->mwindow = mwindow;
125 int CreateDVD_MenuItem::handle_event()
127 mwindow->create_dvd->start();
132 DVD_BatchRenderJob::DVD_BatchRenderJob(Preferences *preferences,
133 int labeled, int farmed, int standard, int muxed)
134 : BatchRenderJob("DVD_JOB", preferences, labeled, farmed)
136 this->standard = standard;
144 void DVD_BatchRenderJob::copy_from(DVD_BatchRenderJob *src)
146 standard = src->standard;
148 BatchRenderJob::copy_from(src);
151 DVD_BatchRenderJob *DVD_BatchRenderJob::copy()
153 DVD_BatchRenderJob *t = new DVD_BatchRenderJob(preferences,
154 labeled, farmed, standard, muxed);
159 void DVD_BatchRenderJob::load(FileXML *file)
161 standard = file->tag.get_property("STANDARD", standard);
162 muxed = file->tag.get_property("MUXED", muxed);
163 BatchRenderJob::load(file);
166 void DVD_BatchRenderJob::save(FileXML *file)
168 file->tag.set_property("STANDARD", standard);
169 file->tag.set_property("MUXED", muxed);
170 BatchRenderJob::save(file);
173 void DVD_BatchRenderJob::create_chapter(double pos)
175 fprintf(fp,"%s", !chapter++? "\" chapters=\"" : ",");
176 int secs = pos, mins = secs/60;
177 int frms = (pos-secs) * edl->session->frame_rate;
178 fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
181 char *DVD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
183 char script[BCTEXTLEN];
184 strcpy(script, edl_path);
187 char *bp = strrchr(script,'/');
190 strcpy(bp, "/dvd.sh");
191 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
194 fp = fdopen(fd, "w");
196 char err[BCTEXTLEN], msg[BCTEXTLEN];
197 strerror_r(errno, err, sizeof(err));
198 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
199 MainError::show_error(msg);
203 fprintf(fp,"#!/bin/bash\n");
204 fprintf(fp,"sdir=`dirname $0`\n");
205 fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
206 fprintf(fp,"echo \"running %s\"\n", script);
208 const char *exec_path = File::get_cinlib_path();
209 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
210 int file_seq = farmed || labeled ? 1 : 0;
213 fprintf(fp, "cat > $dir/dvd.m2v $dir/dvd.m2v[0-9]*\n");
214 fprintf(fp, "mplex -M -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
218 fprintf(fp, "mplex -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
220 fprintf(fp,"rm -rf $dir/iso\n");
221 fprintf(fp,"mkdir -p $dir/iso\n");
223 // dvdauthor ver 0.7.0 requires this to work
224 int norm = dvd_formats[standard].norm;
225 const char *name = dvd_norms[norm].name;
226 fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
227 fprintf(fp,"dvdauthor -x - <<eof\n");
228 fprintf(fp,"<dvdauthor dest=\"$dir/iso\">\n");
229 fprintf(fp," <vmgm>\n");
230 fprintf(fp," <fpc> jump title 1; </fpc>\n");
231 fprintf(fp," </vmgm>\n");
232 fprintf(fp," <titleset>\n");
233 fprintf(fp," <titles>\n");
234 char std[BCSTRLEN], *cp = std;
235 for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
237 EDLSession *session = edl->session;
238 fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
239 std, (int)session->aspect_w, (int)session->aspect_h,
240 session->output_w, session->output_h);
241 fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
242 fprintf(fp," <pgc>\n");
243 int total_idxbls = !file_seq ? 1 : idxbls->size();
246 double total_length = edl->tracks->total_length();
247 Label *label = edl->labels->first;
248 for( int i=0; i<total_idxbls; ++i ) {
249 Indexable *idxbl = idxbls->get(i);
250 double video_length = idxbl->have_video() && idxbl->get_frame_rate() > 0 ?
251 (double)idxbl->get_video_frames() / idxbl->get_frame_rate() : 0 ;
252 double audio_length = idxbl->have_audio() && idxbl->get_sample_rate() > 0 ?
253 (double)idxbl->get_audio_samples() / idxbl->get_sample_rate() : 0 ;
254 double length = idxbl->have_video() && idxbl->have_audio() ?
255 bmin(video_length, audio_length) :
256 idxbl->have_video() ? video_length :
257 idxbl->have_audio() ? audio_length : 0;
258 fprintf(fp," <vob file=\"%s", !file_seq ? "$dir/dvd.mpg" : idxbl->path);
260 double vob_end = i+1>=total_idxbls ? total_length : vob_pos + length;
262 while( label && label->position < vob_end ) {
263 create_chapter(label->position - vob_pos);
268 while( secs < vob_end ) {
269 create_chapter(secs - vob_pos);
270 secs += 10*60; // ch every 10 minutes
273 fprintf(fp,"\"/>\n");
276 fprintf(fp," </pgc>\n");
277 fprintf(fp," </titles>\n");
278 fprintf(fp," </titleset>\n");
279 fprintf(fp,"</dvdauthor>\n");
282 fprintf(fp,"echo To burn dvd, load blank media and run:\n");
283 fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $dir/iso\n");
284 fprintf(fp,"kill $$\n");
287 return cstrdup(script);
291 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
294 this->mwindow = mwindow;
296 this->use_deinterlace = 0;
298 this->use_histogram = 0;
299 this->use_inverse_telecine = 0;
300 this->use_wide_audio = 0;
301 this->use_ffmpeg = 0;
302 this->use_resize_tracks = 0;
303 this->use_labeled = 0;
304 this->use_farmed = 0;
306 this->dvd_size = DVD_SIZE;
307 this->dvd_width = DVD_WIDTH;
308 this->dvd_height = DVD_HEIGHT;
309 this->dvd_aspect_width = DVD_ASPECT_WIDTH;
310 this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
311 this->dvd_framerate = DVD_FRAMERATE;
312 this->dvd_samplerate = DVD_SAMPLERATE;
313 this->dvd_max_bitrate = DVD_MAX_BITRATE;
314 this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
315 this->max_w = this->max_h = 0;
318 CreateDVD_Thread::~CreateDVD_Thread()
323 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
325 EDL *edl = mwindow->edl;
326 if( !edl || !edl->session ) {
328 sprintf(msg, _("No EDL/Session"));
329 MainError::show_error(msg);
332 EDLSession *session = edl->session;
333 double total_length = edl->tracks->total_length();
334 if( total_length <= 0 ) {
336 sprintf(msg, _("No content: %s"), asset_title);
337 MainError::show_error(msg);
341 if( mkdir(asset_dir, 0777) ) {
342 char err[BCTEXTLEN], msg[BCTEXTLEN];
343 strerror_r(errno, err, sizeof(err));
344 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
345 MainError::show_error(msg);
349 double old_samplerate = session->sample_rate;
350 double old_framerate = session->frame_rate;
352 session->video_channels = DVD_STREAMS;
353 session->video_tracks = DVD_STREAMS;
354 session->frame_rate = dvd_framerate;
355 session->output_w = dvd_width;
356 session->output_h = dvd_height;
357 session->aspect_w = dvd_aspect_width;
358 session->aspect_h = dvd_aspect_height;
359 session->sample_rate = dvd_samplerate;
360 session->audio_channels = session->audio_tracks =
361 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
363 session->audio_channels = session->audio_tracks =
364 !use_wide_audio ? DVD_CHANNELS : DVD_WIDE_CHANNELS;
365 for( int i=0; i<MAX_CHANNELS; ++i )
366 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
367 int audio_mapping = edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS &&
368 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
369 mwindow->remap_audio(audio_mapping);
371 double new_samplerate = session->sample_rate;
372 double new_framerate = session->frame_rate;
375 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
376 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
378 int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
379 int64_t vid_size = dvd_size*0.96 - aud_size;
380 int64_t vid_bitrate = (vid_size * 8) / total_length;
381 vid_bitrate /= 1000; vid_bitrate *= 1000;
382 if( vid_bitrate > dvd_max_bitrate )
383 vid_bitrate = dvd_max_bitrate;
385 char xml_filename[BCTEXTLEN];
386 sprintf(xml_filename, "%s/dvd.xml", asset_dir);
388 edl->save_xml(&xml_file, xml_filename);
389 xml_file.terminate_string();
390 if( xml_file.write_to_file(xml_filename) ) {
392 sprintf(msg, _("Unable to save: %s"), xml_filename);
393 MainError::show_error(msg);
397 BatchRenderJob *job = new DVD_BatchRenderJob(mwindow->preferences,
398 use_labeled, use_farmed, use_standard, 0);// use_ffmpeg);
400 strcpy(&job->edl_path[0], xml_filename);
401 Asset *asset = job->asset;
403 asset->layers = DVD_STREAMS;
404 asset->frame_rate = session->frame_rate;
405 asset->width = session->output_w;
406 asset->height = session->output_h;
407 asset->aspect_ratio = session->aspect_w / session->aspect_h;
410 char option_path[BCTEXTLEN];
411 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
412 asset->format = FILE_FFMPEG;
413 strcpy(asset->fformat, "dvd");
414 // if there are many renderfarm jobs, then there are small audio fragments of
415 // silence that are used at the end of a render to fill the last audio "block".
416 // this extra data gradually skews the audio/video sync. Therefore, the audio
417 // is not rendered muxed for ffmpeg, and is remuxed as with mjpeg rendering.
418 // since this audio is in one file, the only fragment is at the end and is ok.
420 asset->audio_data = 1;
421 asset->channels = session->audio_channels;
422 asset->sample_rate = session->sample_rate;
423 strcpy(asset->acodec, "dvd.dvd");
424 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
425 FFMPEG::load_options(option_path, asset->ff_audio_options,
426 sizeof(asset->ff_audio_options));
427 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
429 asset->video_data = 1;
430 strcpy(asset->vcodec, "dvd.dvd");
431 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
432 FFMPEG::load_options(option_path, asset->ff_video_options,
433 sizeof(asset->ff_video_options));
434 asset->ff_video_bitrate = vid_bitrate;
435 asset->ff_video_quality = -1;
436 use_farmed = job->farmed;
438 asset->video_data = 1;
439 strcpy(asset->vcodec, "raw.dvd");
440 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
441 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
442 FFMPEG::load_options(option_path, asset->ff_video_options,
443 sizeof(asset->ff_video_options));
444 asset->ff_video_bitrate = vid_bitrate;
445 asset->ff_video_quality = -1;
446 use_farmed = job->farmed;
448 job = new BatchRenderJob(mwindow->preferences, 0, 0);
450 strcpy(&job->edl_path[0], xml_filename);
452 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
453 asset->format = FILE_AC3;
454 asset->audio_data = 1;
455 asset->channels = session->audio_channels;
456 asset->sample_rate = session->sample_rate;
457 asset->ac3_bitrate = dvd_kaudio_rate;
461 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
462 asset->video_data = 1;
463 asset->format = FILE_VMPEG;
464 asset->vmpeg_cmodel = BC_YUV420P;
465 asset->vmpeg_fix_bitrate = 1;
466 asset->vmpeg_bitrate = vid_bitrate;
467 asset->vmpeg_quantization = 15;
468 asset->vmpeg_iframe_distance = 15;
469 asset->vmpeg_progressive = 0;
470 asset->vmpeg_denoise = 0;
471 asset->vmpeg_seq_codes = 0;
472 asset->vmpeg_derivative = 2;
473 asset->vmpeg_preset = 8;
474 asset->vmpeg_field_order = 0;
475 asset->vmpeg_pframe_distance = 0;
476 use_farmed = job->farmed;
477 job = new BatchRenderJob(mwindow->preferences, 0, 0);
479 strcpy(&job->edl_path[0], xml_filename);
482 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
483 asset->audio_data = 1;
484 asset->format = FILE_AC3;
485 asset->channels = session->audio_channels;
486 asset->sample_rate = session->sample_rate;
488 asset->byte_order = 0;
492 asset->ac3_bitrate = dvd_kaudio_rate;
498 void CreateDVD_Thread::handle_close_event(int result)
501 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
502 mwindow->batch_render->load_defaults(mwindow->defaults);
503 mwindow->undo->update_undo_before();
504 KeyFrame keyframe; char data[BCTEXTLEN];
505 if( use_deinterlace ) {
506 sprintf(data,"<DEINTERLACE MODE=1>");
507 keyframe.set_data(data);
508 insert_video_plugin("Deinterlace", &keyframe);
510 if( use_inverse_telecine ) {
511 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
512 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
513 keyframe.set_data(data);
514 insert_video_plugin("Inverse Telecine", &keyframe);
516 if( use_scale != Rescale::none ) {
517 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
519 Tracks *tracks = mwindow->edl->tracks;
520 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
521 if( vtrk->data_type != TRACK_VIDEO ) continue;
522 if( !vtrk->is_armed() ) continue;
523 vtrk->expand_view = 1;
524 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
525 vtrk->plugin_set.append(plugin_set);
526 Edits *edits = vtrk->edits;
527 for( Edit *edit=edits->first; edit; edit=edit->next ) {
528 Indexable *indexable = edit->get_source();
529 if( !indexable ) continue;
530 Rescale in(indexable);
531 Rescale out(dvd_width, dvd_height, dvd_aspect);
532 float src_w, src_h, dst_w, dst_h;
533 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
534 sprintf(data,"<SCALERATIO TYPE=%d"
535 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
536 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
537 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
538 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
539 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
540 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
541 keyframe.set_data(data);
542 plugin_set->insert_plugin(_("Scale Ratio"),
543 edit->startproject, edit->length,
544 PLUGIN_STANDALONE, 0, &keyframe, 0);
550 if( use_resize_tracks )
552 if( use_histogram ) {
554 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
555 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
556 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
557 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
558 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
559 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
560 "<POINTS><POINT X=6.0e-02 Y=0>"
561 "<POINT X=9.4e-01 Y=1></POINTS>");
563 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
564 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
565 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
566 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
567 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
568 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
571 keyframe.set_data(data);
572 insert_video_plugin("Histogram", &keyframe);
574 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
575 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
576 snprintf(jobs_path, sizeof(jobs_path), "%s/dvd.jobs", asset_dir);
577 mwindow->batch_render->reset(jobs_path);
578 int ret = create_dvd_jobs(&mwindow->batch_render->jobs, asset_dir);
579 mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
580 mwindow->resync_guis();
582 mwindow->batch_render->save_jobs();
583 mwindow->batch_render->start(-use_farmed, -use_labeled);
586 BC_Window* CreateDVD_Thread::new_gui()
588 strcpy(tmp_path,"/tmp");
589 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
590 memset(asset_title,0,sizeof(asset_title));
591 time_t dt; time(&dt);
592 struct tm dtm; localtime_r(&dt, &dtm);
593 sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
594 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
595 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
597 use_scale = Rescale::none;
599 use_inverse_telecine = 0;
602 use_resize_tracks = 0;
605 use_standard = DVD_NTSC_4x3;
608 dvd_width = DVD_WIDTH;
609 dvd_height = DVD_HEIGHT;
610 dvd_aspect_width = DVD_ASPECT_WIDTH;
611 dvd_aspect_height = DVD_ASPECT_HEIGHT;
612 dvd_framerate = DVD_FRAMERATE;
613 dvd_samplerate = DVD_SAMPLERATE;
614 dvd_max_bitrate = DVD_MAX_BITRATE;
615 dvd_kaudio_rate = DVD_KAUDIO_RATE;
616 max_w = 0; max_h = 0;
618 int has_standard = -1;
620 EDLSession *session = mwindow->edl->session;
621 double framerate = session->frame_rate;
622 double aspect_ratio = session->aspect_h > 0 ?
623 session->aspect_w / session->aspect_h > 0 : 1;
624 int output_w = session->output_w, output_h = session->output_h;
625 // match the session to any known standard
626 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
627 int norm = dvd_formats[i].norm;
628 if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
629 if( output_w != dvd_norms[norm].w ) continue;
630 if( output_h != dvd_norms[norm].h ) continue;
631 int aspect = dvd_formats[i].aspect;
632 double dvd_aspect_ratio =
633 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
634 if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
635 has_standard = i; break;
637 if( has_standard < 0 ) {
638 // or use the default standard
639 if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
640 else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
643 if( has_standard >= 0 )
644 use_standard = has_standard;
647 int scr_x = mwindow->gui->get_screen_x(0, -1);
648 int scr_w = mwindow->gui->get_screen_w(0, -1);
649 int scr_h = mwindow->gui->get_screen_h(0, -1);
650 int w = xS(560), h = yS(280);
651 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
653 gui = new CreateDVD_GUI(this, x, y, w, h);
654 gui->create_objects();
659 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
663 set_tooltip(_("end setup, start batch render"));
666 CreateDVD_OK::~CreateDVD_OK()
670 int CreateDVD_OK::button_press_event()
672 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
679 int CreateDVD_OK::keypress_event()
681 return context_help_check_and_show();
685 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
686 : BC_CancelButton(x, y)
691 CreateDVD_Cancel::~CreateDVD_Cancel()
695 int CreateDVD_Cancel::button_press_event()
697 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
705 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
706 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
711 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
715 int64_t CreateDVD_DiskSpace::tmp_path_space()
717 const char *path = gui->thread->tmp_path;
718 if( access(path,R_OK+W_OK) ) return 0;
720 if( statfs(path, &sfs) ) return 0;
721 return (int64_t)sfs.f_bsize * sfs.f_bfree;
724 void CreateDVD_DiskSpace::update()
726 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
727 int64_t disk_space = tmp_path_space();
728 double media_size = 15e9, msz = 0, m = 1;
730 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
731 int i = sizeof(suffix)/sizeof(suffix[0]);
732 while( --i >= 0 && strcmp(sfx, suffix[i]) );
733 while( --i >= 0 ) m *= 1000;
734 media_size = msz * m;
736 m = gui->thread->use_ffmpeg ? 2 : 3;
737 int color = disk_space < media_size*m ? RED : GREEN;
739 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
740 char text[BCTEXTLEN];
741 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
742 gui->disk_space->BC_Title::update(text);
743 gui->disk_space->set_color(color);
746 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
747 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
748 gui->thread->tmp_path, 1, MEDIUMFONT)
753 CreateDVD_TmpPath::~CreateDVD_TmpPath()
757 int CreateDVD_TmpPath::handle_event()
760 gui->disk_space->update();
765 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
766 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
767 gui->thread->asset_title, 1, MEDIUMFONT)
772 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
776 int CreateDVD_AssetTitle::handle_event()
783 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
784 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
789 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
793 int CreateDVD_Deinterlace::handle_event()
796 gui->need_inverse_telecine->set_value(0);
797 gui->thread->use_inverse_telecine = 0;
799 return BC_CheckBox::handle_event();
803 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
804 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
809 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
813 int CreateDVD_InverseTelecine::handle_event()
816 gui->need_deinterlace->set_value(0);
817 gui->thread->use_deinterlace = 0;
819 return BC_CheckBox::handle_event();
823 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
824 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
829 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
834 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
835 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
840 CreateDVD_Histogram::~CreateDVD_Histogram()
844 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
845 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
850 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
854 CreateDVD_UseRenderFarm::CreateDVD_UseRenderFarm(CreateDVD_GUI *gui, int x, int y)
855 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
860 CreateDVD_UseRenderFarm::~CreateDVD_UseRenderFarm()
864 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
865 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
870 CreateDVD_WideAudio::~CreateDVD_WideAudio()
874 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
875 : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
880 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
887 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
888 : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
890 this->thread = thread;
891 at_x = at_y = tmp_x = tmp_y = 0;
892 ok_x = ok_y = ok_w = ok_h = 0;
893 cancel_x = cancel_y = cancel_w = cancel_h = 0;
900 need_deinterlace = 0;
901 need_inverse_telecine = 0;
902 need_resize_tracks = 0;
909 // *** CONTEXT_HELP ***
910 context_help_set_keyword("DVD and Bluray Creation");
913 CreateDVD_GUI::~CreateDVD_GUI()
917 void CreateDVD_GUI::create_objects()
919 int xs10 = xS(10), xs35 = xS(35), xs170 = xS(170);
920 int ys5 = yS(5), ys10 = yS(10);
921 lock_window("CreateDVD_GUI::create_objects");
922 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
923 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
924 int x = padx/2, y = pady/2;
925 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
926 add_subwindow(title);
927 at_x = x + title->get_w(); at_y = y;
928 asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
929 add_subwindow(asset_title);
930 y += title->get_h() + pady/2;
931 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
932 add_subwindow(title);
933 tmp_x = x + title->get_w(); tmp_y = y;
934 tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-xs35);
935 add_subwindow(tmp_path);
936 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
937 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
938 _("Work path"), _("Select a Work directory:"), 1);
939 add_subwindow(btmp_path);
940 y += title->get_h() + pady/2;
941 disk_space = new CreateDVD_DiskSpace(this, x, y);
942 add_subwindow(disk_space);
943 int x0 = get_w() - xs170;
944 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
945 add_subwindow(title);
946 int x1 = x0+title->get_w()+padx;
947 media_size = new CreateDVD_MediaSize(this, x1, y);
948 media_size->create_objects();
949 media_sizes.append(new BC_ListBoxItem("4.7GB"));
950 media_sizes.append(new BC_ListBoxItem("8.3GB"));
951 media_size->update_list(&media_sizes);
952 media_size->update(media_sizes[0]->get_text());
953 disk_space->update();
954 y += disk_space->get_h() + pady/2;
955 title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
956 add_subwindow(title);
957 standard = new CreateDVD_Format(this, title->get_w() + padx, y);
958 add_subwindow(standard);
959 standard->create_objects();
961 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
962 add_subwindow(title);
963 x1 = x0+title->get_w()+padx;
964 scale = new CreateDVD_Scale(this, x1, y);
965 add_subwindow(scale);
966 scale->create_objects();
967 y += standard->get_h() + pady/2;
969 need_deinterlace = new CreateDVD_Deinterlace(this, x1, y);
970 add_subwindow(need_deinterlace);
971 y += need_deinterlace->get_h() + pady/2;
972 need_histogram = new CreateDVD_Histogram(this, x, y);
973 add_subwindow(need_histogram);
975 need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
976 add_subwindow(need_inverse_telecine);
977 y += need_inverse_telecine->get_h() + pady/2;
978 need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
979 add_subwindow(need_wide_audio);
980 y += need_wide_audio->get_h() + pady/2;
981 need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x1, y);
982 add_subwindow(need_use_ffmpeg);
983 y += need_use_ffmpeg->get_h() + pady/2;
984 need_resize_tracks = new CreateDVD_ResizeTracks(this, x1, y);
985 add_subwindow(need_resize_tracks);
987 need_labeled = new CreateDVD_LabelChapters(this, x1, y);
988 add_subwindow(need_labeled);
989 y += need_labeled->get_h() + pady/2;
990 need_farmed = new CreateDVD_UseRenderFarm(this, x1, y);
991 add_subwindow(need_farmed);
992 ok_w = BC_OKButton::calculate_w();
993 ok_h = BC_OKButton::calculate_h();
995 ok_y = get_h() - ok_h - ys10;
996 ok = new CreateDVD_OK(this, ok_x, ok_y);
998 cancel_w = BC_CancelButton::calculate_w();
999 cancel_h = BC_CancelButton::calculate_h();
1000 cancel_x = get_w() - cancel_w - xs10,
1001 cancel_y = get_h() - cancel_h - ys10;
1002 cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
1003 add_subwindow(cancel);
1008 int CreateDVD_GUI::resize_event(int w, int h)
1010 int xs10 = xS(10), xs35 = xS(35);
1012 asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
1013 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-xs35);
1014 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
1015 ok_y = h - ok_h - ys10;
1016 ok->reposition_window(ok_x, ok_y);
1017 cancel_x = w - cancel_w - xs10,
1018 cancel_y = h - cancel_h - ys10;
1019 cancel->reposition_window(cancel_x, cancel_y);
1023 int CreateDVD_GUI::translation_event()
1028 int CreateDVD_GUI::close_event()
1034 void CreateDVD_GUI::update()
1036 scale->set_value(thread->use_scale);
1037 need_deinterlace->set_value(thread->use_deinterlace);
1038 need_inverse_telecine->set_value(thread->use_inverse_telecine);
1039 need_use_ffmpeg->set_value(thread->use_ffmpeg);
1040 need_resize_tracks->set_value(thread->use_resize_tracks);
1041 need_histogram->set_value(thread->use_histogram);
1042 need_wide_audio->set_value(thread->use_wide_audio);
1043 need_labeled->set_value(thread->use_labeled);
1044 need_farmed->set_value(thread->use_farmed);
1047 int CreateDVD_Thread::
1048 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
1050 Tracks *tracks = mwindow->edl->tracks;
1051 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1052 if( vtrk->data_type != TRACK_VIDEO ) continue;
1053 if( !vtrk->is_armed() ) continue;
1054 vtrk->expand_view = 1;
1055 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
1056 vtrk->plugin_set.append(plugin_set);
1057 Edits *edits = vtrk->edits;
1058 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1059 plugin_set->insert_plugin(_(title),
1060 edit->startproject, edit->length,
1061 PLUGIN_STANDALONE, 0, default_keyframe, 0);
1068 int CreateDVD_Thread::
1071 Tracks *tracks = mwindow->edl->tracks;
1072 int trk_w = max_w, trk_h = max_h;
1073 if( trk_w < dvd_width ) trk_w = dvd_width;
1074 if( trk_h < dvd_height ) trk_h = dvd_height;
1075 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1076 if( vtrk->data_type != TRACK_VIDEO ) continue;
1077 if( !vtrk->is_armed() ) continue;
1078 vtrk->track_w = trk_w;
1079 vtrk->track_h = trk_h;
1084 int CreateDVD_Thread::
1087 // reset only probed options
1088 use_deinterlace = 0;
1089 use_scale = Rescale::none;
1090 use_resize_tracks = 0;
1095 if( !mwindow->edl ) return 1;
1097 int norm = dvd_formats[use_standard].norm;
1098 dvd_width = dvd_norms[norm].w;
1099 dvd_height = dvd_norms[norm].h;
1100 dvd_framerate = dvd_norms[norm].framerate;
1101 int aspect = dvd_formats[use_standard].aspect;
1102 dvd_aspect_width = dvd_aspects[aspect].w;
1103 dvd_aspect_height = dvd_aspects[aspect].h;
1104 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
1106 Tracks *tracks = mwindow->edl->tracks;
1107 max_w = 0; max_h = 0;
1108 int has_deinterlace = 0, has_scale = 0;
1109 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1110 if( !trk->is_armed() ) continue;
1111 Edits *edits = trk->edits;
1112 switch( trk->data_type ) {
1114 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1115 if( edit->silence() ) continue;
1116 Indexable *indexable = edit->get_source();
1117 int w = indexable->get_w();
1118 if( w > max_w ) max_w = w;
1119 if( w != dvd_width ) use_scale = Rescale::scaled;
1120 int h = indexable->get_h();
1121 if( h > max_h ) max_h = h;
1122 if( h != dvd_height ) use_scale = Rescale::scaled;
1124 MWindow::create_aspect_ratio(aw, ah, w, h);
1125 double aspect = ah > 0 ? aw / ah : 1;
1126 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
1128 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1129 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1130 plugin; plugin=(Plugin*)plugin->next ) {
1131 if( !strcmp(plugin->title, "Deinterlace") )
1132 has_deinterlace = 1;
1133 if( !strcmp(plugin->title, "Auto Scale") ||
1134 !strcmp(plugin->title, "Scale Ratio") ||
1135 !strcmp(plugin->title, "Scale") )
1143 use_scale = Rescale::none;
1144 if( use_scale != Rescale::none ) {
1145 if( max_w != dvd_width ) use_resize_tracks = 1;
1146 if( max_h != dvd_height ) use_resize_tracks = 1;
1148 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1149 if( !trk->is_armed() ) continue;
1150 switch( trk->data_type ) {
1152 if( trk->track_w != max_w ) use_resize_tracks = 1;
1153 if( trk->track_h != max_h ) use_resize_tracks = 1;
1157 if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
1158 Labels *labels = mwindow->edl->labels;
1159 use_labeled = labels && labels->first ? 1 : 0;
1161 if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
1164 use_farmed = mwindow->preferences->use_renderfarm;
1170 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
1171 int standard, const char *text)
1174 this->popup = popup;
1175 this->standard = standard;
1178 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1182 int CreateDVD_FormatItem::handle_event()
1184 popup->set_text(get_text());
1185 popup->gui->thread->use_standard = standard;
1186 return popup->handle_event();
1190 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1191 : BC_PopupMenu(x, y, xS(180), "", 1)
1196 CreateDVD_Format::~CreateDVD_Format()
1200 void CreateDVD_Format::create_objects()
1202 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1203 int norm = dvd_formats[i].norm;
1204 int aspect = dvd_formats[i].aspect;
1205 char item_text[BCTEXTLEN];
1206 sprintf(item_text,"%4s (%5.2f) %dx%d",
1207 dvd_norms[norm].name, dvd_norms[norm].framerate,
1208 dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1209 add_item(new CreateDVD_FormatItem(this, i, item_text));
1211 set_value(gui->thread->use_standard);
1214 int CreateDVD_Format::handle_event()
1216 gui->thread->option_presets();
1222 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1223 int scale, const char *text)
1226 this->popup = popup;
1227 this->scale = scale;
1230 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1234 int CreateDVD_ScaleItem::handle_event()
1236 popup->gui->thread->use_scale = scale;
1237 popup->set_value(scale);
1238 return popup->handle_event();
1242 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1243 : BC_PopupMenu(x, y, xS(140), "", 1)
1248 CreateDVD_Scale::~CreateDVD_Scale()
1252 void CreateDVD_Scale::create_objects()
1255 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1256 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1258 set_value(gui->thread->use_scale);
1261 int CreateDVD_Scale::handle_event()
1268 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1269 : BC_PopupTextBox(gui, 0, 0, x, y, xS(70), 50)
1274 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1278 int CreateDVD_MediaSize::handle_event()
1280 gui->disk_space->update();