Skip to content

Commit

Permalink
Edit of some video stsd values (version and temporal quality)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Mar 12, 2024
1 parent 9ce2063 commit eb2a4ab
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 37 deletions.
15 changes: 14 additions & 1 deletion Source/Common/mp4/mp4_.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ protected: \
void Write_Internal(); \
}; \

//Chunk with modification/insertion/write
#define CHUNK_M(_Level, _Name) \
class mp4_##_Name : public mp4_Base \
{ \
public: \
mp4_##_Name(global* Global):mp4_Base(Global, _Level) {Chunk.Header.Name=Elements::_Name;} \
protected: \
void Read_Internal(); \
void Modify_Internal(); \
size_t Insert_Internal(int32u Chunk_Name_Insert); \
void Write_Internal(); \
}; \

CHUNK_W(1, mdat);
CHUNK_W(1, free);
CHUNK_I(1, moov);
Expand All @@ -117,7 +130,7 @@ CHUNK__(3, moov_trak_mdia);
CHUNK__(4, moov_trak_mdia_minf);
CHUNK__(5, moov_trak_mdia_minf_stbl);
CHUNK__(6, moov_trak_mdia_minf_stbl_stsd);
CHUNK_I(7, moov_trak_mdia_minf_stbl_stsd_xxxxVideo);
CHUNK_M(7, moov_trak_mdia_minf_stbl_stsd_xxxxVideo);
CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_clap);
CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_colr);
CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_fiel);
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/mp4/mp4_moov_trak_mdia_mdhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_mdhd::Read_Internal()
{
Chunk.trak_Index=Global->moov_trak.size();
Chunk.trak_Index=Global->moov_trak.size()-1;
Global->moov_trak_mdia_mdhd[Chunk.trak_Index]=new global::block_moov_trak_mdia_mdhd();

Read_Internal_ReadAllInBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxSound::Read_Internal ()
Chunk.Content.Size=Chunk.Content.Before_Subs_Content_Size; // Trick to read only node data
Read_Internal_ReadAllInBuffer();
Chunk.Content.Size=Content_Size;
Chunk.trak_Index=Global->moov_trak.size();
Chunk.trak_Index=Global->moov_trak.size()-1;

Skip_XX(6); // Reserved;
Skip_XX(2); // Data reference index
Expand Down
87 changes: 67 additions & 20 deletions Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo::Read_Internal ()
{
Chunk.trak_Index=Global->moov_trak.size()-1;

if (Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo.count(Chunk.trak_Index))
throw exception_read_block("2 moov trak mdia minf stbl stsd xxxxVideo blocks");

Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]=new global::block_moov_trak_mdia_minf_stbl_stsd_xxxxVideo();

//Reading
if (Chunk.Content.Size<78)
Expand All @@ -24,29 +30,29 @@ void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo::Read_Internal ()
Chunk.Content.Size=Chunk.Content.Before_Subs_Content_Size; // Trick to read only node data
Read_Internal_ReadAllInBuffer();
Chunk.Content.Size=Content_Size;
Chunk.trak_Index=Global->moov_trak.size();

uint16_t Version, Depth, ColorTableID;

Skip_XX(6); // Reserved
Skip_XX(2); // Data reference index
Get_B2(Version);
if (Version>3)
Get_B6(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Reserved);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->DataReferenceIndex);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Version);
if (Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Version>3)
throw exception_read_block("Can not parse moov trak mdia minf stbl stsd xxxxVideo (version not supported)");
Skip_XX(2); // Revision level
Skip_XX(4); // Vendor
Skip_XX(4); // Temporal quality
Skip_XX(4); // Spatial quality
Skip_XX(2); // Width
Skip_XX(2); // Height
Skip_XX(4); // Horizontal resolution
Skip_XX(4); // Vertical resolution
Skip_XX(4); // Data size
Skip_XX(2); //Frame count
Skip_XX(32); // CompressorName
Get_B2(Depth);
Get_B2(ColorTableID);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->RevisionLevel);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Vendor);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->TemporalQuality);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->SpatialQuality);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Width);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Height);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->HorizontalResolution);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->VerticalResolution);
Get_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->DataSize);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->FrameCount);

Get_String(32, Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->CompressorName);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Depth);
Get_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->ColorTableID);

uint16_t Depth=Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Depth;
uint16_t ColorTableID=Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->ColorTableID;
bool IsGreyscale;
if (Depth>0x20 && Depth<0x40)
{
Expand Down Expand Up @@ -130,3 +136,44 @@ size_t mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo::Insert_Internal (int32u Chun
return Subs.size();
}
}

//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo::Modify_Internal()
{
if (Chunk.Content.IsModified)
return;

if (!Global->moov_trak_mdia_minf_stbl_stsd_xxxx_colr.count(Chunk.trak_Index))
return;

if (Chunk.Content.Buffer)
delete[] Chunk.Content.Buffer;
Chunk.Content.Buffer_Offset = 0;
Chunk.Content.Buffer = new int8u[Chunk.Content.Before_Subs_Content_Size];

Put_B6(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Reserved);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->DataReferenceIndex);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Version);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->RevisionLevel);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Vendor);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->TemporalQuality);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->SpatialQuality);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Width);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Height);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->HorizontalResolution);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->VerticalResolution);
Put_B4(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->DataSize);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->FrameCount);
Put_String(32, Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->CompressorName);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->Depth);
Put_B2(Global->moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Chunk.trak_Index]->ColorTableID);

Chunk.Content.IsModified=true;
Chunk.Content.Size_IsModified=true;
}

//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxVideo::Write_Internal()
{
mp4_Base::Write_Internal(Chunk.Content.Buffer, (size_t)Chunk.Content.Size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_chan::Read_Internal()
{
Chunk.trak_Index=Global->moov_trak.size();
Chunk.trak_Index=Global->moov_trak.size()-1;

Global->moov_trak_mdia_minf_stbl_stsd_xxxx_chan[Chunk.trak_Index]=new global::block_moov_trak_mdia_minf_stbl_stsd_xxxx_chan();

Expand Down
6 changes: 3 additions & 3 deletions Source/Common/mp4/mp4_moov_trak_tkhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//---------------------------------------------------------------------------
void mp4_moov_trak_tkhd::Read_Internal()
{
Chunk.trak_Index=Global->moov_trak.size();
Chunk.trak_Index=Global->moov_trak.size()-1;

Read_Internal_ReadAllInBuffer();

Expand All @@ -33,7 +33,7 @@ void mp4_moov_trak_tkhd::Read_Internal()
Get_B4(Width);
Get_B4(Height);

if (Chunk.trak_Index==1 && Version<= 1 &&Width && Height)
if (Chunk.trak_Index==0 && Version<= 1 &&Width && Height)
{
Global->moov_trak_tkhd=new global::block_moov_trak_tkhd();
Global->moov_trak_tkhd->Width_Scale=((double)Width_Scale/(double)(1<<16));
Expand All @@ -49,7 +49,7 @@ void mp4_moov_trak_tkhd::Read_Internal()
void mp4_moov_trak_tkhd::Modify_Internal()
{
if (Chunk.Content.IsModified ||
Chunk.trak_Index!=1 ||
Chunk.trak_Index!=0 ||
!Chunk.Content.Size ||
!Global->moov_trak_tkhd ||
Chunk.Content.Size<Global->moov_trak_tkhd->Width_Scale_Pos+4)
Expand Down
45 changes: 45 additions & 0 deletions Source/Common/mp4_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,43 @@ class mp4_Base
Height=0;
}
};
struct block_moov_trak_mdia_minf_stbl_stsd_xxxxVideo
{
int64u Reserved;
int16u DataReferenceIndex;
int16u Version;
int16u RevisionLevel;
int32u Vendor;
int32u TemporalQuality;
int32u SpatialQuality;
int16u Width;
int16u Height;
int32u HorizontalResolution;
int32u VerticalResolution;
int32u DataSize;
int16u FrameCount;
string CompressorName;
int16u Depth;
int16u ColorTableID;
block_moov_trak_mdia_minf_stbl_stsd_xxxxVideo()
{
Reserved=0;
DataReferenceIndex=0;
Version=0;
RevisionLevel=0;
Vendor=0;
TemporalQuality=0;
SpatialQuality=0;
Width=0;
Height=0;
HorizontalResolution=0;
VerticalResolution=0;
DataSize=0;
FrameCount=0;
Depth=0;
ColorTableID=0;
}
};
struct block_moov_trak_mdia_minf_stbl_stsd_xxxx_fiel
{
uint8_t Fields;
Expand Down Expand Up @@ -437,6 +474,8 @@ class mp4_Base
bool moov_trak_tapt_prof_Modified; // For FirstVideoIndex
map<size_t, block_moov_trak_tapt_xxxx*> moov_trak_tapt_enof;
bool moov_trak_tapt_enof_Modified; // For FirstVideoIndex
map<size_t, block_moov_trak_mdia_minf_stbl_stsd_xxxxVideo*> moov_trak_mdia_minf_stbl_stsd_xxxxVideo;
bool moov_trak_mdia_minf_stbl_stsd_xxxxVideo_Modified; // For FirstVideoIndex
map<size_t, block_moov_trak_mdia_minf_stbl_stsd_xxxx_clap*> moov_trak_mdia_minf_stbl_stsd_xxxx_clap;
bool moov_trak_mdia_minf_stbl_stsd_xxxx_clap_Modified; // For FirstVideoIndex
map<size_t, block_moov_trak_mdia_minf_stbl_stsd_xxxx_colr*> moov_trak_mdia_minf_stbl_stsd_xxxx_colr;
Expand Down Expand Up @@ -483,6 +522,7 @@ class mp4_Base
moov_trak_tapt_clef_Modified=false;
moov_trak_tapt_prof_Modified=false;
moov_trak_tapt_enof_Modified=false;
moov_trak_mdia_minf_stbl_stsd_xxxxVideo_Modified=false;
moov_trak_mdia_minf_stbl_stsd_xxxx_clap_Modified=false;
moov_trak_mdia_minf_stbl_stsd_xxxx_colr_Modified=false;
moov_trak_mdia_minf_stbl_stsd_xxxx_fiel_Modified=false;
Expand Down Expand Up @@ -531,6 +571,9 @@ class mp4_Base
for (size_t Pos=0; Pos<moov_trak_tapt_enof.size(); Pos++)
delete moov_trak_tapt_enof[Pos];

for (size_t Pos=0; Pos<moov_trak_mdia_minf_stbl_stsd_xxxxVideo.size(); Pos++)
delete moov_trak_mdia_minf_stbl_stsd_xxxxVideo[Pos];

for (size_t Pos=0; Pos<moov_trak_mdia_minf_stbl_stsd_xxxx_clap.size(); Pos++)
delete moov_trak_mdia_minf_stbl_stsd_xxxx_clap[Pos];

Expand Down Expand Up @@ -681,6 +724,8 @@ class mp4_Base
void Put_B3 (int32u Value);
void Get_B4 (int32u &Value);
void Put_B4 (int32u Value);
void Get_B6 (int64u &Value);
void Put_B6 (int64u Value);
void Get_B8 (int64u &Value);
void Put_B8 (int64u Value);
void Get_B16 (int128u &Value);
Expand Down
16 changes: 16 additions & 0 deletions Source/Common/mp4_Base_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ void mp4_Base::Put_B4 (int32u Value)
Chunk.Content.Buffer_Offset+=4;
}

//---------------------------------------------------------------------------
void mp4_Base::Get_B6 (int64u &Value)
{
INTEGRITY_SIZE_ATLEAST_INT(6);
Value=BigEndian2int48u(Chunk.Content.Buffer+Chunk.Content.Buffer_Offset);
Chunk.Content.Buffer_Offset+=6;
}

//---------------------------------------------------------------------------
void mp4_Base::Put_B6 (int64u Value)
{
INTEGRITY_SIZE_ATLEAST_INT(6);
int48u2BigEndian(Chunk.Content.Buffer+Chunk.Content.Buffer_Offset, Value);
Chunk.Content.Buffer_Offset+=6;
}

//---------------------------------------------------------------------------
void mp4_Base::Get_B8 (int64u &Value)
{
Expand Down
Loading

0 comments on commit eb2a4ab

Please sign in to comment.