X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmov.c;h=fd170baa57f9e476d787ad4b3767ba76abf9563b;hb=48e4eda11d537c6ed52d1000aaa6ce5cbb641e25;hp=5fc597ee26de13042d3bf4a9d67956ca7ee4f636;hpb=73198aca2c27712e45f29dec769f4c343ee40c20;p=ffmpeg diff --git a/libavformat/mov.c b/libavformat/mov.c index 5fc597ee26d..fd170baa57f 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3298,6 +3298,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) int packet_skip_samples = 0; MOVIndexRange *current_index_range; int i; + int found_keyframe_after_edit = 0; if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) { return; @@ -3393,6 +3394,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Iterate over index and arrange it according to edit list edit_list_start_encountered = 0; + found_keyframe_after_edit = 0; for (; current < e_old_end; current++, index++) { // check if frame outside edit list mark it for discard frame_duration = (current + 1 < e_old_end) ? @@ -3505,18 +3507,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } // Break when found first key frame after edit entry completion - if (((curr_cts + frame_duration) >= (edit_list_duration + edit_list_media_time)) && + if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) && ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)))) { - - if (ctts_data_old && ctts_sample_old != 0) { - if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, - &msc->ctts_allocated_size, - ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration) == -1) { - av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", - ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration); - break; + if (ctts_data_old) { + // If we have CTTS and this is the the first keyframe after edit elist, + // wait for one more, because there might be trailing B-frames after this I-frame + // that do belong to the edit. + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && found_keyframe_after_edit == 0) { + found_keyframe_after_edit = 1; + continue; + } + if (ctts_sample_old != 0) { + if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, + &msc->ctts_allocated_size, + ctts_sample_old - edit_list_start_ctts_sample, + ctts_data_old[ctts_index_old].duration) == -1) { + av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", + ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample, + ctts_data_old[ctts_index_old].duration); + break; + } } } break;