buildroot/package/bento4/0005-AVC-extract-VUI-values...

97 lines
3.4 KiB
Diff

From 56e0acde44adbc5503da20dd96c31db33f744bd7 Mon Sep 17 00:00:00 2001
From: peak3d <pfau@peak3d.de>
Date: Thu, 22 Jul 2021 10:27:50 +0200
Subject: [PATCH] AVC extract VUI values from SPS
Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
---
Source/C++/Codecs/Ap4AvcParser.cpp | 54 +++++++++++++++++++++++++-----
Source/C++/Codecs/Ap4AvcParser.h | 3 +-
2 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/Source/C++/Codecs/Ap4AvcParser.cpp b/Source/C++/Codecs/Ap4AvcParser.cpp
index 7efb5c9..7f4fc34 100644
--- a/Source/C++/Codecs/Ap4AvcParser.cpp
+++ b/Source/C++/Codecs/Ap4AvcParser.cpp
@@ -287,18 +287,54 @@ AP4_AvcSequenceParameterSet::AP4_AvcSequenceParameterSet() :
/*----------------------------------------------------------------------
| AP4_AvcSequenceParameterSet::GetInfo
+---------------------------------------------------------------------*/
-void
+bool
AP4_AvcSequenceParameterSet::GetInfo(unsigned int& width, unsigned int& height)
{
- width = (pic_width_in_mbs_minus1+1) * 16;
- height = (2-frame_mbs_only_flag) * (pic_height_in_map_units_minus1+1) * 16;
+ unsigned int nwidth = (pic_width_in_mbs_minus1+1) * 16;
+ unsigned int nheight = (2-frame_mbs_only_flag) * (pic_height_in_map_units_minus1+1) * 16;
- if (frame_cropping_flag) {
- unsigned int crop_h = 2*(frame_crop_left_offset+frame_crop_right_offset);
- unsigned int crop_v = 2*(frame_crop_top_offset+frame_crop_bottom_offset)*(2-frame_mbs_only_flag);
- if (crop_h < width) width -= crop_h;
- if (crop_v < height) height -= crop_v;
- }
+ if (frame_cropping_flag) {
+ unsigned int crop_h = 2*(frame_crop_left_offset+frame_crop_right_offset);
+ unsigned int crop_v = 2*(frame_crop_top_offset+frame_crop_bottom_offset)*(2-frame_mbs_only_flag);
+ if (crop_h < nwidth) nwidth -= crop_h;
+ if (crop_v < nheight) nheight -= crop_v;
+ }
+ if (nwidth != width || nheight != height)
+ {
+ width = nwidth;
+ height = nheight;
+ return true;
+ }
+ return false;
+}
+
+/*----------------------------------------------------------------------
+| AP4_AvcSequenceParameterSet::GetVUIInfo
++---------------------------------------------------------------------*/
+bool
+AP4_AvcSequenceParameterSet::GetVUIInfo(unsigned int& fps_ticks, unsigned int& fps_scale, float &aspect)
+{
+ bool ret(false);
+ if (timing_info_present_flag && fixed_frame_rate_flag)
+ {
+ if (fps_scale != (num_units_in_tick << 1) || fps_ticks != time_scale)
+ {
+ fps_scale = num_units_in_tick << 1;
+ fps_ticks = time_scale;
+ ret = true;
+ }
+ }
+ unsigned int w, h;
+ if (aspect_ratio_info_present_flag && GetInfo(w, h))
+ {
+ float a((float)(sar_width * w) / (sar_height * h));
+ if (a != aspect)
+ {
+ aspect = a;
+ ret = true;
+ }
+ }
+ return ret;
}
/*----------------------------------------------------------------------
diff --git a/Source/C++/Codecs/Ap4AvcParser.h b/Source/C++/Codecs/Ap4AvcParser.h
index 9f97892..431a294 100644
--- a/Source/C++/Codecs/Ap4AvcParser.h
+++ b/Source/C++/Codecs/Ap4AvcParser.h
@@ -91,7 +91,8 @@ typedef struct {
struct AP4_AvcSequenceParameterSet {
AP4_AvcSequenceParameterSet();
- void GetInfo(unsigned int& width, unsigned int& height);
+ bool GetInfo(unsigned int& width, unsigned int& height);
+ bool GetVUIInfo(unsigned int& fps_ticks, unsigned int& fps_scale, float &aspect);
AP4_DataBuffer raw_bytes;
--
2.30.2