コード例 #1
0
extern int mp4_split(struct mp4_context_t* mp4_context,
                     unsigned int* trak_sample_start,
                     unsigned int* trak_sample_end,
                     mp4_split_options_t const* options)
{
  int result;

  float start_time = options->start;
  float end_time = options->end;

//  moov_build_index(mp4_context, mp4_context->moov);

  {
    struct moov_t const* moov = mp4_context->moov;
    long moov_time_scale = moov->mvhd_->timescale_;
    int64_t start = (int64_t)(start_time * moov_time_scale + 0.5f);
    int64_t end = (int64_t)(end_time * moov_time_scale + 0.5f);

    // for every trak, convert seconds to sample (time-to-sample).
    // adjust sample to keyframe
    result = get_aligned_start_and_end(mp4_context, start, end,
                                       trak_sample_start, trak_sample_end);
  }

  return result;
}
コード例 #2
0
extern int mp4_split(struct mp4_context_t* mp4_context,
                     unsigned int* trak_sample_start,
                     unsigned int* trak_sample_end,
                     mp4_split_options_t const* options)
{
  int result;

  float start_time = options->start;
  float end_time = options->end;

  moov_build_index(mp4_context, mp4_context->moov);

  {
    struct moov_t const* moov = mp4_context->moov;
    long moov_time_scale = moov->mvhd_->timescale_;
    unsigned int start = (unsigned int)(start_time * moov_time_scale + 0.5f);
    unsigned int end = (unsigned int)(end_time * moov_time_scale + 0.5f);

    // for every trak, convert seconds to sample (time-to-sample).
    // adjust sample to keyframe
    result = get_aligned_start_and_end(mp4_context, start, end,
                                       trak_sample_start, trak_sample_end);

    if (options->exact){
      // now we need to find the audio track and RESET *its* trak_sample_start
      // time to the exact start time we want, regardless of keyframes
      unsigned int i=0;
      for(i=0; i != moov->tracks_; ++i){
        struct trak_t* trak = moov->traks_[i];
        if (trak->mdia_->hdlr_->handler_type_ == FOURCC('s','o','u','n')){
          // the FOURCC is soun(d) AKA audio track
          long trak_time_scale = trak->mdia_->mdhd_->timescale_;
          struct stts_t* stts = trak->mdia_->minf_->stbl_->stts_;
          unsigned int start_exact_time_sample = stts_get_sample(stts, moov_time_to_trak_time((options->start * moov_time_scale), moov_time_scale, trak_time_scale));
          MP4_WARNING("FFGOP: AUDIO REWRITING trak_sample_start[%i]: %u => %u\n", i, trak_sample_start[i], start_exact_time_sample);
          trak_sample_start[i] = start_exact_time_sample;
        }
      }
    }
  }

  return result;
}