[FFmpeg-devel] [WIP][RFC][PATCH] png: support for skiping decoding data

Paul B Mahol onemda at gmail.com
Fri Aug 9 15:40:39 CEST 2013


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---

Crude attempt at parsing only frame and not doing decoding.
It returns frames with data, not calling ff_get_video_buffer()
gives error.
Perhaps doing this from parser is better solution.

---
 libavcodec/pngdec.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 1358ac5..067948c 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -65,6 +65,7 @@ typedef struct PNGDecContext {
     int pass_row_size; /* decompress row size of the current pass */
     int y;
     z_stream zstream;
+    int decode_data;
 } PNGDecContext;
 
 /* Mask to determine which pixels are valid in a pass */
@@ -364,6 +365,11 @@ static int png_decode_idat(PNGDecContext *s, int length)
     s->zstream.next_in  = (unsigned char *)s->gb.buffer;
     bytestream2_skip(&s->gb, length);
 
+    if (!s->decode_data) {
+        s->state |= PNG_ALLIMAGE;
+        return 0;
+    }
+
     /* decode one line if possible */
     while (s->zstream.avail_in > 0) {
         ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
@@ -512,6 +518,8 @@ static int decode_frame(AVCodecContext *avctx,
     int64_t sig;
     int ret;
 
+
+    s->decode_data = !(avctx->skip_frame == AVDISCARD_ALL);
     bytestream2_init(&s->gb, buf, buf_size);
 
     /* check signature */
@@ -641,6 +649,7 @@ static int decode_frame(AVCodecContext *avctx,
                 p->key_frame        = 1;
                 p->interlaced_frame = !!s->interlace_type;
 
+                if (s->decode_data) {
                 /* compute the compressed row size */
                 if (!s->interlace_type) {
                     s->crow_size = s->row_size + 1;
@@ -677,6 +686,7 @@ static int decode_frame(AVCodecContext *avctx,
                 s->crow_buf          = crow_buf_base + 15;
                 s->zstream.avail_out = s->crow_size;
                 s->zstream.next_out  = s->crow_buf;
+                }
             }
             s->state |= PNG_IDAT;
             if (png_decode_idat(s, length) < 0)
@@ -737,6 +747,8 @@ static int decode_frame(AVCodecContext *avctx,
                 goto fail;
             }
             bytestream2_skip(&s->gb, 4); /* crc */
+            if (!s->decode_data)
+                goto skip_decoding;
             goto exit_loop;
         default:
             /* skip tag */
@@ -840,6 +852,7 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
 
+skip_decoding:
     av_frame_set_metadata(p, metadata);
     metadata   = NULL;
 
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list