Index: libhb/stream.c
===================================================================
--- libhb/stream.c (revision 1652)
+++ libhb/stream.c (working copy)
@@ -2575,12 +2575,24 @@
memcpy( buf->data, pkt.data, pkt.size );
buf->id = pkt.stream_index;
buf->size = pkt.size;
- int64_t pts = pkt.pts != AV_NOPTS_VALUE? pkt.pts :
- pkt.dts != AV_NOPTS_VALUE? pkt.dts : -1;
- buf->start = av_to_hb_pts( pts,
+ // We were setting PTS to DTS if there was no PTS available.
+ // This caused problems with P frames in dvd ps streams.
+ // Just pass a negative PTS when its invalid. The frames
+ // proper display time will be figured out upstream
+ int64_t pts = pkt.pts != AV_NOPTS_VALUE? pkt.pts : -1;
+ if (pts != -1)
+ buf->start = av_to_hb_pts( pts,
+ av_q2d(stream->ffmpeg_ic->streams[pkt.stream_index]->time_base)*90000. );
+ else
+ buf->start = -1;
+
+ int64_t dts = pkt.dts != AV_NOPTS_VALUE? pkt.dts :
+ pkt.pts != AV_NOPTS_VALUE? pkt.pts : -1;
+ if (dts != -1)
+ buf->renderOffset = av_to_hb_pts( dts,
av_q2d(stream->ffmpeg_ic->streams[pkt.stream_index]->time_base)*90000. );
- buf->renderOffset = av_to_hb_pts( pkt.pts,
- av_q2d(stream->ffmpeg_ic->streams[pkt.stream_index]->time_base)*90000. );
+ else
+ buf->renderOffset = 0;
av_free_packet( &pkt );
return 1;
}
Index: libhb/decavcodec.c
===================================================================
--- libhb/decavcodec.c (revision 1652)
+++ libhb/decavcodec.c (working copy)
@@ -745,6 +745,10 @@
hb_log( "overwriting pts %lld with %lld (diff %d)",
pv->pts, pts, pts - pv->pts );
}
+#if 0
+ // The pts value here comes from the stream. Frames from
+ // the stream can be out of pts order. So it doen't make since
+ // to drop out of order frames here.
if ( pv->pts_next - pts >= pv->duration )
{
// this frame starts more than a frame time before where
@@ -758,9 +762,21 @@
hb_buffer_close( &in );
return HB_WORK_OK;
}
+#endif
pv->pts = pts;
}
}
+ else
+ {
+ // While feeding a dvd ps stream through ffmpeg, I discovered
+ // that ffpmeg was not supplying a PTS for P frames.
+ // When you feed the frames into ffmpeg to be decoded, it provides
+ // the decoded frames in the proper order. But we were tagging
+ // such frames with a bad PTS and causing confusion
+ // Setting PTS to -1 here tags the frame. When it emerges
+ // later from ffmpeg, we know to use pts_next as its PTS.
+ pv->pts = -1;
+ }
if ( in->new_chap )
{