summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvan <[email protected]>2008-02-25 06:39:42 +0000
committervan <[email protected]>2008-02-25 06:39:42 +0000
commitba18c96e06f6b5f40f772c439405df58ec55001e (patch)
tree45401151182e1d565012346a2caa00899d87e810
parent07d0fa8c83ce7f79a0d192771e1520b98fbe79fe (diff)
Don't allow negative durations. These shouldn't happen but occasionally do due to upstream bugs. Replace them with a small positive duration so the mp4 file will be playable.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1316 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--libhb/muxmp4.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c
index d586559f8..d4681c614 100644
--- a/libhb/muxmp4.c
+++ b/libhb/muxmp4.c
@@ -351,7 +351,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
{
hb_job_t * job = m->job;
- uint64_t duration;
+ int64_t duration;
if( mux_data == job->mux_data )
{
@@ -398,6 +398,23 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
doesn't go out of sync */
int64_t bias = ( buf->start * job->arate / 90000 ) - m->sum_dur;
duration = ( buf->stop - buf->start ) * job->arate / 90000 + bias;
+ if ( duration <= 0 )
+ {
+ /* We got an illegal mp4/h264 duration. This shouldn't
+ be possible and usually indicates a bug in the upstream code.
+ Complain in the hope that someone will go find the bug but
+ try to fix the error so that the file will still be playable. */
+ hb_log("MP4Mux: illegal duration %lld, bias %lld, start %lld (%lld),"
+ "stop %lld (%lld), sum_dur %lld",
+ duration, bias, buf->start * job->arate / 90000, buf->start,
+ buf->stop * job->arate / 90000, buf->stop, m->sum_dur );
+ /* we don't know when the next frame starts so we can't pick a
+ valid duration for this one so we pick something "short"
+ (roughly 1/3 of an NTSC frame time) and rely on the bias calc
+ for the next frame to correct things (a duration underestimate
+ just results in a large bias on the next frame). */
+ duration = 1000 * job->arate / 90000;
+ }
m->sum_dur += duration;
}
else