OSDN Git Service

- Don't allow chapter durations to go negative (since durations are unsigned the...
authorvan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 25 Apr 2008 06:44:35 +0000 (06:44 +0000)
committervan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 25 Apr 2008 06:44:35 +0000 (06:44 +0000)
 - Revert the change to sync that pushed out the final frame of video -- on many DVDs this frame seems to be junk that's not intended to be displayed.

git-svn-id: svn://localhost/HandBrake/trunk@1438 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/muxmp4.c
libhb/sync.c

index c401c96..b20b9a4 100644 (file)
@@ -388,6 +388,15 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
             {
                 duration += buf->renderOffset * m->samplerate / 90000;
             }
+            if ( duration <= 0 )
+            {
+                /* The initial & final chapters can have very short durations
+                 * (less than the error in our total duration estimate) so
+                 * the duration calc above can result in a negative number.
+                 * when this happens give the chapter a short duration (1/3
+                 * of an ntsc frame time). */
+                duration = 1000 * m->samplerate / 90000;
+            }
 
             sample = MP4GenerateChapterSample( m, duration, buf->new_chap );
 
@@ -467,8 +476,18 @@ static int MP4End( hb_mux_object_t * m )
     /* Write our final chapter marker */
     if( m->job->chapter_markers )
     {
-        struct hb_text_sample_s *sample = MP4GenerateChapterSample( m,
-                                                (m->sum_dur - m->chapter_duration),
+        int64_t duration = m->sum_dur - m->chapter_duration;
+        if ( duration <= 0 )
+        {
+            /* The initial & final chapters can have very short durations
+             * (less than the error in our total duration estimate) so
+             * the duration calc above can result in a negative number.
+             * when this happens give the chapter a short duration (1/3
+             * of an ntsc frame time). */
+            duration = 1000 * m->samplerate / 90000;
+        }
+
+        struct hb_text_sample_s *sample = MP4GenerateChapterSample( m, duration,
                                                 m->current_chapter + 1 );
 
         if( !MP4WriteSample(m->file,
index 90e7fc3..d783985 100644 (file)
@@ -289,10 +289,9 @@ static int SyncVideo( hb_work_object_t * w )
         return HB_WORK_OK;
     }
     cur = pv->cur;
-    if( cur->size == 0 && pv->pts_offset == INT64_MIN )
+    if( cur->size == 0 )
     {
-        /* we got an end-of-stream with no video frames (happens during
-         * an indepth_scan). Feed the eos downstream & signal that we're done. */
+        /* we got an end-of-stream. Feed it downstream & signal that we're done. */
         hb_fifo_push( job->fifo_sync, hb_buffer_init( 0 ) );
         pv->done = 1;
         return HB_WORK_DONE;
@@ -309,13 +308,14 @@ static int SyncVideo( hb_work_object_t * w )
 
         if( next->size == 0 )
         {
-            // we got the empty buffer that signals end-of-stream
-            // note that we're done but continue to the end of this
-            // loop so that the final frame gets processed.
+            /* we got an end-of-stream. Feed it downstream & signal that
+             * we're done. Note that this means we drop the final frame of
+             * video (we don't know its duration). On DVDs the final frame
+             * is often strange and dropping it seems to be a good idea. */
+            hb_fifo_push( job->fifo_sync, hb_buffer_init( 0 ) );
             pv->done = 1;
-            next->start = pv->next_pts + 90*30;
+            return HB_WORK_DONE;
         }
-
         if( pv->pts_offset == INT64_MIN )
         {
             /* This is our first frame */
@@ -625,13 +625,9 @@ static int SyncVideo( hb_work_object_t * w )
         /* Make sure we won't get more frames then expected */
         if( pv->count_frames >= pv->count_frames_max * 2)
         {
-            hb_log( "sync: got too many frames (%d), exiting early", pv->count_frames );
+            hb_log( "sync: got too many frames (%d), exiting early",
+                    pv->count_frames );
             pv->done = 1;
-        }
-
-        if ( pv->done )
-        {
-            hb_buffer_close( &pv->cur );
 
             // Drop an empty buffer into our output to ensure that things
             // get flushed all the way out.