[FFmpeg-devel] [PATCH] Fixed presentation_delayed bug in compute_pkt_fields function

zhihang wang zhihang.wang at gmail.com
Tue May 31 05:05:33 CEST 2011


the patch is updated. :)



>From c1790d37aba7c98f608d843aa3e6b71144e7f617 Mon Sep 17 00:00:00 2001
From: xxthink <zhihang.wang at gmail.com>
Date: Tue, 31 May 2011 11:04:59 +0800
Subject: [PATCH] fixed setting presentation_delayed bug

---
 libavcodec/mpeg12.c    |    3 +--
 libavformat/avformat.h |    1 +
 libavformat/utils.c    |   16 ++++++++++++++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 6227efd..0877652 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -2442,8 +2442,7 @@ static int decode_chunks(AVCodecContext *avctx,
         case GOP_START_CODE:
             if(last_code == 0){
             s2->first_field=0;
-            mpeg_decode_gop(avctx,
-                                    buf_ptr, input_size);
+            mpeg_decode_gop(avctx, buf_ptr, input_size);
                 s->sync=1;
             }else{
                 av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after
%X\n", last_code);
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 41830ad..d038952 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -852,6 +852,7 @@ typedef struct AVFormatContext {
      * This will be moved into demuxer private options. Thus no API/ABI
compatibility
      */
     int ts_id;
+    int closed_gop;
 } AVFormatContext;

 typedef struct AVPacketList {
diff --git a/libavformat/utils.c b/libavformat/utils.c
index f0080bc..2373981 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -24,6 +24,7 @@
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
+#include "libavcodec/mpegvideo.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/raw.h"
 #include "libavutil/opt.h"
@@ -914,8 +915,12 @@ static void compute_pkt_fields(AVFormatContext *s,
AVStream *st,

     /* XXX: need has_b_frame, but cannot get it if the codec is
         not initialized */
-    if (delay &&
-        pc && pc->pict_type != AV_PICTURE_TYPE_B)
+    if (s->closed_gop)
+    {
+        if (delay && pc && pc->pict_type == FF_P_TYPE)
+            presentation_delayed = 1;
+    }
+    else if (delay && pc && pc->pict_type != AV_PICTURE_TYPE_B)
         presentation_delayed = 1;

     if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts
> pkt->pts && st->pts_wrap_bits<63
@@ -2389,7 +2394,14 @@ int av_find_stream_info(AVFormatContext *ic)
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
         if(st->codec->codec)
+        {
+            if ((st->codec->codec_id == CODEC_ID_MPEG2VIDEO ||
st->codec->codec_id == CODEC_ID_MPEG1VIDEO) && st->codec->priv_data)
+            {
+                MpegEncContext *s = st->codec->priv_data;
+                ic->closed_gop = s->closed_gop;
+            }
             avcodec_close(st->codec);
+        }
     }
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
-- 
1.7.0.4



Best Regards
zhihang wang


More information about the ffmpeg-devel mailing list