Skip to content

Commit 0529b46

Browse files
Fixing seek in fMP4 files.
1 parent fddf4bc commit 0529b46

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

libavformat/mov.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef struct MOVParseTableEntry {
8585
static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
8686
static int mov_read_mfra(MOVContext *c, AVIOContext *f);
8787
static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
88+
static int mov_switch_root(AVFormatContext *s, int64_t target, int index);
8889
static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
8990
int count, int duration);
9091

@@ -1653,6 +1654,31 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st,
16531654
return frag_stream_info->sidx_pts;
16541655
}
16551656

1657+
1658+
// Check if the requested stream is present in the fragment
1659+
int exists = 0;
1660+
for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
1661+
if (dst_st->id != frag_index->item[index].stream_info[i].id) {
1662+
continue;
1663+
}
1664+
1665+
if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) {
1666+
exists = 1;
1667+
break;
1668+
}
1669+
if ( mov_switch_root(s,-1,index) < 0)
1670+
return AV_NOPTS_VALUE;
1671+
1672+
if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) {
1673+
exists = 1;
1674+
break;
1675+
}
1676+
}
1677+
1678+
if (!exists)
1679+
return AV_NOPTS_VALUE;
1680+
1681+
16561682
for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
16571683
AVStream *frag_stream = NULL;
16581684
frag_stream_info = &frag_index->item[index].stream_info[i];

0 commit comments

Comments
 (0)