changeset 4651:ff9749708137 libavcodec

Respect the gop size (-g) for marking I frames. Use -g 0 gives the old behaviour.
author banan
date Sun, 11 Mar 2007 21:01:33 +0000
parents 31bf54d9353d
children 6679d37a3338
files flashsvenc.c
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flashsvenc.c	Sun Mar 11 20:30:06 2007 +0000
+++ b/flashsvenc.c	Sun Mar 11 21:01:33 2007 +0000
@@ -74,6 +74,7 @@
     uint8_t* encbuffer;
     int block_size;
     z_stream zstream;
+    int last_key_frame;
 } FlashSVContext;
 
 static int copy_region_enc(uint8_t *sptr, uint8_t *dptr,
@@ -125,6 +126,8 @@
     }
 */
 
+    s->last_key_frame=0;
+
     s->image_width = avctx->width;
     s->image_height = avctx->height;
 
@@ -238,6 +241,7 @@
 
     *p = *pict;
 
+    /* First frame needs to be a keyframe */
     if (avctx->frame_number == 0) {
         s->previous_frame = av_mallocz(p->linesize[0]*s->image_height);
         if (!s->previous_frame) {
@@ -247,6 +251,13 @@
         I_frame = 1;
     }
 
+    /* Check the placement of keyframes */
+    if (avctx->gop_size > 0) {
+        if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) {
+            I_frame = 1;
+        }
+    }
+
 #if 0
     int w, h;
     int optim_sizes[16][16];
@@ -297,6 +308,8 @@
     if (I_frame) {
         p->pict_type = FF_I_TYPE;
         p->key_frame = 1;
+        s->last_key_frame = avctx->frame_number;
+        av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n",avctx->frame_number);
     } else {
         p->pict_type = FF_P_TYPE;
         p->key_frame = 0;