batchrender cleanup, bd/dvd create upgrades, remote ctrl booby fix
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / dvdcreate.C
1 #include "asset.h"
2 #include "bchash.h"
3 #include "clip.h"
4 #include "dvdcreate.h"
5 #include "edl.h"
6 #include "edit.h"
7 #include "edits.h"
8 #include "edlsession.h"
9 #include "file.h"
10 #include "filexml.h"
11 #include "keyframe.h"
12 #include "labels.h"
13 #include "mainerror.h"
14 #include "mainundo.h"
15 #include "mwindow.h"
16 #include "mwindowgui.h"
17 #include "plugin.h"
18 #include "pluginset.h"
19 #include "preferences.h"
20 #include "rescale.h"
21 #include "track.h"
22 #include "tracks.h"
23
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <sys/stat.h>
28 #include <sys/statfs.h>
29
30
31 #define DVD_PAL_4x3     0
32 #define DVD_PAL_16x9    1
33 #define DVD_NTSC_4x3    2
34 #define DVD_NTSC_16x9   3
35
36 #define DVD_NORM_PAL    0
37 #define DVD_NORM_NTSC   1
38
39 #define DVD_ASPECT_4x3  0
40 #define DVD_ASPECT_16x9 1
41
42 static struct dvd_norm {
43         const char *name;
44         int w, h;
45         double framerate;
46 } dvd_norms[] = {
47         { "PAL",  720,576, 25 },
48         { "NTSC", 720,480, 29.97 },
49 };
50
51 static struct dvd_aspect {
52         int w, h;
53 } dvd_aspects[] = {
54         { 4, 3, },
55         { 16, 9, },
56 };
57
58 // DVD Creation
59
60 static struct dvd_format {
61         int norm, aspect;
62 } dvd_formats[] = {
63         { DVD_NORM_PAL,  DVD_ASPECT_4x3, },
64         { DVD_NORM_PAL,  DVD_ASPECT_16x9, },
65         { DVD_NORM_NTSC, DVD_ASPECT_4x3, },
66         { DVD_NORM_NTSC, DVD_ASPECT_16x9, },
67 };
68
69 const int64_t CreateDVD_Thread::DVD_SIZE = 4700000000;
70 const int CreateDVD_Thread::DVD_STREAMS = 1;
71 const int CreateDVD_Thread::DVD_WIDTH = 720;
72 const int CreateDVD_Thread::DVD_HEIGHT = 480;
73 const double CreateDVD_Thread::DVD_ASPECT_WIDTH = 4.;
74 const double CreateDVD_Thread::DVD_ASPECT_HEIGHT = 3.;
75 const double CreateDVD_Thread::DVD_WIDE_ASPECT_WIDTH = 16.;
76 const double CreateDVD_Thread::DVD_WIDE_ASPECT_HEIGHT = 9.;
77 const double CreateDVD_Thread::DVD_FRAMERATE = 30000. / 1001.;
78 const int CreateDVD_Thread::DVD_MAX_BITRATE = 8000000;
79 const int CreateDVD_Thread::DVD_CHANNELS = 2;
80 const int CreateDVD_Thread::DVD_WIDE_CHANNELS = 6;
81 const double CreateDVD_Thread::DVD_SAMPLERATE = 48000;
82 const double CreateDVD_Thread::DVD_KAUDIO_RATE = 224;
83
84
85 CreateDVD_MenuItem::CreateDVD_MenuItem(MWindow *mwindow)
86  : BC_MenuItem(_("DVD Render..."), _("Shift-D"), 'D')
87 {
88         set_shift(1);
89         this->mwindow = mwindow;
90 }
91
92 int CreateDVD_MenuItem::handle_event()
93 {
94         mwindow->create_dvd->start();
95         return 1;
96 }
97
98
99 DVD_BatchRenderJob::DVD_BatchRenderJob(Preferences *preferences,
100                 int labeled, int farmed, int standard, int muxed)
101  : BatchRenderJob("DVD_JOB", preferences, labeled, farmed)
102 {
103         this->standard = standard;
104         this->muxed = muxed;
105
106         chapter = -1;
107         edl = 0;
108         fp =0;
109 }
110
111 void DVD_BatchRenderJob::copy_from(DVD_BatchRenderJob *src)
112 {
113         standard = src->standard;
114         muxed = src->muxed;
115         BatchRenderJob::copy_from(src);
116 }
117
118 DVD_BatchRenderJob *DVD_BatchRenderJob::copy()
119 {
120         DVD_BatchRenderJob *t = new DVD_BatchRenderJob(preferences,
121                 labeled, farmed, standard, muxed);
122         t->copy_from(this);
123         return t;
124 }
125
126 void DVD_BatchRenderJob::load(FileXML *file)
127 {
128         standard = file->tag.get_property("STANDARD", standard);
129         muxed = file->tag.get_property("MUXED", muxed);
130         BatchRenderJob::load(file);
131 }
132
133 void DVD_BatchRenderJob::save(FileXML *file)
134 {
135         file->tag.set_property("STANDARD", standard);
136         file->tag.set_property("MUXED", muxed);
137         BatchRenderJob::save(file);
138 }
139
140 void DVD_BatchRenderJob::create_chapter(double pos)
141 {
142         fprintf(fp,"%s", !chapter++? "\" chapters=\"" : ",");
143         int secs = pos, mins = secs/60;
144         int frms = (pos-secs) * edl->session->frame_rate;
145         fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
146 }
147
148 char *DVD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
149 {
150         char script[BCTEXTLEN];
151         strcpy(script, edl_path);
152         this->edl = edl;
153         this->fp = 0;
154         char *bp = strrchr(script,'/');
155         int fd = -1;
156         if( bp ) {
157                 strcpy(bp, "/dvd.sh");
158                 fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
159         }
160         if( fd >= 0 )
161                 fp = fdopen(fd, "w");
162         if( !fp ) {
163                 char err[BCTEXTLEN], msg[BCTEXTLEN];
164                 strerror_r(errno, err, sizeof(err));
165                 sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
166                 MainError::show_error(msg);
167                 return 0;
168         }
169
170         fprintf(fp,"#!/bin/bash\n");
171         fprintf(fp,"dir=`dirname $0`\n");
172         fprintf(fp,"echo \"running %s\"\n", script);
173         fprintf(fp,"\n");
174         const char *exec_path = File::get_cinlib_path();
175         fprintf(fp,"PATH=$PATH:%s\n",exec_path);
176         int file_seq = farmed || labeled ? 1 : 0;
177         if( !muxed ) {
178                 if( file_seq ) {
179                         fprintf(fp, "cat > $dir/dvd.m2v $dir/dvd.m2v0*\n");
180                         fprintf(fp, "mplex -M -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
181                         file_seq = 0;
182                 }
183                 else
184                         fprintf(fp, "mplex -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
185         }
186         fprintf(fp,"rm -rf $dir/iso\n");
187         fprintf(fp,"mkdir -p $dir/iso\n");
188         fprintf(fp,"\n");
189 // dvdauthor ver 0.7.0 requires this to work
190         int norm = dvd_formats[standard].norm;
191         const char *name = dvd_norms[norm].name;
192         fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
193         fprintf(fp,"dvdauthor -x - <<eof\n");
194         fprintf(fp,"<dvdauthor dest=\"$dir/iso\">\n");
195         fprintf(fp,"  <vmgm>\n");
196         fprintf(fp,"    <fpc> jump title 1; </fpc>\n");
197         fprintf(fp,"  </vmgm>\n");
198         fprintf(fp,"  <titleset>\n");
199         fprintf(fp,"    <titles>\n");
200         char std[BCSTRLEN], *cp = std;
201         for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
202         *cp = 0;
203         EDLSession *session = edl->session;
204         fprintf(fp,"    <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
205                 std, (int)session->aspect_w, (int)session->aspect_h,
206                 session->output_w, session->output_h);
207         fprintf(fp,"    <audio format=\"ac3\" lang=\"en\"/>\n");
208         fprintf(fp,"    <pgc>\n");
209         int total_idxbls = !file_seq ? 1 : idxbls->size();
210         int secs = 0;
211         double vob_pos = 0;
212         double total_length = edl->tracks->total_length();
213         Label *label = edl->labels->first;
214         for( int i=0; i<total_idxbls; ++i ) {
215                 Indexable *idxbl = idxbls->get(i);
216                 double video_length = idxbl->have_video() && idxbl->get_frame_rate() > 0 ?
217                         (double)idxbl->get_video_frames() / idxbl->get_frame_rate() : 0 ;
218                 double audio_length = idxbl->have_audio() && idxbl->get_sample_rate() > 0 ?
219                         (double)idxbl->get_audio_samples() / idxbl->get_sample_rate() : 0 ;
220                 double length = idxbl->have_video() && idxbl->have_audio() ?
221                                 bmin(video_length, audio_length) :
222                         idxbl->have_video() ? video_length :
223                         idxbl->have_audio() ? audio_length : 0;
224                 fprintf(fp,"      <vob file=\"%s", !file_seq ? "dvd.mpg" : idxbl->path);
225                 chapter = 0;
226                 double vob_end = i+1>=total_idxbls ? total_length : vob_pos + length;
227                 if( labeled ) {
228                         while( label && label->position < vob_end ) {
229                                 create_chapter(label->position - vob_pos);
230                                 label = label->next;
231                         }
232                 }
233                 else {
234                         while( secs < vob_end ) {
235                                 create_chapter(secs - vob_pos);
236                                 secs += 10*60;  // ch every 10 minutes
237                         }
238                 }
239                 fprintf(fp,"\"/>\n");
240                 vob_pos = vob_end;
241         }
242         fprintf(fp,"    </pgc>\n");
243         fprintf(fp,"    </titles>\n");
244         fprintf(fp,"  </titleset>\n");
245         fprintf(fp,"</dvdauthor>\n");
246         fprintf(fp,"eof\n");
247         fprintf(fp,"\n");
248         fprintf(fp,"echo To burn dvd, load blank media and run:\n");
249         fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $dir/iso\n");
250         fprintf(fp,"kill $$\n");
251         fprintf(fp,"\n");
252         fclose(fp);
253         return cstrdup(script);
254 }
255
256
257 CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow)
258  : BC_DialogThread()
259 {
260         this->mwindow = mwindow;
261         this->gui = 0;
262         this->use_deinterlace = 0;
263         this->use_scale = 0;
264         this->use_histogram = 0;
265         this->use_inverse_telecine = 0;
266         this->use_wide_audio = 0;
267         this->use_ffmpeg = 0;
268         this->use_resize_tracks = 0;
269         this->use_labeled = 0;
270         this->use_farmed = 0;
271
272         this->dvd_size = DVD_SIZE;
273         this->dvd_width = DVD_WIDTH;
274         this->dvd_height = DVD_HEIGHT;
275         this->dvd_aspect_width = DVD_ASPECT_WIDTH;
276         this->dvd_aspect_height = DVD_ASPECT_HEIGHT;
277         this->dvd_framerate = DVD_FRAMERATE;
278         this->dvd_samplerate = DVD_SAMPLERATE;
279         this->dvd_max_bitrate = DVD_MAX_BITRATE;
280         this->dvd_kaudio_rate = DVD_KAUDIO_RATE;
281         this->max_w = this->max_h = 0;
282 }
283
284 CreateDVD_Thread::~CreateDVD_Thread()
285 {
286         close_window();
287 }
288
289 int CreateDVD_Thread::create_dvd_jobs(ArrayList<BatchRenderJob*> *jobs, const char *asset_dir)
290 {
291         EDL *edl = mwindow->edl;
292         if( !edl || !edl->session ) {
293                 char msg[BCTEXTLEN];
294                 sprintf(msg, _("No EDL/Session"));
295                 MainError::show_error(msg);
296                 return 1;
297         }
298         EDLSession *session = edl->session;
299         double total_length = edl->tracks->total_length();
300         if( total_length <= 0 ) {
301                 char msg[BCTEXTLEN];
302                 sprintf(msg, _("No content: %s"), asset_title);
303                 MainError::show_error(msg);
304                 return 1;
305         }
306
307         if( mkdir(asset_dir, 0777) ) {
308                 char err[BCTEXTLEN], msg[BCTEXTLEN];
309                 strerror_r(errno, err, sizeof(err));
310                 sprintf(msg, _("Unable to create directory: %s\n-- %s"), asset_dir, err);
311                 MainError::show_error(msg);
312                 return 1;
313         }
314
315         double old_samplerate = session->sample_rate;
316         double old_framerate = session->frame_rate;
317
318         session->video_channels = DVD_STREAMS;
319         session->video_tracks = DVD_STREAMS;
320         session->frame_rate = dvd_framerate;
321         session->output_w = dvd_width;
322         session->output_h = dvd_height;
323         session->aspect_w = dvd_aspect_width;
324         session->aspect_h = dvd_aspect_height;
325         session->sample_rate = dvd_samplerate;
326         session->audio_channels = session->audio_tracks =
327                 use_wide_audio ? DVD_WIDE_CHANNELS : DVD_CHANNELS;
328
329         session->audio_channels = session->audio_tracks =
330                 !use_wide_audio ? DVD_CHANNELS : DVD_WIDE_CHANNELS;
331         for( int i=0; i<MAX_CHANNELS; ++i )
332                 session->achannel_positions[i] = default_audio_channel_position(i, session->audio_channels);
333         int audio_mapping = edl->tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS &&
334                 !use_wide_audio ? MWindow::AUDIO_5_1_TO_2 : MWindow::AUDIO_1_TO_1;
335         mwindow->remap_audio(audio_mapping);
336
337         double new_samplerate = session->sample_rate;
338         double new_framerate = session->frame_rate;
339         edl->retrack();
340         edl->rechannel();
341         edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
342         edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
343
344         int64_t aud_size = ((dvd_kaudio_rate * total_length)/8 + 1000-1) * 1000;
345         int64_t vid_size = dvd_size*0.96 - aud_size;
346         int64_t vid_bitrate = (vid_size * 8) / total_length;
347         vid_bitrate /= 1000;  vid_bitrate *= 1000;
348         if( vid_bitrate > dvd_max_bitrate )
349                 vid_bitrate = dvd_max_bitrate;
350
351         char xml_filename[BCTEXTLEN];
352         sprintf(xml_filename, "%s/dvd.xml", asset_dir);
353         FileXML xml_file;
354         edl->save_xml(&xml_file, xml_filename);
355         xml_file.terminate_string();
356         if( xml_file.write_to_file(xml_filename) ) {
357                 char msg[BCTEXTLEN];
358                 sprintf(msg, _("Unable to save: %s"), xml_filename);
359                 MainError::show_error(msg);
360                 return 1;
361         }
362
363         BatchRenderJob *job = new DVD_BatchRenderJob(mwindow->preferences,
364                 use_labeled, use_farmed, use_standard, use_ffmpeg);
365         jobs->append(job);
366         strcpy(&job->edl_path[0], xml_filename);
367         Asset *asset = job->asset;
368
369         asset->layers = DVD_STREAMS;
370         asset->frame_rate = session->frame_rate;
371         asset->width = session->output_w;
372         asset->height = session->output_h;
373         asset->aspect_ratio = session->aspect_w / session->aspect_h;
374
375         if( use_ffmpeg ) {
376                 char option_path[BCTEXTLEN];
377                 sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir);
378                 asset->format = FILE_FFMPEG;
379                 strcpy(asset->fformat, "dvd");
380
381                 asset->audio_data = 1;
382                 asset->channels = session->audio_channels;
383                 asset->sample_rate = session->sample_rate;
384                 strcpy(asset->acodec, "dvd.dvd");
385                 FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
386                 FFMPEG::load_options(option_path, asset->ff_audio_options,
387                          sizeof(asset->ff_audio_options));
388                 asset->ff_audio_bitrate = dvd_kaudio_rate * 1000;
389
390                 asset->video_data = 1;
391                 strcpy(asset->vcodec, "dvd.dvd");
392                 FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec);
393                 FFMPEG::load_options(option_path, asset->ff_video_options,
394                          sizeof(asset->ff_video_options));
395                 asset->ff_video_bitrate = vid_bitrate;
396                 asset->ff_video_quality = -1;
397                 use_farmed = job->farmed;
398         }
399         else {
400                 sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir);
401                 asset->video_data = 1;
402                 asset->format = FILE_VMPEG;
403                 asset->vmpeg_cmodel = BC_YUV420P;
404                 asset->vmpeg_fix_bitrate = 1;
405                 asset->vmpeg_bitrate = vid_bitrate;
406                 asset->vmpeg_quantization = 15;
407                 asset->vmpeg_iframe_distance = 15;
408                 asset->vmpeg_progressive = 0;
409                 asset->vmpeg_denoise = 0;
410                 asset->vmpeg_seq_codes = 0;
411                 asset->vmpeg_derivative = 2;
412                 asset->vmpeg_preset = 8;
413                 asset->vmpeg_field_order = 0;
414                 asset->vmpeg_pframe_distance = 0;
415                 use_farmed = job->farmed;
416                 job = new BatchRenderJob(mwindow->preferences, 0, 0);
417                 jobs->append(job);
418                 strcpy(&job->edl_path[0], xml_filename);
419                 asset = job->asset;
420
421                 sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir);
422                 asset->audio_data = 1;
423                 asset->format = FILE_AC3;
424                 asset->channels = session->audio_channels;
425                 asset->sample_rate = session->sample_rate;
426                 asset->bits = 16;
427                 asset->byte_order = 0;
428                 asset->signed_ = 1;
429                 asset->header = 0;
430                 asset->dither = 0;
431                 asset->ac3_bitrate = dvd_kaudio_rate;
432         }
433
434         return 0;
435 }
436
437 void CreateDVD_Thread::handle_close_event(int result)
438 {
439         if( result ) return;
440         mwindow->defaults->update("WORK_DIRECTORY", tmp_path);
441         mwindow->batch_render->load_defaults(mwindow->defaults);
442         mwindow->undo->update_undo_before();
443         KeyFrame keyframe;  char data[BCTEXTLEN];
444         if( use_deinterlace ) {
445                 sprintf(data,"<DEINTERLACE MODE=1>");
446                 keyframe.set_data(data);
447                 insert_video_plugin("Deinterlace", &keyframe);
448         }
449         if( use_inverse_telecine ) {
450                 sprintf(data,"<IVTC FRAME_OFFSET=0 FIRST_FIELD=0 "
451                         "AUTOMATIC=1 AUTO_THRESHOLD=2.0e+00 PATTERN=2>");
452                 keyframe.set_data(data);
453                 insert_video_plugin("Inverse Telecine", &keyframe);
454         }
455         if( use_scale != Rescale::none ) {
456                 double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
457
458                 Tracks *tracks = mwindow->edl->tracks;
459                 for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
460                         if( vtrk->data_type != TRACK_VIDEO ) continue;
461                         if( !vtrk->record ) continue;
462                         vtrk->expand_view = 1;
463                         PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
464                         vtrk->plugin_set.append(plugin_set);
465                         Edits *edits = vtrk->edits;
466                         for( Edit *edit=edits->first; edit; edit=edit->next ) {
467                                 Indexable *indexable = edit->get_source();
468                                 if( !indexable ) continue;
469                                 Rescale in(indexable);
470                                 Rescale out(dvd_width, dvd_height, dvd_aspect);
471                                 float src_w, src_h, dst_w, dst_h;
472                                 in.rescale(out,use_scale, src_w,src_h, dst_w,dst_h);
473                                 sprintf(data,"<SCALERATIO TYPE=%d"
474                                         " IN_W=%d IN_H=%d IN_ASPECT_RATIO=%f"
475                                         " OUT_W=%d OUT_H=%d OUT_ASPECT_RATIO=%f"
476                                         " SRC_X=%f SRC_Y=%f SRC_W=%f SRC_H=%f"
477                                         " DST_X=%f DST_Y=%f DST_W=%f DST_H=%f>", use_scale,
478                                         in.w, in.h, in.aspect, out.w, out.h, out.aspect,
479                                         0., 0., src_w, src_h, 0., 0., dst_w, dst_h);
480                                 keyframe.set_data(data);
481                                 plugin_set->insert_plugin(_("Scale Ratio"),
482                                         edit->startproject, edit->length,
483                                         PLUGIN_STANDALONE, 0, &keyframe, 0);
484                         }
485                         vtrk->optimize();
486                 }
487         }
488
489         if( use_resize_tracks )
490                 resize_tracks();
491         if( use_histogram ) {
492 #if 0
493                 sprintf(data, "<HISTOGRAM OUTPUT_MIN_0=0 OUTPUT_MAX_0=1 "
494                         "OUTPUT_MIN_1=0 OUTPUT_MAX_1=1 "
495                         "OUTPUT_MIN_2=0 OUTPUT_MAX_2=1 "
496                         "OUTPUT_MIN_3=0 OUTPUT_MAX_3=1 "
497                         "AUTOMATIC=0 THRESHOLD=9.0-01 PLOT=0 SPLIT=0>"
498                         "<POINTS></POINTS><POINTS></POINTS><POINTS></POINTS>"
499                         "<POINTS><POINT X=6.0e-02 Y=0>"
500                                 "<POINT X=9.4e-01 Y=1></POINTS>");
501 #else
502                 sprintf(data, "<HISTOGRAM AUTOMATIC=0 THRESHOLD=1.0e-01 "
503                         "PLOT=0 SPLIT=0 W=440 H=500 PARADE=0 MODE=3 "
504                         "LOW_OUTPUT_0=0 HIGH_OUTPUT_0=1 LOW_INPUT_0=0 HIGH_INPUT_0=1 GAMMA_0=1 "
505                         "LOW_OUTPUT_1=0 HIGH_OUTPUT_1=1 LOW_INPUT_1=0 HIGH_INPUT_1=1 GAMMA_1=1 "
506                         "LOW_OUTPUT_2=0 HIGH_OUTPUT_2=1 LOW_INPUT_2=0 HIGH_INPUT_2=1 GAMMA_2=1 "
507                         "LOW_OUTPUT_3=0 HIGH_OUTPUT_3=1 LOW_INPUT_3=0.044 HIGH_INPUT_3=0.956 "
508                         "GAMMA_3=1>");
509 #endif
510                 keyframe.set_data(data);
511                 insert_video_plugin("Histogram", &keyframe);
512         }
513         char asset_dir[BCTEXTLEN], jobs_path[BCTEXTLEN];
514         snprintf(asset_dir, sizeof(asset_dir), "%s/%s", tmp_path, asset_title);
515         snprintf(jobs_path, sizeof(jobs_path), "%s/dvd.jobs", asset_dir);
516         mwindow->batch_render->reset(jobs_path);
517         int ret = create_dvd_jobs(&mwindow->batch_render->jobs, asset_dir);
518         mwindow->undo->update_undo_after(_("create dvd"), LOAD_ALL);
519         mwindow->resync_guis();
520         if( ret ) return;
521         mwindow->batch_render->save_jobs();
522         mwindow->batch_render->start(-use_farmed, -use_labeled);
523 }
524
525 BC_Window* CreateDVD_Thread::new_gui()
526 {
527         strcpy(tmp_path,"/tmp");
528         mwindow->defaults->get("WORK_DIRECTORY", tmp_path);
529         memset(asset_title,0,sizeof(asset_title));
530         time_t dt;  time(&dt);
531         struct tm dtm;  localtime_r(&dt, &dtm);
532         sprintf(asset_title, "dvd_%02d%02d%02d-%02d%02d%02d",
533                 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
534                 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
535         use_deinterlace = 0;
536         use_scale = Rescale::none;
537         use_histogram = 0;
538         use_inverse_telecine = 0;
539         use_wide_audio = 0;
540         use_ffmpeg = 0;
541         use_resize_tracks = 0;
542         use_labeled = 0;
543         use_farmed = 0;
544         use_standard = DVD_NTSC_4x3;
545
546         dvd_size = DVD_SIZE;
547         dvd_width = DVD_WIDTH;
548         dvd_height = DVD_HEIGHT;
549         dvd_aspect_width = DVD_ASPECT_WIDTH;
550         dvd_aspect_height = DVD_ASPECT_HEIGHT;
551         dvd_framerate = DVD_FRAMERATE;
552         dvd_samplerate = DVD_SAMPLERATE;
553         dvd_max_bitrate = DVD_MAX_BITRATE;
554         dvd_kaudio_rate = DVD_KAUDIO_RATE;
555         max_w = 0; max_h = 0;
556
557         int has_standard = -1;
558         if( mwindow->edl ) {
559                 EDLSession *session = mwindow->edl->session;
560                 double framerate = session->frame_rate;
561                 double aspect_ratio = session->aspect_h > 0 ?
562                         session->aspect_w / session->aspect_h > 0 : 1;
563                 int output_w = session->output_w, output_h = session->output_h;
564 // match the session to any known standard
565                 for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
566                         int norm = dvd_formats[i].norm;
567                         if( !EQUIV(framerate, dvd_norms[norm].framerate) ) continue;
568                         if( output_w != dvd_norms[norm].w ) continue;
569                         if( output_h != dvd_norms[norm].h ) continue;
570                         int aspect = dvd_formats[i].aspect;
571                         double dvd_aspect_ratio =
572                                 (double)dvd_aspects[aspect].w / dvd_aspects[aspect].h;
573                         if( !EQUIV(aspect_ratio, dvd_aspect_ratio) ) continue;
574                         has_standard = i;  break;
575                 }
576                 if( has_standard < 0 ) {
577 // or use the default standard
578                         if( !strcmp(mwindow->default_standard, "NTSC") ) has_standard = DVD_NTSC_4x3;
579                         else if( !strcmp(mwindow->default_standard, "PAL") ) has_standard = DVD_PAL_4x3;
580                 }
581         }
582         if( has_standard >= 0 )
583                 use_standard = has_standard;
584
585         option_presets();
586         int scr_x = mwindow->gui->get_screen_x(0, -1);
587         int scr_w = mwindow->gui->get_screen_w(0, -1);
588         int scr_h = mwindow->gui->get_screen_h(0, -1);
589         int w = 520, h = 280;
590         int x = scr_x + scr_w/2 - w/2, y = scr_h/2 - h/2;
591
592         gui = new CreateDVD_GUI(this, x, y, w, h);
593         gui->create_objects();
594         return gui;
595 }
596
597
598 CreateDVD_OK::CreateDVD_OK(CreateDVD_GUI *gui, int x, int y)
599  : BC_OKButton(x, y)
600 {
601         this->gui = gui;
602         set_tooltip(_("end setup, start batch render"));
603 }
604
605 CreateDVD_OK::~CreateDVD_OK()
606 {
607 }
608
609 int CreateDVD_OK::button_press_event()
610 {
611         if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
612                 gui->set_done(0);
613                 return 1;
614         }
615         return 0;
616 }
617
618 int CreateDVD_OK::keypress_event()
619 {
620         return 0;
621 }
622
623
624 CreateDVD_Cancel::CreateDVD_Cancel(CreateDVD_GUI *gui, int x, int y)
625  : BC_CancelButton(x, y)
626 {
627         this->gui = gui;
628 }
629
630 CreateDVD_Cancel::~CreateDVD_Cancel()
631 {
632 }
633
634 int CreateDVD_Cancel::button_press_event()
635 {
636         if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) {
637                 gui->set_done(1);
638                 return 1;
639         }
640         return 0;
641 }
642
643
644 CreateDVD_DiskSpace::CreateDVD_DiskSpace(CreateDVD_GUI *gui, int x, int y)
645  : BC_Title(x, y, "", MEDIUMFONT, GREEN)
646 {
647         this->gui = gui;
648 }
649
650 CreateDVD_DiskSpace::~CreateDVD_DiskSpace()
651 {
652 }
653
654 int64_t CreateDVD_DiskSpace::tmp_path_space()
655 {
656         const char *path = gui->thread->tmp_path;
657         if( access(path,R_OK+W_OK) ) return 0;
658         struct statfs sfs;
659         if( statfs(path, &sfs) ) return 0;
660         return (int64_t)sfs.f_bsize * sfs.f_bfree;
661 }
662
663 void CreateDVD_DiskSpace::update()
664 {
665         static const char *suffix[] = { "", "KB", "MB", "GB", "TB", "PB" };
666         int64_t disk_space = tmp_path_space();
667         double media_size = 15e9, msz = 0, m = 1;
668         char sfx[BCSTRLEN];
669         if( sscanf(gui->media_size->get_text(), "%lf%s", &msz, sfx) == 2 ) {
670                 int i = sizeof(suffix)/sizeof(suffix[0]);
671                 while( --i >= 0 && strcmp(sfx, suffix[i]) );
672                 while( --i >= 0 ) m *= 1000;
673                 media_size = msz * m;
674         }
675         m = gui->thread->use_ffmpeg ? 2 : 3;
676         int color = disk_space < media_size*m ? RED : GREEN;
677         int i = 0;
678         for( int64_t space=disk_space; i<5 && (space/=1000)>0; disk_space=space, ++i );
679         char text[BCTEXTLEN];
680         sprintf(text, "%s%3jd%s", _("disk space: "), disk_space, suffix[i]);
681         gui->disk_space->BC_Title::update(text);
682         gui->disk_space->set_color(color);
683 }
684
685 CreateDVD_TmpPath::CreateDVD_TmpPath(CreateDVD_GUI *gui, int x, int y, int w)
686  : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->tmp_path),
687                 gui->thread->tmp_path, 1, MEDIUMFONT)
688 {
689         this->gui = gui;
690 }
691
692 CreateDVD_TmpPath::~CreateDVD_TmpPath()
693 {
694 }
695
696 int CreateDVD_TmpPath::handle_event()
697 {
698         get_text();
699         gui->disk_space->update();
700         return 1;
701 }
702
703
704 CreateDVD_AssetTitle::CreateDVD_AssetTitle(CreateDVD_GUI *gui, int x, int y, int w)
705  : BC_TextBox(x, y, w, 1, -(int)sizeof(gui->thread->asset_title),
706                 gui->thread->asset_title, 1, MEDIUMFONT)
707 {
708         this->gui = gui;
709 }
710
711 CreateDVD_AssetTitle::~CreateDVD_AssetTitle()
712 {
713 }
714
715 int CreateDVD_AssetTitle::handle_event()
716 {
717         get_text();
718         return 1;
719 }
720
721
722 CreateDVD_Deinterlace::CreateDVD_Deinterlace(CreateDVD_GUI *gui, int x, int y)
723  : BC_CheckBox(x, y, &gui->thread->use_deinterlace, _("Deinterlace"))
724 {
725         this->gui = gui;
726 }
727
728 CreateDVD_Deinterlace::~CreateDVD_Deinterlace()
729 {
730 }
731
732 int CreateDVD_Deinterlace::handle_event()
733 {
734         if( get_value() ) {
735                 gui->need_inverse_telecine->set_value(0);
736                 gui->thread->use_inverse_telecine = 0;
737         }
738         return BC_CheckBox::handle_event();
739 }
740
741
742 CreateDVD_InverseTelecine::CreateDVD_InverseTelecine(CreateDVD_GUI *gui, int x, int y)
743  : BC_CheckBox(x, y, &gui->thread->use_inverse_telecine, _("Inverse Telecine"))
744 {
745         this->gui = gui;
746 }
747
748 CreateDVD_InverseTelecine::~CreateDVD_InverseTelecine()
749 {
750 }
751
752 int CreateDVD_InverseTelecine::handle_event()
753 {
754         if( get_value() ) {
755                 gui->need_deinterlace->set_value(0);
756                 gui->thread->use_deinterlace = 0;
757         }
758         return BC_CheckBox::handle_event();
759 }
760
761
762 CreateDVD_ResizeTracks::CreateDVD_ResizeTracks(CreateDVD_GUI *gui, int x, int y)
763  : BC_CheckBox(x, y, &gui->thread->use_resize_tracks, _("Resize Tracks"))
764 {
765         this->gui = gui;
766 }
767
768 CreateDVD_ResizeTracks::~CreateDVD_ResizeTracks()
769 {
770 }
771
772
773 CreateDVD_Histogram::CreateDVD_Histogram(CreateDVD_GUI *gui, int x, int y)
774  : BC_CheckBox(x, y, &gui->thread->use_histogram, _("Histogram"))
775 {
776         this->gui = gui;
777 }
778
779 CreateDVD_Histogram::~CreateDVD_Histogram()
780 {
781 }
782
783 CreateDVD_LabelChapters::CreateDVD_LabelChapters(CreateDVD_GUI *gui, int x, int y)
784  : BC_CheckBox(x, y, &gui->thread->use_labeled, _("Chapters at Labels"))
785 {
786         this->gui = gui;
787 }
788
789 CreateDVD_LabelChapters::~CreateDVD_LabelChapters()
790 {
791 }
792
793 CreateDVD_UseRenderFarm::CreateDVD_UseRenderFarm(CreateDVD_GUI *gui, int x, int y)
794  : BC_CheckBox(x, y, &gui->thread->use_farmed, _("Use render farm"))
795 {
796         this->gui = gui;
797 }
798
799 CreateDVD_UseRenderFarm::~CreateDVD_UseRenderFarm()
800 {
801 }
802
803 CreateDVD_WideAudio::CreateDVD_WideAudio(CreateDVD_GUI *gui, int x, int y)
804  : BC_CheckBox(x, y, &gui->thread->use_wide_audio, _("Audio 5.1"))
805 {
806         this->gui = gui;
807 }
808
809 CreateDVD_WideAudio::~CreateDVD_WideAudio()
810 {
811 }
812
813 CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y)
814  : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, _("Use FFMPEG"))
815 {
816         this->gui = gui;
817 }
818
819 CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg()
820 {
821 }
822
823
824
825
826 CreateDVD_GUI::CreateDVD_GUI(CreateDVD_Thread *thread, int x, int y, int w, int h)
827  : BC_Window(_(PROGRAM_NAME ": Create DVD"), x, y, w, h, 50, 50, 1, 0, 1)
828 {
829         this->thread = thread;
830         at_x = at_y = tmp_x = tmp_y = 0;
831         ok_x = ok_y = ok_w = ok_h = 0;
832         cancel_x = cancel_y = cancel_w = cancel_h = 0;
833         asset_title = 0;
834         tmp_path = 0;
835         btmp_path = 0;
836         disk_space = 0;
837         standard = 0;
838         scale = 0;
839         need_deinterlace = 0;
840         need_inverse_telecine = 0;
841         need_resize_tracks = 0;
842         need_histogram = 0;
843         need_wide_audio = 0;
844         need_labeled = 0;
845         need_farmed = 0;
846         ok = 0;
847         cancel = 0;
848 }
849
850 CreateDVD_GUI::~CreateDVD_GUI()
851 {
852 }
853
854 void CreateDVD_GUI::create_objects()
855 {
856         lock_window("CreateDVD_GUI::create_objects");
857         int pady = BC_TextBox::calculate_h(this, MEDIUMFONT, 0, 1) + 5;
858         int padx = BC_Title::calculate_w(this, (char*)"X", MEDIUMFONT);
859         int x = padx/2, y = pady/2;
860         BC_Title *title = new BC_Title(x, y, _("Title:"), MEDIUMFONT, YELLOW);
861         add_subwindow(title);
862         at_x = x + title->get_w();  at_y = y;
863         asset_title = new CreateDVD_AssetTitle(this, at_x, at_y, get_w()-at_x-10);
864         add_subwindow(asset_title);
865         y += title->get_h() + pady/2;
866         title = new BC_Title(x, y, _("Work path:"), MEDIUMFONT, YELLOW);
867         add_subwindow(title);
868         tmp_x = x + title->get_w();  tmp_y = y;
869         tmp_path = new CreateDVD_TmpPath(this, tmp_x, tmp_y,  get_w()-tmp_x-35);
870         add_subwindow(tmp_path);
871         btmp_path = new BrowseButton(thread->mwindow->theme, this, tmp_path,
872                 tmp_x+tmp_path->get_w(), tmp_y, "/tmp",
873                 _("Work path"), _("Select a Work directory:"), 1);
874         add_subwindow(btmp_path);
875         y += title->get_h() + pady/2;
876         disk_space = new CreateDVD_DiskSpace(this, x, y);
877         add_subwindow(disk_space);
878         int x0 = get_w() - 170;
879         title = new BC_Title(x0, y, _("Media:"), MEDIUMFONT, YELLOW);
880         add_subwindow(title);
881         int x1 = x0+title->get_w()+padx;
882         media_size = new CreateDVD_MediaSize(this, x1, y);
883         media_size->create_objects();
884         media_sizes.append(new BC_ListBoxItem("4.7GB"));
885         media_sizes.append(new BC_ListBoxItem("8.3GB"));
886         media_size->update_list(&media_sizes);
887         media_size->update(media_sizes[0]->get_text());
888         disk_space->update();
889         y += disk_space->get_h() + pady/2;
890         title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
891         add_subwindow(title);
892         standard = new CreateDVD_Format(this, title->get_w() + padx, y);
893         add_subwindow(standard);
894         standard->create_objects();
895         x0 -= 30;
896         title = new BC_Title(x0, y, _("Scale:"), MEDIUMFONT, YELLOW);
897         add_subwindow(title);
898         x1 = x0+title->get_w()+padx;
899         scale = new CreateDVD_Scale(this, x1, y);
900         add_subwindow(scale);
901         scale->create_objects();
902         y += standard->get_h() + pady/2;
903         x1 = x;  int y1 = y;
904         need_deinterlace = new CreateDVD_Deinterlace(this, x1, y);
905         add_subwindow(need_deinterlace);
906         y += need_deinterlace->get_h() + pady/2;
907         need_histogram = new CreateDVD_Histogram(this, x, y);
908         add_subwindow(need_histogram);
909         y = y1;  x1 += 170;
910         need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y);
911         add_subwindow(need_inverse_telecine);
912         y += need_inverse_telecine->get_h() + pady/2;
913         need_wide_audio = new CreateDVD_WideAudio(this, x1, y);
914         add_subwindow(need_wide_audio);
915         y += need_wide_audio->get_h() + pady/2;
916         need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x1, y);
917         add_subwindow(need_use_ffmpeg);
918         y += need_use_ffmpeg->get_h() + pady/2;
919         need_resize_tracks = new CreateDVD_ResizeTracks(this, x1, y);
920         add_subwindow(need_resize_tracks);
921         y = y1;  x1 += 170;
922         need_labeled = new CreateDVD_LabelChapters(this, x1, y);
923         add_subwindow(need_labeled);
924         y += need_labeled->get_h() + pady/2;
925         need_farmed = new CreateDVD_UseRenderFarm(this, x1, y);
926         add_subwindow(need_farmed);
927         ok_w = BC_OKButton::calculate_w();
928         ok_h = BC_OKButton::calculate_h();
929         ok_x = 10;
930         ok_y = get_h() - ok_h - 10;
931         ok = new CreateDVD_OK(this, ok_x, ok_y);
932         add_subwindow(ok);
933         cancel_w = BC_CancelButton::calculate_w();
934         cancel_h = BC_CancelButton::calculate_h();
935         cancel_x = get_w() - cancel_w - 10,
936         cancel_y = get_h() - cancel_h - 10;
937         cancel = new CreateDVD_Cancel(this, cancel_x, cancel_y);
938         add_subwindow(cancel);
939         show_window();
940         unlock_window();
941 }
942
943 int CreateDVD_GUI::resize_event(int w, int h)
944 {
945         asset_title->reposition_window(at_x, at_y, get_w()-at_x-10);
946         tmp_path->reposition_window(tmp_x, tmp_y,  get_w()-tmp_x-35);
947         btmp_path->reposition_window(tmp_x+tmp_path->get_w(), tmp_y);
948         ok_y = h - ok_h - 10;
949         ok->reposition_window(ok_x, ok_y);
950         cancel_x = w - cancel_w - 10,
951         cancel_y = h - cancel_h - 10;
952         cancel->reposition_window(cancel_x, cancel_y);
953         return 0;
954 }
955
956 int CreateDVD_GUI::translation_event()
957 {
958         return 1;
959 }
960
961 int CreateDVD_GUI::close_event()
962 {
963         set_done(1);
964         return 1;
965 }
966
967 void CreateDVD_GUI::update()
968 {
969         scale->set_value(thread->use_scale);
970         need_deinterlace->set_value(thread->use_deinterlace);
971         need_inverse_telecine->set_value(thread->use_inverse_telecine);
972         need_use_ffmpeg->set_value(thread->use_ffmpeg);
973         need_resize_tracks->set_value(thread->use_resize_tracks);
974         need_histogram->set_value(thread->use_histogram);
975         need_wide_audio->set_value(thread->use_wide_audio);
976         need_labeled->set_value(thread->use_labeled);
977         need_farmed->set_value(thread->use_farmed);
978 }
979
980 int CreateDVD_Thread::
981 insert_video_plugin(const char *title, KeyFrame *default_keyframe)
982 {
983         Tracks *tracks = mwindow->edl->tracks;
984         for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
985                 if( vtrk->data_type != TRACK_VIDEO ) continue;
986                 if( !vtrk->record ) continue;
987                 vtrk->expand_view = 1;
988                 PluginSet *plugin_set = new PluginSet(mwindow->edl, vtrk);
989                 vtrk->plugin_set.append(plugin_set);
990                 Edits *edits = vtrk->edits;
991                 for( Edit *edit=edits->first; edit; edit=edit->next ) {
992                         plugin_set->insert_plugin(_(title),
993                                 edit->startproject, edit->length,
994                                 PLUGIN_STANDALONE, 0, default_keyframe, 0);
995                 }
996                 vtrk->optimize();
997         }
998         return 0;
999 }
1000
1001 int CreateDVD_Thread::
1002 resize_tracks()
1003 {
1004         Tracks *tracks = mwindow->edl->tracks;
1005         int trk_w = max_w, trk_h = max_h;
1006         if( trk_w < dvd_width ) trk_w = dvd_width;
1007         if( trk_h < dvd_height ) trk_h = dvd_height;
1008         for( Track *vtrk=tracks->first; vtrk; vtrk=vtrk->next ) {
1009                 if( vtrk->data_type != TRACK_VIDEO ) continue;
1010                 if( !vtrk->record ) continue;
1011                 vtrk->track_w = trk_w;
1012                 vtrk->track_h = trk_h;
1013         }
1014         return 0;
1015 }
1016
1017 int CreateDVD_Thread::
1018 option_presets()
1019 {
1020 // reset only probed options
1021         use_deinterlace = 0;
1022         use_scale = Rescale::none;
1023         use_resize_tracks = 0;
1024         use_wide_audio = 0;
1025         use_labeled = 0;
1026         use_farmed = 0;
1027
1028         if( !mwindow->edl ) return 1;
1029
1030         int norm = dvd_formats[use_standard].norm;
1031         dvd_width = dvd_norms[norm].w;
1032         dvd_height = dvd_norms[norm].h;
1033         dvd_framerate = dvd_norms[norm].framerate;
1034         int aspect = dvd_formats[use_standard].aspect;
1035         dvd_aspect_width = dvd_aspects[aspect].w;
1036         dvd_aspect_height = dvd_aspects[aspect].h;
1037         double dvd_aspect = dvd_aspect_height > 0 ? dvd_aspect_width/dvd_aspect_height : 1;
1038
1039         Tracks *tracks = mwindow->edl->tracks;
1040         max_w = 0;  max_h = 0;
1041         int has_deinterlace = 0, has_scale = 0;
1042         for( Track *trk=tracks->first; trk; trk=trk->next ) {
1043                 if( !trk->record ) continue;
1044                 Edits *edits = trk->edits;
1045                 switch( trk->data_type ) {
1046                 case TRACK_VIDEO:
1047                         for( Edit *edit=edits->first; edit; edit=edit->next ) {
1048                                 if( edit->silence() ) continue;
1049                                 Indexable *indexable = edit->get_source();
1050                                 int w = indexable->get_w();
1051                                 if( w > max_w ) max_w = w;
1052                                 if( w != dvd_width ) use_scale = Rescale::scaled;
1053                                 int h = indexable->get_h();
1054                                 if( h > max_h ) max_h = h;
1055                                 if( h != dvd_height ) use_scale = Rescale::scaled;
1056                                 float aw, ah;
1057                                 MWindow::create_aspect_ratio(aw, ah, w, h);
1058                                 double aspect = ah > 0 ? aw / ah : 1;
1059                                 if( !EQUIV(aspect, dvd_aspect) ) use_scale = Rescale::scaled;
1060                         }
1061                         for( int i=0; i<trk->plugin_set.size(); ++i ) {
1062                                 for( Plugin *plugin = (Plugin*)trk->plugin_set[i]->first;
1063                                                 plugin; plugin=(Plugin*)plugin->next ) {
1064                                         if( !strcmp(plugin->title, "Deinterlace") )
1065                                                 has_deinterlace = 1;
1066                                         if( !strcmp(plugin->title, "Auto Scale") ||
1067                                             !strcmp(plugin->title, "Scale Ratio") ||
1068                                             !strcmp(plugin->title, "Scale") )
1069                                                 has_scale = 1;
1070                                 }
1071                         }
1072                         break;
1073                 }
1074         }
1075         if( has_scale )
1076                 use_scale = Rescale::none;
1077         if( use_scale != Rescale::none ) {
1078                 if( max_w != dvd_width ) use_resize_tracks = 1;
1079                 if( max_h != dvd_height ) use_resize_tracks = 1;
1080         }
1081         for( Track *trk=tracks->first; trk && !use_resize_tracks; trk=trk->next ) {
1082                 if( !trk->record ) continue;
1083                 switch( trk->data_type ) {
1084                 case TRACK_VIDEO:
1085                         if( trk->track_w != max_w ) use_resize_tracks = 1;
1086                         if( trk->track_h != max_h ) use_resize_tracks = 1;
1087                         break;
1088                 }
1089         }
1090         if( !has_deinterlace && max_h > 2*dvd_height ) use_deinterlace = 1;
1091         Labels *labels = mwindow->edl->labels;
1092         use_labeled = labels && labels->first ? 1 : 0;
1093
1094         if( tracks->recordable_audio_tracks() == DVD_WIDE_CHANNELS )
1095                 use_wide_audio = 1;
1096
1097         use_farmed = mwindow->preferences->use_renderfarm;
1098         return 0;
1099 }
1100
1101
1102
1103 CreateDVD_FormatItem::CreateDVD_FormatItem(CreateDVD_Format *popup,
1104                 int standard, const char *text)
1105  : BC_MenuItem(text)
1106 {
1107         this->popup = popup;
1108         this->standard = standard;
1109 }
1110
1111 CreateDVD_FormatItem::~CreateDVD_FormatItem()
1112 {
1113 }
1114
1115 int CreateDVD_FormatItem::handle_event()
1116 {
1117         popup->set_text(get_text());
1118         popup->gui->thread->use_standard = standard;
1119         return popup->handle_event();
1120 }
1121
1122
1123 CreateDVD_Format::CreateDVD_Format(CreateDVD_GUI *gui, int x, int y)
1124  : BC_PopupMenu(x, y, 180, "", 1)
1125 {
1126         this->gui = gui;
1127 }
1128
1129 CreateDVD_Format::~CreateDVD_Format()
1130 {
1131 }
1132
1133 void CreateDVD_Format::create_objects()
1134 {
1135         for( int i=0; i<(int)(sizeof(dvd_formats)/sizeof(dvd_formats[0])); ++i ) {
1136                 int norm = dvd_formats[i].norm;
1137                 int aspect = dvd_formats[i].aspect;
1138                 char item_text[BCTEXTLEN];
1139                 sprintf(item_text,"%4s (%5.2f) %dx%d",
1140                         dvd_norms[norm].name, dvd_norms[norm].framerate,
1141                         dvd_aspects[aspect].w, dvd_aspects[aspect].h);
1142                 add_item(new CreateDVD_FormatItem(this, i, item_text));
1143         }
1144         set_value(gui->thread->use_standard);
1145 }
1146
1147 int CreateDVD_Format::handle_event()
1148 {
1149         gui->thread->option_presets();
1150         gui->update();
1151         return 1;
1152 }
1153
1154
1155 CreateDVD_ScaleItem::CreateDVD_ScaleItem(CreateDVD_Scale *popup,
1156                 int scale, const char *text)
1157  : BC_MenuItem(text)
1158 {
1159         this->popup = popup;
1160         this->scale = scale;
1161 }
1162
1163 CreateDVD_ScaleItem::~CreateDVD_ScaleItem()
1164 {
1165 }
1166
1167 int CreateDVD_ScaleItem::handle_event()
1168 {
1169         popup->gui->thread->use_scale = scale;
1170         popup->set_value(scale);
1171         return popup->handle_event();
1172 }
1173
1174
1175 CreateDVD_Scale::CreateDVD_Scale(CreateDVD_GUI *gui, int x, int y)
1176  : BC_PopupMenu(x, y, 100, "", 1)
1177 {
1178         this->gui = gui;
1179 }
1180
1181 CreateDVD_Scale::~CreateDVD_Scale()
1182 {
1183 }
1184
1185 void CreateDVD_Scale::create_objects()
1186 {
1187
1188         for( int i=0; i<(int)Rescale::n_scale_types; ++i ) {
1189                 add_item(new CreateDVD_ScaleItem(this, i, Rescale::scale_types[i]));
1190         }
1191         set_value(gui->thread->use_scale);
1192 }
1193
1194 int CreateDVD_Scale::handle_event()
1195 {
1196         gui->update();
1197         return 1;
1198 }
1199
1200
1201 CreateDVD_MediaSize::CreateDVD_MediaSize(CreateDVD_GUI *gui, int x, int y)
1202  : BC_PopupTextBox(gui, 0, 0, x, y, 70,50)
1203 {
1204         this->gui = gui;
1205 }
1206
1207 CreateDVD_MediaSize::~CreateDVD_MediaSize()
1208 {
1209 }
1210
1211 int CreateDVD_MediaSize::handle_event()
1212 {
1213         gui->disk_space->update();
1214         return 1;
1215 }
1216