From b998ecfab557daeec21fc368124df8370cb5dae3 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Tue, 19 Oct 2021 10:50:11 +0800 Subject: [PATCH] Fix mp4 edts trace info 1. Media time is signed value 2. Media time is in unit of mdhd time scale. Since mdhd comes after edts, we don't know mdhd_TimeScale yet when handle edts. Give a hint to user on which time scale to use. Fix #1441 --- Source/MediaInfo/File__Analyze.h | 2 ++ Source/MediaInfo/File__Analyze_Buffer.cpp | 19 +++++++++++++++++++ Source/MediaInfo/Multiple/File_Mpeg4.h | 2 +- .../Multiple/File_Mpeg4_Elements.cpp | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/MediaInfo/File__Analyze.h b/Source/MediaInfo/File__Analyze.h index c70ddcdfbf..b6790f128b 100644 --- a/Source/MediaInfo/File__Analyze.h +++ b/Source/MediaInfo/File__Analyze.h @@ -574,10 +574,12 @@ public : void Get_B2 (int16u &Info, const char* Name); void Get_B3 (int32u &Info, const char* Name); void Get_B4 (int32u &Info, const char* Name); + void Get_B4S (int32s &Info, const char* Name); void Get_B5 (int64u &Info, const char* Name); void Get_B6 (int64u &Info, const char* Name); void Get_B7 (int64u &Info, const char* Name); void Get_B8 (int64u &Info, const char* Name); + void Get_B8S (int64s &Info, const char* Name); void Get_B16 (int128u &Info, const char* Name); void Get_BF2 (float32 &Info, const char* Name); void Get_BF4 (float32 &Info, const char* Name); diff --git a/Source/MediaInfo/File__Analyze_Buffer.cpp b/Source/MediaInfo/File__Analyze_Buffer.cpp index 2581e15a53..8024667f91 100644 --- a/Source/MediaInfo/File__Analyze_Buffer.cpp +++ b/Source/MediaInfo/File__Analyze_Buffer.cpp @@ -187,6 +187,16 @@ void File__Analyze::Get_B4(int32u &Info, const char* Name) Element_Offset+=4; } +//--------------------------------------------------------------------------- +void File__Analyze::Get_B4S(int32s &Info, const char* Name) +{ + INTEGRITY_SIZE_ATLEAST_INT(4); + Info=BigEndian2int32s(Buffer+Buffer_Offset+(size_t)Element_Offset); + if (Trace_Activated) + Param(Name, Info); + Element_Offset+=4; +} + //--------------------------------------------------------------------------- void File__Analyze::Get_B5(int64u &Info, const char* Name) { @@ -223,6 +233,15 @@ void File__Analyze::Get_B8(int64u &Info, const char* Name) Element_Offset+=8; } +//--------------------------------------------------------------------------- +void File__Analyze::Get_B8S(int64s &Info, const char* Name) +{ + INTEGRITY_SIZE_ATLEAST_INT(8); + Info=BigEndian2int64s(Buffer+Buffer_Offset+(size_t)Element_Offset); + if (Trace_Activated) Param(Name, Info); + Element_Offset+=8; +} + //--------------------------------------------------------------------------- void File__Analyze::Get_B16(int128u &Info, const char* Name) { diff --git a/Source/MediaInfo/Multiple/File_Mpeg4.h b/Source/MediaInfo/Multiple/File_Mpeg4.h index d75528fd26..43e8dd2602 100644 --- a/Source/MediaInfo/Multiple/File_Mpeg4.h +++ b/Source/MediaInfo/Multiple/File_Mpeg4.h @@ -434,7 +434,7 @@ private : struct edts_struct { int64u Duration; - int64u Delay; + int64s Delay; int32u Rate; }; std::vector edts; diff --git a/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp b/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp index 89f6ae0d04..8596e13fe5 100644 --- a/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp +++ b/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp @@ -1469,6 +1469,19 @@ void File_Mpeg4::Data_Parse() Get_B8(_INFO, _NAME); \ } \ +// Bigendian signed +#define Get_BS_DEPENDOFVERSION(_INFO, _NAME) \ + { \ + if (Version==0) \ + { \ + int32s Info; \ + Get_B4S(Info, _NAME); \ + _INFO=Info; \ + } \ + else \ + Get_B8S(_INFO, _NAME); \ + } \ + #define Get_DATE1904_DEPENDOFVERSION(_INFO, _NAME) \ { \ if (Version==0) \ @@ -3856,7 +3869,7 @@ void File_Mpeg4::moov_trak_edts_elst() stream::edts_struct edts; Element_Begin1("Entry"); Get_B_DEPENDOFVERSION(edts.Duration, "Track duration"); Param_Info2C(moov_mvhd_TimeScale, (int64u)edts.Duration*1000/moov_mvhd_TimeScale, " ms"); - Get_B_DEPENDOFVERSION(edts.Delay, "Media time"); Param_Info2C(moov_mvhd_TimeScale && (edts.Delay!=(int32u)-1), (int64u)edts.Delay*1000/moov_mvhd_TimeScale, " ms"); + Get_BS_DEPENDOFVERSION(edts.Delay, "Media time"); Param_Info2C(edts.Delay > 0, edts.Delay, " / media header time scale"); Get_B4 (edts.Rate, "Media rate"); Param_Info1(((float)edts.Rate)/0x10000); Element_End0();