OSDN Git Service

libhb support for live preview
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 11 Nov 2008 16:05:16 +0000 (16:05 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 11 Nov 2008 16:05:16 +0000 (16:05 +0000)
set job->start_at_preview to the preview frame you want to start at
set job->pts_to_stop to the number of 90khz ticks duration

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

libhb/common.h
libhb/reader.c
libhb/sync.c

index adf7a2d..44706af 100644 (file)
@@ -222,6 +222,14 @@ struct hb_job_s
     int subtitle_force;
     char * native_language;
 
+    int64_t         pts_to_stop;        // declare eof when we pass this pts in
+                                        //  the time-linearized input stream
+    int             start_at_preview;   // if non-zero, encoding will start
+                                        //  at the position of preview n (1-10)
+    uint32_t        frames_to_skip;     // decode but discard this many frames
+                                        //  initially (for frame accurate positioning
+                                        //  to non-I frames).
+
 #ifdef __LIBHB__
     /* Internal data */
     hb_handle_t   * h;
index c93c2a0..9dfd915 100644 (file)
@@ -181,30 +181,41 @@ static void ReaderFunc( void * _r )
 
     if (r->dvd)
     {
-      /*
-       * XXX this code is a temporary hack that should go away if/when
-       *     chapter merging goes away in libhb/dvd.c
-       * map the start and end chapter numbers to on-media chapter
-       * numbers since chapter merging could cause the handbrake numbers
-       * to diverge from the media numbers and, if our chapter_end is after
-       * a media chapter that got merged, we'll stop ripping too early.
-       */
-      int start = r->job->chapter_start;
-      hb_chapter_t * chap = hb_list_item( r->title->list_chapter, chapter_end - 1 );
-
-      chapter_end = chap->index;
-      if (start > 1)
-      {
-         chap = hb_list_item( r->title->list_chapter, start - 1 );
-         start = chap->index;
-      }
-      /* end chapter mapping XXX */
-
-      if( !hb_dvd_start( r->dvd, r->title->index, start ) )
-      {
-          hb_dvd_close( &r->dvd );
-          return;
-      }
+        /*
+         * XXX this code is a temporary hack that should go away if/when
+         *     chapter merging goes away in libhb/dvd.c
+         * map the start and end chapter numbers to on-media chapter
+         * numbers since chapter merging could cause the handbrake numbers
+         * to diverge from the media numbers and, if our chapter_end is after
+         * a media chapter that got merged, we'll stop ripping too early.
+         */
+        int start = r->job->chapter_start;
+        hb_chapter_t *chap = hb_list_item( r->title->list_chapter, chapter_end - 1 );
+
+        chapter_end = chap->index;
+        if (start > 1)
+        {
+           chap = hb_list_item( r->title->list_chapter, start - 1 );
+           start = chap->index;
+        }
+        /* end chapter mapping XXX */
+
+        if( !hb_dvd_start( r->dvd, r->title->index, start ) )
+        {
+            hb_dvd_close( &r->dvd );
+            return;
+        }
+
+        if ( r->job->start_at_preview )
+        {
+            // XXX code from DecodePreviews - should go into its own routine
+            hb_dvd_seek( r->dvd, (float)r->job->start_at_preview / 11. );
+        }
+    }
+    else if ( r->stream && r->job->start_at_preview )
+    {
+        // XXX code from DecodePreviews - should go into its own routine
+        hb_stream_seek( r->stream, (float)( r->job->start_at_preview - 1 ) / 11. );
     }
 
     list  = hb_list_init();
@@ -351,7 +362,16 @@ static void ReaderFunc( void * _r )
                     }
                 }
                 if ( buf->start != -1 )
+                {
                     buf->start -= r->scr_offset;
+                    if ( r->job->pts_to_stop && buf->start > r->job->pts_to_stop )
+                    {
+                        // we're doing a subset of the input and we've hit the
+                        // stopping point.
+                        hb_buffer_close( &buf );
+                        goto done;
+                    }
+                }
 
                 buf->sequence = r->sequence++;
                 /* if there are mutiple output fifos, send a copy of the
@@ -374,6 +394,7 @@ static void ReaderFunc( void * _r )
         }
     }
 
+  done:
     // send empty buffers downstream to video & audio decoders to signal we're done.
     push_buf( r, r->job->fifo_mpeg2, hb_buffer_init(0) );
 
index 0c359f1..03de54c 100644 (file)
@@ -97,14 +97,21 @@ int syncInit( hb_work_object_t * w, hb_job_t * job )
     pv->pts_offset     = INT64_MIN;
 
     /* Calculate how many video frames we are expecting */
-    duration = 0;
-    for( i = job->chapter_start; i <= job->chapter_end; i++ )
+    if (job->pts_to_stop)
     {
-        chapter   = hb_list_item( title->list_chapter, i - 1 );
-        duration += chapter->duration;
+        duration = job->pts_to_stop + 90000;
     }
-    duration += 90000;
+    else
+    {
+        duration = 0;
+        for( i = job->chapter_start; i <= job->chapter_end; i++ )
+        {
+            chapter   = hb_list_item( title->list_chapter, i - 1 );
+            duration += chapter->duration;
+        }
+        duration += 90000;
         /* 1 second safety so we're sure we won't miss anything */
+    }
     pv->count_frames_max = duration * job->vrate / job->vrate_base / 90000;
 
     hb_log( "sync: expecting %d video frames", pv->count_frames_max );