From 26025371d6e75ba52ad6cb248292a2a2c454f6c2 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 26 Nov 2012 18:01:50 +0100 Subject: [PATCH] Add frame dropping possibilities to recorder. --- record/ffemu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/record/ffemu.c b/record/ffemu.c index fb7e9027ad..4d0a198cd8 100644 --- a/record/ffemu.c +++ b/record/ffemu.c @@ -70,6 +70,9 @@ struct ff_video_info // Input pixel format. Only used by sws. enum PixelFormat in_pix_fmt; + unsigned frame_drop_ratio; + unsigned frame_drop_count; + // Input pixel size. size_t pix_size; @@ -122,6 +125,7 @@ struct ff_config_param char format[64]; enum PixelFormat out_pix_fmt; unsigned threads; + unsigned frame_drop_ratio; unsigned sample_rate; unsigned scale_factor; @@ -312,7 +316,7 @@ static bool ffemu_init_video(struct ff_config_param *params, struct ff_video_inf video->codec->codec_type = AVMEDIA_TYPE_VIDEO; video->codec->width = param->out_width; video->codec->height = param->out_height; - video->codec->time_base = av_d2q(1.0 / param->fps, 1000000); // Arbitrary big number. + video->codec->time_base = av_d2q((double)params->frame_drop_ratio / param->fps, 1000000); // Arbitrary big number. video->codec->sample_aspect_ratio = av_d2q(param->aspect_ratio * param->out_height / param->out_width, 255); video->codec->pix_fmt = video->pix_fmt; @@ -325,6 +329,8 @@ static bool ffemu_init_video(struct ff_config_param *params, struct ff_video_inf video->outbuf_size = 1 << 23; video->outbuf = (uint8_t*)av_malloc(video->outbuf_size); + video->frame_drop_ratio = params->frame_drop_ratio; + size_t size = avpicture_get_size(video->pix_fmt, param->out_width, param->out_height); video->conv_frame_buf = (uint8_t*)av_malloc(size); video->conv_frame = avcodec_alloc_frame(); @@ -354,6 +360,10 @@ static bool ffemu_init_config(struct ff_config_param *params, const char *config if (!config_get_uint(params->conf, "threads", ¶ms->threads)) params->threads = 1; + if (!config_get_uint(params->conf, "frame_drop_ratio", ¶ms->frame_drop_ratio) + || !params->frame_drop_ratio) + params->frame_drop_ratio = 1; + if (!config_get_uint(params->conf, "sample_rate", ¶ms->sample_rate)) params->sample_rate = 0; if (!config_get_uint(params->conf, "scale_factor", ¶ms->scale_factor)) @@ -591,6 +601,11 @@ void ffemu_free(ffemu_t *handle) bool ffemu_push_video(ffemu_t *handle, const struct ffemu_video_data *data) { + bool drop_frame = handle->video.frame_drop_count++ % handle->video.frame_drop_ratio; + handle->video.frame_drop_count %= handle->video.frame_drop_ratio; + if (drop_frame) + return true; + for (;;) { slock_lock(handle->lock);