Commit: 1045253f67d000477882ec17a018ae55bbfdba1e Author: Richard Antalik Date: Tue Mar 16 12:26:23 2021 +0100 Branches: temp-vse-h264-proxy https://developer.blender.org/rB1045253f67d000477882ec17a018ae55bbfdba1e
Improve proxy building performance There are minimal changes to current code: - Use h264 codec for output - Specify number of threads for encoding to be same as system thread count - Specify same nuber of threads for decoding. This may work only with some codecs(only h264 tested so far), but performance gain in encoding improves overall performance by big margin still. I have tested variety of codecs, and all were transcoded properly. This is much simpler and straightforward patch than previous two, and this was in fact first thing I have tried to do in the beginning, but there was no improvement unless I have removed following lines: ``` rv->c->thread_count = BLI_system_thread_count(); rv->c->thread_type = FF_THREAD_SLICE; ``` I am not even sure how I found that these two lines were problematic. Differential Revision: https://developer.blender.org/D10731 =================================================================== M source/blender/imbuf/intern/indexer.c =================================================================== diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index c9581c108c0..7de82555711 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -477,7 +477,6 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( struct proxy_output_ctx *rv = MEM_callocN(sizeof(struct proxy_output_ctx), "alloc_proxy_output"); char fname[FILE_MAX]; - int ffmpeg_quality; rv->proxy_size = proxy_size; rv->anim = anim; @@ -496,12 +495,15 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( rv->st->id = 0; rv->c = rv->st->codec; - rv->c->thread_count = BLI_system_thread_count(); - rv->c->thread_type = FF_THREAD_SLICE; rv->c->codec_type = AVMEDIA_TYPE_VIDEO; - rv->c->codec_id = AV_CODEC_ID_MJPEG; + rv->c->codec_id = AV_CODEC_ID_H264; rv->c->width = width; rv->c->height = height; + rv->c->gop_size = 2; + rv->c->max_b_frames = 0; + /* Correct wrong default ffmpeg param which crash x264. */ + rv->c->qmin = 10; + rv->c->qmax = 51; rv->of->oformat->video_codec = rv->c->codec_id; rv->codec = avcodec_find_encoder(rv->c->codec_id); @@ -527,11 +529,13 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( rv->c->time_base.num = 1; rv->st->time_base = rv->c->time_base; - /* there's no way to set JPEG quality in the same way as in AVI JPEG and image sequence, - * but this seems to be giving expected quality result */ - ffmpeg_quality = (int)(1.0f + 30.0f * (1.0f - (float)quality / 100.0f) + 0.5f); - av_opt_set_int(rv->c, "qmin", ffmpeg_quality, 0); - av_opt_set_int(rv->c, "qmax", ffmpeg_quality, 0); + AVDictionary *codec_opts = NULL; + /* High quality preset value. */ + av_dict_set_int(&codec_opts, "crf", 20, 0); + /* Prefer smaller filesize. */ + av_dict_set(&codec_opts, "preset", "slow", 0); + /* Thread count. */ + av_dict_set_int(&codec_opts, "threads", BLI_system_thread_count(), 0); if (rv->of->flags & AVFMT_GLOBALHEADER) { rv->c->flags |= CODEC_FLAG_GLOBAL_HEADER; @@ -545,7 +549,7 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( return 0; } - avcodec_open2(rv->c, rv->codec, NULL); + avcodec_open2(rv->c, rv->codec, &codec_opts); rv->orig_height = av_get_cropped_height_from_codec(st->codec); @@ -783,7 +787,11 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, context->iCodecCtx->workaround_bugs = 1; - if (avcodec_open2(context->iCodecCtx, context->iCodec, NULL) < 0) { + AVDictionary *codec_opts = NULL; + /* Thread count. */ + av_dict_set_int(&codec_opts, "threads", BLI_system_thread_count(), 0); + + if (avcodec_open2(context->iCodecCtx, context->iCodec, &codec_opts) < 0) { avformat_close_input(&context->iFormatCtx); MEM_freeN(context); return NULL; _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
