Skip to content

Commit

Permalink
[demuxers/Matroska] Support files with two SeekHead elements, fallbac…
Browse files Browse the repository at this point in the history
…k to brute force search for the Tracks element if none referenced in parsed SeekHeads
  • Loading branch information
eumagga0x2a committed Nov 29, 2019
1 parent bc1da71 commit 9d570bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
28 changes: 25 additions & 3 deletions avidemux_plugins/ADM_demuxers/Matroska/ADM_mkv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,23 @@ uint8_t mkvHeader::open(const char *name)
_segmentPosition=ebml.tell();
ADM_info("[MKV] found Segment at 0x%llx\n",(uint64_t)_segmentPosition);
/* Now find tracks */
bool tracksElemFound=false;
uint64_t nextHead=0;
if(ebml.find(ADM_MKV_SECONDARY,MKV_SEGMENT,MKV_SEEK_HEAD,&alen))
{
ADM_ebml_file seekHead( &ebml,alen);
readSeekHead(&seekHead);
}else
tracksElemFound = readSeekHead(&seekHead,&nextHead);
if(!tracksElemFound && nextHead)
{
ebml.seek(nextHead);
if(ebml.simplefind(MKV_SEEK_HEAD,&len,false))
{
ADM_ebml_file secondary(&ebml,len);
tracksElemFound = readSeekHead(&secondary);
}
}
}
if(!tracksElemFound)
{ // No valid seek_head, try to find MKV_TRACKS
ADM_info("Searching for MKV_TRACKS\n");
int headerLen;
Expand Down Expand Up @@ -1197,10 +1209,12 @@ bool mkvHeader::setPtsDts(uint32_t frame,uint64_t pts,uint64_t dts)
* \fn readSeekHead
* \bried used to locate the interesting parts of the file
*/
bool mkvHeader::readSeekHead(ADM_ebml_file *body)
bool mkvHeader::readSeekHead(ADM_ebml_file *body, uint64_t *nexthead)
{
uint64_t vlen,len;
ADM_info("Parsing SeekHead\n");
if(nexthead)
*nexthead=0;
while(!body->finished())
{
if(!body->simplefind(MKV_SEEK,&vlen,false))
Expand Down Expand Up @@ -1247,6 +1261,14 @@ bool mkvHeader::readSeekHead(ADM_ebml_file *body)
uint64_t position=item.readUnsignedInt(len);
switch(t)
{
case MKV_SEEK_HEAD:
{
uint64_t chained=position+_segmentPosition;
ADM_info("Chained MKV_SEEK_HEAD at position %" PRIu64"\n",chained);
if(nexthead)
*nexthead=chained;
break;
}
case MKV_CUES:
_cuePosition=position+_segmentPosition;
ADM_info(" at position 0x%llx\n",_cuePosition);
Expand Down
2 changes: 1 addition & 1 deletion avidemux_plugins/ADM_demuxers/Matroska/ADM_mkv.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class mkvHeader :public vidHeader
uint8_t walk(void *seed);
uint64_t walkAndFind(void *seed,MKV_ELEM_ID searched);
int searchTrackFromTid(uint32_t tid);
bool readSeekHead(ADM_ebml_file *body);
bool readSeekHead(ADM_ebml_file *body,uint64_t *nexthead=NULL);
//
//
int isBufferingNeeded(mkvTrak *trk); // Split audio blocks into smaller pieces if needed
Expand Down
2 changes: 2 additions & 0 deletions avidemux_plugins/ADM_demuxers/Matroska/mkv_tagenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
MKTAG(MKV_CUE_TRACK,0xF7,ADM_MKV_TYPE_UINTEGER),
MKTAG(MKV_CUE_BLOCK_NUMBER,0x5378,ADM_MKV_TYPE_UINTEGER),

MKTAG(MKV_CHAPTERS,0x1043A770,ADM_MKV_TYPE_CONTAINER),

MKTAG(MKV_VOID,0xEC,ADM_MKV_TYPE_BINARY),
MKTAG(MKV_DURATION,0x4489,ADM_MKV_TYPE_FLOAT),
MKTAG(MKV_SEGMENT_UID,0x73A4,ADM_MKV_TYPE_BINARY),
Expand Down

0 comments on commit 9d570bb

Please sign in to comment.