]> granicus.if.org Git - handbrake/commitdiff
vpx: add encoder presets
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 29 May 2016 15:43:56 +0000 (09:43 -0600)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 29 May 2016 15:46:12 +0000 (09:46 -0600)
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

gtk/src/presets.c
gtk/src/videohandler.c
gtk/src/videohandler.h
libhb/common.c
libhb/encavcodec.c
libhb/hbffmpeg.h
libhb/work.c

index be2b893ddaa6141bfad538bd2c4eadd85f54a84b..c0e238405b2707f6951accf4160a790261c50976 100644 (file)
@@ -364,23 +364,12 @@ ghb_preset_to_settings(GhbValue *settings, GhbValue *preset)
         ghb_dict_remove(settings, "x264Option");
     }
 
-    int                 ii, encoder;
-    const char * const *videoPresets;
+    int                 encoder;
     const char         *videoPreset;
 
     encoder      = ghb_get_video_encoder(settings);
-    videoPresets = hb_video_encoder_get_presets(encoder);
     videoPreset  = ghb_dict_get_string(settings, "VideoPreset");
-    for (ii = 0; videoPreset && videoPresets && videoPresets[ii]; ii++)
-    {
-        if (!strcasecmp(videoPreset, videoPresets[ii]))
-        {
-            ghb_dict_set_int(settings, "VideoPresetSlider", ii);
-            break;
-        }
-    }
-    if (videoPreset != NULL)
-        ghb_dict_set_string(settings, "VideoPreset", videoPreset);
+    ghb_set_video_preset(settings, encoder, videoPreset);
 
     char *videoTune;
     char *tune = NULL;
index 10724f3330519616ffde2b025ba3d304ce123d5e..0ef8ec1bb9ffdd0b46fcd8050ad10e91831bef33 100644 (file)
@@ -40,6 +40,26 @@ int ghb_get_video_encoder(GhbValue *settings)
     return hb_video_encoder_get_from_name(encoder);
 }
 
+void ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset)
+{
+    const char * const * videoPresets;
+    int                  ii;
+
+    videoPresets = hb_video_encoder_get_presets(encoder);
+    for (ii = 0; preset && videoPresets && videoPresets[ii]; ii++)
+    {
+        if (!strcasecmp(preset, videoPresets[ii]))
+        {
+            ghb_dict_set_int(settings, "VideoPresetSlider", ii);
+            break;
+        }
+    }
+    if (preset != NULL)
+    {
+        ghb_dict_set_string(settings, "VideoPreset", preset);
+    }
+}
+
 G_MODULE_EXPORT void
 vcodec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
 {
@@ -79,6 +99,9 @@ vcodec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
     {
         gtk_range_set_range(GTK_RANGE(presetSlider), 0, count-1);
     }
+    ghb_set_video_preset(ud->settings, encoder, "medium");
+    GhbValue *gval = ghb_dict_get_value(ud->settings, "VideoPresetSlider");
+    ghb_ui_settings_update(ud, ud->settings, "VideoPresetSlider", gval);
 
     // Advanced options are only for x264
     if (!(encoder & HB_VCODEC_X264_MASK))
index 3159339244c636ee8ba075e640bb68ed46822fb7..1ddb9ce8018ced417f6e566e9aa55c01ead903b5 100644 (file)
@@ -30,5 +30,6 @@
 
 int ghb_get_video_encoder(GhbValue *settings);
 void ghb_video_setting_changed(GtkWidget *widget, signal_user_data_t *ud);
+void ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset);
 
 #endif // _VIDEOHANDLER_H_
index c6a272cae5353410f039043d9b18ac17d2e3d03c..c75e4e564e7a678c0fcbcbe73d47af96f445ac8e 100644 (file)
@@ -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:
index 50dda9a6c53e297ea99238626928e79338c52f78..08d13efcde378410d3260e444aa7bdc3ae5b6468 100644 (file)
@@ -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;
+    }
+}
index 0b348ac3be7040b99c21b7191c7f196fdeb2ecfa..5efd4244b249ed65e9a62465840a3ded7647aca2 100644 (file)
@@ -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);
index d318fe447d126c16224d62b85ff66cc79758dacf..afb8663945a0b9af7362e0326bdab01f22c7dfb7 100644 (file)
@@ -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)
         {