AVCodecContext *avctx;
uint8_t *previous_frame;
AVFrame frame;
- int first_frame;
int image_width, image_height;
int block_width, block_height;
uint8_t* tmpblock;
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,
static int flashsv_encode_init(AVCodecContext *avctx)
{
- FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+ FlashSVContext *s = avctx->priv_data;
s->avctx = avctx;
return -1;
}
- s->first_frame = 1;
-
// Needed if zlib unused or init aborted before deflateInit
memset(&(s->zstream), 0, sizeof(z_stream));
/*
}
*/
+ s->last_key_frame=0;
+
s->image_width = avctx->width;
s->image_height = avctx->height;
static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
{
- FlashSVContext * const s = (FlashSVContext *)avctx->priv_data;
+ FlashSVContext * const s = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p = &s->frame;
int res;
*p = *pict;
- if (s->first_frame) {
+ /* 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) {
av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
return -1;
}
I_frame = 1;
- s->first_frame = 0;
+ }
+
+ /* 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
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;
static int flashsv_encode_end(AVCodecContext *avctx)
{
- FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+ FlashSVContext *s = avctx->priv_data;
deflateEnd(&(s->zstream));