From 40e41e3569648ba2f70208b2ed1fbedf1156ca83 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Tue, 9 Jan 2024 05:30:15 +0300
Subject: [PATCH 3/5] Add diff between codec sar/dar and container sar/dar,
 mostly for troubleshooting aspect ratio problesms

---
 cinelerra-5.1/cinelerra/ffmpeg.C | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 47e811b2..51171a01 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -2546,8 +2546,9 @@ int FFMPEG::info(char *text, int len)
 		report("/ range:%s\n", rg ? rg : unkn);
 
 		AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, st, NULL);
-		if(sar.num) {
 		AVRational display_aspect_ratio;
+		if(sar.num) {
+		
     		av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
                   st->codecpar->width  * (int64_t)sar.num,
                   st->codecpar->height * (int64_t)sar.den,
@@ -2555,15 +2556,21 @@ int FFMPEG::info(char *text, int len)
 		report("  Guessed SAR: %d:%d, ", sar.num, sar.den );
 		report("DAR: %d:%d \n", display_aspect_ratio.num, display_aspect_ratio.den);
 		}
-		if (st->sample_aspect_ratio.num  &&
-		av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio))
+		if (st->sample_aspect_ratio.num)
 		{
-		AVRational display_aspect_ratio;
     		av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
                   st->codecpar->width  * (int64_t)st->sample_aspect_ratio.num,
                   st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
                   1024 * 1024);
-		report("  Detected SAR: %d:%d , DAR %d:%d \n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den);
+		report("  container Detected SAR: %d:%d , DAR %d:%d \n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den);
+		}
+		if (st->codecpar->sample_aspect_ratio.num)
+		{
+    		av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
+                  st->codecpar->width  * (int64_t)st->codecpar->sample_aspect_ratio.num,
+                  st->codecpar->height * (int64_t)st->codecpar->sample_aspect_ratio.den,
+                  1024 * 1024);
+		report("  codec Detected SAR: %d:%d , DAR %d:%d \n", st->codecpar->sample_aspect_ratio.num, st->codecpar->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den);
 		}
 		double secs = to_secs(st->duration, st->time_base);
 		int64_t length = secs * vid->frame_rate + 0.5;
-- 
2.43.0

