diff --git a/mp4frag/mp4frag.cc b/mp4frag/mp4frag.cc index 41d87ff..44067e9 100644 --- a/mp4frag/mp4frag.cc +++ b/mp4frag/mp4frag.cc @@ -34,6 +34,7 @@ using namespace boost::system; void generate_fragments(std::vector& fragments, boost::shared_ptr& ctx, double timestep) { double limit_ts = timestep; double now; + double timebase = 0; unsigned nsample = 0; fragments.clear(); @@ -45,6 +46,10 @@ void generate_fragments(std::vector& fragments, boost::shared_ptrtimestamp(); if ( si->_video && si->_keyframe && now >= limit_ts ) { + if ( fragments.size() ) { + fragments.back()._duration = now - timebase; + timebase = now; + } fragments.push_back(Fragment()); samplelist = &(fragments.back()._samples); limit_ts = now + timestep; @@ -57,6 +62,9 @@ void generate_fragments(std::vector& fragments, boost::shared_ptr_sample_size + 11 + (si->_video ? 5 : 2) + 4; } + if ( fragments.size() ) { + fragments.back()._duration = ctx->duration() - timebase; + } }