Merge commit '4abfa387b8234736f6e0e541951e3d5eb60eb843'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 15 Feb 2015 23:27:04 +0000 (00:27 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 16 Feb 2015 00:28:02 +0000 (01:28 +0100)
* commit '4abfa387b8234736f6e0e541951e3d5eb60eb843':
  mov: Change DTS-based seek into CTS-based seek.

Conflicts:
libavformat/mov.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/mov.c

@@@ -2346,11 -2131,9 +2348,9 @@@ static void mov_build_index(MOVContext 
          unsigned int rap_group_index = 0;
          unsigned int rap_group_sample = 0;
          int rap_group_present = sc->rap_group_count && sc->rap_group;
 -        int key_off = (sc->keyframes && sc->keyframes[0] > 0) || (sc->stps_data && sc->stps_data[0] > 0);
 +        int key_off = (sc->keyframe_count && sc->keyframes[0] > 0) || (sc->stps_count && sc->stps_data[0] > 0);
  
-         current_dts -= sc->dts_shift;
 -        if (!sc->sample_count)
 +        if (!sc->sample_count || st->nb_index_entries)
              return;
          if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
              return;
                      e->size = sample_size;
                      e->min_distance = distance;
                      e->flags = keyframe ? AVINDEX_KEYFRAME : 0;
-                     av_dlog(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
+                     av_dlog(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", cts %"PRId64", "
                              "size %d, distance %d, keyframe %d\n", st->index, current_sample,
-                             current_offset, current_dts, sample_size, distance, keyframe);
+                             current_offset, current_cts, sample_size, distance, keyframe);
 +                    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100)
 +                        ff_rfps_add_frame(mov->fc, st, current_dts);
                  }
  
                  current_offset += sample_size;
@@@ -3108,32 -2801,10 +3116,34 @@@ static int mov_read_trun(MOVContext *c
          if (flags & MOV_TRUN_SAMPLE_DURATION) sample_duration = avio_rb32(pb);
          if (flags & MOV_TRUN_SAMPLE_SIZE)     sample_size     = avio_rb32(pb);
          if (flags & MOV_TRUN_SAMPLE_FLAGS)    sample_flags    = avio_rb32(pb);
-         sc->ctts_data[sc->ctts_count].count = 1;
-         sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ?
-                                                   avio_rb32(pb) : 0;
+         if (flags & MOV_TRUN_SAMPLE_CTS)      sample_cts      = avio_rb32(pb);
+         sc->ctts_data[sc->ctts_count].count    = 1;
+         sc->ctts_data[sc->ctts_count].duration = sample_cts;
 +        mov_update_dts_shift(sc, sc->ctts_data[sc->ctts_count].duration);
 +        if (frag->time != AV_NOPTS_VALUE) {
 +            if (c->use_mfra_for == FF_MOV_FLAG_MFRA_PTS) {
 +                int64_t pts = frag->time;
 +                av_log(c->fc, AV_LOG_DEBUG, "found frag time %"PRId64
 +                        " sc->dts_shift %d ctts.duration %d"
 +                        " sc->time_offset %"PRId64" flags & MOV_TRUN_SAMPLE_CTS %d\n", pts,
 +                        sc->dts_shift, sc->ctts_data[sc->ctts_count].duration,
 +                        sc->time_offset, flags & MOV_TRUN_SAMPLE_CTS);
 +                dts = pts - sc->dts_shift;
 +                if (flags & MOV_TRUN_SAMPLE_CTS) {
 +                    dts -= sc->ctts_data[sc->ctts_count].duration;
 +                } else {
 +                    dts -= sc->time_offset;
 +                }
 +                av_log(c->fc, AV_LOG_DEBUG, "calculated into dts %"PRId64"\n", dts);
 +            } else {
 +                dts = frag->time;
 +                av_log(c->fc, AV_LOG_DEBUG, "found frag time %"PRId64
 +                        ", using it for dts\n", dts);
 +            }
 +            frag->time = AV_NOPTS_VALUE;
 +        }
+         cts = dts + sample_cts;
++
          sc->ctts_count++;
          if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
              keyframe = 1;