Skip to content

Commit

Permalink
add directive to set the number of threads used by avcodec
Browse files Browse the repository at this point in the history
  • Loading branch information
wandenberg committed Feb 15, 2015
1 parent 4211eec commit e0a7c2f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.textile
Expand Up @@ -334,6 +334,19 @@ Set the size of the padding to be used between the frames.
!test/test_video_2_cols_2_rows_3_padding.jpg(using 3px of padding)!


h2(#video_thumbextractor_threads). video_thumbextractor_threads

*syntax:* _video_thumbextractor_threads string_

*default:* _auto_

*context:* _http_

*release version:* _0.6.0_

Set the number of threads used by avcodec.


h1(#contributors). Contributors

"People":contributors
Expand All @@ -344,6 +357,7 @@ h1(#changelog). Changelog
h2(#0_6_0). v0.6.0

* add support to tile filter, used to make story boards or sprites
* add directive to control the number of threads used by avcodec

h2(#0_5_0). v0.5.0

Expand Down
2 changes: 2 additions & 0 deletions include/ngx_http_video_thumbextractor_module.h
Expand Up @@ -55,6 +55,8 @@ typedef struct {
ngx_flag_t only_keyframe;
ngx_flag_t next_time;

ngx_str_t threads;

ngx_flag_t enabled;
} ngx_http_video_thumbextractor_loc_conf_t;

Expand Down
9 changes: 9 additions & 0 deletions src/ngx_http_video_thumbextractor_module_setup.c
Expand Up @@ -163,6 +163,12 @@ static ngx_command_t ngx_http_video_thumbextractor_commands[] = {
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_video_thumbextractor_loc_conf_t, jpeg_dpi),
NULL },
{ ngx_string("video_thumbextractor_threads"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_video_thumbextractor_loc_conf_t, threads),
NULL },
ngx_null_command
};

Expand Down Expand Up @@ -228,6 +234,7 @@ ngx_http_video_thumbextractor_create_loc_conf(ngx_conf_t *cf)
conf->jpeg_dpi = NGX_CONF_UNSET_UINT;
conf->only_keyframe = NGX_CONF_UNSET_UINT;
conf->next_time = NGX_CONF_UNSET_UINT;
ngx_str_null(&conf->threads);

return conf;
}
Expand Down Expand Up @@ -276,6 +283,8 @@ ngx_http_video_thumbextractor_merge_loc_conf(ngx_conf_t *cf, void *parent, void
ngx_conf_merge_value(conf->only_keyframe, prev->only_keyframe, 1);
ngx_conf_merge_value(conf->next_time, prev->next_time, 1);

ngx_conf_merge_str_value(conf->threads, prev->threads, "auto");

// if video thumb extractor is disable the other configurations don't have to be checked
if (!conf->enabled) {
return NGX_CONF_OK;
Expand Down
7 changes: 6 additions & 1 deletion src/ngx_http_video_thumbextractor_module_utils.c
Expand Up @@ -106,6 +106,7 @@ ngx_http_video_thumbextractor_get_thumb(ngx_http_video_thumbextractor_loc_conf_t
AVFilterGraph *filter_graph = NULL;
int need_flush = 0;
int64_t second = ctx->second;
char value[10];

ngx_memzero(&info->file, sizeof(ngx_file_t));
info->file.name = *info->filename;
Expand Down Expand Up @@ -186,8 +187,12 @@ ngx_http_video_thumbextractor_get_thumb(ngx_http_video_thumbextractor_loc_conf_t
goto exit;
}

AVDictionary *dict = NULL;
ngx_sprintf((u_char *) value, "%V%Z", &cf->threads);
av_dict_set(&dict, "threads", value, 0);

// Open codec
if ((avcodec_open2(pCodecCtx, pCodec, NULL)) < 0) {
if ((avcodec_open2(pCodecCtx, pCodec, &dict)) < 0) {
ngx_log_error(NGX_LOG_ERR, log, 0, "video thumb extractor module: Could not open codec");
goto exit;
}
Expand Down

0 comments on commit e0a7c2f

Please sign in to comment.