]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
update vaapi
authoralingherghescu <alin_gherghescu@yahoo.com>
Tue, 31 Jan 2023 00:15:04 +0000 (16:15 -0800)
committerFlole998 <Flole998@users.noreply.github.com>
Sun, 5 Feb 2023 16:32:00 +0000 (17:32 +0100)
- update libvpx to ver. 1.12.0
- replaced tvherror() with tvhinfo for bitrate report
- converted from bps to kbps
- reduced B frame to max 3 (4 is generating artifacts on my system)
- I had to set also bf otherwise will be set later in profile_video_class() with 3
- when low power is enabled max B frame will be disabled (because codec is not using B frames in low power mode)
- h264_vaapi and hevc_vaapi have also dynamic enable/disable for max B frame
- vp9 super frames can be enabled/disabled from the interface
- clean-up some javascript code

Makefile.ffmpeg
src/transcoding/codec/codecs/libs/vaapi.c
src/webui/static/app/codec.js

index 94f6e977ac05d9391bef56c99a20d2f2af80f60e..561c1e288f4215880a8e82beda12afc4cc1659d3 100644 (file)
@@ -69,11 +69,11 @@ LIBX265_DIFFS  = libx265.pic.diff
 endif
 LIBX265_DIFFS  += libx265-silence.patch
 
-LIBVPX_VER     = 1.9.0
+LIBVPX_VER     = 1.12.0
 LIBVPX         = libvpx-$(LIBVPX_VER)
 LIBVPX_TB      = $(LIBVPX).tar.gz
 LIBVPX_URL     = https://github.com/webmproject/libvpx/archive/v$(LIBVPX_VER)/$(LIBVPX_TB)
-LIBVPX_SHA1    = 2ab8203ad8922bdf3256e4a197d1348fa8db9a62
+LIBVPX_SHA1    = e5f344d28752344d4c6e0c83b055093932b8d2c9
 
 LIBOGG         = libogg-1.3.4
 LIBOGG_TB      = $(LIBOGG).tar.gz
index 0f3727ca5f4b95db3b358124681b1e982eef2be6..e74e33d02d0151a61c3fcf23c0da51dd8d5b351f 100644 (file)
@@ -138,6 +138,7 @@ typedef struct {
     int level;
     int qmin;
     int qmax;
+    int super_frame;
 } tvh_codec_profile_vaapi_t;
 
 #if defined(__linux__)
@@ -254,7 +255,7 @@ static const codec_profile_class_t codec_profile_vaapi_class = {
                 .type     = PT_BOOL,
                 .id       = "low_power",     // Don't change
                 .name     = N_("Low Power"),
-                .desc     = N_("Set low power mode.[if disabled will not send paramter to libav]"),
+                .desc     = N_("Set low power mode.[if disabled will not send parameter to libav, if enabled codec will disable B frames]"),
                 .group    = 3,
                 .opts     = PO_EXPERT,
                 .get_opts = codec_profile_class_get_opts,
@@ -276,11 +277,11 @@ static const codec_profile_class_t codec_profile_vaapi_class = {
                 .type     = PT_INT,
                 .id       = "desired_b_depth",     // Don't change
                 .name     = N_("Maximum B-frame"),
-                .desc     = N_("Maximum B-frame reference depth (from 1 to 4) (default 1)"),
+                .desc     = N_("Maximum B-frame reference depth (from 1 to 3) (default 1)"),
                 .group    = 3,
                 .get_opts = codec_profile_class_get_opts,
                 .off      = offsetof(tvh_codec_profile_vaapi_t, desired_b_depth),
-                .intextra = INTEXTRA_RANGE(0, 4, 1),
+                .intextra = INTEXTRA_RANGE(0, 3, 1),
                 .def.i    = 1,
             },
             {
@@ -394,7 +395,7 @@ tvh_codec_profile_vaapi_h264_open(tvh_codec_profile_vaapi_t *self,
     int int_bitrate = (int)((double)(self->bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
     int int_buffer_size = (int)((double)(self->bit_rate) * 2048.0 * self->buff_factor * (1.0 + self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480));
     int int_max_bitrate = (int)((double)(self->max_bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
-    tvherror(LS_VAAPI, "Bitrate = %d bps; Buffer size = %d bps; Max bitrate = %d bps", int_bitrate, int_buffer_size, int_max_bitrate);
+    tvhinfo(LS_VAAPI, "Bitrate = %d kbps; Buffer size = %d kbps; Max bitrate = %d kbps", int_bitrate / 1024, int_buffer_size / 1024, int_max_bitrate / 1024);
     // https://wiki.libav.org/Hardware/vaapi
     // https://blog.wmspanel.com/2017/03/vaapi-libva-support-nimble-streamer.html
     // to find available parameters use:
@@ -454,8 +455,10 @@ tvh_codec_profile_vaapi_h264_open(tvh_codec_profile_vaapi_t *self,
         case 0:
             // Uncontrained --> will allow any combination of parameters (valid or invalid)
             // this mode is usefull fur future platform and for debugging.
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             if (self->bit_rate) {
                 AV_DICT_SET_INT(opts, "b", int_bitrate, AV_DICT_DONT_OVERWRITE);
@@ -488,8 +491,10 @@ tvh_codec_profile_vaapi_h264_open(tvh_codec_profile_vaapi_t *self,
             break;
         case 1:
             // Intel
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             switch (self->rc_mode) {
                 case -1:
@@ -677,7 +682,7 @@ tvh_codec_profile_vaapi_hevc_open(tvh_codec_profile_vaapi_t *self,
     int int_bitrate = (int)((double)(self->bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
     int int_buffer_size = (int)((double)(self->bit_rate) * 2048.0 * self->buff_factor * (1.0 + self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480));
     int int_max_bitrate = (int)((double)(self->max_bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
-    tvherror(LS_VAAPI, "Bitrate = %d bps; Buffer size = %d bps; Max bitrate = %d bps", int_bitrate, int_buffer_size, int_max_bitrate);
+    tvhinfo(LS_VAAPI, "Bitrate = %d kbps; Buffer size = %d kbps; Max bitrate = %d kbps", int_bitrate / 1024, int_buffer_size / 1024, int_max_bitrate / 1024);
     // https://wiki.libav.org/Hardware/vaapi
     // to find available parameters use:
     // ffmpeg -hide_banner -h encoder=hevc_vaapi
@@ -727,8 +732,10 @@ tvh_codec_profile_vaapi_hevc_open(tvh_codec_profile_vaapi_t *self,
         case 0:
             // Unconstrained --> will allow any combination of parameters (valid or invalid)
             // this mode is usefull fur future platform and for debugging.
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             if (self->bit_rate) {
                 AV_DICT_SET_INT(opts, "b", int_bitrate, AV_DICT_DONT_OVERWRITE);
@@ -761,8 +768,10 @@ tvh_codec_profile_vaapi_hevc_open(tvh_codec_profile_vaapi_t *self,
             break;
         case 1:
             // Intel
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             switch (self->rc_mode) {
                 case -1:
@@ -945,7 +954,7 @@ tvh_codec_profile_vaapi_vp8_open(tvh_codec_profile_vaapi_t *self,
     int int_bitrate = (int)((double)(self->bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
     int int_buffer_size = (int)((double)(self->bit_rate) * 2048.0 * self->buff_factor * (1.0 + self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480));
     int int_max_bitrate = (int)((double)(self->max_bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
-    tvherror(LS_VAAPI, "Bitrate = %d bps; Buffer size = %d bps; Max bitrate = %d bps", int_bitrate, int_buffer_size, int_max_bitrate);
+    tvhinfo(LS_VAAPI, "Bitrate = %d kbps; Buffer size = %d kbps; Max bitrate = %d kbps", int_bitrate / 1024, int_buffer_size / 1024, int_max_bitrate / 1024);
     // https://wiki.libav.org/Hardware/vaapi
     // to find available parameters use:
     // ffmpeg -hide_banner -h encoder=vp8_vaapi
@@ -971,8 +980,10 @@ tvh_codec_profile_vaapi_vp8_open(tvh_codec_profile_vaapi_t *self,
         case 0:
             // Unconstrained --> will allow any combination of parameters (valid or invalid)
             // this mode is usefull fur future platform and for debugging.
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             if (self->bit_rate) {
                 AV_DICT_SET_INT(opts, "b", int_bitrate, AV_DICT_DONT_OVERWRITE);
@@ -1008,8 +1019,10 @@ tvh_codec_profile_vaapi_vp8_open(tvh_codec_profile_vaapi_t *self,
             break;
         case 1:
             // Intel
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
             }
             if (self->quality >= 0) {
                 AV_DICT_SET_INT(opts, "global_quality", self->quality, AV_DICT_DONT_OVERWRITE);
@@ -1209,7 +1222,7 @@ tvh_codec_profile_vaapi_vp9_open(tvh_codec_profile_vaapi_t *self,
     int int_bitrate = (int)((double)(self->bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
     int int_buffer_size = (int)((double)(self->bit_rate) * 2048.0 * self->buff_factor * (1.0 + self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480));
     int int_max_bitrate = (int)((double)(self->max_bit_rate) * 1024.0 * (1.0 + (self->bit_rate_scale_factor * ((double)(self->size.den) - 480.0) / 480.0)));
-    tvherror(LS_VAAPI, "Bitrate = %d bps; Buffer size = %d bps; Max bitrate = %d bps", int_bitrate, int_buffer_size, int_max_bitrate);
+    tvhinfo(LS_VAAPI, "Bitrate = %d kbps; Buffer size = %d kbps; Max bitrate = %d kbps", int_bitrate / 1024, int_buffer_size / 1024, int_max_bitrate / 1024);
     // https://wiki.libav.org/Hardware/vaapi
     // to find available parameters use:
     // ffmpeg -hide_banner -h encoder=vp9_vaapi
@@ -1235,8 +1248,12 @@ tvh_codec_profile_vaapi_vp9_open(tvh_codec_profile_vaapi_t *self,
         case 0:
             // Unconstrained --> will allow any combination of parameters (valid or invalid)
             // this mode is usefull fur future platform and for debugging.
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+            }
+            if (self->super_frame) {
                 // according to example from https://trac.ffmpeg.org/wiki/Hardware/VAAPI
                 // -bsf:v vp9_raw_reorder,vp9_superframe
                 AV_DICT_SET(opts, "bsf", "vp9_raw_reorder,vp9_superframe", AV_DICT_DONT_OVERWRITE);
@@ -1275,8 +1292,12 @@ tvh_codec_profile_vaapi_vp9_open(tvh_codec_profile_vaapi_t *self,
             break;
         case 1:
             // Intel
-            if (self->desired_b_depth) {
+            if ((self->low_power == 0) && (self->desired_b_depth)) {
                 AV_DICT_SET_INT(opts, "b_depth", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+                // max_b_frames
+                AV_DICT_SET_INT(opts, "bf", self->desired_b_depth, AV_DICT_DONT_OVERWRITE);
+            }
+            if (self->super_frame) {
                 // according to example from https://trac.ffmpeg.org/wiki/Hardware/VAAPI
                 // -bsf:v vp9_raw_reorder,vp9_superframe
                 AV_DICT_SET(opts, "bsf", "vp9_raw_reorder,vp9_superframe", AV_DICT_DONT_OVERWRITE);
@@ -1446,6 +1467,17 @@ static const codec_profile_class_t codec_profile_vaapi_vp9_class = {
                 .intextra = INTEXTRA_RANGE(-1, 15, 1),
                 .def.i    = 4,
             },
+            {
+                .type     = PT_BOOL,
+                .id       = "super_frame",              // Don't change
+                .name     = N_("Super Frame"),
+                .desc     = N_("Enable Super Frame for vp9 encoder.[default disabled]"),
+                .group    = 5,
+                .opts     = PO_EXPERT,
+                .get_opts = codec_profile_class_get_opts,
+                .off      = offsetof(tvh_codec_profile_vaapi_t, super_frame),
+                .def.i    = 0,
+            },
             {}
         }
     },
index 6ca5beba01bbfeaf4c1e4234c31e645d5ef53c03..b35b528d4fb15e4ef48a5190368d111e2138d575 100644 (file)
@@ -239,6 +239,7 @@ var codec_profile_forms = {
             var bit_rate_scale_factor_field = form.findField('bit_rate_scale_factor');
             var qp_field = form.findField('qp');
             var low_power_field = form.findField('low_power');
+            var desired_b_depth_field = form.findField('desired_b_depth');
 
             var platform = platform_field.getValue();
             switch (platform) {
@@ -252,9 +253,12 @@ var codec_profile_forms = {
                     bit_rate_scale_factor_field.setDisabled(false);
                     qp_field.setDisabled(false);
                     low_power_field.setDisabled(false);
+                    desired_b_depth_field.setDisabled(false);
                     break;
                 case 1:
                     // Intel
+                    // low_power is disabling Max B frame
+                    desired_b_depth_field.setDisabled(low_power_field.getValue());
                     var rc_mode = rc_mode_field.getValue();
                     switch (rc_mode) {
                         case -1:
@@ -314,11 +318,14 @@ var codec_profile_forms = {
                     // AMD --> will allow any combination of parameters
                     // I am unable to confirm this platform because I don't have the HW
                     // Is only going to override bf to 0 (as highlited by the previous implementation)
+                    // NOTE: filters to be added later
                     bit_rate_field.setDisabled(false);
                     max_bit_rate_field.setDisabled(false);
                     buff_factor_field.setDisabled(false);
                     bit_rate_scale_factor_field.setDisabled(false);
                     qp_field.setDisabled(false);
+                    low_power_field.setDisabled(false);
+                    desired_b_depth_field.setDisabled(false);
                     break;
                 default:
             }
@@ -326,15 +333,20 @@ var codec_profile_forms = {
 
         var platform_field = form.findField('platform');
         var rc_mode_field = form.findField('rc_mode');
+        var low_power_field = form.findField('low_power');
         // first time we have to call this manually
         updateFilters(form);
         
         // on platform change
-        platform_field.on('select', function(spinner) {
+        platform_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
         // on rc_mode change
-        rc_mode_field.on('select', function(spinner) {
+        rc_mode_field.on('select', function(combo, record, index) {
+            updateFilters(form);
+        });
+        // on low_power change
+        low_power_field.on('check', function(checkbox, value) {
             updateFilters(form);
         });
     },
@@ -349,6 +361,7 @@ var codec_profile_forms = {
             var bit_rate_scale_factor_field = form.findField('bit_rate_scale_factor');
             var qp_field = form.findField('qp');
             var low_power_field = form.findField('low_power');
+            var desired_b_depth_field = form.findField('desired_b_depth');
 
             var platform = platform_field.getValue();
             switch (platform) {
@@ -362,9 +375,12 @@ var codec_profile_forms = {
                     bit_rate_scale_factor_field.setDisabled(false);
                     qp_field.setDisabled(false);
                     low_power_field.setDisabled(false);
+                    desired_b_depth_field.setDisabled(false);
                     break;
                 case 1:
                     // Intel
+                    // low_power is disabling Max B frame
+                    desired_b_depth_field.setDisabled(low_power_field.getValue());
                     var rc_mode = rc_mode_field.getValue();
                     switch (rc_mode) {
                         case -1:
@@ -424,11 +440,14 @@ var codec_profile_forms = {
                     // AMD --> will allow any combination of parameters
                     // I am unable to confirm this platform because I don't have the HW
                     // Is only going to override bf to 0 (as highlited by the previous implementation)
+                    // NOTE: filters to be added later
                     bit_rate_field.setDisabled(false);
                     max_bit_rate_field.setDisabled(false);
                     buff_factor_field.setDisabled(false);
                     bit_rate_scale_factor_field.setDisabled(false);
                     qp_field.setDisabled(false);
+                    low_power_field.setDisabled(false);
+                    desired_b_depth_field.setDisabled(false);
                     break;
                 default:
             }
@@ -436,15 +455,20 @@ var codec_profile_forms = {
 
         var platform_field = form.findField('platform');
         var rc_mode_field = form.findField('rc_mode');
+        var low_power_field = form.findField('low_power');
         // first time we have to call this manually
         updateFilters(form);
         
         // on platform change
-        platform_field.on('select', function(spinner) {
+        platform_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
         // on rc_mode change
-        rc_mode_field.on('select', function(spinner) {
+        rc_mode_field.on('select', function(combo, record, index) {
+            updateFilters(form);
+        });
+        // on low_power change
+        low_power_field.on('check', function(checkbox, value) {
             updateFilters(form);
         });
     },
@@ -531,6 +555,7 @@ var codec_profile_forms = {
                     // AMD --> will allow any combination of parameters
                     // I am unable to confirm this platform because I don't have the HW
                     // Is only going to override bf to 0 (as highlited by the previous implementation)
+                    // NOTE: filters to be added later
                     bit_rate_field.setDisabled(false);
                     max_bit_rate_field.setDisabled(false);
                     buff_factor_field.setDisabled(false);
@@ -547,11 +572,11 @@ var codec_profile_forms = {
         updateFilters(form);
 
         // on platform change
-        platform_field.on('select', function(spinner) {
+        platform_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
         // on rc_mode change
-        rc_mode_field.on('select', function(spinner) {
+        rc_mode_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
     },
@@ -638,6 +663,7 @@ var codec_profile_forms = {
                     // AMD --> will allow any combination of parameters
                     // I am unable to confirm this platform because I don't have the HW
                     // Is only going to override bf to 0 (as highlited by the previous implementation)
+                    // NOTE: filters to be added later
                     bit_rate_field.setDisabled(false);
                     max_bit_rate_field.setDisabled(false);
                     buff_factor_field.setDisabled(false);
@@ -654,11 +680,11 @@ var codec_profile_forms = {
         updateFilters(form);
 
         // on platform change
-        platform_field.on('select', function(spinner) {
+        platform_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
         // on rc_mode change
-        rc_mode_field.on('select', function(spinner) {
+        rc_mode_field.on('select', function(combo, record, index) {
             updateFilters(form);
         });
     }