+DVD_BatchRenderJob::DVD_BatchRenderJob(Preferences *preferences,
+ int labeled, int farmed, int standard, int muxed)
+ : BatchRenderJob("DVD_JOB", preferences, labeled, farmed)
+{
+ this->standard = standard;
+ this->muxed = muxed;
+
+ chapter = -1;
+ edl = 0;
+ fp =0;
+}
+
+void DVD_BatchRenderJob::copy_from(DVD_BatchRenderJob *src)
+{
+ standard = src->standard;
+ muxed = src->muxed;
+ BatchRenderJob::copy_from(src);
+}
+
+DVD_BatchRenderJob *DVD_BatchRenderJob::copy()
+{
+ DVD_BatchRenderJob *t = new DVD_BatchRenderJob(preferences,
+ labeled, farmed, standard, muxed);
+ t->copy_from(this);
+ return t;
+}
+
+void DVD_BatchRenderJob::load(FileXML *file)
+{
+ standard = file->tag.get_property("STANDARD", standard);
+ muxed = file->tag.get_property("MUXED", muxed);
+ BatchRenderJob::load(file);
+}
+
+void DVD_BatchRenderJob::save(FileXML *file)
+{
+ file->tag.set_property("STANDARD", standard);
+ file->tag.set_property("MUXED", muxed);
+ BatchRenderJob::save(file);
+}
+
+void DVD_BatchRenderJob::create_chapter(double pos)
+{
+ fprintf(fp,"%s", !chapter++? "\" chapters=\"" : ",");
+ int secs = pos, mins = secs/60;
+ int frms = (pos-secs) * edl->session->frame_rate;
+ fprintf(fp,"%d:%02d:%02d.%d", mins/60, mins%60, secs%60, frms);
+}
+
+char *DVD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
+{
+ char script[BCTEXTLEN];
+ strcpy(script, edl_path);
+ this->edl = edl;
+ this->fp = 0;
+ char *bp = strrchr(script,'/');
+ int fd = -1;
+ if( bp ) {
+ strcpy(bp, "/dvd.sh");
+ fd = open(script, O_WRONLY+O_CREAT+O_TRUNC, 0755);
+ }
+ if( fd >= 0 )
+ fp = fdopen(fd, "w");
+ if( !fp ) {
+ char err[BCTEXTLEN], msg[BCTEXTLEN];
+ strerror_r(errno, err, sizeof(err));
+ sprintf(msg, _("Unable to save: %s\n-- %s"), script, err);
+ MainError::show_error(msg);
+ return 0;
+ }
+
+ fprintf(fp,"#!/bin/bash\n");
+ fprintf(fp,"sdir=`dirname $0`\n");
+ fprintf(fp,"dir=`cd \"$sdir\"; pwd`\n");
+ fprintf(fp,"echo \"running %s\"\n", script);
+ fprintf(fp,"\n");
+ const char *exec_path = File::get_cinlib_path();
+ fprintf(fp,"PATH=$PATH:%s\n",exec_path);
+ int file_seq = farmed || labeled ? 1 : 0;
+ if( !muxed ) {
+ if( file_seq ) {
+ fprintf(fp, "cat > $dir/dvd.m2v $dir/dvd.m2v[0-9]*\n");
+ fprintf(fp, "mplex -M -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
+ file_seq = 0;
+ }
+ else
+ fprintf(fp, "mplex -f 8 -o $dir/dvd.mpg $dir/dvd.m2v $dir/dvd.ac3\n");
+ }
+ fprintf(fp,"rm -rf $dir/iso\n");
+ fprintf(fp,"mkdir -p $dir/iso\n");
+ fprintf(fp,"\n");
+// dvdauthor ver 0.7.0 requires this to work
+ int norm = dvd_formats[standard].norm;
+ const char *name = dvd_norms[norm].name;
+ fprintf(fp,"export VIDEO_FORMAT=%s\n", name);
+ fprintf(fp,"dvdauthor -x - <<eof\n");
+ fprintf(fp,"<dvdauthor dest=\"$dir/iso\">\n");
+ fprintf(fp," <vmgm>\n");
+ fprintf(fp," <fpc> jump title 1; </fpc>\n");
+ fprintf(fp," </vmgm>\n");
+ fprintf(fp," <titleset>\n");
+ fprintf(fp," <titles>\n");
+ char std[BCSTRLEN], *cp = std;
+ for( const char *np=name; *np!=0; ++cp,++np) *cp = *np + 'a'-'A';
+ *cp = 0;
+ EDLSession *session = edl->session;
+ fprintf(fp," <video format=\"%s\" aspect=\"%d:%d\" resolution=\"%dx%d\"/>\n",
+ std, (int)session->aspect_w, (int)session->aspect_h,
+ session->output_w, session->output_h);
+ fprintf(fp," <audio format=\"ac3\" lang=\"en\"/>\n");
+ fprintf(fp," <pgc>\n");
+ int total_idxbls = !file_seq ? 1 : idxbls->size();
+ int secs = 0;
+ double vob_pos = 0;
+ double total_length = edl->tracks->total_length();
+ Label *label = edl->labels->first;
+ for( int i=0; i<total_idxbls; ++i ) {
+ Indexable *idxbl = idxbls->get(i);
+ double video_length = idxbl->have_video() && idxbl->get_frame_rate() > 0 ?
+ (double)idxbl->get_video_frames() / idxbl->get_frame_rate() : 0 ;
+ double audio_length = idxbl->have_audio() && idxbl->get_sample_rate() > 0 ?
+ (double)idxbl->get_audio_samples() / idxbl->get_sample_rate() : 0 ;
+ double length = idxbl->have_video() && idxbl->have_audio() ?
+ bmin(video_length, audio_length) :
+ idxbl->have_video() ? video_length :
+ idxbl->have_audio() ? audio_length : 0;
+ fprintf(fp," <vob file=\"%s", !file_seq ? "$dir/dvd.mpg" : idxbl->path);
+ chapter = 0;
+ double vob_end = i+1>=total_idxbls ? total_length : vob_pos + length;
+ if( labeled ) {
+ while( label && label->position < vob_end ) {
+ create_chapter(label->position - vob_pos);
+ label = label->next;
+ }
+ }
+ else {
+ while( secs < vob_end ) {
+ create_chapter(secs - vob_pos);
+ secs += 10*60; // ch every 10 minutes
+ }
+ }
+ fprintf(fp,"\"/>\n");
+ vob_pos = vob_end;
+ }
+ fprintf(fp," </pgc>\n");
+ fprintf(fp," </titles>\n");
+ fprintf(fp," </titleset>\n");
+ fprintf(fp,"</dvdauthor>\n");
+ fprintf(fp,"eof\n");
+ fprintf(fp,"\n");
+ fprintf(fp,"echo To burn dvd, load blank media and run:\n");
+ fprintf(fp,"echo growisofs -dvd-compat -Z /dev/dvd -dvd-video $dir/iso\n");
+ fprintf(fp,"kill $$\n");
+ fprintf(fp,"\n");
+ fclose(fp);
+ return cstrdup(script);
+}
+
+