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
28 #include "edlsession.h"
31 #include "interlacemodes.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
66 // selected by timezone
67 #define BD_1920x1080_2997i 0
68 #define BD_1920x1080_25i 3
70 static struct bd_format {
76 // framerates are frames, not fields, per second, *=not standard
77 { "1920x1080 29.97i", 1920,1080, 29.97, 1, ILACE_MODE_TOP_FIRST },
78 { "1920x1080 29.97p*", 1920,1080, 29.97, 1, ILACE_MODE_FAKE_INTERLACE },
79 { "1920x1080 24p", 1920,1080, 24., 1, ILACE_MODE_NOTINTERLACED },
80 { "1920x1080 25i", 1920,1080, 25., 1, ILACE_MODE_TOP_FIRST },
81 { "1920x1080 25p*", 1920,1080, 25., 1, ILACE_MODE_FAKE_INTERLACE },
82 { "1920x1080 23.976p", 1920,1080, 23.976, 1, ILACE_MODE_NOTINTERLACED },
83 { "1440x1080 29.97i", 1440,1080, 29.97, 1, ILACE_MODE_TOP_FIRST },
84 { "1440x1080 25i", 1440,1080, 25., 1, ILACE_MODE_TOP_FIRST },
85 { "1440x1080 24p", 1440,1080, 24., 1, ILACE_MODE_NOTINTERLACED },
86 { "1440x1080 23.976p", 1440,1080, 23.976, 1, ILACE_MODE_NOTINTERLACED },
87 { "1280x720 59.94p", 1280,720, 59.94, 1, ILACE_MODE_NOTINTERLACED },
88 { "1280x720 50p", 1280,720, 50., 1, ILACE_MODE_NOTINTERLACED },
89 { "1280x720 29.97p*", 1280,720, 29.97, 1, ILACE_MODE_NOTINTERLACED },
90 { "1280x720 25p*", 1280,720, 25., 1, ILACE_MODE_NOTINTERLACED },
91 { "1280x720 24p", 1280,720, 24., 1, ILACE_MODE_NOTINTERLACED },
92 { "1280x720 23.976p", 1280,720, 23.976, 1, ILACE_MODE_NOTINTERLACED },
93 { "720x576 25i", 720,576, 25., 0, ILACE_MODE_BOTTOM_FIRST },
94 { "720x576 25p*", 720,576, 25., 0, ILACE_MODE_NOTINTERLACED },
95 { "720x576(w) 25i", 720,576, 25., 1, ILACE_MODE_BOTTOM_FIRST },
96 { "720x576(w) 25p*", 720,576, 25., 1, ILACE_MODE_NOTINTERLACED },
97 { "720x480 29.97i", 720,480, 29.97, 0, ILACE_MODE_BOTTOM_FIRST },
98 { "720x480 29.97p*", 720,480, 29.97, 0, ILACE_MODE_NOTINTERLACED },
99 { "720x480(w) 29.97i", 720,480, 29.97, 1, ILACE_MODE_BOTTOM_FIRST },
100 { "720x480(w) 29.97p*", 720,480, 29.97, 1, ILACE_MODE_NOTINTERLACED },
104 static struct bd_profile {
108 {"bluray_lpcm.m2ts"},
112 const int64_t CreateBD_Thread::BD_SIZE = 25000000000;
113 const int CreateBD_Thread::BD_STREAMS = 1;
114 const int CreateBD_Thread::BD_WIDTH = 1920;
115 const int CreateBD_Thread::BD_HEIGHT = 1080;
116 const double CreateBD_Thread::BD_WIDE_ASPECT_WIDTH = 16.;
117 const double CreateBD_Thread::BD_WIDE_ASPECT_HEIGHT = 9.;
118 const double CreateBD_Thread::BD_ASPECT_WIDTH = 4.;
119 const double CreateBD_Thread::BD_ASPECT_HEIGHT = 3.;
120 const double CreateBD_Thread::BD_FRAMERATE = 24000. / 1001.;
121 //const int CreateBD_Thread::BD_MAX_BITRATE = 40000000;
122 const int CreateBD_Thread::BD_MAX_BITRATE = 10000000;
123 const int CreateBD_Thread::BD_CHANNELS = 2;
124 const int CreateBD_Thread::BD_WIDE_CHANNELS = 6;
125 const double CreateBD_Thread::BD_SAMPLERATE = 48000;
126 const double CreateBD_Thread::BD_KAUDIO_RATE = 192;
127 const int CreateBD_Thread::BD_INTERLACE_MODE = ILACE_MODE_NOTINTERLACED;
129 CreateBD_MenuItem::CreateBD_MenuItem(MWindow *mwindow)
130 : BC_MenuItem(_("BD Render..."), _("Ctrl-Shift-D"), 'D')
134 this->mwindow = mwindow;
137 int CreateBD_MenuItem::handle_event()
139 mwindow->create_bd->start();
143 BD_BatchRenderJob::BD_BatchRenderJob(Preferences *preferences, int labeled, int farmed)
144 : BatchRenderJob("BD_JOB", preferences, labeled, farmed)
148 int BD_BatchRenderJob::get_udfs_mount(char *udfs, char *mopts, char *mntpt)
151 // default: mount -t udf -o loop $dir/bd.udfs $dir/udfs
152 strcpy(udfs,"$dir/bd.udfs");
153 strcpy(mopts,"-t udf -o loop $dir/bd.udfs ");
154 strcpy(mntpt,"$dir/udfs");
155 const char *home = getenv("HOME");
156 if( !home ) return ret;
157 FILE *fp = fopen("/etc/fstab","r");
158 if( !fp ) return ret;
159 int len = strlen(home);
160 char line[BCTEXTLEN], typ[BCTEXTLEN], file[BCTEXTLEN];
161 char mpnt[BCTEXTLEN], opts[BCTEXTLEN];
162 while( fgets(line,sizeof(line),fp) ) {
163 // search "/etc/fstab" for: $HOME/img_file $HOME/bluray udf noauto,loop,rw,user
164 if( line[0] == '#' || line[0] == ';' ) continue;
165 if( sscanf(line,"%s %s %s %s ", &file[0], &mpnt[0], &typ[0], &opts[0]) != 4 )
167 if( strcmp("udf", typ) ) continue;
168 if( strncmp(home, file, len) || file[len] != '/' ) continue;
169 if( strncmp(home, mpnt, len) ) continue;
170 if( strcmp(&mpnt[len], "/bluray") ) continue;
171 int loop = 0, user = 0, rw = 0, noauto = 0;
172 char *op = opts, *ep = op + sizeof(opts)-1;
173 while( op < ep && *op ) {
174 char opt[BCTEXTLEN], *cp = opt;
175 while( op < ep && *op && (*cp=*op++)!=',' ) ++cp;
177 if( !strcmp("loop", opt) ) loop = 1;
178 else if( !strcmp("user", opt) ) user = 1;
179 else if( !strcmp("noauto", opt) ) noauto = 1;
180 else if( !strcmp("rw", opt) ) rw = 1;
182 if( loop && user && rw && noauto ) {
196 char *BD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
198 char script[BCTEXTLEN];
199 strcpy(script, edl_path);
202 char *bp = strrchr(script,'/');
205 strcpy(bp, "/bd.sh");
206 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
209 fp = fdopen(fd, "w");
211 char err[BCTEXTLEN], msg[BCTEXTLEN];
212 strerror_r(errno, err, sizeof(err));
213 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
214 MainError::show_error(msg);
217 char udfs[BCTEXTLEN], mopts[BCTEXTLEN], mntpt[BCTEXTLEN];
218 int is_usr_mnt = get_udfs_mount(udfs, mopts, mntpt);
219 const char *exec_path = File::get_cinlib_path();
220 fprintf(fp,"#!/bin/bash -ex\n");
221 fprintf(fp,"sdir=`dirname $0`\n");
222 fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
223 fprintf(fp,"PATH=$PATH:%s\n",exec_path);
224 fprintf(fp,"mkdir -p $dir/udfs\n");
225 fprintf(fp,"sz=`du -cb $dir/bd.m2ts* | tail -1 | sed -e 's/[ ].*//'`\n");
226 fprintf(fp,"blks=$((sz/2048 + 4096))\n");
227 fprintf(fp,"rm -f %s\n", udfs);
228 fprintf(fp,"if [ -f $dir/bd.meta ]; then\n");
229 fprintf(fp,"sed -i \"s|bd.m2ts|$dir\/bd.m2ts|g\" $dir/bd.meta\n");
230 fprintf(fp,"tsmuxer $dir/bd.meta $dir/bd.iso \n");
231 fprintf(fp,"mv $dir/bd.iso $dir/bd.udfs\n");
232 fprintf(fp,"else\n");
233 fprintf(fp,"mkudffs -b 2048 %s $blks\n", udfs);
234 fprintf(fp,"mount %s%s\n", mopts, mntpt);
235 fprintf(fp,"bdwrite %s $dir/bd.m2ts*\n",mntpt);
236 fprintf(fp,"umount %s\n",mntpt);
239 fprintf(fp,"mv -f %s $dir/bd.udfs\n", udfs);
240 fprintf(fp,"echo To burn bluray, load writable media and run:\n");
241 fprintf(fp,"echo for WORM: growisofs -dvd-compat -Z /dev/bd=$dir/bd.udfs\n");
242 fprintf(fp,"echo for RW: dd if=$dir/bd.udfs of=/dev/bd bs=2048000\n");
243 fprintf(fp,"kill $$\n");
246 return cstrdup(script);
250 CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
253 this->mwindow = mwindow;
255 this->use_deinterlace = 0;
256 this->use_scale = Rescale::none;
257 this->use_histogram = 0;
258 this->use_inverse_telecine = 0;
259 this->use_wide_audio = 0;
260 this->use_resize_tracks = 0;
261 this->use_labeled = 0;
262 this->use_farmed = 0;
263 this->use_tsmuxer = 0;
265 strcpy(use_profile,"bluray.m2ts");
267 this->bd_size = BD_SIZE;
268 this->bd_width = BD_WIDTH;
269 this->bd_height = BD_HEIGHT;
270 this->bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
271 this->bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
272 this->bd_framerate = BD_FRAMERATE;
273 this->bd_samplerate = BD_SAMPLERATE;
274 this->bd_max_bitrate = BD_MAX_BITRATE;
275 this->bd_kaudio_rate = BD_KAUDIO_RATE;
276 this->max_w = this->max_h = 0;
277 this->batchrender = 0;
280 CreateBD_Thread::~CreateBD_Thread()
285 int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
287 EDL *edl = mwindow->edl;
288 if( !edl || !edl->session ) {
290 sprintf(msg, _("No EDL/Session"));
291 MainError::show_error(msg);
294 EDLSession *session = edl->session;
296 double total_length = edl->tracks->total_length();
297 if( total_length <= 0 ) {
299 sprintf(msg, _("No content: %s"), asset_title);
300 MainError::show_error(msg);
304 if( mkdir(asset_dir, 0777) ) {
305 char err[BCTEXTLEN], msg[BCTEXTLEN];
306 strerror_r(errno, err, sizeof(err));
307 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
308 MainError::show_error(msg);
312 double old_samplerate = session->sample_rate;
313 double old_framerate = session->frame_rate;
315 session->video_channels = BD_STREAMS;
316 session->video_tracks = BD_STREAMS;
317 session->frame_rate = bd_framerate;
318 session->output_w = bd_width;
319 session->output_h = bd_height;
320 session->aspect_w = bd_aspect_width;
321 session->aspect_h = bd_aspect_height;
322 session->sample_rate = bd_samplerate;
323 session->audio_channels = session->audio_tracks =
324 use_wide_audio ? BD_WIDE_CHANNELS : BD_CHANNELS;
325 session->interlace_mode = bd_interlace_mode;
327 session->audio_channels = session->audio_tracks =
328 !use_wide_audio ? BD_CHANNELS : BD_WIDE_CHANNELS;
329 for( int i=0; i<MAX_CHANNELS; ++i )
330 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
331 int audio_mapping = edl->tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS &&
332 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
333 mwindow->remap_audio(audio_mapping);
335 double new_samplerate = session->sample_rate;
336 double new_framerate = session->frame_rate;
339 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
340 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
342 int64_t aud_size = ((bd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
343 int64_t vid_size = bd_size*0.96 - aud_size;
344 int64_t vid_bitrate = (vid_size * 8) / total_length;
345 vid_bitrate /= 1000; vid_bitrate *= 1000;
346 if( vid_bitrate > bd_max_bitrate ) vid_bitrate = bd_max_bitrate;
348 char xml_filename[BCTEXTLEN];
349 sprintf(xml_filename, "%s/bd.xml", asset_dir);
351 edl->save_xml(&xml_file, xml_filename);
352 xml_file.terminate_string();
353 if( xml_file.write_to_file(xml_filename) ) {
355 sprintf(msg, _("Unable to save: %s"), xml_filename);
356 MainError::show_error(msg);
361 char meta_script[BCTEXTLEN];
362 strcpy(meta_script, "/");
365 char *bp = strrchr(meta_script,'/');
368 char script_filename[BCTEXTLEN];
369 sprintf(script_filename, "%s/bd.meta", asset_dir);
370 strcpy(bp, script_filename);
371 fd = open(meta_script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
374 fp = fdopen(fd, "w");
376 char err[BCTEXTLEN], msg[BCTEXTLEN];
377 strerror_r(errno, err, sizeof(err));
378 sprintf(msg, _("Unable to save: %s\n-- %s"), meta_script, err);
379 MainError::show_error(msg);
384 fprintf(fp,"MUXOPT --blu-ray --hdmv-descriptors --auto-chapters=5\n");
385 fprintf(fp,"V_MPEG4/ISO/AVC, bd.m2ts, track=4113\n");
386 if(!strcmp(use_profile, "bluray.m2ts"))
387 fprintf(fp,"A_AC3, bd.m2ts, track=4352\n");
388 if(!strcmp(use_profile, "bluray_lpcm.m2ts"))
389 fprintf(fp,"A_LPCM, bd.m2ts, track=4352\n");
390 if(!strcmp(use_profile, "bluray_truehd.m2ts"))
391 fprintf(fp,"A_MLP, bd.m2ts, track=4352\n");
397 BatchRenderJob *job = new BD_BatchRenderJob(mwindow->preferences,
398 use_labeled, use_farmed);
400 strcpy(&job->edl_path[0], xml_filename);
401 Asset *asset = job->asset;
403 asset->layers = BD_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;
408 asset->interlace_mode = session->interlace_mode;
410 char option_path[BCTEXTLEN];
411 sprintf(&asset->path[0],"%s/bd.m2ts", asset_dir);
412 asset->format = FILE_FFMPEG;
413 strcpy(asset->fformat, "m2ts");
415 asset->audio_data = 1;
416 strcpy(asset->acodec, use_profile);
417 //mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
418 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
419 FFMPEG::load_options(option_path, asset->ff_audio_options,
420 sizeof(asset->ff_audio_options));
421 asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
423 asset->video_data = 1;
424 const char *vcodec = use_profile;
425 switch( asset->interlace_mode ) {
426 case ILACE_MODE_TOP_FIRST: vcodec = "bluray_tff.m2ts"; break;
427 case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts"; break;
428 case ILACE_MODE_FAKE_INTERLACE : vcodec = "bluray_fakeinterlace.m2ts"; break;
430 strcpy(asset->vcodec, vcodec);
431 //mwindow->defaults->get("DEFAULT_BLURAY_VCODEC", asset->vcodec);
432 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
433 FFMPEG::load_options(option_path, asset->ff_video_options,
434 sizeof(asset->ff_video_options));
435 if(session->aspect_w == 16) {
436 char aspect_line[100];
437 float par = (float)((float)asset->width / (float)asset->height);
438 sprintf(aspect_line, "aspect=%f\n", asset->aspect_ratio/par);
439 strcat(asset->ff_video_options, aspect_line);
440 //printf("Aspect line: %s par: %f width: %i height: %i\n ", aspect_line, par, asset->width, asset->height);
442 asset->ff_video_bitrate = vid_bitrate;
443 asset->ff_video_quality = -1;
447 void CreateBD_Thread::handle_close_event(int result)
450 mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
451 mwindow->batch_render->load_defaults(mwindow->defaults);
452 mwindow->undo->update_undo_before();
453 KeyFrame keyframe; char data[BCTEXTLEN];
454 if( use_deinterlace ) {
455 sprintf(data,"<DEINTERLACE MODE=1>");
456 keyframe.set_data(data);
457 insert_video_plugin("Deinterlace", &keyframe);
459 if( use_inverse_telecine ) {
460 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
461 "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
462 keyframe.set_data(data);
463 insert_video_plugin("Inverse Telecine", &keyframe);
465 if( use_scale != Rescale::none ) {
466 double bd_aspect = bd_aspect_height > 0 ? bd_aspect_width / bd_aspect_height : 1;
468 Tracks *tracks = mwindow->edl->tracks;
469 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
470 if( vtrk->data_type != TRACK_VIDEO ) continue;
471 if( !vtrk->is_armed() ) continue;
472 vtrk->expand_view = 1;
473 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
474 vtrk->plugin_set.append(plugin_set);
475 Edits *edits = vtrk->edits;
476 for( Edit *edit=edits->first; edit; edit=edit->next ) {
477 Indexable *indexable = edit->get_source();
478 if( !indexable ) continue;
479 Rescale in(indexable);
480 Rescale out(bd_width, bd_height, bd_aspect);
481 float src_w, src_h, dst_w, dst_h;
482 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
483 sprintf(data,"<SCALERATIO TYPE=%d"
484 " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
485 " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
486 " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
487 " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
488 in.w, in.h, in.aspect, out.w, out.h, out.aspect,
489 0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
490 keyframe.set_data(data);
491 plugin_set->insert_plugin(_("Scale Ratio"),
492 edit->startproject, edit->length,
493 PLUGIN_STANDALONE, 0, &keyframe, 0);
498 if( use_resize_tracks )
500 if( use_histogram ) {
502 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
503 "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
504 "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
505 "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
506 "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
507 "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
508 "<POINTS><POINT X=6.0e-02 Y=0>"
509 "<POINT X=9.4e-01 Y=1></POINTS>");
511 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
512 "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
513 "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
514 "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
515 "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
516 "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
519 keyframe.set_data(data);
520 insert_video_plugin("Histogram", &keyframe);
523 char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
524 snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
525 snprintf(jobs_path, sizeof(jobs_path), "%s/bd.jobs", asset_dir);
526 //batchrender->tsmuxered = use_tsmuxer;
527 mwindow->batch_render->reset(jobs_path);
528 int ret = create_bd_jobs(&mwindow->batch_render->jobs, asset_dir);
529 mwindow->undo->update_undo_after(_("create bd"), LOAD_ALL);
530 mwindow->resync_guis();
532 mwindow->batch_render->save_jobs();
533 mwindow->batch_render->start(-use_farmed, -use_labeled);
536 BC_Window* CreateBD_Thread::new_gui()
538 strcpy(tmp_path, "/tmp");
539 mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
540 memset(asset_title,0,sizeof(asset_title));
541 time_t dt; time(&dt);
542 struct tm dtm; localtime_r(&dt, &dtm);
543 sprintf(asset_title, "bd_%02d%02d%02d-%02d%02d%02d",
544 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
545 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
547 use_scale = Rescale::none;
549 use_inverse_telecine = 0;
551 use_resize_tracks = 0;
555 use_standard = !strcmp(mwindow->default_std(),"NTSC") ?
556 BD_1920x1080_2997i : BD_1920x1080_25i;
559 bd_height = BD_HEIGHT;
560 bd_aspect_width = BD_WIDE_ASPECT_WIDTH;
561 bd_aspect_height = BD_WIDE_ASPECT_HEIGHT;
562 bd_framerate = BD_FRAMERATE;
563 bd_samplerate = BD_SAMPLERATE;
564 bd_max_bitrate = BD_MAX_BITRATE;
565 bd_kaudio_rate = BD_KAUDIO_RATE;
566 bd_interlace_mode = BD_INTERLACE_MODE;
567 max_w = 0; max_h = 0;
569 int has_standard = -1;
571 EDLSession *session = mwindow->edl->session;
572 // match the session to any known standard
573 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
574 if( !EQUIV(session->frame_rate, bd_formats[i].framerate) ) continue;
575 if( session->output_w != bd_formats[i].w ) continue;
576 if( session->output_h != bd_formats[i].h ) continue;
577 has_standard = i; break;
580 if( has_standard >= 0 )
581 use_standard = has_standard;
584 int scr_x = mwindow->gui->get_screen_x(0, -1);
585 int scr_w = mwindow->gui->get_screen_w(0, -1);
586 int scr_h = mwindow->gui->get_screen_h(0, -1);
587 int w = xS(560), h = yS(340);
588 int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
590 gui = new CreateBD_GUI(this, x, y, w, h);
591 gui->create_objects();
593 if( getuid() != 0 ) {
594 mwindow->show_warning(
595 &mwindow->preferences->bd_warn_root,
596 _("Must be root to mount UDFS images\n"));
602 CreateBD_OK::CreateBD_OK(CreateBD_GUI *gui, int x, int y)
606 set_tooltip(_("end setup, start batch render"));
609 CreateBD_OK::~CreateBD_OK()
613 int CreateBD_OK::button_press_event()
615 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
622 int CreateBD_OK::keypress_event()
624 return context_help_check_and_show();
628 CreateBD_Cancel::CreateBD_Cancel(CreateBD_GUI *gui, int x, int y)
629 : BC_CancelButton(x, y)
634 CreateBD_Cancel::~CreateBD_Cancel()
638 int CreateBD_Cancel::button_press_event()
640 if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
648 CreateBD_DiskSpace::CreateBD_DiskSpace(CreateBD_GUI *gui, int x, int y)
649 : BC_Title(x, y, "", MEDIUMFONT, GREEN)
654 CreateBD_DiskSpace::~CreateBD_DiskSpace()
658 int64_t CreateBD_DiskSpace::tmp_path_space()
660 const char *path = gui->thread->tmp_path;
661 if( access(path,R_OK+W_OK) ) return 0;
663 if( statfs(path, &sfs) ) return 0;
664 return (int64_t)sfs.f_bsize * sfs.f_bfree;
667 void CreateBD_DiskSpace::update()
669 static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
670 int64_t disk_space = tmp_path_space();
671 double media_size = 100e9, msz = 0, m = 1;
673 if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
674 int i = sizeof(suffix)/sizeof(suffix[0]);
675 while( --i >= 0 && strcmp(sfx, suffix[i]) );
676 while( --i >= 0 ) m *= 1000;
677 media_size = msz * m;
679 int color = disk_space < media_size*2 ? RED : GREEN;
681 for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
682 char text[BCTEXTLEN];
683 sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
684 gui->disk_space->BC_Title::update(text);
685 gui->disk_space->set_color(color);
688 CreateBD_TmpPath::CreateBD_TmpPath(CreateBD_GUI *gui, int x, int y, int w)
689 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
690 gui->thread->tmp_path, 1, MEDIUMFONT)
695 CreateBD_TmpPath::~CreateBD_TmpPath()
699 int CreateBD_TmpPath::handle_event()
702 gui->disk_space->update();
707 CreateBD_AssetTitle::CreateBD_AssetTitle(CreateBD_GUI *gui, int x, int y, int w)
708 : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
709 gui->thread->asset_title, 1, MEDIUMFONT)
714 CreateBD_AssetTitle::~CreateBD_AssetTitle()
718 int CreateBD_AssetTitle::handle_event()
724 CreateBD_Deinterlace::CreateBD_Deinterlace(CreateBD_GUI *gui, int x, int y)
725 : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
730 CreateBD_Deinterlace::~CreateBD_Deinterlace()
734 int CreateBD_Deinterlace::handle_event()
737 gui->need_inverse_telecine->set_value(0);
738 gui->thread->use_inverse_telecine = 0;
740 return BC_CheckBox::handle_event();
744 CreateBD_InverseTelecine::CreateBD_InverseTelecine(CreateBD_GUI *gui, int x, int y)
745 : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
750 CreateBD_InverseTelecine::~CreateBD_InverseTelecine()
754 int CreateBD_InverseTelecine::handle_event()
757 gui->need_deinterlace->set_value(0);
758 gui->thread->use_deinterlace = 0;
760 return BC_CheckBox::handle_event();
764 CreateBD_ResizeTracks::CreateBD_ResizeTracks(CreateBD_GUI *gui, int x, int y)
765 : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
770 CreateBD_ResizeTracks::~CreateBD_ResizeTracks()
775 CreateBD_Histogram::CreateBD_Histogram(CreateBD_GUI *gui, int x, int y)
776 : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
781 CreateBD_Histogram::~CreateBD_Histogram()
785 CreateBD_LabelChapters::CreateBD_LabelChapters(CreateBD_GUI *gui, int x, int y)
786 : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
791 CreateBD_LabelChapters::~CreateBD_LabelChapters()
795 CreateBD_UseRenderFarm::CreateBD_UseRenderFarm(CreateBD_GUI *gui, int x, int y)
796 : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
801 CreateBD_UseRenderFarm::~CreateBD_UseRenderFarm()
806 CreateBD_WideAudio::CreateBD_WideAudio(CreateBD_GUI *gui, int x, int y)
807 : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
812 CreateBD_WideAudio::~CreateBD_WideAudio()
816 CreateBD_UseTsmuxer::CreateBD_UseTsmuxer(CreateBD_GUI *gui, int x, int y)
817 : BC_CheckBox(x, y, &gui->thread->use_tsmuxer, _("use tsmuxer"))
822 CreateBD_UseTsmuxer::~CreateBD_UseTsmuxer()
827 CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
828 : BC_Window(_(PROGRAM_NAME ": Create BD"), x, y, w, h, xS(50), yS(50), 1, 0, 1)
830 this->thread = thread;
831 at_x = at_y = tmp_x = tmp_y = 0;
832 ok_x = ok_y = ok_w = ok_h = 0;
833 cancel_x = cancel_y = cancel_w = cancel_h = 0;
841 need_deinterlace = 0;
842 need_inverse_telecine = 0;
843 need_resize_tracks = 0;
852 // *** CONTEXT_HELP ***
853 context_help_set_keyword("DVD and Bluray Creation");
856 CreateBD_GUI::~CreateBD_GUI()
860 void CreateBD_GUI::create_objects()
863 int xs10 = xS(10), xs35 = xS(35);
864 int xs60 = xS(60), xs160 = xS(160), xs170 = xS(170);
865 int ys5 = yS(5), ys10 = yS(10);
866 lock_window("CreateBD_GUI::create_objects");
867 int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + ys5;
868 int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
869 int x = padx/2, y = pady/2;
870 BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
871 add_subwindow(title);
872 at_x = x + title->get_w(); at_y = y;
873 asset_title = new CreateBD_AssetTitle(this, at_x, at_y, get_w()-at_x-xs10);
874 add_subwindow(asset_title);
875 y += title->get_h() + pady/2;
876 title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
877 add_subwindow(title);
878 tmp_x = x + title->get_w(); tmp_y = y;
879 tmp_path = new CreateBD_TmpPath(this, tmp_x, tmp_y, get_w()-tmp_x-xs35);
880 add_subwindow(tmp_path);
881 btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
882 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
883 _("Work path"), _("Select a Work directory:"), 1);
884 add_subwindow(btmp_path);
885 y += title->get_h() + pady/2;
886 disk_space = new CreateBD_DiskSpace(this, x, y);
887 add_subwindow(disk_space);
888 int x0 = get_w() - xs170;
889 title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
890 add_subwindow(title);
891 int x1 = x0+title->get_w()+padx;
892 media_size = new CreateBD_MediaSize(this, x1, y);
893 media_size->create_objects();
894 media_sizes.append(new BC_ListBoxItem("25GB"));
895 media_sizes.append(new BC_ListBoxItem("50GB"));
896 media_size->update_list(&media_sizes);
897 media_size->update(media_sizes[0]->get_text());
898 disk_space->update();
899 y += disk_space->get_h() + pady/2;
901 title = new BC_Title(x, y, _("Profile:"), MEDIUMFONT, YELLOW);
902 add_subwindow(title);
904 x += title->get_w()+padx;
905 profile = new CreateBD_Profile(this, x, y);
906 profile->create_objects();
907 profiles.append(new BC_ListBoxItem("bluray.m2ts"));
908 profiles.append(new BC_ListBoxItem("bluray_lpcm.m2ts"));
909 /* profiles.append(new BC_ListBoxItem("bluray_truehd.m2ts")); */
910 profile->update_list(&profiles);
911 profile->update(profiles[0]->get_text());
913 x += profile->get_w()+padx;
914 need_tsmuxer = new CreateBD_UseTsmuxer(this, x, y);
915 add_subwindow(need_tsmuxer);
916 y += need_tsmuxer->get_h() + pady;
918 title = new BC_Title(start_x, y, _("Format:"), MEDIUMFONT, YELLOW);
919 add_subwindow(title);
920 standard = new CreateBD_Format(this, title->get_w() + padx, y);
921 add_subwindow(standard);
922 standard->create_objects();
923 standard->set_text(bd_formats[thread->use_standard].name);
925 title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
926 add_subwindow(title);
927 x1 = x0+title->get_w()+padx;
928 scale = new CreateBD_Scale(this, x1, y);
929 add_subwindow(scale);
930 scale->create_objects();
931 y += standard->get_h() + pady/2;
933 need_deinterlace = new CreateBD_Deinterlace(this, start_x, y);
934 add_subwindow(need_deinterlace);
935 y += need_deinterlace->get_h() + pady/2;
936 need_histogram = new CreateBD_Histogram(this, start_x, y);
937 add_subwindow(need_histogram);
938 y += need_histogram->get_h() + pady/2;
939 non_standard = new BC_Title(x1, y+ys5, "", MEDIUMFONT, RED);
940 add_subwindow(non_standard);
942 need_inverse_telecine = new CreateBD_InverseTelecine(this, x1, y);
943 add_subwindow(need_inverse_telecine);
944 y += need_inverse_telecine->get_h() + pady/2;
945 need_wide_audio = new CreateBD_WideAudio(this, x1, y);
946 add_subwindow(need_wide_audio);
947 y += need_wide_audio->get_h() + pady/2;
948 need_resize_tracks = new CreateBD_ResizeTracks(this, x1, y);
949 add_subwindow(need_resize_tracks);
951 need_labeled = new CreateBD_LabelChapters(this, x1, y);
952 add_subwindow(need_labeled);
953 y += need_labeled->get_h() + pady/2;
954 need_farmed = new CreateBD_UseRenderFarm(this, x1, y);
955 add_subwindow(need_farmed);
956 ok_w = BC_OKButton::calculate_w();
957 ok_h = BC_OKButton::calculate_h();
959 ok_y = get_h() - ok_h - xs10;
960 ok = new CreateBD_OK(this, ok_x, ok_y);
962 cancel_w = BC_CancelButton::calculate_w();
963 cancel_h = BC_CancelButton::calculate_h();
964 cancel_x = get_w() - cancel_w - xs10,
965 cancel_y = get_h() - cancel_h - ys10;
966 cancel = new CreateBD_Cancel(this, cancel_x, cancel_y);
967 add_subwindow(cancel);
972 int CreateBD_GUI::resize_event(int w, int h)
974 int xs10 = xS(10), xs35 = xS(35);
976 asset_title->reposition_window(at_x, at_y, get_w()-at_x-xs10);
977 tmp_path->reposition_window(tmp_x, tmp_y, get_w()-tmp_x-xs35);
978 btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
979 ok_y = h - ok_h - ys10;
980 ok->reposition_window(ok_x, ok_y);
981 cancel_x = w - cancel_w - xs10,
982 cancel_y = h - cancel_h - ys10;
983 cancel->reposition_window(cancel_x, cancel_y);
987 int CreateBD_GUI::translation_event()
992 int CreateBD_GUI::close_event()
998 void CreateBD_GUI::update()
1000 scale->set_value(thread->use_scale);
1001 need_deinterlace->set_value(thread->use_deinterlace);
1002 need_inverse_telecine->set_value(thread->use_inverse_telecine);
1003 need_resize_tracks->set_value(thread->use_resize_tracks);
1004 need_histogram->set_value(thread->use_histogram);
1005 need_wide_audio->set_value(thread->use_wide_audio);
1006 need_labeled->set_value(thread->use_labeled);
1007 need_farmed->set_value(thread->use_farmed);
1008 need_tsmuxer->set_value(thread->use_tsmuxer);
1011 int CreateBD_Thread::
1012 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
1014 Tracks *tracks = mwindow->edl->tracks;
1015 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1016 if( vtrk->data_type != TRACK_VIDEO ) continue;
1017 if( !vtrk->is_armed() ) continue;
1018 vtrk->expand_view = 1;
1019 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
1020 vtrk->plugin_set.append(plugin_set);
1021 Edits *edits = vtrk->edits;
1022 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1023 plugin_set->insert_plugin(_(title),
1024 edit->startproject, edit->length,
1025 PLUGIN_STANDALONE, 0, default_keyframe, 0);
1032 int CreateBD_Thread::
1035 Tracks *tracks = mwindow->edl->tracks;
1036 int trk_w = max_w, trk_h = max_h;
1037 if( trk_w < bd_width ) trk_w = bd_width;
1038 if( trk_h < bd_height ) trk_h = bd_height;
1039 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1040 if( vtrk->data_type != TRACK_VIDEO ) continue;
1041 if( !vtrk->is_armed() ) continue;
1042 vtrk->track_w = trk_w;
1043 vtrk->track_h = trk_h;
1048 int CreateBD_Thread::
1051 // reset only probed options
1052 use_deinterlace = 0;
1053 use_scale = Rescale::none;
1054 use_resize_tracks = 0;
1060 if( !mwindow->edl ) return 1;
1062 bd_width = bd_formats[use_standard].w;
1063 bd_height = bd_formats[use_standard].h;
1064 bd_framerate = bd_formats[use_standard].framerate;
1065 int wide = bd_formats[use_standard].wide;
1066 bd_aspect_width = wide < 0 ? 1. :
1067 wide > 0 ? BD_WIDE_ASPECT_WIDTH : BD_ASPECT_WIDTH;
1068 bd_aspect_height = wide < 0 ? 1. :
1069 wide > 0 ? BD_WIDE_ASPECT_HEIGHT : BD_ASPECT_HEIGHT;
1070 bd_interlace_mode = bd_formats[use_standard].interlaced;
1071 double bd_aspect = bd_aspect_width / bd_aspect_height;
1073 Tracks *tracks = mwindow->edl->tracks;
1074 max_w = 0; max_h = 0;
1075 int has_deinterlace = 0, has_scale = 0;
1076 for( Track *trk=tracks->first; trk; trk=trk->next ) {
1077 if( !trk->is_armed() ) continue;
1078 Edits *edits = trk->edits;
1079 switch( trk->data_type ) {
1081 for( Edit *edit=edits->first; edit; edit=edit->next ) {
1082 if( edit->silence() ) continue;
1083 Indexable *indexable = edit->get_source();
1084 int w = indexable->get_w();
1085 if( w > max_w ) max_w = w;
1086 if( w != bd_width ) use_scale = Rescale::scaled;
1087 int h = indexable->get_h();
1088 if( h > max_h ) max_h = h;
1089 if( h != bd_height ) use_scale = Rescale::scaled;
1091 MWindow::create_aspect_ratio(aw, ah, w, h);
1092 double aspect = ah > 0 ? aw / ah : 1;
1093 if( wide >= 0 && !EQUIV(aspect, bd_aspect) )
1094 use_scale = Rescale::scaled;
1096 for( int i=0; i<trk->plugin_set.size(); ++i ) {
1097 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1098 plugin; plugin=(Plugin*)plugin->next ) {
1099 if( !strcmp(plugin->title, "Deinterlace") )
1100 has_deinterlace = 1;
1101 if( !strcmp(plugin->title, "Auto Scale") ||
1102 !strcmp(plugin->title, "Scale Ratio") ||
1103 !strcmp(plugin->title, "Scale") )
1111 use_scale = Rescale::none;
1112 if( use_scale != Rescale::none ) {
1113 if( max_w != bd_width ) use_resize_tracks = 1;
1114 if( max_h != bd_height ) use_resize_tracks = 1;
1116 for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1117 if( !trk->is_armed() ) continue;
1118 switch( trk->data_type ) {
1120 if( trk->track_w != max_w ) use_resize_tracks = 1;
1121 if( trk->track_h != max_h ) use_resize_tracks = 1;
1125 if( !has_deinterlace && max_h > 2*bd_height ) use_deinterlace = 1;
1127 if( tracks->recordable_audio_tracks() == BD_WIDE_CHANNELS )
1134 CreateBD_FormatItem::CreateBD_FormatItem(CreateBD_Format *popup,
1135 int standard, const char *name)
1138 this->popup = popup;
1139 this->standard = standard;
1142 CreateBD_FormatItem::~CreateBD_FormatItem()
1146 int CreateBD_FormatItem::handle_event()
1148 const char *text = get_text();
1149 int standard = this->standard;
1150 if( standard < 0 ) {
1151 BC_SubMenu *submenu = get_submenu();
1152 CreateBD_FormatItem *sub_item0 =
1153 (CreateBD_FormatItem *)submenu->get_item(0);
1154 standard = sub_item0->standard;
1155 text = sub_item0->get_text();
1157 popup->gui->thread->use_standard = standard;
1158 popup->set_text(text);
1159 int n = strlen(text)-1;
1160 int not_standard = n >= 0 && text[n] == '*' ? 1 : 0;
1161 popup->gui->non_standard->update(not_standard ? _(" * non-standard format") : "", 0);
1162 return popup->handle_event();
1166 CreateBD_Format::CreateBD_Format(CreateBD_GUI *gui, int x, int y)
1167 : BC_PopupMenu(x, y, xS(200), bd_formats[gui->thread->use_standard].name, 1)
1172 CreateBD_Format::~CreateBD_Format()
1176 void CreateBD_Format::create_objects()
1178 BC_SubMenu *submenu = 0;
1179 CreateBD_FormatItem *item = 0;
1181 for( int i=0; i<(int)(sizeof(bd_formats)/sizeof(bd_formats[0])); ++i ) {
1182 if( ww != bd_formats[i].w || hh != bd_formats[i].h ) {
1183 ww = bd_formats[i].w; hh = bd_formats[i].h;
1184 char string[BCSTRLEN];
1185 sprintf(string, "%dx%d", ww,hh);
1186 add_item(item = new CreateBD_FormatItem(this, -1, string));
1187 item->add_submenu(submenu = new BC_SubMenu());
1189 submenu->add_submenuitem(new CreateBD_FormatItem(this, i, bd_formats[i].name));
1193 int CreateBD_Format::handle_event()
1195 gui->thread->option_presets();
1201 CreateBD_ScaleItem::CreateBD_ScaleItem(CreateBD_Scale *popup,
1202 int scale, const char *text)
1205 this->popup = popup;
1206 this->scale = scale;
1209 CreateBD_ScaleItem::~CreateBD_ScaleItem()
1213 int CreateBD_ScaleItem::handle_event()
1215 popup->gui->thread->use_scale = scale;
1216 popup->set_value(scale);
1217 return popup->handle_event();
1221 CreateBD_Scale::CreateBD_Scale(CreateBD_GUI *gui, int x, int y)
1222 : BC_PopupMenu(x, y, xS(140), "", 1)
1227 CreateBD_Scale::~CreateBD_Scale()
1231 void CreateBD_Scale::create_objects()
1234 for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1235 add_item(new CreateBD_ScaleItem(this, i, Rescale::scale_types[i]));
1237 set_value(gui->thread->use_scale);
1240 int CreateBD_Scale::handle_event()
1247 CreateBD_MediaSize::CreateBD_MediaSize(CreateBD_GUI *gui, int x, int y)
1248 : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
1253 CreateBD_MediaSize::~CreateBD_MediaSize()
1257 int CreateBD_MediaSize::handle_event()
1259 gui->disk_space->update();
1263 CreateBD_Profile::CreateBD_Profile(CreateBD_GUI *gui, int x, int y)
1264 : BC_PopupTextBox(gui, 0, 0, x, y, xS(170),yS(50))
1267 strcpy(gui->thread->use_profile, "bluray.m2ts");
1270 CreateBD_Profile::~CreateBD_Profile()
1274 int CreateBD_Profile::handle_event()
1276 strcpy(gui->thread->use_profile, get_text());