well, me and gui not quite get along... (see new layout of 'create bd'
window..)

but... it seems to work?

you can choose profile (out of two) and it will appear in rendering
window..
From 5891130a5838bbe2cccd7344edc9eb45690fe91d Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Wed, 8 Dec 2021 15:50:09 +0300
Subject: [PATCH 01/15] ffmpeg 4.4 bluray lpcm encoder

---
 .../thirdparty/src/ffmpeg-4.4.patch_9         | 353 ++++++++++++++++++
 1 file changed, 353 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9
new file mode 100644
index 00000000..717f0bd3
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9
@@ -0,0 +1,353 @@
+--- /dev/null	2021-12-05 17:02:04.576000000 +0300
++++ ./libavcodec/pcm-bluenc.c	2021-12-08 13:28:00.778956966 +0300
+@@ -0,0 +1,330 @@
++/*
++ * LPCM codecs for PCM formats found in Blu-ray m2ts streams
++ * Copyright (c) 2018 Paul B Mahol
++ *
++ * This file is part of FFmpeg.
++ *
++ * FFmpeg is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU Lesser General Public
++ * License as published by the Free Software Foundation; either
++ * version 2.1 of the License, or (at your option) any later version.
++ *
++ * FFmpeg is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ * Lesser General Public License for more details.
++ *
++ * You should have received a copy of the GNU Lesser General Public
++ * License along with FFmpeg; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
++ */
++
++#include "avcodec.h"
++#include "bytestream.h"
++#include "internal.h"
++
++typedef struct PCMBDContext {
++    uint8_t header[4];       // Header added to every frame
++    int block_size;          // Size of a block of samples in bytes
++    int samples_per_block;   // Number of samples per channel per block
++    int groups_per_block;    // Number of 20/24-bit sample groups per block
++    uint8_t *extra_samples;  // Pointer to leftover samples from a frame
++    int extra_sample_count;  // Number of leftover samples in the buffer
++} PCMBDContext;
++
++static av_cold int pcm_bd_encode_init(AVCodecContext *avctx)
++{
++    PCMBDContext *s = avctx->priv_data;
++    int quant, freq;
++    uint16_t frame_size;
++    uint8_t ch_layout = 0;
++
++    switch (avctx->sample_rate) {
++    case 48000:
++        freq = 1;
++        break;
++    case 96000:
++        freq = 4;
++        break;
++    case 192000:
++	freq = 5;
++	break;
++    }
++
++    switch (avctx->sample_fmt) {
++    case AV_SAMPLE_FMT_S16:
++        avctx->bits_per_coded_sample = 16;
++        quant = 1;
++        break;
++/*    case AV_SAMPLE_FMT_S20:
++        avctx->bits_per_coded_sample = 20;
++        quant = 2;
++        break;
++*/
++    case AV_SAMPLE_FMT_S32:
++        avctx->bits_per_coded_sample = 24;
++        quant = 3;
++        break;
++    }
++
++    avctx->block_align           = avctx->channels * avctx->bits_per_coded_sample / 8;
++    avctx->bit_rate              = avctx->block_align * 8LL * avctx->sample_rate;
++    if (avctx->bit_rate > 19800000) {
++        av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, bitdepth or channels.\n");
++        return AVERROR(EINVAL);
++    }
++
++    if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
++	switch (avctx->channels) {
++	case 1:
++	    s->block_size = avctx->channels * 4;
++	    break;
++	default:
++        s->block_size        = avctx->channels * 2;
++        break;
++        }
++        s->samples_per_block = 1;
++        frame_size           = 2008 / s->block_size;
++    } else {
++        switch (avctx->channels) {
++        case 1:
++            s->block_size        = 2 * avctx->channels * avctx->bits_per_coded_sample / 8;
++    	    s->samples_per_block = 1;
++        break;
++        case 2:
++        case 4:
++            /* one group has all the samples needed */
++            s->block_size        = avctx->channels * avctx->bits_per_coded_sample / 8;
++            s->samples_per_block = 1;
++            s->groups_per_block  = 2;
++            break;
++        case 8:
++        case 6:
++            /* two groups have all the samples needed */
++            s->block_size        = avctx->channels * avctx->bits_per_coded_sample / 8;
++            s->samples_per_block = 1;
++            // s->groups_per_block  = 2;
++            break;
++        default:
++            /* need avctx->channels groups */
++            s->block_size        = 4 * avctx->channels *
++                                   avctx->bits_per_coded_sample / 8;
++            s->samples_per_block = 4;
++            s->groups_per_block  = avctx->channels;
++            break;
++        }
++
++        frame_size = FFALIGN(2008 / s->block_size, s->samples_per_block);
++    }
++
++    switch(avctx->channel_layout) {
++	case AV_CH_LAYOUT_MONO:
++		ch_layout = 1;
++		break;
++	case AV_CH_LAYOUT_STEREO:
++		ch_layout = 3;
++		break;
++	case AV_CH_LAYOUT_5POINT1:
++		ch_layout = 9;
++		break;
++	case AV_CH_LAYOUT_7POINT1:
++		ch_layout = 11;
++		break;
++	default:
++		av_log(avctx, AV_LOG_ERROR, "Not yet implemented ch layout!\n");
++	}
++// description on the web:
++/* http://forum.doom9.org/showthread.php?t=152897
++
++It's a header.
++
++size in bytes = 16 bits (big endian)
++channel assignment = 4 bits
++sampling frequency = 4 bits
++bits per sample = 2 bits
++start flag = 1 bit
++reserved = 5 bits
++
++channel assignment
++1 = mono
++3 = stereo
++4 = 3/0
++5 = 2/1
++6 = 3/1
++7 = 2/2
++8 = 3/2
++9 = 3/2+lfe
++10 = 3/4
++11 = 3/4+lfe
++
++sampling frequency
++1 = 48 kHz
++4 = 96 kHz
++5 = 192 kHz
++
++bits per sample
++1 = 16
++2 = 20
++3 = 24
++*/
++
++    s->header[2] = (ch_layout << 4) | (freq);
++    s->header[3] = (quant << 6) | 0x1 ;
++
++
++        avctx->frame_size = frame_size; // in num. of samples
++
++    return 0;
++}
++
++static int pcm_bd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
++                                const AVFrame *frame, int *got_packet_ptr)
++{
++    PCMBDContext *s = avctx->priv_data;
++    int samples, channels;
++    int64_t pkt_size = (frame->nb_samples / s->samples_per_block) * s->block_size + 4;
++    const int16_t *src16;
++    const int32_t *src32;
++    PutByteContext pb;
++    int ret;
++
++    if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
++        return ret;
++
++    AV_WB16(s->header, pkt_size - 4);
++    memcpy(avpkt->data, s->header, 4);
++
++    src16 = (const int16_t *)frame->data[0];
++    src32 = (const int32_t *)frame->data[0];
++
++    bytestream2_init_writer(&pb, avpkt->data + 4, avpkt->size - 4);
++
++    int num_source_channels = FFALIGN(avctx->channels, 2);
++    // int num_source_channels = avctx->channels;
++    // int sample_size = (num_source_channels *
++    //               (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
++    samples = frame->nb_samples * num_source_channels;
++
++    switch (avctx->sample_fmt) {
++    case AV_SAMPLE_FMT_S16:
++    switch (avctx->channels) {
++	case 1:
++	    do {
++                   do {
++                	channels = avctx->channels;
++            		    bytestream2_put_be16(&pb, *src16++);
++            	} while (--channels);
++            	bytestream2_put_be16(&pb, 0);
++            	} while (--samples);
++        break;
++    	case 2:
++	do {
++            bytestream2_put_be16(&pb, *src16++);
++        } while (--samples);
++        break;
++	case 6:
++	do {
++	    bytestream2_put_be16(&pb, src16[0]);
++	    bytestream2_put_be16(&pb, src16[1]);
++	    bytestream2_put_be16(&pb, src16[2]);
++	    bytestream2_put_be16(&pb, src16[4]);
++	    bytestream2_put_be16(&pb, src16[5]);
++	    bytestream2_put_be16(&pb, src16[3]);
++	    src16+=6;
++        } while (--samples);
++	break;
++	case 8:
++	do {
++	    bytestream2_put_be16(&pb, src16[0]);
++	    bytestream2_put_be16(&pb, src16[1]);
++	    bytestream2_put_be16(&pb, src16[2]);
++	    bytestream2_put_be16(&pb, src16[6]);
++	    bytestream2_put_be16(&pb, src16[4]);
++	    bytestream2_put_be16(&pb, src16[5]);
++	    bytestream2_put_be16(&pb, src16[7]);
++	    bytestream2_put_be16(&pb, src16[3]);
++	    src16+=8;
++        } while (--samples);
++	break;
++
++	default:
++	av_log(avctx, AV_LOG_ERROR, "this ch config not implemented for s16!\n");
++        break;
++        }
++        break;
++    case AV_SAMPLE_FMT_S32:
++            	switch (avctx->channels) {
++    			case 2:
++    			case 4:
++    			    do {
++            		        bytestream2_put_be24(&pb, (*src32++) >> 8);
++            		    } while (--samples);
++                    break;
++                        case 8:
++                            do {
++                    	    bytestream2_put_be24(&pb, src32[0] >> 8);
++			    bytestream2_put_be24(&pb, src32[1] >> 8);
++			    bytestream2_put_be24(&pb, src32[2] >> 8);
++			    bytestream2_put_be24(&pb, src32[6] >> 8);
++			    bytestream2_put_be24(&pb, src32[4] >> 8);
++			    bytestream2_put_be24(&pb, src32[5] >> 8);
++			    bytestream2_put_be24(&pb, src32[7] >> 8);
++			    bytestream2_put_be24(&pb, src32[3] >> 8);
++			    src32+=8;
++			    } while (--samples);
++		    break;
++			case 6:
++			do {
++                    	    bytestream2_put_be24(&pb, src32[0] >> 8);
++			    bytestream2_put_be24(&pb, src32[1] >> 8);
++			    bytestream2_put_be24(&pb, src32[2] >> 8);
++			    bytestream2_put_be24(&pb, src32[4] >> 8);
++			    bytestream2_put_be24(&pb, src32[5] >> 8);
++			    bytestream2_put_be24(&pb, src32[3] >> 8);
++			    src32+=6;
++			    } while (--samples);
++		    break;
++                	case 1:
++                	    do {
++                	       do {
++                	    	    channels = avctx->channels;
++            		        bytestream2_put_be24(&pb, (*src32++) >> 8);
++            			} while (--channels);
++            		    bytestream2_put_be24(&pb, 0);
++            		    } while (--samples);
++                    break;
++                	default:
++                	av_log(avctx, AV_LOG_ERROR, "this bitdepth not implemented!\n");
++                    break;
++                }
++    break;
++    }
++
++    avpkt->pts      = frame->pts;
++    avpkt->size     = pkt_size;
++    avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
++    *got_packet_ptr = 1;
++
++    return 0;
++}
++
++AVCodec ff_pcm_bluray_encoder = {
++    .name           = "pcm_bluray",
++    .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 16|24-bit big-endian for bluray media"),
++    .type           = AVMEDIA_TYPE_AUDIO,
++    .id             = AV_CODEC_ID_PCM_BLURAY,
++    .priv_data_size = sizeof(PCMBDContext),
++    .init           = pcm_bd_encode_init,
++    .encode2        = pcm_bd_encode_frame,
++    .capabilities   = AV_CODEC_CAP_SMALL_LAST_FRAME,
++    .supported_samplerates = (const int[]) { 48000, 96000, 192000, 0},
++    .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
++                                            AV_CH_LAYOUT_STEREO,
++                                            AV_CH_LAYOUT_5POINT1,
++                                            AV_CH_LAYOUT_7POINT1,
++                                            0 },
++    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
++                                                     AV_SAMPLE_FMT_S32,
++                                                     AV_SAMPLE_FMT_NONE },
++    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
++};
+--- ./libavcodec/allcodecs.orig	2021-04-09 00:28:39.000000000 +0300
++++ ./libavcodec/allcodecs.c	2021-12-06 15:45:03.333762281 +0300
+@@ -523,6 +523,7 @@
+ /* PCM codecs */
+ extern AVCodec ff_pcm_alaw_encoder;
+ extern AVCodec ff_pcm_alaw_decoder;
++extern AVCodec ff_pcm_bluray_encoder;
+ extern AVCodec ff_pcm_bluray_decoder;
+ extern AVCodec ff_pcm_dvd_encoder;
+ extern AVCodec ff_pcm_dvd_decoder;
+--- ./libavcodec/Makefile.orig	2021-04-09 00:28:39.000000000 +0300
++++ ./libavcodec/Makefile	2021-12-06 21:11:19.365842066 +0300
+@@ -789,6 +789,7 @@
+ OBJS-$(CONFIG_PCM_ALAW_DECODER)           += pcm.o
+ OBJS-$(CONFIG_PCM_ALAW_ENCODER)           += pcm.o
+ OBJS-$(CONFIG_PCM_BLURAY_DECODER)         += pcm-bluray.o
++OBJS-$(CONFIG_PCM_BLURAY_ENCODER)         += pcm-bluenc.o
+ OBJS-$(CONFIG_PCM_DVD_DECODER)            += pcm-dvd.o
+ OBJS-$(CONFIG_PCM_DVD_ENCODER)            += pcm-dvdenc.o
+ OBJS-$(CONFIG_PCM_F16LE_DECODER)          += pcm.o
-- 
2.34.1

From 8b7ec4c5dd2078a78178dcc6c5125e9fd8391c23 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Wed, 8 Dec 2021 16:53:43 +0300
Subject: [PATCH 02/15] Fix ffmpeg 4.4 bluray lpcm patch for 5.1 ?

---
 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9
index 717f0bd3..f973f2fc 100644
--- a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_9
@@ -1,6 +1,6 @@
 --- /dev/null	2021-12-05 17:02:04.576000000 +0300
-+++ ./libavcodec/pcm-bluenc.c	2021-12-08 13:28:00.778956966 +0300
-@@ -0,0 +1,330 @@
++++ ./libavcodec/pcm-bluenc.c	2021-12-08 16:22:32.519865993 +0300
+@@ -0,0 +1,332 @@
 +/*
 + * LPCM codecs for PCM formats found in Blu-ray m2ts streams
 + * Copyright (c) 2018 Paul B Mahol
@@ -128,6 +128,7 @@
 +		ch_layout = 3;
 +		break;
 +	case AV_CH_LAYOUT_5POINT1:
++	case AV_CH_LAYOUT_5POINT1_BACK:
 +		ch_layout = 9;
 +		break;
 +	case AV_CH_LAYOUT_7POINT1:
@@ -324,6 +325,7 @@
 +    .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
 +                                            AV_CH_LAYOUT_STEREO,
 +                                            AV_CH_LAYOUT_5POINT1,
++                                            AV_CH_LAYOUT_5POINT1_BACK,
 +                                            AV_CH_LAYOUT_7POINT1,
 +                                            0 },
 +    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
-- 
2.34.1

From 931663eefb02914679155f391ac09f654abfc286 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Wed, 8 Dec 2021 16:55:22 +0300
Subject: [PATCH 03/15] Add simple m2ts lpcm profile

---
 cinelerra-5.1/ffmpeg/audio/m2ts_pcm.m2ts | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 cinelerra-5.1/ffmpeg/audio/m2ts_pcm.m2ts

diff --git a/cinelerra-5.1/ffmpeg/audio/m2ts_pcm.m2ts b/cinelerra-5.1/ffmpeg/audio/m2ts_pcm.m2ts
new file mode 100644
index 00000000..284f433a
--- /dev/null
+++ b/cinelerra-5.1/ffmpeg/audio/m2ts_pcm.m2ts
@@ -0,0 +1,2 @@
+bluray pcm_bluray
+id 0x1100
-- 
2.34.1

From 79710e73635284525d0477a603783d4db406cc10 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 03:16:44 +0300
Subject: [PATCH 11/15] EXPERIMENTAL: add bd_profile array to bdcreate.C (so in
 future we can diff between encoders)

---
 cinelerra-5.1/cinelerra/bdcreate.C | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
index 150f835d..20a953e2 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.C
+++ b/cinelerra-5.1/cinelerra/bdcreate.C
@@ -62,6 +62,13 @@ static struct bd_format {
 	{ "720x480   29.97p*",	 720,480,  29.97,  0, ILACE_MODE_NOTINTERLACED },
 };
 
+static struct bd_profile {
+	const char *name;
+} bd_profiles[] = {
+	{"bluray.m2ts"},
+};
+
+
 const int64_t CreateBD_Thread::BD_SIZE = 25000000000;
 const int CreateBD_Thread::BD_STREAMS = 1;
 const int CreateBD_Thread::BD_WIDTH = 1920;
@@ -316,7 +323,7 @@ int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char
 	strcpy(asset->fformat, "m2ts");
 
 	asset->audio_data = 1;
-	strcpy(asset->acodec, "bluray.m2ts");
+	strcpy(asset->acodec, bd_profiles[0].name);
 	//mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
 	FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
 	FFMPEG::load_options(option_path, asset->ff_audio_options,
@@ -324,7 +331,7 @@ int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char
 	asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
 
 	asset->video_data = 1;
-	const char *vcodec = "bluray.m2ts";
+	const char *vcodec = bd_profiles[0].name;
 	switch( asset->interlace_mode ) {
 	case ILACE_MODE_TOP_FIRST:    vcodec = "bluray_tff.m2ts";  break;
 	case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts";  break;
-- 
2.34.1

From e11a346ae2d50ea8211c875f2e175793828c0709 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 02:56:49 +0300
Subject: [PATCH 10/15] EXPERIMENTAL: add variable chapter interval to bdwrite

---
 cinelerra-5.1/cinelerra/bdwrite.C | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
index b184e0c6..a2131251 100644
--- a/cinelerra-5.1/cinelerra/bdwrite.C
+++ b/cinelerra-5.1/cinelerra/bdwrite.C
@@ -1219,7 +1219,7 @@ public:
   ArrayList<mpls_pl *> pl;
 
   void add_movie(uint32_t *ops, int n);
-  int compose();
+  int compose(int ch_interval);
   int write(char *fn);
 
   Media() { path = 0;  filename[0] = 0; }
@@ -2805,7 +2805,7 @@ Media::add_movie(uint32_t *ops, int n)
 }
 
 int
-Media::compose()
+Media::compose(int ch_interval)
 {
 // movie
   bs.init();
@@ -2978,8 +2978,11 @@ Media::compose()
       }
       pp->play_item.append(pi);
     }
-// chapter marks every ch_duration ticks
-    int64_t ch_duration = 45000 * 60*5;
+// chapter marks every ch_duration ticks, default 5 min
+    int PCR_FREQ = 45000;
+    if (ch_interval == 0)
+    ch_interval = 60*5;
+    int64_t ch_duration = PCR_FREQ * ch_interval;
     int64_t mrktm = ch_duration;
     int64_t plytm = 0;
     int pmark = 0, pitem = 0;
@@ -3156,8 +3159,14 @@ main(int ac, char **av)
   //av_log_set_level(AV_LOG_DEBUG);
   Media media;
   media_info *mp = 0;
+  int start, chapter_every_n_sec;
+  
+  if (strcmp (av[2], "c")) {
+  chapter_every_n_sec = optarg[0]; start = 3; }
+  else
+  start = 2;
 
-  for( int ii=2; ii<ac; ++ii ) {
+  for( int ii=start; ii<ac; ++ii ) {
     char *ap = av[ii];
     // any dash seq followed by number sets curr title pgm_pid
     // single dash only sets title pgm_pid
@@ -3188,7 +3197,7 @@ main(int ac, char **av)
 
   if( mp ) mp->brk = 1;
 
-  if( media.compose() ) {
+  if( media.compose(chapter_every_n_sec) ) {
     fprintf(stderr, "cant compose media\n");
     return 1;
   }
-- 
2.34.1

From 1ebb5b1fa0387aefe3acc8eabed92f7ee207e591 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 01:46:40 +0300
Subject: [PATCH 09/15] EXPERIMENT: update bdwrite for lpcm/hevc

---
 cinelerra-5.1/cinelerra/bdwrite.C | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
index 6a2b4ca3..b184e0c6 100644
--- a/cinelerra-5.1/cinelerra/bdwrite.C
+++ b/cinelerra-5.1/cinelerra/bdwrite.C
@@ -102,6 +102,7 @@ enum {
   BLURAY_STREAM_TYPE_VIDEO_VC1 = 0xea,
   BLURAY_STREAM_TYPE_VIDEO_H264 = 0x1b,
   BLURAY_STREAM_TYPE_VIDEO_H264_MVC = 0x20,
+  BLURAY_STREAM_TYPE_VIDEO_HEVC = 0x24,
   BLURAY_STREAM_TYPE_SUB_PG = 0x90,
   BLURAY_STREAM_TYPE_SUB_IG = 0x91,
   BLURAY_STREAM_TYPE_SUB_TEXT = 0x92,
@@ -122,6 +123,7 @@ enum {
   BLURAY_VIDEO_FORMAT_720P = 5,  // SMPTE 296M
   BLURAY_VIDEO_FORMAT_1080P = 6, // SMPTE 274M
   BLURAY_VIDEO_FORMAT_576P = 7,  // ITU-R BT.1358
+  BLURAY_VIDEO_FORMAT_2160P = 8,
 
   BLURAY_VIDEO_RATE_24000_1001 = 1, // 23.976
   BLURAY_VIDEO_RATE_24 = 2,
@@ -1505,6 +1507,7 @@ clpi_prog_stream::write()
   case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
   case BLURAY_STREAM_TYPE_VIDEO_VC1:
   case BLURAY_STREAM_TYPE_VIDEO_H264:
+  case BLURAY_STREAM_TYPE_VIDEO_HEVC:
   case 0x20:
     bs.write(format, 4);
     bs.write(rate, 4);
@@ -1905,18 +1908,18 @@ write()
 
   bs.write(stream_type, 8);
   switch (stream_type) {
-  case 0x01:
+  case BLURAY_STREAM_TYPE_VIDEO_MPEG1:
     bs.write(pid, 16);
     break;
 
-  case 0x02:
-  case 0x04:
+  case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
+  case BLURAY_STREAM_TYPE_AUDIO_MPEG2:
     bs.write(subpath_id, 8);
     bs.write(subclip_id, 8);
     bs.write(pid, 16);
     break;
 
-  case 0x03:
+  case BLURAY_STREAM_TYPE_AUDIO_MPEG1:
     bs.write(subpath_id, 8);
     bs.write(pid, 16);
     break;
@@ -1935,6 +1938,7 @@ write()
   case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
   case BLURAY_STREAM_TYPE_VIDEO_VC1:
   case BLURAY_STREAM_TYPE_VIDEO_H264:
+  case BLURAY_STREAM_TYPE_VIDEO_HEVC:
     bs.write(format, 4);
     bs.write(rate, 4);
     break;
@@ -2406,6 +2410,9 @@ static int bd_stream_type(AVCodecID codec_id)
   case AV_CODEC_ID_H264:
     stream_type = BLURAY_STREAM_TYPE_VIDEO_H264;
     break;
+  case AV_CODEC_ID_HEVC:
+    stream_type = BLURAY_STREAM_TYPE_VIDEO_HEVC;
+    break;
   case AV_CODEC_ID_MP2:
     stream_type = BLURAY_STREAM_TYPE_AUDIO_MPEG1;
     break;
@@ -2424,6 +2431,9 @@ static int bd_stream_type(AVCodecID codec_id)
   case AV_CODEC_ID_TRUEHD:
     stream_type = BLURAY_STREAM_TYPE_AUDIO_TRUHD;
     break;
+  case AV_CODEC_ID_PCM_BLURAY:
+    stream_type = BLURAY_STREAM_TYPE_AUDIO_LPCM;
+    break;
   case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
     stream_type = BLURAY_STREAM_TYPE_SUB_PG;
     break;
@@ -2478,6 +2488,8 @@ static int bd_video_format(int w, int h, int ilace)
   if( w == 1280 && h ==  720 /* && !ilace*/ ) return BLURAY_VIDEO_FORMAT_720P;
   if( w == 1440 && h == 1080 /* &&  ilace*/ ) return BLURAY_VIDEO_FORMAT_1080I;
   if( w == 1920 && h == 1080 /* && !ilace*/ ) return BLURAY_VIDEO_FORMAT_1080P;
+  if( w == 3840 && h == 2160 &&  !ilace ) return BLURAY_VIDEO_FORMAT_2160P;
+  
   fprintf(stderr, "unknown bluray video format %dx%d %silace\n",
     w, h, !ilace ? "not " : "");
   exit(1);
-- 
2.34.1

From b586a366ea5422580761b700e5458638eba97a13 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 10 Dec 2021 17:26:40 +0300
Subject: [PATCH 04/15] Improve truehd decoder/encoder from ffmpeg.git

---
 .../thirdparty/src/ffmpeg-4.4.patch_5         | 180 ++++++++++++++++++
 .../thirdparty/src/ffmpeg-4.4.patch_6         |  24 +++
 .../thirdparty/src/ffmpeg-4.4.patch_7         |  41 ++++
 .../thirdparty/src/ffmpeg-4.4.patch_8         |  43 +++++
 4 files changed, 288 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_5
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_6
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_7
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_8

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_5 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_5
new file mode 100644
index 00000000..126e51e6
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_5
@@ -0,0 +1,180 @@
+X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/fea4f953b5c6e04b84ce9c11664c9cbcac171a60..9f420163c6207b9c54badd30056974a6b3450bfd:/libavcodec/mlpenc.c
+
+diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
+index 8b61fc6b1e..37052d9e38 100644
+--- a/libavcodec/mlpenc.c
++++ b/libavcodec/mlpenc.c
+@@ -103,7 +103,7 @@ typedef struct BestOffset {
+ /** Number of possible codebooks (counting "no codebooks") */
+ #define NUM_CODEBOOKS       4
+
+-typedef struct {
++typedef struct MLPEncodeContext {
+     AVCodecContext *avctx;
+
+     int             num_substreams;         ///< Number of substreams contained within this stream.
+@@ -129,7 +129,8 @@ typedef struct {
+     int32_t        *write_buffer;           ///< Pointer to data currently being written to bitstream.
+     int32_t        *sample_buffer;          ///< Pointer to current access unit samples.
+     int32_t        *major_scratch_buffer;   ///< Scratch buffer big enough to fit all data for one entire major frame interval.
+-    int32_t        *last_frame;             ///< Pointer to last frame with data to encode.
++    int32_t        last_frames;             ///< Signal last frames.
++    int32_t        last_index;
+
+     int32_t        *lpc_sample_buffer;
+
+@@ -201,6 +202,10 @@ typedef struct {
+
+     unsigned int    max_codebook_search;
+
++    int             shorten_by;
++
++    int64_t         pts;
++
+     LPCContext      lpc_ctx;
+ } MLPEncodeContext;
+
+@@ -1116,9 +1121,13 @@ static uint8_t *write_substrs(MLPEncodeContext *ctx, uint8_t *buf, int buf_size,
+
+         rh->lossless_check_data ^= *lossless_check_data++;
+
+-        if (ctx->last_frame == ctx->inout_buffer) {
+-            /* TODO find a sample and implement shorten_by. */
+-            put_bits(&pb, 32, END_OF_STREAM);
++        if (ctx->last_frames == 0 && ctx->shorten_by) {
++            if (ctx->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
++                put_bits(&pb, 16, END_OF_STREAM & 0xFFFF);
++                put_bits(&pb, 16, (ctx->shorten_by & 0x1FFF) | 0x2000);
++            } else {
++                put_bits(&pb, 32, END_OF_STREAM);
++            }
+         }
+
+         /* Data must be flushed for the checksum and parity to be correct;
+@@ -2216,42 +2225,35 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+     int restart_frame, ret;
+     uint8_t *data;
+
++    if (!frame && !ctx->last_frames--)
++        return 0;
++
+     if ((ret = ff_alloc_packet2(avctx, avpkt, 87500 * avctx->channels, 0)) < 0)
+         return ret;
+
+-    /* add current frame to queue */
+-    if ((ret = ff_af_queue_add(&ctx->afq, frame)) < 0)
+-        return ret;
++    if (frame) {
++        /* add current frame to queue */
++        if ((ret = ff_af_queue_add(&ctx->afq, frame)) < 0)
++            return ret;
++        ctx->last_frames = ctx->max_restart_interval;
++        ctx->last_index = ctx->frame_index;
++    }
+
+-    data = frame->data[0];
++    data = frame ? frame->data[0] : NULL;
+
+     ctx->frame_index = avctx->frame_number % ctx->max_restart_interval;
+
+     ctx->inout_buffer = ctx->major_inout_buffer
+                       + ctx->frame_index * ctx->one_sample_buffer_size;
+
+-    if (ctx->last_frame == ctx->inout_buffer) {
+-        return 0;
+-    }
+-
+     ctx->sample_buffer = ctx->major_scratch_buffer
+                        + ctx->frame_index * ctx->one_sample_buffer_size;
+
+     ctx->write_buffer = ctx->inout_buffer;
+
+     if (avctx->frame_number < ctx->max_restart_interval) {
+-        if (data) {
++        if (data)
+             goto input_and_return;
+-        } else {
+-            /* There are less frames than the requested major header interval.
+-             * Update the context to reflect this.
+-             */
+-            ctx->max_restart_interval = avctx->frame_number;
+-            ctx->frame_index = 0;
+-
+-            ctx->sample_buffer = ctx->major_scratch_buffer;
+-            ctx->inout_buffer = ctx->major_inout_buffer;
+-        }
+     }
+
+     if (ctx->frame_size[ctx->frame_index] > MAX_BLOCKSIZE) {
+@@ -2278,14 +2280,13 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+
+ input_and_return:
+
+-    if (data) {
+-        ctx->frame_size[ctx->frame_index] = avctx->frame_size;
+-        ctx->next_major_frame_size += avctx->frame_size;
+-        ctx->next_major_number_of_frames++;
++    if (frame)
++        ctx->shorten_by = avctx->frame_size - frame->nb_samples;
++    ctx->frame_size[ctx->frame_index] = avctx->frame_size;
++    ctx->next_major_frame_size += avctx->frame_size;
++    ctx->next_major_number_of_frames++;
++    if (data)
+         input_data(ctx, data);
+-    } else if (!ctx->last_frame) {
+-        ctx->last_frame = ctx->inout_buffer;
+-    }
+
+     restart_frame = (ctx->frame_index + 1) % ctx->min_restart_interval;
+
+@@ -2315,10 +2316,11 @@ input_and_return:
+                                        (ctx->frame_index / ctx->min_restart_interval)*(ctx->sequence_size)*(ctx->num_substreams) +
+                                        (ctx->seq_offset[seq_index])*(ctx->num_substreams);
+
+-            for (index = 0; index < ctx->number_of_frames; index++) {
++            for (index = 0; index < ctx->number_of_frames; index++)
+                 number_of_samples += ctx->frame_size[(ctx->starting_frame_index + index) % ctx->max_restart_interval];
+-            }
+             ctx->number_of_samples = number_of_samples;
++            if (!ctx->number_of_samples)
++                break;
+
+             for (index = 0; index < ctx->seq_size[seq_index]; index++) {
+                 clear_channel_params(ctx->seq_channel_params + index * ctx->avctx->channels, ctx->avctx->channels);
+@@ -2343,8 +2345,16 @@ input_and_return:
+
+ no_data_left:
+
+-    ff_af_queue_remove(&ctx->afq, avctx->frame_size, &avpkt->pts,
+-                       &avpkt->duration);
++    if (ctx->afq.frame_count > 0) {
++        ff_af_queue_remove(&ctx->afq, avctx->frame_size, &avpkt->pts,
++                           &avpkt->duration);
++        ctx->pts = avpkt->pts + avpkt->duration;
++    } else {
++        avpkt->pts = ctx->pts;
++        ctx->pts += avctx->frame_size;
++    }
++    if (!frame)
++        avctx->frame_number++;
+     avpkt->size = bytes_written;
+     *got_packet = 1;
+     return 0;
+@@ -2379,7 +2389,7 @@ const AVCodec ff_mlp_encoder = {
+     .init                   = mlp_encode_init,
+     .encode2                = mlp_encode_frame,
+     .close                  = mlp_encode_close,
+-    .capabilities           = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_EXPERIMENTAL,
++    .capabilities           = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
+     .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
+     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+     .channel_layouts        = ff_mlp_channel_layouts,
+@@ -2396,7 +2406,7 @@ const AVCodec ff_truehd_encoder = {
+     .init                   = mlp_encode_init,
+     .encode2                = mlp_encode_frame,
+     .close                  = mlp_encode_close,
+-    .capabilities           = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_EXPERIMENTAL,
++    .capabilities           = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
+     .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
+     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+     .channel_layouts        = (const uint64_t[]) {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK, 0},
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_6 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_6
new file mode 100644
index 00000000..3c0b4352
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_6
@@ -0,0 +1,24 @@
+X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/61c2c9ef8e66920c8ba308e8fa9f36ae602f8245..2bb9d2be5e2e1d971e5b80358098f2a7fce06e0e:/libavcodec/mlpenc.c
+
+diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
+index 37052d9e38..443cb41cf5 100644
+--- a/libavcodec/mlpenc.c
++++ b/libavcodec/mlpenc.c
+@@ -2390,7 +2390,7 @@ const AVCodec ff_mlp_encoder = {
+     .encode2                = mlp_encode_frame,
+     .close                  = mlp_encode_close,
+     .capabilities           = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
+-    .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
++    .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
+     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+     .channel_layouts        = ff_mlp_channel_layouts,
+     .caps_internal          = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+@@ -2407,7 +2407,7 @@ const AVCodec ff_truehd_encoder = {
+     .encode2                = mlp_encode_frame,
+     .close                  = mlp_encode_close,
+     .capabilities           = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
+-    .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE},
++    .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
+     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+     .channel_layouts        = (const uint64_t[]) {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK, 0},
+     .caps_internal          = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_7 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_7
new file mode 100644
index 00000000..2203a3a9
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_7
@@ -0,0 +1,41 @@
+X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/a4c98c507ed3c729fc92d641b974385f8aa37b33..5673a4842556b79a92a1ede6e9696506fd4161ad:/libavcodec/mlpdec.c
+
+diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
+index e4992550ee..0fac5ad754 100644
+--- a/libavcodec/mlpdec.c
++++ b/libavcodec/mlpdec.c
+@@ -1330,6 +1330,18 @@ error:
+     return AVERROR_INVALIDDATA;
+ }
+
++static void mlp_decode_flush(AVCodecContext *avctx)
++{
++    MLPDecodeContext *m = avctx->priv_data;
++
++    m->params_valid = 0;
++    for (int substr = 0; substr <= m->max_decoded_substream; substr++){
++        SubStream *s = &m->substream[substr];
++
++        s->lossless_check_data = 0xffffffff;
++    }
++}
++
+ #if CONFIG_MLP_DECODER
+ const AVCodec ff_mlp_decoder = {
+     .name           = "mlp",
+@@ -1339,6 +1351,7 @@ const AVCodec ff_mlp_decoder = {
+     .priv_data_size = sizeof(MLPDecodeContext),
+     .init           = mlp_decode_init,
+     .decode         = read_access_unit,
++    .flush          = mlp_decode_flush,
+     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
+     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+ };
+@@ -1352,6 +1365,7 @@ const AVCodec ff_truehd_decoder = {
+     .priv_data_size = sizeof(MLPDecodeContext),
+     .init           = mlp_decode_init,
+     .decode         = read_access_unit,
++    .flush          = mlp_decode_flush,
+     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
+     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+ };
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_8 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_8
new file mode 100644
index 00000000..c59a5ee8
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_8
@@ -0,0 +1,43 @@
+X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/9f420163c6207b9c54badd30056974a6b3450bfd..034133a0df5f327aba36ee25db9452cda9e1a62b:/libavcodec/mlpdec.c
+
+diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
+index 0fac5ad754..08db5dc63c 100644
+--- a/libavcodec/mlpdec.c
++++ b/libavcodec/mlpdec.c
+@@ -53,6 +53,8 @@
+ typedef struct SubStream {
+     /// Set if a valid restart header has been read. Otherwise the substream cannot be decoded.
+     uint8_t     restart_seen;
++    /// Set if end of stream is encountered
++    uint8_t     end_of_stream;
+
+     //@{
+     /** restart header data */
+@@ -1286,8 +1288,8 @@ static int read_access_unit(AVCodecContext *avctx, void* data,
+             else if (m->avctx->codec_id == AV_CODEC_ID_MLP    && shorten_by != 0xD234)
+                 return AVERROR_INVALIDDATA;
+
+-            if (substr == m->max_decoded_substream)
+-                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
++            av_log(m->avctx, AV_LOG_DEBUG, "End of stream indicated.\n");
++            s->end_of_stream = 1;
+         }
+
+         if (substream_parity_present[substr]) {
+@@ -1319,6 +1321,16 @@ next_substr:
+     if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)
+         return ret;
+
++    for (substr = 0; substr <= m->max_decoded_substream; substr++){
++        SubStream *s = &m->substream[substr];
++
++        if (s->end_of_stream) {
++            s->lossless_check_data = 0xffffffff;
++            s->end_of_stream = 0;
++            m->params_valid = 0;
++        }
++    }
++
+     return length;
+
+ substream_length_mismatch:
-- 
2.34.1

From c1ff125573d9132fe6c07c63bb53d3f746ad9d86 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 04:26:11 +0300
Subject: [PATCH 12/15] EXPERIMENTAL: bdcreate: add m2ts profiles, part 1

---
 cinelerra-5.1/cinelerra/bdcreate.C   | 31 ++++++++++++++++++++++++++++
 cinelerra-5.1/cinelerra/bdcreate.h   | 14 +++++++++++++
 cinelerra-5.1/cinelerra/bdcreate.inc |  1 +
 3 files changed, 46 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
index 20a953e2..67745a8d 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.C
+++ b/cinelerra-5.1/cinelerra/bdcreate.C
@@ -66,6 +66,7 @@ static struct bd_profile {
 	const char *name;
 } bd_profiles[] = {
 	{"bluray.m2ts"},
+	{"bluray_lpcm.m2ts"},
 };
 
 
@@ -211,6 +212,7 @@ CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
 	this->use_resize_tracks = 0;
 	this->use_labeled = 0;
 	this->use_farmed = 0;
+	this->use_termux = 0;
 
 	this->bd_size = BD_SIZE;
 	this->bd_width = BD_WIDTH;
@@ -453,6 +455,7 @@ BC_Window* CreateBD_Thread::new_gui()
 	use_resize_tracks = 0;
 	use_labeled = 0;
 	use_farmed = 0;
+	use_termux = 0;
 	use_standard = !strcmp(mwindow->default_std(),"NTSC") ?
 		 BD_1920x1080_2997i : BD_1920x1080_25i;
 	bd_size = BD_SIZE;
@@ -728,6 +731,7 @@ CreateBD_GUI::CreateBD_GUI(CreateBD_Thread *thread, int x, int y, int w, int h)
 	disk_space = 0;
 	standard = 0;
 	scale = 0;
+	profile = 0;
 	need_deinterlace = 0;
 	need_inverse_telecine = 0;
 	need_resize_tracks = 0;
@@ -785,6 +789,18 @@ void CreateBD_GUI::create_objects()
 	media_size->update(media_sizes[0]->get_text());
 	disk_space->update();
 	y += disk_space->get_h() + pady/2;
+	
+	title = new BC_Title(x, y, _("Profile:"), MEDIUMFONT, YELLOW);
+	add_subwindow(title);
+	y +=  title->get_h()+pady;
+	profile = new CreateBD_Profile(this, x1, y);
+	profile->create_objects();
+	profiles.append(new BC_ListBoxItem("bluray.m2ts"));
+	profiles.append(new BC_ListBoxItem("bluray_lpcm.m2ts"));
+	profile->update_list(&profiles);
+	profile->update(profiles[0]->get_text());
+	
+	
 	title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
 	add_subwindow(title);
 	standard = new CreateBD_Format(this, title->get_w() + padx, y);
@@ -1128,3 +1144,18 @@ int CreateBD_MediaSize::handle_event()
 	return 1;
 }
 
+CreateBD_Profile::CreateBD_Profile(CreateBD_GUI *gui, int x, int y)
+ : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
+{
+	this->gui = gui;
+}
+
+CreateBD_Profile::~CreateBD_Profile()
+{
+}
+
+int CreateBD_Profile::handle_event()
+{
+	return 1;
+}
+
diff --git a/cinelerra-5.1/cinelerra/bdcreate.h b/cinelerra-5.1/cinelerra/bdcreate.h
index 89ee83bb..81f11120 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.h
+++ b/cinelerra-5.1/cinelerra/bdcreate.h
@@ -62,6 +62,7 @@ public:
 	int use_wide_audio, use_farmed;
 	int use_histogram, use_labeled;
 	int use_standard;
+	int use_termux;
 
 	int64_t bd_size;
 	int bd_width;
@@ -232,6 +233,8 @@ public:
 	CreateBD_OK *ok;
 	int cancel_x, cancel_y, cancel_w, cancel_h;
 	CreateBD_Cancel *cancel;
+	ArrayList<BC_ListBoxItem *> profiles;
+	CreateBD_Profile *profile;
 };
 
 class CreateBD_FormatItem : public BC_MenuItem
@@ -290,4 +293,15 @@ public:
 	CreateBD_GUI *gui;
 };
 
+class CreateBD_Profile : public BC_PopupTextBox
+{
+public:
+	CreateBD_Profile(CreateBD_GUI *gui, int x, int y);
+	~CreateBD_Profile();
+	int handle_event();
+
+	CreateBD_GUI *gui;
+};
+
+
 #endif
diff --git a/cinelerra-5.1/cinelerra/bdcreate.inc b/cinelerra-5.1/cinelerra/bdcreate.inc
index d44320c6..5db9568b 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.inc
+++ b/cinelerra-5.1/cinelerra/bdcreate.inc
@@ -41,5 +41,6 @@ class CreateBD_GUI;
 class CreateBD_FormatItem;
 class CreateBD_Format;
 class CreateBD_MediaSize;
+class CreateBD_Profile;
 
 #endif
-- 
2.34.1

From 96ee3224bc716f18452786811eabb296aade0256 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 05:13:15 +0300
Subject: [PATCH 13/15] Fix bdcreate.C layout

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

diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
index 67745a8d..90fb8734 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.C
+++ b/cinelerra-5.1/cinelerra/bdcreate.C
@@ -792,16 +792,17 @@ void CreateBD_GUI::create_objects()
 	
 	title = new BC_Title(x, y, _("Profile:"), MEDIUMFONT, YELLOW);
 	add_subwindow(title);
-	y +=  title->get_h()+pady;
-	profile = new CreateBD_Profile(this, x1, y);
+	x += title->get_w()+padx;
+	int prev_title_w = title->get_w()+padx;
+	profile = new CreateBD_Profile(this, x, y);
 	profile->create_objects();
 	profiles.append(new BC_ListBoxItem("bluray.m2ts"));
 	profiles.append(new BC_ListBoxItem("bluray_lpcm.m2ts"));
 	profile->update_list(&profiles);
 	profile->update(profiles[0]->get_text());
+	y += profile->get_h() + pady;
 	
-	
-	title = new BC_Title(x, y, _("Format:"), MEDIUMFONT, YELLOW);
+	title = new BC_Title(x-prev_title_w, y, _("Format:"), MEDIUMFONT, YELLOW);
 	add_subwindow(title);
 	standard = new CreateBD_Format(this, title->get_w() + padx, y);
 	add_subwindow(standard);
@@ -1145,7 +1146,7 @@ int CreateBD_MediaSize::handle_event()
 }
 
 CreateBD_Profile::CreateBD_Profile(CreateBD_GUI *gui, int x, int y)
- : BC_PopupTextBox(gui, 0, 0, x, y, xS(70),yS(50))
+ : BC_PopupTextBox(gui, 0, 0, x, y, xS(170),yS(50))
 {
 	this->gui = gui;
 }
-- 
2.34.1

From 1c87ddea4253994bd68ccb04c91033f7abf5f8b4 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 06:35:25 +0300
Subject: [PATCH 15/15] Rename m2ts_pcm.m2ts to bluray_lpcm.m2ts

---
 cinelerra-5.1/ffmpeg/audio/bluray_lpcm.m2ts | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 cinelerra-5.1/ffmpeg/audio/bluray_lpcm.m2ts

diff --git a/cinelerra-5.1/ffmpeg/audio/bluray_lpcm.m2ts b/cinelerra-5.1/ffmpeg/audio/bluray_lpcm.m2ts
new file mode 100644
index 00000000..284f433a
--- /dev/null
+++ b/cinelerra-5.1/ffmpeg/audio/bluray_lpcm.m2ts
@@ -0,0 +1,2 @@
+bluray pcm_bluray
+id 0x1100
-- 
2.34.1

From 5d7c20c738b00b8fbb0d9bcce26d44bbecf8bec1 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 17 Dec 2021 06:25:32 +0300
Subject: [PATCH 14/15] EXPERIMENTAL: attempt to get value from popuptextbox

---
 cinelerra-5.1/cinelerra/bdcreate.C | 7 +++++--
 cinelerra-5.1/cinelerra/bdcreate.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
index 90fb8734..291f7e7e 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.C
+++ b/cinelerra-5.1/cinelerra/bdcreate.C
@@ -213,6 +213,8 @@ CreateBD_Thread::CreateBD_Thread(MWindow *mwindow)
 	this->use_labeled = 0;
 	this->use_farmed = 0;
 	this->use_termux = 0;
+	
+	strcpy(use_profile,"bluray.m2ts");
 
 	this->bd_size = BD_SIZE;
 	this->bd_width = BD_WIDTH;
@@ -325,7 +327,7 @@ int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char
 	strcpy(asset->fformat, "m2ts");
 
 	asset->audio_data = 1;
-	strcpy(asset->acodec, bd_profiles[0].name);
+	strcpy(asset->acodec, use_profile);
 	//mwindow->defaults->get("DEFAULT_BLURAY_ACODEC", asset->acodec);
 	FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec);
 	FFMPEG::load_options(option_path, asset->ff_audio_options,
@@ -333,7 +335,7 @@ int CreateBD_Thread::create_bd_jobs(ArrayList<BatchRenderJob*> *jobs, const char
 	asset->ff_audio_bitrate = bd_kaudio_rate * 1000;
 
 	asset->video_data = 1;
-	const char *vcodec = bd_profiles[0].name;
+	const char *vcodec = use_profile;
 	switch( asset->interlace_mode ) {
 	case ILACE_MODE_TOP_FIRST:    vcodec = "bluray_tff.m2ts";  break;
 	case ILACE_MODE_BOTTOM_FIRST: vcodec = "bluray_bff.m2ts";  break;
@@ -1157,6 +1159,7 @@ CreateBD_Profile::~CreateBD_Profile()
 
 int CreateBD_Profile::handle_event()
 {
+	strcpy(gui->thread->use_profile, get_text());
 	return 1;
 }
 
diff --git a/cinelerra-5.1/cinelerra/bdcreate.h b/cinelerra-5.1/cinelerra/bdcreate.h
index 81f11120..e91d3c0a 100644
--- a/cinelerra-5.1/cinelerra/bdcreate.h
+++ b/cinelerra-5.1/cinelerra/bdcreate.h
@@ -57,6 +57,7 @@ public:
 	CreateBD_GUI *gui;
 	char asset_title[BCTEXTLEN];
 	char tmp_path[BCTEXTLEN];
+	char use_profile[BCTEXTLEN];
 	int use_deinterlace, use_inverse_telecine;
 	int use_scale, use_resize_tracks;
 	int use_wide_audio, use_farmed;
-- 
2.34.1

-- 
Cin mailing list
[email protected]
https://lists.cinelerra-gg.org/mailman/listinfo/cin

Reply via email to