diff options
author | John Stebbins <[email protected]> | 2016-05-29 09:43:56 -0600 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-05-29 09:46:12 -0600 |
commit | 1db4f9898de375ee7d83fdf56e2af5de3ef53671 (patch) | |
tree | 09508f3552acd9d169f312529d95e0cc2364315e /libhb | |
parent | aae64bbd7be3907633e833d30edde605a5887de1 (diff) |
vpx: add encoder presets
presets are
veryfast - deadline=good:cpu-used=5
faster - deadline=good:cpu-used=4
fast - deadline=good:cpu-used=3
medium - deadline=good:cpu-used=2
slow - deadline=good:cpu-used=1
slower - deadline=good:cpu-used=0
veryslow - deadline=best:cpu-used=0
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.c | 5 | ||||
-rw-r--r-- | libhb/encavcodec.c | 86 | ||||
-rw-r--r-- | libhb/hbffmpeg.h | 1 | ||||
-rw-r--r-- | libhb/work.c | 18 |
4 files changed, 91 insertions, 19 deletions
diff --git a/libhb/common.c b/libhb/common.c index c6a272cae..c75e4e564 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -1332,6 +1332,11 @@ const char* const* hb_video_encoder_get_presets(int encoder) } #endif + if (encoder & HB_VCODEC_FFMPEG_MASK) + { + return hb_av_preset_get_names(encoder); + } + switch (encoder) { case HB_VCODEC_X264_8BIT: diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 50dda9a6c..08d13efcd 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -48,6 +48,9 @@ int encavcodecInit( hb_work_object_t *, hb_job_t * ); int encavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** ); void encavcodecClose( hb_work_object_t * ); +static void apply_encoder_preset(int vcodec, AVDictionary ** av_opts, + const char * preset); + hb_work_object_t hb_encavcodec = { WORK_ENCAVCODEC, @@ -57,6 +60,11 @@ hb_work_object_t hb_encavcodec = encavcodecClose }; +static const char * const vpx_preset_names[] = +{ + "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", NULL +}; + int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) { AVCodec * codec; @@ -171,15 +179,11 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) lavc_opts = hb_encopts_to_dict(job->encoder_options, job->vcodec); } - AVDictionary * av_opts = NULL; if (job->vquality != HB_INVALID_VIDEO_QUALITY) { if ( w->codec_param == AV_CODEC_ID_VP8 || w->codec_param == AV_CODEC_ID_VP9 ) { - // Default quality/speed settings - av_dict_set( &av_opts, "deadline", "good", 0); - av_dict_set( &av_opts, "cpu-used", "2", 0); //This value was chosen to make the bitrate high enough //for libvpx to "turn off" the maximum bitrate feature //that is normally applied to constant quality. @@ -187,6 +191,9 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) } } + AVDictionary * av_opts = NULL; + apply_encoder_preset(job->vcodec, &av_opts, job->encoder_preset); + /* iterate through lavc_opts and have avutil parse the options for us */ hb_dict_iter_t iter; for (iter = hb_dict_iter_init(lavc_opts); @@ -626,4 +633,75 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, return final_flushing_call? HB_WORK_DONE : HB_WORK_OK; } +static void apply_vpx_preset(AVDictionary ** av_opts, const char * preset) +{ + if (!strcasecmp("veryfast", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "5", 0); + } + else if (!strcasecmp("faster", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "4", 0); + } + else if (!strcasecmp("fast", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "3", 0); + } + else if (!strcasecmp("medium", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "2", 0); + } + else if (!strcasecmp("slow", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "1", 0); + } + else if (!strcasecmp("slower", preset)) + { + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "0", 0); + } + else if (!strcasecmp("veryslow", preset)) + { + av_dict_set( av_opts, "deadline", "best", 0); + av_dict_set( av_opts, "cpu-used", "0", 0); + } + else + { + // default "medium" + hb_error("apply_vpx_preset: Unknown preset %s, using medium", preset); + av_dict_set( av_opts, "deadline", "good", 0); + av_dict_set( av_opts, "cpu-used", "2", 0); + } +} +static void apply_encoder_preset(int vcodec, AVDictionary ** av_opts, + const char * preset) +{ + switch (vcodec) + { + case HB_VCODEC_FFMPEG_VP8: + case HB_VCODEC_FFMPEG_VP9: + apply_vpx_preset(av_opts, preset); + break; + default: + break; + } +} + +const char* const* hb_av_preset_get_names(int encoder) +{ + switch (encoder) + { + case HB_VCODEC_FFMPEG_VP8: + case HB_VCODEC_FFMPEG_VP9: + return vpx_preset_names; + + default: + return NULL; + } +} diff --git a/libhb/hbffmpeg.h b/libhb/hbffmpeg.h index 0b348ac3b..5efd4244b 100644 --- a/libhb/hbffmpeg.h +++ b/libhb/hbffmpeg.h @@ -24,6 +24,7 @@ void hb_avcodec_init(void); int hb_avcodec_open(AVCodecContext *, AVCodec *, AVDictionary **, int); int hb_avcodec_close(AVCodecContext *); +const char* const* hb_av_preset_get_names(int encoder); uint64_t hb_ff_mixdown_xlat(int hb_mixdown, int *downmix_mode); void hb_ff_set_sample_fmt(AVCodecContext *, AVCodec *, enum AVSampleFormat); diff --git a/libhb/work.c b/libhb/work.c index d318fe447..afb866394 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -422,22 +422,10 @@ void hb_display_job_info(hb_job_t *job) hb_log(" + encoder: %s", hb_video_encoder_get_long_name(job->vcodec)); - if (job->encoder_preset && *job->encoder_preset) + if (job->encoder_preset && *job->encoder_preset && + hb_video_encoder_get_presets(job->vcodec) != NULL) { - switch (job->vcodec) - { - case HB_VCODEC_X264_8BIT: - case HB_VCODEC_X264_10BIT: - case HB_VCODEC_X265_8BIT: - case HB_VCODEC_X265_10BIT: - case HB_VCODEC_X265_12BIT: - case HB_VCODEC_X265_16BIT: - case HB_VCODEC_QSV_H264: - case HB_VCODEC_QSV_H265: - hb_log(" + preset: %s", job->encoder_preset); - default: - break; - } + hb_log(" + preset: %s", job->encoder_preset); } if (job->encoder_tune && *job->encoder_tune) { |