Skip to content

Commit

Permalink
Add --delete-timecode option
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 22, 2024
1 parent 085f431 commit 9e54000
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Project/GNU/CLI/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ movmetaedit_SOURCES = \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_clli.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxxSound.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_chan.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxxUnknown.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_vmhd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_smhd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd_tmcd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_mdia_mdhd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_tkhd.cpp \
../../../Source/Common/mp4/mp4_moov_trak_tref.cpp \
../../../Source/Common/mp4/mp4_moov_trak_tref_tmcd.cpp \
../../../Source/Common/mp4/mp4_moov_meta.cpp \
../../../Source/Common/mp4/mp4_moov_meta_hdlr.cpp \
../../../Source/Common/mp4/mp4_moov_meta_ilst.cpp \
Expand Down
5 changes: 5 additions & 0 deletions Project/MSVC2017/CLI/MOVMetaEdit_CLI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_clli.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_stbl_stsd_xxxxSound.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_chan.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_stbl_stsd_xxxxUnknown.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_mdhd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_vmhd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_smhd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_gmhd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_mdia_minf_gmhd_tmcd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_tref.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4\mp4_moov_trak_tref_tmcd.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4_Base.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4_Base_parsing.cpp" />
<ClCompile Include="..\..\..\Source\Common\mp4_Handler.cpp" />
Expand Down
5 changes: 5 additions & 0 deletions Project/Qt/movmetaedit-gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ SOURCES += \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_clli.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxxSound.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxx_chan.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd_xxxxUnknown.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_mdhd.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_vmhd.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_smhd.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd.cpp \
../../Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd_tmcd.cpp \
../../Source/Common/mp4/mp4_moov_trak_tref.cpp \
../../Source/Common/mp4/mp4_moov_trak_tref_tmcd.cpp \
../../Source/Common/mp4/mp4_moov_meta.cpp \
../../Source/Common/mp4/mp4_moov_meta_hdlr.cpp \
../../Source/Common/mp4/mp4_moov_meta_ilst.cpp \
Expand Down
4 changes: 4 additions & 0 deletions Source/CLI/Help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ ReturnValue Help_Tech(bool WithExamples)
TEXTOUT(" Read HDR values from DolbyLabsMDF XML");
TEXTOUT(" --from-id VALUE");
TEXTOUT(" Read HDR values from the MasteringDisplay with the the specified ID in the XML");
TEXTOUT("Options related to the timecode track:");
TEXTOUT(" --timecode-delete");
TEXTOUT(" Remove the timecode track and all related references atoms");
TEXTOUT("");
TEXTOUT("Options related to the media header atom:");
TEXTOUT(" --language, --languages VALUE");
TEXTOUT(" Modify the media header language to VALUE for the specified audio track, \"[trackIndex=]lang[,[trackIndex=]lang...]\" format, e.g en,fr or 0=eng,1=fra");
Expand Down
11 changes: 11 additions & 0 deletions Source/Common/mp4/mp4_.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ namespace Elements
const uint32_t moov_trak_mdia_minf_stbl_stsd_xxxx_clli = 0x636C6C69;
const uint32_t moov_trak_mdia_minf_stbl_stsd_xxxxSound = 0xFFFFFFFF;
const uint32_t moov_trak_mdia_minf_stbl_stsd_xxxx_chan = 0x6368616E;
const uint32_t moov_trak_mdia_minf_stbl_stsd_xxxxUnknown = 0xFFFFFFFF;
const uint32_t moov_trak_mdia_minf_stbl_stsd_tmcd = 0x746D6364;
const uint32_t moov_trak_mdia_minf_vmhd = 0x766D6864;
const uint32_t moov_trak_mdia_minf_smhd = 0x736D6864;
const uint32_t moov_trak_mdia_minf_gmhd = 0x676D6864;
const uint32_t moov_trak_mdia_minf_gmhd_tmcd = 0x746D6364;
const uint32_t moov_trak_mdia_mdhd = 0x6D646864;
const uint32_t moov_trak_tkhd = 0x746B6864;
const uint32_t moov_trak_tref = 0x74726566;
const uint32_t moov_trak_tref_tmcd = 0x746D6364;
const uint32_t moov_meta = 0x6D657461;
const uint32_t moov_meta_hdlr = 0x68646C72;
const uint32_t moov_meta_keys = 0x6B657973;
Expand Down Expand Up @@ -140,10 +146,15 @@ CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_mdcv);
CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_clli);
CHUNK_I(7, moov_trak_mdia_minf_stbl_stsd_xxxxSound);
CHUNK_W(8, moov_trak_mdia_minf_stbl_stsd_xxxx_chan);
CHUNK__(7, moov_trak_mdia_minf_stbl_stsd_xxxxUnknown);
CHUNK__(5, moov_trak_mdia_minf_vmhd);
CHUNK__(5, moov_trak_mdia_minf_smhd);
CHUNK__(5, moov_trak_mdia_minf_gmhd);
CHUNK__(5, moov_trak_mdia_minf_gmhd_tmcd);
CHUNK_W(4, moov_trak_mdia_mdhd);
CHUNK_W(3, moov_trak_tkhd);
CHUNK__(3, moov_trak_tref);
CHUNK_W(4, moov_trak_tref_tmcd);
CHUNK_I(2, moov_meta);
CHUNK_W(3, moov_meta_hdlr);
CHUNK_W(3, moov_meta_ilst);
Expand Down
1 change: 1 addition & 0 deletions Source/Common/mp4/mp4_moov_trak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void mp4_moov_trak::Read_Internal ()
SUBS_BEGIN();
SUB_ELEMENT(moov_trak_tkhd);
SUB_ELEMENT(moov_trak_tapt);
SUB_ELEMENT(moov_trak_tref);
SUB_ELEMENT(moov_trak_mdia);
SUBS_END();
}
Expand Down
1 change: 1 addition & 0 deletions Source/Common/mp4/mp4_moov_trak_mdia_minf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ void mp4_moov_trak_mdia_minf::Read_Internal ()
SUB_ELEMENT(moov_trak_mdia_minf_stbl);
SUB_ELEMENT(moov_trak_mdia_minf_vmhd);
SUB_ELEMENT(moov_trak_mdia_minf_smhd);
SUB_ELEMENT(moov_trak_mdia_minf_gmhd);
SUBS_END();
}
21 changes: 21 additions & 0 deletions Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a MIT-style license that can
* be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "Common/mp4/mp4_.h"
//---------------------------------------------------------------------------

//***************************************************************************
// Read
//***************************************************************************

//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_gmhd::Read_Internal ()
{
SUBS_BEGIN();
SUB_ELEMENT(moov_trak_mdia_minf_gmhd_tmcd);
SUBS_END();
}
19 changes: 19 additions & 0 deletions Source/Common/mp4/mp4_moov_trak_mdia_minf_gmhd_tmcd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a MIT-style license that can
* be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "Common/mp4/mp4_.h"
//---------------------------------------------------------------------------

//***************************************************************************
// Read
//***************************************************************************

//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_gmhd_tmcd::Read_Internal ()
{
Global->moov_trak.back()->IsTimeCode=true;
}
6 changes: 6 additions & 0 deletions Source/Common/mp4/mp4_moov_trak_mdia_minf_stbl_stsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ void mp4_moov_trak_mdia_minf_stbl_stsd::Read_Internal ()
SUB_ELEMENT_DEFAULT(moov_trak_mdia_minf_stbl_stsd_xxxxSound);
SUBS_END_DEFAULT();
}
else
{
SUBS_BEGIN();
SUB_ELEMENT_DEFAULT(moov_trak_mdia_minf_stbl_stsd_xxxxUnknown);
SUBS_END_DEFAULT();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a MIT-style license that can
* be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "Common/mp4/mp4_.h"
//---------------------------------------------------------------------------

//***************************************************************************
// Read
//***************************************************************************

//---------------------------------------------------------------------------
void mp4_moov_trak_mdia_minf_stbl_stsd_xxxxUnknown::Read_Internal ()
{
if (Chunk.Header.Name==Elements::moov_trak_mdia_minf_stbl_stsd_tmcd)
{
Global->moov_trak.back()->moov_trak_mdia_minf_stbl_stsd_tmcd_Present=true;
Global->TimeCode_Track_Present=true;
}
}
21 changes: 21 additions & 0 deletions Source/Common/mp4/mp4_moov_trak_tref.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a MIT-style license that can
* be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "Common/mp4/mp4_.h"
//---------------------------------------------------------------------------

//***************************************************************************
// Read
//***************************************************************************

//---------------------------------------------------------------------------
void mp4_moov_trak_tref::Read_Internal ()
{
SUBS_BEGIN();
SUB_ELEMENT(moov_trak_tref_tmcd);
SUBS_END();
}
47 changes: 47 additions & 0 deletions Source/Common/mp4/mp4_moov_trak_tref_tmcd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a MIT-style license that can
* be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "Common/mp4/mp4_.h"
//---------------------------------------------------------------------------

#include <iostream>

//***************************************************************************
// Read
//***************************************************************************

//---------------------------------------------------------------------------
void mp4_moov_trak_tref_tmcd::Read_Internal()
{
Read_Internal_ReadAllInBuffer();
}

//***************************************************************************
// Modify
//***************************************************************************

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

if (Global->TimeCode_Track_Delete)
{
Chunk.Content.IsRemovable = true;
return;
}

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

//---------------------------------------------------------------------------
void mp4_moov_trak_tref_tmcd::Write_Internal()
{
mp4_Base::Write_Internal(Chunk.Content.Buffer, (size_t)Chunk.Content.Size);
}
8 changes: 8 additions & 0 deletions Source/Common/mp4_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,19 @@ class mp4_Base
{
bool IsVideo;
bool IsSound;
bool IsTimeCode;
bool moov_trak_mdia_minf_stbl_stsd_xxxxVideo_Present;
bool moov_trak_mdia_minf_stbl_stsd_xxxxSound_Present;
bool moov_trak_mdia_minf_stbl_stsd_tmcd_Present;

block_moov_trak()
{
IsVideo=false;
IsSound=false;
IsTimeCode=false;
moov_trak_mdia_minf_stbl_stsd_xxxxVideo_Present=false;
moov_trak_mdia_minf_stbl_stsd_xxxxSound_Present=false;
moov_trak_mdia_minf_stbl_stsd_tmcd_Present=false;
}
};
struct block_moov_trak_tapt_xxxx
Expand Down Expand Up @@ -507,6 +511,8 @@ class mp4_Base
vector<string> moov_meta_ilst_NewValues;
size_t moov_meta_ilst_AlreadyPresent;
size_t moov_trak_FirstVideoIndex;
bool TimeCode_Track_Present;
bool TimeCode_Track_Delete;
bool NewChunksAtTheEnd;
bool Out_Buffer_File_TryModification;
bool Out_Buffer_File_IsModified;
Expand Down Expand Up @@ -543,6 +549,8 @@ class mp4_Base
moov_meta_keys_AlreadyPresent=0;
moov_meta_ilst_AlreadyPresent=0;
moov_trak_FirstVideoIndex=(size_t)-1;
TimeCode_Track_Present=false;
TimeCode_Track_Delete=false;
NewChunksAtTheEnd=false;
Out_Buffer_WriteAtEnd=false;
Out_Buffer_File_TryModification=true;
Expand Down
60 changes: 60 additions & 0 deletions Source/Common/mp4_Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,54 @@ bool mp4_Handler::Save()
}
}
}

//Remove timecode tracks and chunks
if (Chunks->Global->TimeCode_Track_Delete)
{
size_t trak_Index=0;
for (size_t Pos=0; Pos<Chunks->Subs.size(); Pos++)
{
if (Chunks->Subs[Pos]->Chunk.Header.Name==Elements::moov)
{
for (size_t Pos2=0; Pos2<Chunks->Subs[Pos]->Subs.size(); Pos2++)
{
for (size_t Pos3=0; Pos3<Chunks->Subs[Pos]->Subs[Pos2]->Subs.size(); Pos3++)
{
if (Chunks->Subs[Pos]->Subs[Pos2]->Subs[Pos3]->Chunk.Header.Name==Elements::moov_trak_tref)
{
for (size_t Pos4=0; Pos4<Chunks->Subs[Pos]->Subs[Pos2]->Subs[Pos3]->Subs.size(); Pos4++)
{
if (Chunks->Subs[Pos]->Subs[Pos2]->Subs[Pos3]->Subs[Pos4]->Chunk.Header.Name==Elements::moov_trak_tref_tmcd)
{
Chunks->Subs[Pos]->Subs[Pos2]->Modify(Elements::moov_trak_tref, Elements::moov_trak_tref_tmcd);
Chunks->Subs[Pos]->Chunk.Content.IsModified=true;
Chunks->Subs[Pos]->Chunk.Content.Size_IsModified=true;
Chunks->Chunk.Content.IsModified=true;
Chunks->Chunk.Content.Size_IsModified=true;
}
}
}
}

if (Chunks->Subs[Pos]->Subs[Pos2]->Chunk.Header.Name==Elements::moov_trak)
{
Chunks->Subs[Pos]->Subs[Pos2]->Modify(Elements::moov_trak_tref, Elements::moov_trak_tref_tmcd);
if (trak_Index<Chunks->Global->moov_trak.size() && Chunks->Global->moov_trak[trak_Index]->moov_trak_mdia_minf_stbl_stsd_tmcd_Present)
{
delete Chunks->Subs[Pos]->Subs[Pos2];
Chunks->Subs[Pos]->Subs.erase(Chunks->Subs[Pos]->Subs.begin()+Pos2);
Chunks->Subs[Pos]->Chunk.Content.IsModified=true;
Chunks->Subs[Pos]->Chunk.Content.Size_IsModified=true;
Chunks->Chunk.Content.IsModified=true;
Chunks->Chunk.Content.Size_IsModified=true;
}
trak_Index++;
}
}
}
}
}

if (Chunks->Global->moov_trak_tkhd_Modified)
Chunks->Modify(Elements::moov, Elements::moov_trak, Elements::moov_trak_tkhd);
// Modify mdhd in all audio tracks
Expand Down Expand Up @@ -936,6 +984,13 @@ string mp4_Handler::Get(const string &Field)

return ss.str();
}
else if (Field=="tmcd")
{
if (Chunks->Global->TimeCode_Track_Present && !Chunks->Global->TimeCode_Track_Delete)
return "Present";

return string();
}
else if (Field=="lang")
{
stringstream ss;
Expand Down Expand Up @@ -1950,6 +2005,11 @@ bool mp4_Handler::Remove(const string &Field)

return true;
}
else if (Field=="tmcd")
{
Chunks->Global->TimeCode_Track_Delete=true;
return true;
}
else if (Field=="chan")
{
if (!Chunks->Global->moov_trak_mdia_minf_stbl_stsd_xxxx_chan.empty())
Expand Down
Loading

0 comments on commit 9e54000

Please sign in to comment.