From c0f9aafef7e07275a859804e87ee370a0a313940 Mon Sep 17 00:00:00 2001
From: Dorian Koch <doriank@fsmpi.rwth-aachen.de>
Date: Wed, 24 Apr 2024 18:41:04 +0200
Subject: [PATCH] Fix missing audio channels from Sony camera

---
 transcode.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/transcode.c b/transcode.c
index ece6ccd..f5b9f67 100644
--- a/transcode.c
+++ b/transcode.c
@@ -65,9 +65,18 @@ static void setup_input_stream(char *stream, AVFormatContext *demux,
 	}
 	else if (type == AVMEDIA_TYPE_AUDIO)
 	{
-		p = mprintf("time_base=%d/%d:sample_rate=%d:sample_fmt=%d:channel_layout=%d:channels=%d",
+		// Set channel layout to default if not set
+		if(decs[idx]->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
+			av_channel_layout_default(&decs[idx]->ch_layout, decs[idx]->ch_layout.nb_channels);
+
+		char ch_layout[64];
+		err = av_channel_layout_describe(&decs[idx]->ch_layout, ch_layout, sizeof(ch_layout));
+		if (err < 0)
+			job_failed("Could not describe channel layout: %s", av_err2str(err));
+
+		p = mprintf("time_base=%d/%d:sample_rate=%d:sample_fmt=%d:channel_layout=%s:channels=%d",
 			demux->streams[idx]->time_base.num, demux->streams[idx]->time_base.den,
-			decs[idx]->sample_rate, decs[idx]->sample_fmt, decs[idx]->channel_layout,
+			decs[idx]->sample_rate, decs[idx]->sample_fmt, ch_layout,
 			decs[idx]->channels);
 		err = avfilter_graph_create_filter(&srcs[idx],
 				avfilter_get_by_name("abuffer"), 0, p, 0, fg);
-- 
GitLab