From 4e32f0b58d7a6e97c112ff43f1ac79725f38feea Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Fri, 17 Dec 2021 20:42:30 +0300
Subject: [PATCH 19/24] EXPERIMENTAL: shell script run tsmuxer conditionally on
 bd.meta, bd.meta conditionally written on gui var

---
 cinelerra-5.1/cinelerra/bdcreate.C | 44 ++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
index 738026a4..aa36cc9e 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.C
+++ b/cinelerra-5.1/cinelerra/bdcreate.C
@@ -159,8 +159,6 @@ char *BD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
 	char script[BCTEXTLEN];
 	strcpy(script, edl_path);
 	
-	int tsmuxer = 1;
-	
 	FILE *fp = 0;
 	char *bp = strrchr(script,'/');
 	int fd = -1;
@@ -188,20 +186,22 @@ char *BD_BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
 	fprintf(fp,"sz=`du -cb $dir/bd.m2ts* | tail -1 | sed -e 's/[ 	].*//'`\n");
 	fprintf(fp,"blks=$((sz/2048 + 4096))\n");
 	fprintf(fp,"rm -f %s\n", udfs);
-	if (tsmuxer) {
-	fprintf(fp,"tsmuxer bd.meta $dir/bd.m2ts \n");
-	} else {
+	fprintf(fp,"if [ -f bd.meta ]; then\n");
+	fprintf(fp,"tsmuxer bd.meta $dir/bd.iso \n");
+	fprintf(fp,"mv $dir/bd.iso $dir/bd.udfs\n");
+	fprintf(fp,"else\n");
 	fprintf(fp,"mkudffs -b 2048 %s $blks\n", udfs);
 	fprintf(fp,"mount %s%s\n", mopts, mntpt);
 	fprintf(fp,"bdwrite %s $dir/bd.m2ts*\n",mntpt);
 	fprintf(fp,"umount %s\n",mntpt);
+	fprintf(fp,"fi\n");
 	if( is_usr_mnt )
 		fprintf(fp,"mv -f %s $dir/bd.udfs\n", udfs);
 	fprintf(fp,"echo To burn bluray, load writable media and run:\n");
 	fprintf(fp,"echo for WORM: growisofs -dvd-compat -Z /dev/bd=$dir/bd.udfs\n");
 	fprintf(fp,"echo for RW:   dd if=$dir/bd.udfs of=/dev/bd bs=2048000\n");
 	fprintf(fp,"kill $$\n");
-	fprintf(fp,"\n"); }
+	fprintf(fp,"\n"); 
 	fclose(fp);
 	return cstrdup(script);
 }
@@ -316,6 +316,38 @@ int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char
 		MainError::show_error(msg);
 		return 1;
 	}
+	
+	if (use_tsmuxer) {
+	char meta_script[BCTEXTLEN];
+	strcpy(meta_script, "/");
+	
+	FILE *fp = 0;
+	char *bp = strrchr(meta_script,'/');
+	int fd = -1;
+	if( bp ) {
+		char script_filename[BCTEXTLEN];
+		sprintf(script_filename, "%s/bd.meta", asset_dir);
+		strcpy(bp, script_filename);
+		fd = open(meta_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"), meta_script, err);
+		MainError::show_error(msg);
+		return 0;
+	}
+	
+
+	fprintf(fp,"MUXOPT --blu-ray --hdmv-descriptors\n");
+	fprintf(fp,"V_MPEG4/ISO/AVC, bd.m2ts, track=4113\n");
+	fprintf(fp,"A_AUDIO/AC3, bd.m2ts, track=4352\n");
+	fprintf(fp,"\n"); 
+	fclose(fp);
+	
+	}
 
 	BatchRenderJob *job = new BD_BatchRenderJob(mwindow->preferences,
 		use_labeled, use_farmed);
-- 
2.34.1

