aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorThierry Foucu <tfoucu@gmail.com>2012-04-04 12:01:04 -0700
committerMichael Niedermayer <michaelni@gmx.at>2012-04-05 12:33:33 +0200
commitc99bdd51b2707c13273b2026690358506acef14e (patch)
tree8a43e560214e982b737ad942b9a027c2b8433715 /libavformat/utils.c
parentfa1f92a4f1c0890e501dcafcea8bc9ed5caa53e5 (diff)
downloadffmpeg-c99bdd51b2707c13273b2026690358506acef14e.tar.gz
lavf: Fix the last PTS to be generated using -fflags +genpts
To reproduce the problem, using ffprobe: ./ffprobe -show_packets -print_format compact -fflags +genpts -i fate_samples/mxf/C0023S01.mxf You will notice that the last video frame does not have it's PTS being set, even with using genpts. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 0bf3e2bdd5..1ab8035d90 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1351,14 +1351,30 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
if (next_pkt->dts != AV_NOPTS_VALUE) {
int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;
+ // last dts seen for this stream. if any of packets following
+ // current one had no dts, we will set this to AV_NOPTS_VALUE.
+ int64_t last_dts = next_pkt->dts;
while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {
if (pktl->pkt.stream_index == next_pkt->stream_index &&
- (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) &&
- av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) { //not b frame
- next_pkt->pts = pktl->pkt.dts;
+ (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0)) {
+ if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) { //not b frame
+ next_pkt->pts = pktl->pkt.dts;
+ }
+ if (last_dts != AV_NOPTS_VALUE) {
+ // Once last dts was set to AV_NOPTS_VALUE, we don't change it.
+ last_dts = pktl->pkt.dts;
+ }
}
pktl = pktl->next;
}
+ if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) {
+ // Fixing the last reference frame had none pts issue (For MXF etc).
+ // We only do this when
+ // 1. eof.
+ // 2. we are not able to resolve a pts value for current packet.
+ // 3. the packets for this stream at the end of the files had valid dts.
+ next_pkt->pts = last_dts + next_pkt->duration;
+ }
pktl = s->packet_buffer;
}