[FFmpeg-devel] [PATCH] do not let claculated dts jump back

Rainer Hochecker rainer.hochecker at onlinehome.de
Sat Feb 22 18:22:48 CET 2014


Michael Niedermayer <michaelni <at> gmx.at> writes:

> > 
> > 
> > Yes, reverting 2ba68dd044ca8fc591139c05563840f546a9c0c0 cures the issue.
> > 
> > I don't see how calculation of dts from pts should work reliable with the
> > value of num_reorder_frames. This value indicates the maximum number of
> > frames in the reorder buffer (in this case 4). If we have a missing dts
> > right after an idr frame, dts is set to a already passed pts.
> > 
> > I am wondering if it's better to leave dts at AV_NOPTS_VALUE instead of
> > trying to calculate it. XBMC's player would be happy with this approach.
> 
> dts are needed for remuxing to containers which need dts, like
> mpeg-ts/ps, so setting them nowhere isnt a good solution
> 

I investigated you idea of changing delay. For the sample I provided
has_b_frames is 4. Settings it to 2 gives me good results. When logging out
slice types I see 2 b frames in a row so correcting this value may work.

Here is a new patch:

>From 14dbb0492cb00b527ba2fe0e6c47097dad84d440 Mon Sep 17 00:00:00 2001
From: Rainer Hochecker <fernetmenta at online.de>
Date: Sat, 22 Feb 2014 18:21:30 +0100
Subject: [PATCH] h264: measure num_b_frames

---
 libavcodec/h264.h        |  3 +++
 libavcodec/h264_parser.c | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 552a5af..ab427bd 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -701,6 +701,9 @@ typedef struct H264Context {
     AVBufferPool *mb_type_pool;
     AVBufferPool *motion_val_pool;
     AVBufferPool *ref_index_pool;
+
+    int b_frame_counter;         // counter consecutive b-frames
+    int counted_reorder_frames;  // measured value for num_reordered_frames
 } H264Context;
 
 extern const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM + 1]; ///< One chroma
qp table for each possible bit depth (8-14).
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 4432871..7991a3d 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -506,6 +506,21 @@ static int h264_parse(AVCodecParserContext *s,
 
     *poutbuf      = buf;
     *poutbuf_size = buf_size;
+
+    // measure number of reordered frames
+    // use this value instream of num_reordered_frames which is the maximum
value
+    if (buf_size) {
+    	if (s->pict_type == AV_PICTURE_TYPE_B)
+    		h->b_frame_counter++;
+    	else {
+    		if (h->b_frame_counter > h->counted_reorder_frames) {
+    		    h->counted_reorder_frames = h->b_frame_counter;
+    		}
+    		h->b_frame_counter = 0;
+    	}
+    	if (0 < h->counted_reorder_frames < avctx->has_b_frames)
+    		avctx->has_b_frames = h->counted_reorder_frames;
+    }
     return next;
 }
 
-- 
1.8.3.2




More information about the ffmpeg-devel mailing list