OSDN Git Service

- Always use HandBrake's DTS decoder rather than ffmpeg's even for inputs we read...
authorvan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 8 Nov 2008 06:26:57 +0000 (06:26 +0000)
committervan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 8 Nov 2008 06:26:57 +0000 (06:26 +0000)
 - Teach HB's DTS coder to handle implicit timestamps so that it doesn't screw up on mkv's & some m2ts inputs.
 - mkv's produced from Bluray HD content seem to have large timestamp errors - filter them out in the decoder so that sync doesn't drop big chunks of our audio.

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

libhb/decdca.c
libhb/stream.c

index 0c905af..b58a9ef 100644 (file)
@@ -14,6 +14,7 @@ struct hb_work_private_s
     /* libdca handle */
     dca_state_t * state;
 
+    double        next_pts;
     int           flags_in;
     int           flags_out;
     int           rate;
@@ -145,7 +146,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
     hb_work_private_t * pv = w->private_data;
     hb_buffer_t * buf;
     int           i, j, k;
-    uint64_t      pts, pos;
+    int64_t       pts, pos;
     int           num_blocks;
 
     /* Get a frame header if don't have one yet */
@@ -181,8 +182,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
         }
     }
 
-    if( !pv->sync ||
-        hb_list_bytes( pv->list ) < pv->size )
+    if( !pv->sync || hb_list_bytes( pv->list ) < pv->size )
     {
         /* Need more data */
         return NULL;
@@ -198,9 +198,22 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
     num_blocks = dca_blocks_num( pv->state );
 
     /* num_blocks blocks per frame, 256 samples per block, channelsused channels */
-    buf        = hb_buffer_init( num_blocks * 256 * pv->out_discrete_channels * sizeof( float ) );
-    buf->start = pts + ( pos / pv->size ) * num_blocks * 256 * 90000 / pv->rate;
-    buf->stop  = buf->start + num_blocks * 256 * 90000 / pv->rate;
+    int nsamp = num_blocks * 256;
+    buf = hb_buffer_init( nsamp * pv->out_discrete_channels * sizeof( float ) );
+
+    // mkv files typically use a 1ms timebase which results in a lot of
+    // truncation error in their timestamps. Also, TSMuxer or something
+    // in the m2ts-to-mkv toolchain seems to take a very casual attitude
+    // about time - timestamps seem to randomly offset by ~40ms for a few
+    // seconds then recover. So, if the pts we got is within 50ms of the
+    // pts computed from the data stream, use the data stream pts.
+    if ( pts < 0 || fabs( (double)pts - pv->next_pts ) < 50.*90. )
+    {
+        pts = pv->next_pts;
+    }
+    buf->start = pts;
+    pv->next_pts += (double)nsamp / (double)pv->rate * 90000.;
+    buf->stop  = pv->next_pts;
 
     for( i = 0; i < num_blocks; i++ )
     {
index 665cea6..ee5c5f6 100755 (executable)
@@ -2520,6 +2520,10 @@ static void add_ffmpeg_audio( hb_title_t *title, hb_stream_t *stream, int id )
         {
             audio->config.in.codec = HB_ACODEC_AC3;
         }
+        else if ( codec->codec_id == CODEC_ID_DTS )
+        {
+            audio->config.in.codec = HB_ACODEC_DCA;
+        }
         else
         {
             audio->config.in.codec = HB_ACODEC_FFMPEG;