8 #include "edlsession.h"
11 #include "interlacemodes.h"
13 #include "mainerror.h"
16 #include "mwindowgui.h"
18 #include "pluginset.h"
19 #include "preferences.h"
27 #if !defined(__FreeBSD__)
29 #include <sys/statfs.h>
31 #include <sys/param.h>
32 #include <sys/mount.h>
37 // selected by timezone
38 #define BD_1920x1080_2997i 0
39 #define BD_1920x1080_25i 3
41 static struct bd_format {
47 // framerates are frames, not fields, per second, *=not standard
48 { "1920x1080 29.97i", 1920,1080, 29.97, 1, ILACE_MODE_TOP_FIRST },
49 { "1920x1080 29.97p*", 1920,1080, 29.97, 1, ILACE_MODE_FAKE_INTERLACE },
50 { "1920x1080 24p", 1920,1080, 24., 1, ILACE_MODE_NOTINTERLACED },
51 { "1920x1080 25i", 1920,1080, 25., 1, ILACE_MODE_TOP_FIRST },
52 { "1920x1080 25p*", 1920,1080, 25., 1, ILACE_MODE_FAKE_INTERLACE },
53 { "1920x1080 23.976p", 1920,1080, 23.976, 1, ILACE_MODE_NOTINTERLACED },
54 { "1440x1080 29.97i", 1440,1080, 29.97, -1, ILACE_MODE_TOP_FIRST },
55 { "1440x1080 25i", 1440,1080, 25., -1, ILACE_MODE_TOP_FIRST },
56 { "1440x1080 24p", 1440,1080, 24., -1, ILACE_MODE_NOTINTERLACED },
57 { "1440x1080 23.976p", 1440,1080, 23.976,-1, ILACE_MODE_NOTINTERLACED },
58 { "1280x720 59.94p", 1280,720, 59.94, 1, ILACE_MODE_NOTINTERLACED },
59 { "1280x720 50p", 1280,720, 50., 1, ILACE_MODE_NOTINTERLACED },
60 { "1280x720 29.97p*", 1280,720, 29.97, 1, ILACE_MODE_NOTINTERLACED },
61 { "1280x720 25p*", 1280,720, 25., 1, ILACE_MODE_NOTINTERLACED },
62 { "1280x720 24p", 1280,720, 24., 1, ILACE_MODE_NOTINTERLACED },
63 { "1280x720 23.976p", 1280,720, 23.976, 1, ILACE_MODE_NOTINTERLACED },
64 { "720x576 25i", 720,576, 25., 0, ILACE_MODE_BOTTOM_FIRST },
65 { "720x576 25p*", 720,576, 25., 0, ILACE_MODE_NOTINTERLACED },
66 { "720x480 29.97i", 720,480, 29.97, 0, ILACE_MODE_BOTTOM_FIRST },
67 { "720x480 29.97p*", 720,480, 29.97, 0, ILACE_MODE_NOTINTERLACED },
70 static struct bd_profile {
78 const int64_t CreateBD_Thread::BD_SIZE = 25000000000;
79 const int CreateBD_Thread::BD_STREAMS = 1;
80 const int CreateBD_Thread::BD_WIDTH = 1920;
81 const int CreateBD_Thread::BD_HEIGHT = 1080;
82 const double CreateBD_Thread::BD_WIDE_ASPECT_WIDTH = 16.;
83 const double CreateBD_Thread::BD_WIDE_ASPECT_HEIGHT = 9.;
84 const double CreateBD_Thread::BD_ASPECT_WIDTH = 4.;
85 const double CreateBD_Thread::BD_ASPECT_HEIGHT = 3.;
86 const double CreateBD_Thread::BD_FRAMERATE = 24000. / 1001.;
87 //const int CreateBD_Thread::BD_MAX_BITRATE = 40000000;
88 const int CreateBD_Thread::BD_MAX_BITRATE = 10000000;
89 const int CreateBD_Thread::BD_CHANNELS = 2;
90 const int CreateBD_Thread::BD_WIDE_CHANNELS = 6;
91 const double CreateBD_Thread::BD_SAMPLERATE = 48000;
92 const double CreateBD_Thread::BD_KAUDIO_RATE = 192;
93 const int CreateBD_Thread::BD_INTERLACE_MODE = ILACE_MODE_NOTINTERLACED;
95 CreateBD_MenuItem::CreateBD_MenuItem(MWindow *mwindow)
96 : BC_MenuItem(_("BD Render..."), _("Ctrl-Shift-D"), 'D')
100 this->mwindow = mwindow;
103 int CreateBD_MenuItem::handle_event()
105 mwindow->create_bd->start();
109 BD_BatchRenderJob::BD_BatchRenderJob(Preferences *preferences, int labeled, int farmed)
110 : BatchRenderJob("BD_JOB", preferences, labeled, farmed)
114 int BD_BatchRenderJob::get_udfs_mount(char *udfs, char *mopts, char *mntpt)
117 // default: mount -t udf -o loop $dir/bd.udfs $dir/udfs
118 strcpy(udfs,"$dir/bd.udfs");
119 strcpy(mopts,"-t udf -o loop $dir/bd.udfs ");
120 strcpy(mntpt,"$dir/udfs");
121 const char *home = getenv("HOME");
122 if( !home ) return ret;
123 FILE *fp = fopen("/etc/fstab","r");
124 if( !fp ) return ret;
125 int len = strlen(home);
126 char line[BCTEXTLEN], typ[BCTEXTLEN], file[BCTEXTLEN];
127 char mpnt[BCTEXTLEN], opts[BCTEXTLEN];
128 while( fgets(line,sizeof(line),fp) ) {
129 // search "/etc/fstab" for: $HOME/img_file $HOME/bluray udf noauto,loop,rw,user
130 if( line[0] == '#' || line[0] == ';' ) continue;
131 if( sscanf(line,"%s %s %s %s ", &file[0], &mpnt[0], &typ[0], &opts[0]) != 4 )
133 if( strcmp("udf", typ) ) continue;
134 if( strncmp(home, file, len) || file[len] != '/' ) continue;
135 if( strncmp(home, mpnt, len) ) continue;
136 if( strcmp(&mpnt[len], "/bluray") ) continue;
137 int loop = 0, user = 0, rw = 0, noauto = 0;
138 char *op = opts, *ep = op + sizeof(opts)-1;
139 while( op < ep && *op ) {
140 char opt[BCTEXTLEN], *cp = opt;
141 while( op < ep && *op && (*cp=*op++)!=',' ) ++cp;
143 if( !strcmp("loop", opt) ) loop = 1;
144 else if( !strcmp("user", opt) ) user = 1;
145 else if( !strcmp("noauto", opt) ) noauto = 1;
146 else if( !strcmp("rw", opt) ) rw = 1;
148 if( loop && user && rw && noauto ) {
162 char *BD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
164 char script[BCTEXTLEN];
165 strcpy(script, edl_path);
168 char *bp = strrchr(script,'/');
171 strcpy(bp, "/bd.sh");
172 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
175 fp = fdopen(fd, "w");
177 char err[BCTEXTLEN], msg[BCTEXTLEN];
178 strerror_r(errno, err, sizeof(err));
179 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
180 MainError::show_error(msg);
183 char udfs[BCTEXTLEN], mopts[BCTEXTLEN], mntpt[BCTEXTLEN];
184 int is_usr_mnt = get_udfs_mount(udfs, mopts, mntpt);
185 const char *exec_path = File::get_cinlib_path();
186 fprintf(fp,"#!/bin/bash -ex\n");
187 fprintf(fp,"sdir=`dirname $0`\n");
188 fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
189 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
190 fprintf(fp,"mkdir -p $dir/udfs\n");
191 fprintf(fp,"sz=`du -cb $dir/bd.m2ts* | tail -1 | sed -e 's/[ ].*//'`\n");
192 fprintf(fp,"blks=$((sz/2048 + 4096))\n");
193 fprintf(fp,"rm -f %s\n", udfs);
194 fprintf(fp,"if [ -f bd.meta ]; then\n");
195 fprintf(fp,"tsmuxer bd.meta $dir/bd.iso \n");
196 fprintf(fp,"mv $dir/bd.iso $dir/bd.udfs\n");
197 fprintf(fp,"else\n");
198 fprintf(fp,"mkudffs -b 2048 %s $blks\n", udfs);
199 fprintf(fp,"mount %s%s\n", mopts, mntpt);
200 fprintf(fp,"bdwrite %s $dir/bd.m2ts*\n",mntpt);
201 fprintf(fp,"umount %s\n",mntpt);
204 fprintf(fp,"mv -f %s $dir/bd.udfs\n", udfs);
205 fprintf(fp,"echo To burn bluray, load writable media and run:\n");
206 fprintf(fp,"echo for WORM: growisofs -dvd-compat -Z /dev/bd=$dir/bd.udfs\n");
207 fprintf(fp,"echo for RW: dd if=$dir/bd.udfs of=/dev/bd bs=2048000\n");
208 fprintf(fp,"kill $$\n");
211 return cstrdup(script);
215 CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
218 this->mwindow = mwindow;
220 this->use_deinterlace = 0;
221 this->use_scale = Rescale::none;
222 this->use_histogram = 0;
223 this->use_inverse_telecine = 0;
224 this->use_wide_audio = 0;
225 this->use_resize_tracks = 0;
226 this->use_labeled = 0;
227 this->use_farmed = 0;
228 this->use_tsmuxer = 0;
230 strcpy(use_profile,"bluray.m2ts");
232 this->bd_size = BD_SIZE;
233 this->bd_width = BD_WIDTH;
234 this->bd_height = BD_HEIGHT;
235 this->bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
236 this->bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
237 this->bd_framerate = BD_FRAMERATE;
238 this->bd_samplerate = BD_SAMPLERATE;
239 this->bd_max_bitrate = BD_MAX_BITRATE;
240 this->bd_kaudio_rate = BD_KAUDIO_RATE;
241 this->max_w = this->max_h = 0;
242 this->batchrender = 0;
245 CreateBD_Thread::~CreateBD_Thread()
250 int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
252 EDL *edl = mwindow->edl;
253 if( !edl || !edl->session ) {
255 sprintf(msg, _("No EDL/Session"));
256 MainError::show_error(msg);
259 EDLSession *session = edl->session;
261 double total_length = edl->tracks->total_length();
262 if( total_length <= 0 ) {
264 sprintf(msg, _("No content: %s"), asset_title);
265 MainError::show_error(msg);
269 if( mkdir(asset_dir, 0777) ) {
270 char err[BCTEXTLEN], msg[BCTEXTLEN];
271 strerror_r(errno, err, sizeof(err));
272 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
273 MainError::show_error(msg);
277 double old_samplerate = session->sample_rate;
278 double old_framerate = session->frame_rate;
280 session->video_channels = BD_STREAMS;
281 session->video_tracks = BD_STREAMS;
282 session->frame_rate = bd_framerate;
283 session->output_w = bd_width;
284 session->output_h = bd_height;
285 session->aspect_w = bd_aspect_width;
286 session->aspect_h = bd_aspect_height;
287 session->sample_rate = bd_samplerate;
288 session->audio_channels = session->audio_tracks =
289 use_wide_audio ? BD_WIDE_CHANNELS : BD_CHANNELS;
290 session->interlace_mode = bd_interlace_mode;
292 session->audio_channels = session->audio_tracks =
293 !use_wide_audio ? BD_CHANNELS : BD_WIDE_CHANNELS;
294 for( int i=0; i<MAX_CHANNELS; ++i )
295 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
296 int audio_mapping = edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS &&
297 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
298 mwindow->remap_audio(audio_mapping);
300 double new_samplerate = session->sample_rate;
301 double new_framerate = session->frame_rate;
304 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
305 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
307 int64_t aud_size = ((bd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
308 int64_t vid_size = bd_size*0.96 - aud_size;
309 int64_t vid_bitrate = (vid_size * 8) / total_length;
310 vid_bitrate /= 1000; vid_bitrate *= 1000;
311 if( vid_bitrate > bd_max_bitrate ) vid_bitrate = bd_max_bitrate;
313 char xml_filename[BCTEXTLEN];
314 sprintf(xml_filename, "%s/bd.xml", asset_dir);
316 edl->save_xml(&xml_file, xml_filename);
317 xml_file.terminate_string();
318 if( xml_file.write_to_file(xml_filename) ) {
320 sprintf(msg, _("Unable to save: %s"), xml_filename);
321 MainError::show_error(msg);
326 char meta_script[BCTEXTLEN];
327 strcpy(meta_script, "/");
330 char *bp = strrchr(meta_script,'/');
333 char script_filename[BCTEXTLEN];
334 sprintf(script_filename, "%s/bd.meta", asset_dir);
335 strcpy(bp, script_filename);
336 fd = open(meta_script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
339 fp = fdopen(fd, "w");
341 char err[BCTEXTLEN], msg[BCTEXTLEN];
342 strerror_r(errno, err, sizeof(err));
343 sprintf(msg, _("Unable to save: %s\n-- %s"), meta_script, err);
344 MainError::show_error(msg);
349 fprintf(fp,"MUXOPT --blu-ray --hdmv-descriptors\n");
350 fprintf(fp,"V_MPEG4/ISO/AVC, bd.m2ts, track=4113\n");
351 if(!strcmp(use_profile, "bluray.m2ts"))
352 fprintf(fp,"A_AC3, bd.m2ts, track=4352\n");
353 if(!strcmp(use_profile, "bluray_lpcm.m2ts"))
354 fprintf(fp,"A_LPCM, bd.m2ts, track=4352\n");
360 BatchRenderJob *job = new BD_BatchRenderJob(mwindow->preferences,
361 use_labeled, use_farmed);
363 strcpy(&job->edl_path[0], xml_filename);
364 Asset *asset = job->asset;
366 asset->layers = BD_STREAMS;
367 asset->frame_rate = session->frame_rate;
368 asset->width = session->output_w;
369 asset->height = session->output_h;
370 asset->aspect_ratio = session->aspect_w / session->aspect_h;
371 asset->interlace_mode = session->interlace_mode;
373 char option_path[BCTEXTLEN];
374 sprintf(&asset->path[0],"%s/bd.m2ts", asset_dir);
375 asset->format = FILE_FFMPEG;
376 strcpy(asset->fformat, "m2ts");
378 asset->audio_data = 1;
379 strcpy(asset->acodec, use_profile);
380 //mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
381 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
382 FFMPEG::load_options(option_path, asset->ff_audio_options,
383 sizeof(asset->ff_audio_options));
384 asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
386 asset->video_data = 1;
387 const char *vcodec = use_profile;
388 switch( asset->interlace_mode ) {
389 case ILACE_MODE_TOP_FIRST: vcodec = "bluray_tff.m2ts"; break;
390 case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts"; break;
391 case ILACE_MODE_FAKE_INTERLACE : vcodec = "bluray_fakeinterlace.m2ts"; break;
393 strcpy(asset->vcodec, vcodec);
394 //mwindow->defaults->get("DEFAULT_BLURAY_VCODEC", asset->vcodec);
395 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
396 FFMPEG::load_options(option_path, asset->ff_video_options,
397 sizeof(asset->ff_video_options));
398 asset->ff_video_bitrate = vid_bitrate;
399 asset->ff_video_quality = -1;
403 void CreateBD_Thread::handle_close_event(int result)
406 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
407 mwindow->batch_render->load_defaults(mwindow->defaults);
408 mwindow->undo->update_undo_before();
409 KeyFrame keyframe; char data[BCTEXTLEN];
410 if( use_deinterlace ) {
411 sprintf(data,"<DEINTERLACE MODE=1>");
412 keyframe.set_data(data);
413 insert_video_plugin("Deinterlace", &keyframe);
415 if( use_inverse_telecine ) {
416 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
417 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
418 keyframe.set_data(data);
419 insert_video_plugin("Inverse Telecine", &keyframe);
421 if( use_scale != Rescale::none ) {
422 double bd_aspect = bd_aspect_height > 0 ? bd_aspect_width / bd_aspect_height : 1;
424 Tracks *tracks = mwindow->edl->tracks;
425 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
426 if( vtrk->data_type != TRACK_VIDEO ) continue;
427 if( !vtrk->is_armed() ) continue;
428 vtrk->expand_view = 1;
429 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
430 vtrk->plugin_set.append(plugin_set);
431 Edits *edits = vtrk->edits;
432 for( Edit *edit=edits->first; edit; edit=edit->next ) {
433 Indexable *indexable = edit->get_source();
434 if( !indexable ) continue;
435 Rescale in(indexable);
436 Rescale out(bd_width, bd_height, bd_aspect);
437 float src_w, src_h, dst_w, dst_h;
438 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
439 sprintf(data,"<SCALERATIO TYPE=%d"
440 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
441 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
442 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
443 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
444 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
445 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
446 keyframe.set_data(data);
447 plugin_set->insert_plugin(_("Scale Ratio"),
448 edit->startproject, edit->length,
449 PLUGIN_STANDALONE, 0, &keyframe, 0);
454 if( use_resize_tracks )
456 if( use_histogram ) {
458 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
459 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
460 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
461 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
462 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
463 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
464 "<POINTS><POINT X=6.0e-02 Y=0>"
465 "<POINT X=9.4e-01 Y=1></POINTS>");
467 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
468 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
469 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
470 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
471 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
472 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
475 keyframe.set_data(data);
476 insert_video_plugin("Histogram", &keyframe);
479 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
480 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
481 snprintf(jobs_path, sizeof(jobs_path), "%s/bd.jobs", asset_dir);
482 //batchrender->tsmuxered = use_tsmuxer;
483 mwindow->batch_render->reset(jobs_path);
484 int ret = create_bd_jobs(&mwindow->batch_render->jobs, asset_dir);
485 mwindow->undo->update_undo_after(_("create bd"), LOAD_ALL);
486 mwindow->resync_guis();
488 mwindow->batch_render->save_jobs();
489 mwindow->batch_render->start(-use_farmed, -use_labeled);
492 BC_Window* CreateBD_Thread::new_gui()
494 strcpy(tmp_path, "/tmp");
495 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
496 memset(asset_title,0,sizeof(asset_title));
497 time_t dt; time(&dt);
498 struct tm dtm; localtime_r(&dt, &dtm);
499 sprintf(asset_title, "bd_%02d%02d%02d-%02d%02d%02d",
500 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
501 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
503 use_scale = Rescale::none;
505 use_inverse_telecine = 0;
507 use_resize_tracks = 0;
511 use_standard = !strcmp(mwindow->default_std(),"NTSC") ?
512 BD_1920x1080_2997i : BD_1920x1080_25i;
515 bd_height = BD_HEIGHT;
516 bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
517 bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
518 bd_framerate = BD_FRAMERATE;
519 bd_samplerate = BD_SAMPLERATE;
520 bd_max_bitrate = BD_MAX_BITRATE;
521 bd_kaudio_rate = BD_KAUDIO_RATE;
522 bd_interlace_mode = BD_INTERLACE_MODE;
523 max_w = 0; max_h = 0;
525 int has_standard = -1;
527 EDLSession *session = mwindow->edl->session;
528 // match the session to any known standard
529 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
530 if( !EQUIV(session->frame_rate, bd_formats[i].framerate) ) continue;
531 if( session->output_w != bd_formats[i].w ) continue;
532 if( session->output_h != bd_formats[i].h ) continue;
533 has_standard = i; break;
536 if( has_standard >= 0 )
537 use_standard = has_standard;
540 int scr_x = mwindow->gui->get_screen_x(0, -1);
541 int scr_w = mwindow->gui->get_screen_w(0, -1);
542 int scr_h = mwindow->gui->get_screen_h(0, -1);
543 int w = xS(560), h = yS(340);
544 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
546 gui = new CreateBD_GUI(this, x, y, w, h);
547 gui->create_objects();
549 if( getuid() != 0 ) {
550 mwindow->show_warning(
551 &mwindow->preferences->bd_warn_root,
552 _("Must be root to mount UDFS images\n"));
558 CreateBD_OK::CreateBD_OK(CreateBD_GUI *gui, int x, int y)
562 set_tooltip(_("end setup, start batch render"));
565 CreateBD_OK::~CreateBD_OK()
569 int CreateBD_OK::button_press_event()
571 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
578 int CreateBD_OK::keypress_event()
580 return context_help_check_and_show();
584 CreateBD_Cancel::CreateBD_Cancel(CreateBD_GUI *gui, int x, int y)
585 : BC_CancelButton(x, y)
590 CreateBD_Cancel::~CreateBD_Cancel()
594 int CreateBD_Cancel::button_press_event()
596 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
604 CreateBD_DiskSpace::CreateBD_DiskSpace(CreateBD_GUI *gui, int x, int y)
605 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
610 CreateBD_DiskSpace::~CreateBD_DiskSpace()
614 int64_t CreateBD_DiskSpace::tmp_path_space()
616 const char *path = gui->thread->tmp_path;
617 if( access(path,R_OK+W_OK) ) return 0;
619 if( statfs(path, &sfs) ) return 0;
620 return (int64_t)sfs.f_bsize * sfs.f_bfree;
623 void CreateBD_DiskSpace::update()
625 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
626 int64_t disk_space = tmp_path_space();
627 double media_size = 100e9, msz = 0, m = 1;
629 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
630 int i = sizeof(suffix)/sizeof(suffix[0]);
631 while( --i >= 0 && strcmp(sfx, suffix[i]) );
632 while( --i >= 0 ) m *= 1000;
633 media_size = msz * m;
635 int color = disk_space < media_size*2 ? RED : GREEN;
637 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
638 char text[BCTEXTLEN];
639 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
640 gui->disk_space->BC_Title::update(text);
641 gui->disk_space->set_color(color);
644 CreateBD_TmpPath::CreateBD_TmpPath(CreateBD_GUI *gui, int x, int y, int w)
645 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
646 gui->thread->tmp_path, 1, MEDIUMFONT)
651 CreateBD_TmpPath::~CreateBD_TmpPath()
655 int CreateBD_TmpPath::handle_event()
658 gui->disk_space->update();
663 CreateBD_AssetTitle::CreateBD_AssetTitle(CreateBD_GUI *gui, int x, int y, int w)
664 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
665 gui->thread->asset_title, 1, MEDIUMFONT)
670 CreateBD_AssetTitle::~CreateBD_AssetTitle()
674 int CreateBD_AssetTitle::handle_event()
680 CreateBD_Deinterlace::CreateBD_Deinterlace(CreateBD_GUI *gui, int x, int y)
681 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
686 CreateBD_Deinterlace::~CreateBD_Deinterlace()
690 int CreateBD_Deinterlace::handle_event()
693 gui->need_inverse_telecine->set_value(0);
694 gui->thread->use_inverse_telecine = 0;
696 return BC_CheckBox::handle_event();
700 CreateBD_InverseTelecine::CreateBD_InverseTelecine(CreateBD_GUI *gui, int x, int y)
701 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
706 CreateBD_InverseTelecine::~CreateBD_InverseTelecine()
710 int CreateBD_InverseTelecine::handle_event()
713 gui->need_deinterlace->set_value(0);
714 gui->thread->use_deinterlace = 0;
716 return BC_CheckBox::handle_event();
720 CreateBD_ResizeTracks::CreateBD_ResizeTracks(CreateBD_GUI *gui, int x, int y)
721 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
726 CreateBD_ResizeTracks::~CreateBD_ResizeTracks()
731 CreateBD_Histogram::CreateBD_Histogram(CreateBD_GUI *gui, int x, int y)
732 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
737 CreateBD_Histogram::~CreateBD_Histogram()
741 CreateBD_LabelChapters::CreateBD_LabelChapters(CreateBD_GUI *gui, int x, int y)
742 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
747 CreateBD_LabelChapters::~CreateBD_LabelChapters()
751 CreateBD_UseRenderFarm::CreateBD_UseRenderFarm(CreateBD_GUI *gui, int x, int y)
752 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
757 CreateBD_UseRenderFarm::~CreateBD_UseRenderFarm()
762 CreateBD_WideAudio::CreateBD_WideAudio(CreateBD_GUI *gui, int x, int y)
763 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
768 CreateBD_WideAudio::~CreateBD_WideAudio()
772 CreateBD_UseTsmuxer::CreateBD_UseTsmuxer(CreateBD_GUI *gui, int x, int y)
773 : BC_CheckBox(x, y, &gui->thread->use_tsmuxer, _("use tsmuxer"))
778 CreateBD_UseTsmuxer::~CreateBD_UseTsmuxer()
783 CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
784 : BC_Window(_(PROGRAM_NAME ": Create BD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
786 this->thread = thread;
787 at_x = at_y = tmp_x = tmp_y = 0;
788 ok_x = ok_y = ok_w = ok_h = 0;
789 cancel_x = cancel_y = cancel_w = cancel_h = 0;
797 need_deinterlace = 0;
798 need_inverse_telecine = 0;
799 need_resize_tracks = 0;
808 // *** CONTEXT_HELP ***
809 context_help_set_keyword("DVD and Bluray Creation");
812 CreateBD_GUI::~CreateBD_GUI()
816 void CreateBD_GUI::create_objects()
819 int xs10 = xS(10), xs35 = xS(35);
820 int xs60 = xS(60), xs160 = xS(160), xs170 = xS(170);
821 int ys5 = yS(5), ys10 = yS(10);
822 lock_window("CreateBD_GUI::create_objects");
823 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
824 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
825 int x = padx/2, y = pady/2;
826 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
827 add_subwindow(title);
828 at_x = x + title->get_w(); at_y = y;
829 asset_title = new CreateBD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
830 add_subwindow(asset_title);
831 y += title->get_h() + pady/2;
832 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
833 add_subwindow(title);
834 tmp_x = x + title->get_w(); tmp_y = y;
835 tmp_path = new CreateBD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-xs35);
836 add_subwindow(tmp_path);
837 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
838 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
839 _("Work path"), _("Select a Work directory:"), 1);
840 add_subwindow(btmp_path);
841 y += title->get_h() + pady/2;
842 disk_space = new CreateBD_DiskSpace(this, x, y);
843 add_subwindow(disk_space);
844 int x0 = get_w() - xs170;
845 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
846 add_subwindow(title);
847 int x1 = x0+title->get_w()+padx;
848 media_size = new CreateBD_MediaSize(this, x1, y);
849 media_size->create_objects();
850 media_sizes.append(new BC_ListBoxItem("25GB"));
851 media_sizes.append(new BC_ListBoxItem("50GB"));
852 media_size->update_list(&media_sizes);
853 media_size->update(media_sizes[0]->get_text());
854 disk_space->update();
855 y += disk_space->get_h() + pady/2;
857 title = new BC_Title(x, y, _("Profile:"), MEDIUMFONT, YELLOW);
858 add_subwindow(title);
860 x += title->get_w()+padx;
861 profile = new CreateBD_Profile(this, x, y);
862 profile->create_objects();
863 profiles.append(new BC_ListBoxItem("bluray.m2ts"));
864 profiles.append(new BC_ListBoxItem("bluray_lpcm.m2ts"));
865 /* profiles.append(new BC_ListBoxItem("bluray_truehd.m2ts")); */
866 profile->update_list(&profiles);
867 profile->update(profiles[0]->get_text());
869 x += profile->get_w()+padx;
870 need_tsmuxer = new CreateBD_UseTsmuxer(this, x, y);
871 add_subwindow(need_tsmuxer);
872 y += need_tsmuxer->get_h() + pady;
874 title = new BC_Title(start_x, y, _("Format:"), MEDIUMFONT, YELLOW);
875 add_subwindow(title);
876 standard = new CreateBD_Format(this, title->get_w() + padx, y);
877 add_subwindow(standard);
878 standard->create_objects();
879 standard->set_text(bd_formats[thread->use_standard].name);
881 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
882 add_subwindow(title);
883 x1 = x0+title->get_w()+padx;
884 scale = new CreateBD_Scale(this, x1, y);
885 add_subwindow(scale);
886 scale->create_objects();
887 y += standard->get_h() + pady/2;
889 need_deinterlace = new CreateBD_Deinterlace(this, start_x, y);
890 add_subwindow(need_deinterlace);
891 y += need_deinterlace->get_h() + pady/2;
892 need_histogram = new CreateBD_Histogram(this, start_x, y);
893 add_subwindow(need_histogram);
894 y += need_histogram->get_h() + pady/2;
895 non_standard = new BC_Title(x1, y+ys5, "", MEDIUMFONT, RED);
896 add_subwindow(non_standard);
898 need_inverse_telecine = new CreateBD_InverseTelecine(this, x1, y);
899 add_subwindow(need_inverse_telecine);
900 y += need_inverse_telecine->get_h() + pady/2;
901 need_wide_audio = new CreateBD_WideAudio(this, x1, y);
902 add_subwindow(need_wide_audio);
903 y += need_wide_audio->get_h() + pady/2;
904 need_resize_tracks = new CreateBD_ResizeTracks(this, x1, y);
905 add_subwindow(need_resize_tracks);
907 need_labeled = new CreateBD_LabelChapters(this, x1, y);
908 add_subwindow(need_labeled);
909 y += need_labeled->get_h() + pady/2;
910 need_farmed = new CreateBD_UseRenderFarm(this, x1, y);
911 add_subwindow(need_farmed);
912 ok_w = BC_OKButton::calculate_w();
913 ok_h = BC_OKButton::calculate_h();
915 ok_y = get_h() - ok_h - xs10;
916 ok = new CreateBD_OK(this, ok_x, ok_y);
918 cancel_w = BC_CancelButton::calculate_w();
919 cancel_h = BC_CancelButton::calculate_h();
920 cancel_x = get_w() - cancel_w - xs10,
921 cancel_y = get_h() - cancel_h - ys10;
922 cancel = new CreateBD_Cancel(this, cancel_x, cancel_y);
923 add_subwindow(cancel);
928 int CreateBD_GUI::resize_event(int w, int h)
930 int xs10 = xS(10), xs35 = xS(35);
932 asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
933 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-xs35);
934 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
935 ok_y = h - ok_h - ys10;
936 ok->reposition_window(ok_x, ok_y);
937 cancel_x = w - cancel_w - xs10,
938 cancel_y = h - cancel_h - ys10;
939 cancel->reposition_window(cancel_x, cancel_y);
943 int CreateBD_GUI::translation_event()
948 int CreateBD_GUI::close_event()
954 void CreateBD_GUI::update()
956 scale->set_value(thread->use_scale);
957 need_deinterlace->set_value(thread->use_deinterlace);
958 need_inverse_telecine->set_value(thread->use_inverse_telecine);
959 need_resize_tracks->set_value(thread->use_resize_tracks);
960 need_histogram->set_value(thread->use_histogram);
961 need_wide_audio->set_value(thread->use_wide_audio);
962 need_labeled->set_value(thread->use_labeled);
963 need_farmed->set_value(thread->use_farmed);
966 int CreateBD_Thread::
967 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
969 Tracks *tracks = mwindow->edl->tracks;
970 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
971 if( vtrk->data_type != TRACK_VIDEO ) continue;
972 if( !vtrk->is_armed() ) continue;
973 vtrk->expand_view = 1;
974 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
975 vtrk->plugin_set.append(plugin_set);
976 Edits *edits = vtrk->edits;
977 for( Edit *edit=edits->first; edit; edit=edit->next ) {
978 plugin_set->insert_plugin(_(title),
979 edit->startproject, edit->length,
980 PLUGIN_STANDALONE, 0, default_keyframe, 0);
987 int CreateBD_Thread::
990 Tracks *tracks = mwindow->edl->tracks;
991 int trk_w = max_w, trk_h = max_h;
992 if( trk_w < bd_width ) trk_w = bd_width;
993 if( trk_h < bd_height ) trk_h = bd_height;
994 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
995 if( vtrk->data_type != TRACK_VIDEO ) continue;
996 if( !vtrk->is_armed() ) continue;
997 vtrk->track_w = trk_w;
998 vtrk->track_h = trk_h;
1003 int CreateBD_Thread::
1006 // reset only probed options
1007 use_deinterlace = 0;
1008 use_scale = Rescale::none;
1009 use_resize_tracks = 0;
1014 if( !mwindow->edl ) return 1;
1016 bd_width = bd_formats[use_standard].w;
1017 bd_height = bd_formats[use_standard].h;
1018 bd_framerate = bd_formats[use_standard].framerate;
1019 int wide = bd_formats[use_standard].wide;
1020 bd_aspect_width = wide < 0 ? 1. :
1021 wide > 0 ? BD_WIDE_ASPECT_WIDTH : BD_ASPECT_WIDTH;
1022 bd_aspect_height = wide < 0 ? 1. :
1023 wide > 0 ? BD_WIDE_ASPECT_HEIGHT : BD_ASPECT_HEIGHT;
1024 bd_interlace_mode = bd_formats[use_standard].interlaced;
1025 double bd_aspect = bd_aspect_width / bd_aspect_height;
1027 Tracks *tracks = mwindow->edl->tracks;
1028 max_w = 0; max_h = 0;
1029 int has_deinterlace = 0, has_scale = 0;
1030 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1031 if( !trk->is_armed() ) continue;
1032 Edits *edits = trk->edits;
1033 switch( trk->data_type ) {
1035 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1036 if( edit->silence() ) continue;
1037 Indexable *indexable = edit->get_source();
1038 int w = indexable->get_w();
1039 if( w > max_w ) max_w = w;
1040 if( w != bd_width ) use_scale = Rescale::scaled;
1041 int h = indexable->get_h();
1042 if( h > max_h ) max_h = h;
1043 if( h != bd_height ) use_scale = Rescale::scaled;
1045 MWindow::create_aspect_ratio(aw, ah, w, h);
1046 double aspect = ah > 0 ? aw / ah : 1;
1047 if( wide >= 0 && !EQUIV(aspect, bd_aspect) )
1048 use_scale = Rescale::scaled;
1050 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1051 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1052 plugin; plugin=(Plugin*)plugin->next ) {
1053 if( !strcmp(plugin->title, "Deinterlace") )
1054 has_deinterlace = 1;
1055 if( !strcmp(plugin->title, "Auto Scale") ||
1056 !strcmp(plugin->title, "Scale Ratio") ||
1057 !strcmp(plugin->title, "Scale") )
1065 use_scale = Rescale::none;
1066 if( use_scale != Rescale::none ) {
1067 if( max_w != bd_width ) use_resize_tracks = 1;
1068 if( max_h != bd_height ) use_resize_tracks = 1;
1070 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1071 if( !trk->is_armed() ) continue;
1072 switch( trk->data_type ) {
1074 if( trk->track_w != max_w ) use_resize_tracks = 1;
1075 if( trk->track_h != max_h ) use_resize_tracks = 1;
1079 if( !has_deinterlace && max_h > 2*bd_height ) use_deinterlace = 1;
1081 if( tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
1088 CreateBD_FormatItem::CreateBD_FormatItem(CreateBD_Format *popup,
1089 int standard, const char *name)
1092 this->popup = popup;
1093 this->standard = standard;
1096 CreateBD_FormatItem::~CreateBD_FormatItem()
1100 int CreateBD_FormatItem::handle_event()
1102 const char *text = get_text();
1103 int standard = this->standard;
1104 if( standard < 0 ) {
1105 BC_SubMenu *submenu = get_submenu();
1106 CreateBD_FormatItem *sub_item0 =
1107 (CreateBD_FormatItem *)submenu->get_item(0);
1108 standard = sub_item0->standard;
1109 text = sub_item0->get_text();
1111 popup->gui->thread->use_standard = standard;
1112 popup->set_text(text);
1113 int n = strlen(text)-1;
1114 int not_standard = n >= 0 && text[n] == '*' ? 1 : 0;
1115 popup->gui->non_standard->update(not_standard ? _("* non-standard format") : "", 0);
1116 return popup->handle_event();
1120 CreateBD_Format::CreateBD_Format(CreateBD_GUI *gui, int x, int y)
1121 : BC_PopupMenu(x, y, xS(200), bd_formats[gui->thread->use_standard].name, 1)
1126 CreateBD_Format::~CreateBD_Format()
1130 void CreateBD_Format::create_objects()
1132 BC_SubMenu *submenu = 0;
1133 CreateBD_FormatItem *item = 0;
1135 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
1136 if( ww != bd_formats[i].w || hh != bd_formats[i].h ) {
1137 ww = bd_formats[i].w; hh = bd_formats[i].h;
1138 char string[BCSTRLEN];
1139 sprintf(string, "%dx%d", ww,hh);
1140 add_item(item = new CreateBD_FormatItem(this, -1, string));
1141 item->add_submenu(submenu = new BC_SubMenu());
1143 submenu->add_submenuitem(new CreateBD_FormatItem(this, i, bd_formats[i].name));
1147 int CreateBD_Format::handle_event()
1149 gui->thread->option_presets();
1155 CreateBD_ScaleItem::CreateBD_ScaleItem(CreateBD_Scale *popup,
1156 int scale, const char *text)
1159 this->popup = popup;
1160 this->scale = scale;
1163 CreateBD_ScaleItem::~CreateBD_ScaleItem()
1167 int CreateBD_ScaleItem::handle_event()
1169 popup->gui->thread->use_scale = scale;
1170 popup->set_value(scale);
1171 return popup->handle_event();
1175 CreateBD_Scale::CreateBD_Scale(CreateBD_GUI *gui, int x, int y)
1176 : BC_PopupMenu(x, y, xS(140), "", 1)
1181 CreateBD_Scale::~CreateBD_Scale()
1185 void CreateBD_Scale::create_objects()
1188 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1189 add_item(new CreateBD_ScaleItem(this, i, Rescale::scale_types[i]));
1191 set_value(gui->thread->use_scale);
1194 int CreateBD_Scale::handle_event()
1201 CreateBD_MediaSize::CreateBD_MediaSize(CreateBD_GUI *gui, int x, int y)
1202 : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
1207 CreateBD_MediaSize::~CreateBD_MediaSize()
1211 int CreateBD_MediaSize::handle_event()
1213 gui->disk_space->update();
1217 CreateBD_Profile::CreateBD_Profile(CreateBD_GUI *gui, int x, int y)
1218 : BC_PopupTextBox(gui, 0, 0, x, y, xS(170),yS(50))
1223 CreateBD_Profile::~CreateBD_Profile()
1227 int CreateBD_Profile::handle_event()
1229 strcpy(gui->thread->use_profile, get_text());