On Sat, Apr 13, 2024 at 9:13 PM Andrew Randrianasulu <
[email protected]> wrote:

>
>
> сб, 13 апр. 2024 г., 21:04 Andrea paz <[email protected]>:
>
>> Sometimes I think it is my old projects or even not my own that cause
>> some problems. For example to test ChromaKeyHSV I created my own
>> project, but I also used two projects of IgorV. I could never see
>> precise cause and effect though, so I'm not sure.
>>
>> Regarding AC3, there is a commit in Adam's repository about decoding
>> AC3, but I don't think it is related. Anyway, the link is this one:
>>
>> https://github.com/heroineworshiper/hvirtual/commit/3124ad744154eae8e48bdeff00d81d11613dc9a4
>
>
>
> yeah, looks like quicktime/ffmpeg interaction soecific to HV.
>
> Sorry, still stuck with this mysteriously non-working ac3 encoder ....
>

I think I fixed it, can you try attached patch on top of all previous?
From f269904fef4aab0e66cdfde5518fe5636bd24a4f Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sun, 14 Apr 2024 01:45:22 +0300
Subject: [PATCH 6/6] Fix fileac3 encoding with ffmpeg 7.0?

---
 cinelerra-5.1/cinelerra/fileac3.C | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/fileac3.C b/cinelerra-5.1/cinelerra/fileac3.C
index 1f0083f0..63654f32 100644
--- a/cinelerra-5.1/cinelerra/fileac3.C
+++ b/cinelerra-5.1/cinelerra/fileac3.C
@@ -143,7 +143,9 @@ int FileAC3::open_file(int rd, int wr)
 			int sample_rate = asset->sample_rate;
 			int64_t layout = get_channel_layout(channels);
 			AVChannelLayout ch_layout;
-			av_channel_layout_from_mask(&ch_layout, layout);
+			av_channel_layout_default(&ch_layout, channels);
+			if(!ch_layout.nb_channels) {
+			printf ("av_ch_layut_default failed! \n"); }
 			int bitrate = asset->ac3_bitrate * 1000;
 			av_init_packet(&avpkt);
 			codec_context = avcodec_alloc_context3(codec);
@@ -151,18 +153,28 @@ int FileAC3::open_file(int rd, int wr)
 			codec_context->sample_rate = sample_rate;
 			codec_context->ch_layout.nb_channels = channels;
 			codec_context->ch_layout.u.mask = layout;
+			av_channel_layout_copy(&codec_context->ch_layout, &ch_layout);
 			codec_context->sample_fmt = codec->sample_fmts[0];
-			SwrContext *resample_context = NULL;
-			swr_alloc_set_opts2(&resample_context,
+			SwrContext *tmp_resample_context = NULL;
+			int ret = swr_alloc_set_opts2(&tmp_resample_context,
 					&ch_layout, codec_context->sample_fmt, sample_rate,
 					&ch_layout, AV_SAMPLE_FMT_S16, sample_rate,
 					0, NULL);
-			swr_init(resample_context);
+			if(ret <0) printf("swr_alloc eror: %i \n", ret );
+			if(tmp_resample_context){
+			resample_context = tmp_resample_context;
+			if(swr_init(resample_context))
+			{
+				eprintf(_("FileAC3::open_file failed to init swr.\n"));
+				result = 1;
+			}
+			}
 			if(avcodec_open2(codec_context, codec, 0))
 			{
 				eprintf(_("FileAC3::open_file failed to open codec.\n"));
 				result = 1;
 			}
+			av_channel_layout_uninit(&ch_layout);
 		}
 	}
 
@@ -317,8 +329,9 @@ int FileAC3::write_samples(double **buffer, int64_t len)
 		AVFrame *frame = av_frame_alloc();
 		frame->nb_samples = frame_size;
 		frame->format = avctx->sample_fmt;
-		frame->ch_layout.u.mask = avctx->ch_layout.u.mask;
+		av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
 		frame->sample_rate = avctx->sample_rate;
+
 		ret = av_frame_get_buffer(frame, 0);
 		if( ret >= 0 ) {
 			const uint8_t *samples = (uint8_t *)temp_raw +
@@ -326,7 +339,7 @@ int FileAC3::write_samples(double **buffer, int64_t len)
 			ret = swr_convert(resample_context,
 				(uint8_t **)frame->extended_data, frame_size,
 				&samples, frame_size);
-		}
+		} else { printf("fileAC3: av_frame_get_buffer failed!\n"); }
 		if( ret >= 0 ) {
 			frame->pts = avctx->sample_rate && avctx->time_base.num ?
 				file->get_audio_position() : AV_NOPTS_VALUE ;
-- 
2.35.8

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

Reply via email to