[PATCH v3 6/9] h264: add hardware encoders

Dietmar Maurer posted 9 patches 8 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[PATCH v3 6/9] h264: add hardware encoders
Posted by Dietmar Maurer 8 months ago
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 ui/vnc-enc-h264.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/ui/vnc-enc-h264.c b/ui/vnc-enc-h264.c
index 0f89cafbf6..840674dbdb 100644
--- a/ui/vnc-enc-h264.c
+++ b/ui/vnc-enc-h264.c
@@ -29,15 +29,17 @@
 
 static char *get_available_encoder(const char *encoder_list)
 {
+    char *ret = NULL;
+    char **encoder_array = NULL;
+
     g_assert(encoder_list != NULL);
 
     if (!strcmp(encoder_list, "")) {
         /* use default list */
-        encoder_list = "x264enc openh264enc";
+        encoder_list = "nvh264enc vaapih264enc x264enc openh264enc";
     }
 
-    char *ret = NULL;
-    char **encoder_array = g_strsplit(encoder_list, " ", -1);
+    encoder_array = g_strsplit(encoder_list, " ", -1);
 
     int i = 0;
     do {
@@ -69,7 +71,19 @@ static GstElement *create_encoder(const char *encoder_name)
         return NULL;
     }
 
-    if (!strcmp(encoder_name, "x264enc")) {
+    if (!strcmp(encoder_name, "nvh264enc")) {
+        g_object_set(
+            encoder,
+            "preset", 8,         /* p1 - fastest */
+            "multi-pass", 1,     /* multipass disabled */
+            "tune", 2,           /* low latency */
+            "zerolatency", true, /* low latency */
+            /* avoid access unit delimiters (Nal Unit Type 9) - not required */
+            "aud", false,
+            NULL);
+    } else if (!strcmp(encoder_name, "vaapih264enc")) {
+        g_object_set(encoder, "tune", 1, NULL); /* high compression */
+    } else if (!strcmp(encoder_name, "x264enc")) {
         g_object_set(
             encoder,
             "tune", 4, /* zerolatency */
-- 
2.39.5
Re: [PATCH v3 6/9] h264: add hardware encoders
Posted by Daniel P. Berrangé 7 months, 4 weeks ago
On Fri, Apr 18, 2025 at 01:29:50PM +0200, Dietmar Maurer wrote:

....could at lesat explain what the chosen encoders are..

> Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
> ---
>  ui/vnc-enc-h264.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/ui/vnc-enc-h264.c b/ui/vnc-enc-h264.c
> index 0f89cafbf6..840674dbdb 100644
> --- a/ui/vnc-enc-h264.c
> +++ b/ui/vnc-enc-h264.c
> @@ -29,15 +29,17 @@
>  
>  static char *get_available_encoder(const char *encoder_list)
>  {
> +    char *ret = NULL;
> +    char **encoder_array = NULL;
> +
>      g_assert(encoder_list != NULL);
>  
>      if (!strcmp(encoder_list, "")) {
>          /* use default list */
> -        encoder_list = "x264enc openh264enc";
> +        encoder_list = "nvh264enc vaapih264enc x264enc openh264enc";
>      }
>  
> -    char *ret = NULL;
> -    char **encoder_array = g_strsplit(encoder_list, " ", -1);
> +    encoder_array = g_strsplit(encoder_list, " ", -1);
>  
>      int i = 0;
>      do {
> @@ -69,7 +71,19 @@ static GstElement *create_encoder(const char *encoder_name)
>          return NULL;
>      }
>  
> -    if (!strcmp(encoder_name, "x264enc")) {
> +    if (!strcmp(encoder_name, "nvh264enc")) {
> +        g_object_set(
> +            encoder,
> +            "preset", 8,         /* p1 - fastest */
> +            "multi-pass", 1,     /* multipass disabled */
> +            "tune", 2,           /* low latency */
> +            "zerolatency", true, /* low latency */
> +            /* avoid access unit delimiters (Nal Unit Type 9) - not required */
> +            "aud", false,
> +            NULL);
> +    } else if (!strcmp(encoder_name, "vaapih264enc")) {
> +        g_object_set(encoder, "tune", 1, NULL); /* high compression */
> +    } else if (!strcmp(encoder_name, "x264enc")) {
>          g_object_set(
>              encoder,
>              "tune", 4, /* zerolatency */

Feels like this patch could jsut be folded into patch 4 that first
introduces this method.

> -- 
> 2.39.5
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|