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 $dir/bd.meta ]; then\n");
195 fprintf(fp,"sed -i \"s|bd.m2ts|$dir\/bd.m2ts|g\" $dir/bd.meta\n");
196 fprintf(fp,"tsmuxer $dir/bd.meta $dir/bd.iso \n");
197 fprintf(fp,"mv $dir/bd.iso $dir/bd.udfs\n");
198 fprintf(fp,"else\n");
199 fprintf(fp,"mkudffs -b 2048 %s $blks\n", udfs);
200 fprintf(fp,"mount %s%s\n", mopts, mntpt);
201 fprintf(fp,"bdwrite %s $dir/bd.m2ts*\n",mntpt);
202 fprintf(fp,"umount %s\n",mntpt);
205 fprintf(fp,"mv -f %s $dir/bd.udfs\n", udfs);
206 fprintf(fp,"echo To burn bluray, load writable media and run:\n");
207 fprintf(fp,"echo for WORM: growisofs -dvd-compat -Z /dev/bd=$dir/bd.udfs\n");
208 fprintf(fp,"echo for RW: dd if=$dir/bd.udfs of=/dev/bd bs=2048000\n");
209 fprintf(fp,"kill $$\n");
212 return cstrdup(script);
216 CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
219 this->mwindow = mwindow;
221 this->use_deinterlace = 0;
222 this->use_scale = Rescale::none;
223 this->use_histogram = 0;
224 this->use_inverse_telecine = 0;
225 this->use_wide_audio = 0;
226 this->use_resize_tracks = 0;
227 this->use_labeled = 0;
228 this->use_farmed = 0;
229 this->use_tsmuxer = 0;
231 strcpy(use_profile,"bluray.m2ts");
233 this->bd_size = BD_SIZE;
234 this->bd_width = BD_WIDTH;
235 this->bd_height = BD_HEIGHT;
236 this->bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
237 this->bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
238 this->bd_framerate = BD_FRAMERATE;
239 this->bd_samplerate = BD_SAMPLERATE;
240 this->bd_max_bitrate = BD_MAX_BITRATE;
241 this->bd_kaudio_rate = BD_KAUDIO_RATE;
242 this->max_w = this->max_h = 0;
243 this->batchrender = 0;
246 CreateBD_Thread::~CreateBD_Thread()
251 int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
253 EDL *edl = mwindow->edl;
254 if( !edl || !edl->session ) {
256 sprintf(msg, _("No EDL/Session"));
257 MainError::show_error(msg);
260 EDLSession *session = edl->session;
262 double total_length = edl->tracks->total_length();
263 if( total_length <= 0 ) {
265 sprintf(msg, _("No content: %s"), asset_title);
266 MainError::show_error(msg);
270 if( mkdir(asset_dir, 0777) ) {
271 char err[BCTEXTLEN], msg[BCTEXTLEN];
272 strerror_r(errno, err, sizeof(err));
273 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
274 MainError::show_error(msg);
278 double old_samplerate = session->sample_rate;
279 double old_framerate = session->frame_rate;
281 session->video_channels = BD_STREAMS;
282 session->video_tracks = BD_STREAMS;
283 session->frame_rate = bd_framerate;
284 session->output_w = bd_width;
285 session->output_h = bd_height;
286 session->aspect_w = bd_aspect_width;
287 session->aspect_h = bd_aspect_height;
288 session->sample_rate = bd_samplerate;
289 session->audio_channels = session->audio_tracks =
290 use_wide_audio ? BD_WIDE_CHANNELS : BD_CHANNELS;
291 session->interlace_mode = bd_interlace_mode;
293 session->audio_channels = session->audio_tracks =
294 !use_wide_audio ? BD_CHANNELS : BD_WIDE_CHANNELS;
295 for( int i=0; i<MAX_CHANNELS; ++i )
296 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
297 int audio_mapping = edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS &&
298 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
299 mwindow->remap_audio(audio_mapping);
301 double new_samplerate = session->sample_rate;
302 double new_framerate = session->frame_rate;
305 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
306 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
308 int64_t aud_size = ((bd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
309 int64_t vid_size = bd_size*0.96 - aud_size;
310 int64_t vid_bitrate = (vid_size * 8) / total_length;
311 vid_bitrate /= 1000; vid_bitrate *= 1000;
312 if( vid_bitrate > bd_max_bitrate ) vid_bitrate = bd_max_bitrate;
314 char xml_filename[BCTEXTLEN];
315 sprintf(xml_filename, "%s/bd.xml", asset_dir);
317 edl->save_xml(&xml_file, xml_filename);
318 xml_file.terminate_string();
319 if( xml_file.write_to_file(xml_filename) ) {
321 sprintf(msg, _("Unable to save: %s"), xml_filename);
322 MainError::show_error(msg);
327 char meta_script[BCTEXTLEN];
328 strcpy(meta_script, "/");
331 char *bp = strrchr(meta_script,'/');
334 char script_filename[BCTEXTLEN];
335 sprintf(script_filename, "%s/bd.meta", asset_dir);
336 strcpy(bp, script_filename);
337 fd = open(meta_script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
340 fp = fdopen(fd, "w");
342 char err[BCTEXTLEN], msg[BCTEXTLEN];
343 strerror_r(errno, err, sizeof(err));
344 sprintf(msg, _("Unable to save: %s\n-- %s"), meta_script, err);
345 MainError::show_error(msg);
350 fprintf(fp,"MUXOPT --blu-ray --hdmv-descriptors\n");
351 fprintf(fp,"V_MPEG4/ISO/AVC, bd.m2ts, track=4113\n");
352 if(!strcmp(use_profile, "bluray.m2ts"))
353 fprintf(fp,"A_AC3, bd.m2ts, track=4352\n");
354 if(!strcmp(use_profile, "bluray_lpcm.m2ts"))
355 fprintf(fp,"A_LPCM, bd.m2ts, track=4352\n");
361 BatchRenderJob *job = new BD_BatchRenderJob(mwindow->preferences,
362 use_labeled, use_farmed);
364 strcpy(&job->edl_path[0], xml_filename);
365 Asset *asset = job->asset;
367 asset->layers = BD_STREAMS;
368 asset->frame_rate = session->frame_rate;
369 asset->width = session->output_w;
370 asset->height = session->output_h;
371 asset->aspect_ratio = session->aspect_w / session->aspect_h;
372 asset->interlace_mode = session->interlace_mode;
374 char option_path[BCTEXTLEN];
375 sprintf(&asset->path[0],"%s/bd.m2ts", asset_dir);
376 asset->format = FILE_FFMPEG;
377 strcpy(asset->fformat, "m2ts");
379 asset->audio_data = 1;
380 strcpy(asset->acodec, use_profile);
381 //mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
382 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
383 FFMPEG::load_options(option_path, asset->ff_audio_options,
384 sizeof(asset->ff_audio_options));
385 asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
387 asset->video_data = 1;
388 const char *vcodec = use_profile;
389 switch( asset->interlace_mode ) {
390 case ILACE_MODE_TOP_FIRST: vcodec = "bluray_tff.m2ts"; break;
391 case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts"; break;
392 case ILACE_MODE_FAKE_INTERLACE : vcodec = "bluray_fakeinterlace.m2ts"; break;
394 strcpy(asset->vcodec, vcodec);
395 //mwindow->defaults->get("DEFAULT_BLURAY_VCODEC", asset->vcodec);
396 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
397 FFMPEG::load_options(option_path, asset->ff_video_options,
398 sizeof(asset->ff_video_options));
399 asset->ff_video_bitrate = vid_bitrate;
400 asset->ff_video_quality = -1;
404 void CreateBD_Thread::handle_close_event(int result)
407 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
408 mwindow->batch_render->load_defaults(mwindow->defaults);
409 mwindow->undo->update_undo_before();
410 KeyFrame keyframe; char data[BCTEXTLEN];
411 if( use_deinterlace ) {
412 sprintf(data,"<DEINTERLACE MODE=1>");
413 keyframe.set_data(data);
414 insert_video_plugin("Deinterlace", &keyframe);
416 if( use_inverse_telecine ) {
417 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
418 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
419 keyframe.set_data(data);
420 insert_video_plugin("Inverse Telecine", &keyframe);
422 if( use_scale != Rescale::none ) {
423 double bd_aspect = bd_aspect_height > 0 ? bd_aspect_width / bd_aspect_height : 1;
425 Tracks *tracks = mwindow->edl->tracks;
426 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
427 if( vtrk->data_type != TRACK_VIDEO ) continue;
428 if( !vtrk->is_armed() ) continue;
429 vtrk->expand_view = 1;
430 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
431 vtrk->plugin_set.append(plugin_set);
432 Edits *edits = vtrk->edits;
433 for( Edit *edit=edits->first; edit; edit=edit->next ) {
434 Indexable *indexable = edit->get_source();
435 if( !indexable ) continue;
436 Rescale in(indexable);
437 Rescale out(bd_width, bd_height, bd_aspect);
438 float src_w, src_h, dst_w, dst_h;
439 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
440 sprintf(data,"<SCALERATIO TYPE=%d"
441 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
442 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
443 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
444 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
445 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
446 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
447 keyframe.set_data(data);
448 plugin_set->insert_plugin(_("Scale Ratio"),
449 edit->startproject, edit->length,
450 PLUGIN_STANDALONE, 0, &keyframe, 0);
455 if( use_resize_tracks )
457 if( use_histogram ) {
459 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
460 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
461 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
462 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
463 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
464 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
465 "<POINTS><POINT X=6.0e-02 Y=0>"
466 "<POINT X=9.4e-01 Y=1></POINTS>");
468 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
469 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
470 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
471 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
472 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
473 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
476 keyframe.set_data(data);
477 insert_video_plugin("Histogram", &keyframe);
480 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
481 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
482 snprintf(jobs_path, sizeof(jobs_path), "%s/bd.jobs", asset_dir);
483 //batchrender->tsmuxered = use_tsmuxer;
484 mwindow->batch_render->reset(jobs_path);
485 int ret = create_bd_jobs(&mwindow->batch_render->jobs, asset_dir);
486 mwindow->undo->update_undo_after(_("create bd"), LOAD_ALL);
487 mwindow->resync_guis();
489 mwindow->batch_render->save_jobs();
490 mwindow->batch_render->start(-use_farmed, -use_labeled);
493 BC_Window* CreateBD_Thread::new_gui()
495 strcpy(tmp_path, "/tmp");
496 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
497 memset(asset_title,0,sizeof(asset_title));
498 time_t dt; time(&dt);
499 struct tm dtm; localtime_r(&dt, &dtm);
500 sprintf(asset_title, "bd_%02d%02d%02d-%02d%02d%02d",
501 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
502 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
504 use_scale = Rescale::none;
506 use_inverse_telecine = 0;
508 use_resize_tracks = 0;
512 use_standard = !strcmp(mwindow->default_std(),"NTSC") ?
513 BD_1920x1080_2997i : BD_1920x1080_25i;
516 bd_height = BD_HEIGHT;
517 bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
518 bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
519 bd_framerate = BD_FRAMERATE;
520 bd_samplerate = BD_SAMPLERATE;
521 bd_max_bitrate = BD_MAX_BITRATE;
522 bd_kaudio_rate = BD_KAUDIO_RATE;
523 bd_interlace_mode = BD_INTERLACE_MODE;
524 max_w = 0; max_h = 0;
526 int has_standard = -1;
528 EDLSession *session = mwindow->edl->session;
529 // match the session to any known standard
530 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
531 if( !EQUIV(session->frame_rate, bd_formats[i].framerate) ) continue;
532 if( session->output_w != bd_formats[i].w ) continue;
533 if( session->output_h != bd_formats[i].h ) continue;
534 has_standard = i; break;
537 if( has_standard >= 0 )
538 use_standard = has_standard;
541 int scr_x = mwindow->gui->get_screen_x(0, -1);
542 int scr_w = mwindow->gui->get_screen_w(0, -1);
543 int scr_h = mwindow->gui->get_screen_h(0, -1);
544 int w = xS(560), h = yS(340);
545 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
547 gui = new CreateBD_GUI(this, x, y, w, h);
548 gui->create_objects();
550 if( getuid() != 0 ) {
551 mwindow->show_warning(
552 &mwindow->preferences->bd_warn_root,
553 _("Must be root to mount UDFS images\n"));
559 CreateBD_OK::CreateBD_OK(CreateBD_GUI *gui, int x, int y)
563 set_tooltip(_("end setup, start batch render"));
566 CreateBD_OK::~CreateBD_OK()
570 int CreateBD_OK::button_press_event()
572 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
579 int CreateBD_OK::keypress_event()
581 return context_help_check_and_show();
585 CreateBD_Cancel::CreateBD_Cancel(CreateBD_GUI *gui, int x, int y)
586 : BC_CancelButton(x, y)
591 CreateBD_Cancel::~CreateBD_Cancel()
595 int CreateBD_Cancel::button_press_event()
597 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
605 CreateBD_DiskSpace::CreateBD_DiskSpace(CreateBD_GUI *gui, int x, int y)
606 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
611 CreateBD_DiskSpace::~CreateBD_DiskSpace()
615 int64_t CreateBD_DiskSpace::tmp_path_space()
617 const char *path = gui->thread->tmp_path;
618 if( access(path,R_OK+W_OK) ) return 0;
620 if( statfs(path, &sfs) ) return 0;
621 return (int64_t)sfs.f_bsize * sfs.f_bfree;
624 void CreateBD_DiskSpace::update()
626 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
627 int64_t disk_space = tmp_path_space();
628 double media_size = 100e9, msz = 0, m = 1;
630 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
631 int i = sizeof(suffix)/sizeof(suffix[0]);
632 while( --i >= 0 && strcmp(sfx, suffix[i]) );
633 while( --i >= 0 ) m *= 1000;
634 media_size = msz * m;
636 int color = disk_space < media_size*2 ? RED : GREEN;
638 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
639 char text[BCTEXTLEN];
640 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
641 gui->disk_space->BC_Title::update(text);
642 gui->disk_space->set_color(color);
645 CreateBD_TmpPath::CreateBD_TmpPath(CreateBD_GUI *gui, int x, int y, int w)
646 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
647 gui->thread->tmp_path, 1, MEDIUMFONT)
652 CreateBD_TmpPath::~CreateBD_TmpPath()
656 int CreateBD_TmpPath::handle_event()
659 gui->disk_space->update();
664 CreateBD_AssetTitle::CreateBD_AssetTitle(CreateBD_GUI *gui, int x, int y, int w)
665 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
666 gui->thread->asset_title, 1, MEDIUMFONT)
671 CreateBD_AssetTitle::~CreateBD_AssetTitle()
675 int CreateBD_AssetTitle::handle_event()
681 CreateBD_Deinterlace::CreateBD_Deinterlace(CreateBD_GUI *gui, int x, int y)
682 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
687 CreateBD_Deinterlace::~CreateBD_Deinterlace()
691 int CreateBD_Deinterlace::handle_event()
694 gui->need_inverse_telecine->set_value(0);
695 gui->thread->use_inverse_telecine = 0;
697 return BC_CheckBox::handle_event();
701 CreateBD_InverseTelecine::CreateBD_InverseTelecine(CreateBD_GUI *gui, int x, int y)
702 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
707 CreateBD_InverseTelecine::~CreateBD_InverseTelecine()
711 int CreateBD_InverseTelecine::handle_event()
714 gui->need_deinterlace->set_value(0);
715 gui->thread->use_deinterlace = 0;
717 return BC_CheckBox::handle_event();
721 CreateBD_ResizeTracks::CreateBD_ResizeTracks(CreateBD_GUI *gui, int x, int y)
722 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
727 CreateBD_ResizeTracks::~CreateBD_ResizeTracks()
732 CreateBD_Histogram::CreateBD_Histogram(CreateBD_GUI *gui, int x, int y)
733 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
738 CreateBD_Histogram::~CreateBD_Histogram()
742 CreateBD_LabelChapters::CreateBD_LabelChapters(CreateBD_GUI *gui, int x, int y)
743 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
748 CreateBD_LabelChapters::~CreateBD_LabelChapters()
752 CreateBD_UseRenderFarm::CreateBD_UseRenderFarm(CreateBD_GUI *gui, int x, int y)
753 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
758 CreateBD_UseRenderFarm::~CreateBD_UseRenderFarm()
763 CreateBD_WideAudio::CreateBD_WideAudio(CreateBD_GUI *gui, int x, int y)
764 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
769 CreateBD_WideAudio::~CreateBD_WideAudio()
773 CreateBD_UseTsmuxer::CreateBD_UseTsmuxer(CreateBD_GUI *gui, int x, int y)
774 : BC_CheckBox(x, y, &gui->thread->use_tsmuxer, _("use tsmuxer"))
779 CreateBD_UseTsmuxer::~CreateBD_UseTsmuxer()
784 CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
785 : BC_Window(_(PROGRAM_NAME ": Create BD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
787 this->thread = thread;
788 at_x = at_y = tmp_x = tmp_y = 0;
789 ok_x = ok_y = ok_w = ok_h = 0;
790 cancel_x = cancel_y = cancel_w = cancel_h = 0;
798 need_deinterlace = 0;
799 need_inverse_telecine = 0;
800 need_resize_tracks = 0;
809 // *** CONTEXT_HELP ***
810 context_help_set_keyword("DVD and Bluray Creation");
813 CreateBD_GUI::~CreateBD_GUI()
817 void CreateBD_GUI::create_objects()
820 int xs10 = xS(10), xs35 = xS(35);
821 int xs60 = xS(60), xs160 = xS(160), xs170 = xS(170);
822 int ys5 = yS(5), ys10 = yS(10);
823 lock_window("CreateBD_GUI::create_objects");
824 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
825 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
826 int x = padx/2, y = pady/2;
827 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
828 add_subwindow(title);
829 at_x = x + title->get_w(); at_y = y;
830 asset_title = new CreateBD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
831 add_subwindow(asset_title);
832 y += title->get_h() + pady/2;
833 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
834 add_subwindow(title);
835 tmp_x = x + title->get_w(); tmp_y = y;
836 tmp_path = new CreateBD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-xs35);
837 add_subwindow(tmp_path);
838 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
839 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
840 _("Work path"), _("Select a Work directory:"), 1);
841 add_subwindow(btmp_path);
842 y += title->get_h() + pady/2;
843 disk_space = new CreateBD_DiskSpace(this, x, y);
844 add_subwindow(disk_space);
845 int x0 = get_w() - xs170;
846 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
847 add_subwindow(title);
848 int x1 = x0+title->get_w()+padx;
849 media_size = new CreateBD_MediaSize(this, x1, y);
850 media_size->create_objects();
851 media_sizes.append(new BC_ListBoxItem("25GB"));
852 media_sizes.append(new BC_ListBoxItem("50GB"));
853 media_size->update_list(&media_sizes);
854 media_size->update(media_sizes[0]->get_text());
855 disk_space->update();
856 y += disk_space->get_h() + pady/2;
858 title = new BC_Title(x, y, _("Profile:"), MEDIUMFONT, YELLOW);
859 add_subwindow(title);
861 x += title->get_w()+padx;
862 profile = new CreateBD_Profile(this, x, y);
863 profile->create_objects();
864 profiles.append(new BC_ListBoxItem("bluray.m2ts"));
865 profiles.append(new BC_ListBoxItem("bluray_lpcm.m2ts"));
866 /* profiles.append(new BC_ListBoxItem("bluray_truehd.m2ts")); */
867 profile->update_list(&profiles);
868 profile->update(profiles[0]->get_text());
870 x += profile->get_w()+padx;
871 need_tsmuxer = new CreateBD_UseTsmuxer(this, x, y);
872 add_subwindow(need_tsmuxer);
873 y += need_tsmuxer->get_h() + pady;
875 title = new BC_Title(start_x, y, _("Format:"), MEDIUMFONT, YELLOW);
876 add_subwindow(title);
877 standard = new CreateBD_Format(this, title->get_w() + padx, y);
878 add_subwindow(standard);
879 standard->create_objects();
880 standard->set_text(bd_formats[thread->use_standard].name);
882 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
883 add_subwindow(title);
884 x1 = x0+title->get_w()+padx;
885 scale = new CreateBD_Scale(this, x1, y);
886 add_subwindow(scale);
887 scale->create_objects();
888 y += standard->get_h() + pady/2;
890 need_deinterlace = new CreateBD_Deinterlace(this, start_x, y);
891 add_subwindow(need_deinterlace);
892 y += need_deinterlace->get_h() + pady/2;
893 need_histogram = new CreateBD_Histogram(this, start_x, y);
894 add_subwindow(need_histogram);
895 y += need_histogram->get_h() + pady/2;
896 non_standard = new BC_Title(x1, y+ys5, "", MEDIUMFONT, RED);
897 add_subwindow(non_standard);
899 need_inverse_telecine = new CreateBD_InverseTelecine(this, x1, y);
900 add_subwindow(need_inverse_telecine);
901 y += need_inverse_telecine->get_h() + pady/2;
902 need_wide_audio = new CreateBD_WideAudio(this, x1, y);
903 add_subwindow(need_wide_audio);
904 y += need_wide_audio->get_h() + pady/2;
905 need_resize_tracks = new CreateBD_ResizeTracks(this, x1, y);
906 add_subwindow(need_resize_tracks);
908 need_labeled = new CreateBD_LabelChapters(this, x1, y);
909 add_subwindow(need_labeled);
910 y += need_labeled->get_h() + pady/2;
911 need_farmed = new CreateBD_UseRenderFarm(this, x1, y);
912 add_subwindow(need_farmed);
913 ok_w = BC_OKButton::calculate_w();
914 ok_h = BC_OKButton::calculate_h();
916 ok_y = get_h() - ok_h - xs10;
917 ok = new CreateBD_OK(this, ok_x, ok_y);
919 cancel_w = BC_CancelButton::calculate_w();
920 cancel_h = BC_CancelButton::calculate_h();
921 cancel_x = get_w() - cancel_w - xs10,
922 cancel_y = get_h() - cancel_h - ys10;
923 cancel = new CreateBD_Cancel(this, cancel_x, cancel_y);
924 add_subwindow(cancel);
929 int CreateBD_GUI::resize_event(int w, int h)
931 int xs10 = xS(10), xs35 = xS(35);
933 asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
934 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-xs35);
935 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
936 ok_y = h - ok_h - ys10;
937 ok->reposition_window(ok_x, ok_y);
938 cancel_x = w - cancel_w - xs10,
939 cancel_y = h - cancel_h - ys10;
940 cancel->reposition_window(cancel_x, cancel_y);
944 int CreateBD_GUI::translation_event()
949 int CreateBD_GUI::close_event()
955 void CreateBD_GUI::update()
957 scale->set_value(thread->use_scale);
958 need_deinterlace->set_value(thread->use_deinterlace);
959 need_inverse_telecine->set_value(thread->use_inverse_telecine);
960 need_resize_tracks->set_value(thread->use_resize_tracks);
961 need_histogram->set_value(thread->use_histogram);
962 need_wide_audio->set_value(thread->use_wide_audio);
963 need_labeled->set_value(thread->use_labeled);
964 need_farmed->set_value(thread->use_farmed);
967 int CreateBD_Thread::
968 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
970 Tracks *tracks = mwindow->edl->tracks;
971 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
972 if( vtrk->data_type != TRACK_VIDEO ) continue;
973 if( !vtrk->is_armed() ) continue;
974 vtrk->expand_view = 1;
975 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
976 vtrk->plugin_set.append(plugin_set);
977 Edits *edits = vtrk->edits;
978 for( Edit *edit=edits->first; edit; edit=edit->next ) {
979 plugin_set->insert_plugin(_(title),
980 edit->startproject, edit->length,
981 PLUGIN_STANDALONE, 0, default_keyframe, 0);
988 int CreateBD_Thread::
991 Tracks *tracks = mwindow->edl->tracks;
992 int trk_w = max_w, trk_h = max_h;
993 if( trk_w < bd_width ) trk_w = bd_width;
994 if( trk_h < bd_height ) trk_h = bd_height;
995 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
996 if( vtrk->data_type != TRACK_VIDEO ) continue;
997 if( !vtrk->is_armed() ) continue;
998 vtrk->track_w = trk_w;
999 vtrk->track_h = trk_h;
1004 int CreateBD_Thread::
1007 // reset only probed options
1008 use_deinterlace = 0;
1009 use_scale = Rescale::none;
1010 use_resize_tracks = 0;
1015 if( !mwindow->edl ) return 1;
1017 bd_width = bd_formats[use_standard].w;
1018 bd_height = bd_formats[use_standard].h;
1019 bd_framerate = bd_formats[use_standard].framerate;
1020 int wide = bd_formats[use_standard].wide;
1021 bd_aspect_width = wide < 0 ? 1. :
1022 wide > 0 ? BD_WIDE_ASPECT_WIDTH : BD_ASPECT_WIDTH;
1023 bd_aspect_height = wide < 0 ? 1. :
1024 wide > 0 ? BD_WIDE_ASPECT_HEIGHT : BD_ASPECT_HEIGHT;
1025 bd_interlace_mode = bd_formats[use_standard].interlaced;
1026 double bd_aspect = bd_aspect_width / bd_aspect_height;
1028 Tracks *tracks = mwindow->edl->tracks;
1029 max_w = 0; max_h = 0;
1030 int has_deinterlace = 0, has_scale = 0;
1031 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1032 if( !trk->is_armed() ) continue;
1033 Edits *edits = trk->edits;
1034 switch( trk->data_type ) {
1036 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1037 if( edit->silence() ) continue;
1038 Indexable *indexable = edit->get_source();
1039 int w = indexable->get_w();
1040 if( w > max_w ) max_w = w;
1041 if( w != bd_width ) use_scale = Rescale::scaled;
1042 int h = indexable->get_h();
1043 if( h > max_h ) max_h = h;
1044 if( h != bd_height ) use_scale = Rescale::scaled;
1046 MWindow::create_aspect_ratio(aw, ah, w, h);
1047 double aspect = ah > 0 ? aw / ah : 1;
1048 if( wide >= 0 && !EQUIV(aspect, bd_aspect) )
1049 use_scale = Rescale::scaled;
1051 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1052 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1053 plugin; plugin=(Plugin*)plugin->next ) {
1054 if( !strcmp(plugin->title, "Deinterlace") )
1055 has_deinterlace = 1;
1056 if( !strcmp(plugin->title, "Auto Scale") ||
1057 !strcmp(plugin->title, "Scale Ratio") ||
1058 !strcmp(plugin->title, "Scale") )
1066 use_scale = Rescale::none;
1067 if( use_scale != Rescale::none ) {
1068 if( max_w != bd_width ) use_resize_tracks = 1;
1069 if( max_h != bd_height ) use_resize_tracks = 1;
1071 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1072 if( !trk->is_armed() ) continue;
1073 switch( trk->data_type ) {
1075 if( trk->track_w != max_w ) use_resize_tracks = 1;
1076 if( trk->track_h != max_h ) use_resize_tracks = 1;
1080 if( !has_deinterlace && max_h > 2*bd_height ) use_deinterlace = 1;
1082 if( tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
1089 CreateBD_FormatItem::CreateBD_FormatItem(CreateBD_Format *popup,
1090 int standard, const char *name)
1093 this->popup = popup;
1094 this->standard = standard;
1097 CreateBD_FormatItem::~CreateBD_FormatItem()
1101 int CreateBD_FormatItem::handle_event()
1103 const char *text = get_text();
1104 int standard = this->standard;
1105 if( standard < 0 ) {
1106 BC_SubMenu *submenu = get_submenu();
1107 CreateBD_FormatItem *sub_item0 =
1108 (CreateBD_FormatItem *)submenu->get_item(0);
1109 standard = sub_item0->standard;
1110 text = sub_item0->get_text();
1112 popup->gui->thread->use_standard = standard;
1113 popup->set_text(text);
1114 int n = strlen(text)-1;
1115 int not_standard = n >= 0 && text[n] == '*' ? 1 : 0;
1116 popup->gui->non_standard->update(not_standard ? _("* non-standard format") : "", 0);
1117 return popup->handle_event();
1121 CreateBD_Format::CreateBD_Format(CreateBD_GUI *gui, int x, int y)
1122 : BC_PopupMenu(x, y, xS(200), bd_formats[gui->thread->use_standard].name, 1)
1127 CreateBD_Format::~CreateBD_Format()
1131 void CreateBD_Format::create_objects()
1133 BC_SubMenu *submenu = 0;
1134 CreateBD_FormatItem *item = 0;
1136 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
1137 if( ww != bd_formats[i].w || hh != bd_formats[i].h ) {
1138 ww = bd_formats[i].w; hh = bd_formats[i].h;
1139 char string[BCSTRLEN];
1140 sprintf(string, "%dx%d", ww,hh);
1141 add_item(item = new CreateBD_FormatItem(this, -1, string));
1142 item->add_submenu(submenu = new BC_SubMenu());
1144 submenu->add_submenuitem(new CreateBD_FormatItem(this, i, bd_formats[i].name));
1148 int CreateBD_Format::handle_event()
1150 gui->thread->option_presets();
1156 CreateBD_ScaleItem::CreateBD_ScaleItem(CreateBD_Scale *popup,
1157 int scale, const char *text)
1160 this->popup = popup;
1161 this->scale = scale;
1164 CreateBD_ScaleItem::~CreateBD_ScaleItem()
1168 int CreateBD_ScaleItem::handle_event()
1170 popup->gui->thread->use_scale = scale;
1171 popup->set_value(scale);
1172 return popup->handle_event();
1176 CreateBD_Scale::CreateBD_Scale(CreateBD_GUI *gui, int x, int y)
1177 : BC_PopupMenu(x, y, xS(140), "", 1)
1182 CreateBD_Scale::~CreateBD_Scale()
1186 void CreateBD_Scale::create_objects()
1189 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1190 add_item(new CreateBD_ScaleItem(this, i, Rescale::scale_types[i]));
1192 set_value(gui->thread->use_scale);
1195 int CreateBD_Scale::handle_event()
1202 CreateBD_MediaSize::CreateBD_MediaSize(CreateBD_GUI *gui, int x, int y)
1203 : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
1208 CreateBD_MediaSize::~CreateBD_MediaSize()
1212 int CreateBD_MediaSize::handle_event()
1214 gui->disk_space->update();
1218 CreateBD_Profile::CreateBD_Profile(CreateBD_GUI *gui, int x, int y)
1219 : BC_PopupTextBox(gui, 0, 0, x, y, xS(170),yS(50))
1224 CreateBD_Profile::~CreateBD_Profile()
1228 int CreateBD_Profile::handle_event()
1230 strcpy(gui->thread->use_profile, get_text());