@@ -95,6 +95,7 @@ namespace Cicada {
9595
9696 av_dict_set_int (&mInputOpts , " safe" , 0 , 0 );
9797 av_dict_set (&mInputOpts , " protocol_whitelist" , " file,http,https,tcp,tls" , 0 );
98+ av_dict_set_int (&mInputOpts , " usetoc" , 1 , 0 );
9899 /* If a url with mp4 ext name, but is not a mp4 file, the mp4 demuxer will be matched
99100 * by ext name , mp4 demuxer will try to find moov box, it will ignore the return value
100101 * of the avio_*, and don't check interrupt flag, if the url is a network file, here will
@@ -173,7 +174,7 @@ namespace Cicada {
173174 /*
174175 * this flag is only affect on mp3 and flac
175176 */
176- if (mCtx ->duration > 600 * AV_TIME_BASE) {
177+ if (mCtx ->duration > 600 * AV_TIME_BASE && strcmp ( mCtx -> iformat -> name , " mp3 " ) == 0 ) {
177178 mCtx ->flags |= AVFMT_FLAG_FAST_SEEK;
178179 }
179180
@@ -458,6 +459,7 @@ namespace Cicada {
458459
459460 int avFormatDemuxer::Seek (int64_t us, int flags, int index)
460461 {
462+ us = getWorkAroundSeekPos (us);
461463 if (!bOpened) {
462464 mStartTime = us;
463465 return static_cast <int >(us);
@@ -714,4 +716,12 @@ namespace Cicada {
714716#endif
715717 }
716718
719+ int64_t avFormatDemuxer::getWorkAroundSeekPos (int64_t pos)
720+ {
721+ if (!bOpened || mCtx == nullptr || !(mCtx ->flags & AVFMT_FLAG_FAST_SEEK) || mCtx ->duration <= 0 ) {
722+ return pos;
723+ }
724+
725+ return pos >= mCtx ->duration - 2 * AV_TIME_BASE ? mCtx ->duration - 2 * AV_TIME_BASE : pos;
726+ }
717727}
0 commit comments