[libav-commits] Fix parser not to clobber has_b_frames when extradata is set.

Reinhard Tartler git at libav.org
Sun Apr 1 19:04:58 CEST 2012

Module: libav
Branch: release/0.7
Commit: a02da9ceaf298e57bd6f579ea6158164d32ed18e

Author:    Reinhard Tartler <siretart at tauware.de>
Committer: Reinhard Tartler <siretart at tauware.de>
Date:      Sun Feb 26 10:50:45 2012 +0100

Fix parser not to clobber has_b_frames when extradata is set.

Because in contrast to the decoder, the parser does not setup low_delay.
The code in parse_nal_units would always end up setting has_b_frames
to "1", except when stream is explicitly marked as low delay.
Since the parser itself would create 'extradata', simply reopening
the parser would cause this.

This happens for instance in estimate_timings_from_pts(), which causes the
parser to be reopened on the same stream.

This fixes Libav #22 and FFmpeg (trac) #360

CC: libav-stable at libav.org

Based on a patch by Reimar Döffinger <Reimar.Doeffinger at gmx.de>
(commit 31ac0ac29b6bba744493f7d1040757a3f51b9ad7)

Comments and description adapted by Reinhard Tartler.

Signed-off-by: Reinhard Tartler <siretart at tauware.de>
(cherry picked from commit 790a367d9ecd04360f78616765ee723f3fe65645)

Signed-off-by: Reinhard Tartler <siretart at tauware.de>


 libavcodec/h264_parser.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index c39baeb..4263c4b 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -251,6 +251,13 @@ static int h264_parse(AVCodecParserContext *s,
         h->got_first = 1;
         if (avctx->extradata_size) {
             h->s.avctx = avctx;
+            // must be done like in the decoder.
+            // otherwise opening the parser, creating extradata,
+            // and then closing and opening again
+            // will cause has_b_frames to be always set.
+            // NB: estimate_timings_from_pts behaves exactly like this.
+            if (!avctx->has_b_frames)
+                h->s.low_delay = 1;

More information about the libav-commits mailing list