[vlc-commits] [Git][videolan/vlc][master] 8 commits: codec: jpeg: signal new image encoder capability

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Aug 11 07:11:35 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
d806a17a by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
codec: jpeg: signal new image encoder capability

ImageHandler will use `image encoder`, providing a way to only probe
those when looking for an encoder from src/misc/image.c.

- - - - -
c19b49a3 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
codec: avcodec: signal new image encoder capability

ImageHandler will use `image encoder`, providing a way to only probe
those when looking for an encoder from src/misc/image.c.

- - - - -
73c9ae44 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
codec: png: signal new image encoder capability

ImageHandler will use `image encoder`, providing a way to only probe
those when looking for an encoder from src/misc/image.c.

- - - - -
081d2460 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
codec: vpx: signal new image encoder capability

ImageHandler will use `image encoder`, providing a way to only probe
those when looking for an encoder from src/misc/image.c.

- - - - -
fafa7e08 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
core: add new image encoder capability

Replace the previous capability for encoders like png, jpeg from
`video encoder` into `image encoder`, providing a way to only probe
those when looking for an encoder from src/misc/image.c and clarifying
the capabilities of encoders like avcodec that are able to provide both.

- - - - -
57c673cd by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
lib: picture: refactor available picture format

Use a static stable to map the available libvlc picture format to
vlccore fourcc values, reducing the amount of code needed. Indeed, the
libvlc picture format are limited to the values from the enum, and thus
much simpler to hardcode in an array.

- - - - -
979147c3 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
lib: picture: refactor format validation

Use a separate function to list the picture formats supported by libvlc,
easing the addition of new ones and improving the code readability in
client code.

- - - - -
03ec6533 by Alexandre Janniaux at 2023-08-10T21:34:15+00:00
lib: picture: add support for WebP

WebP has been added as an output format option in the VLC application
from commits ce9d83398e2a0a8a4d40657d30ebd9c79c99a4fa for image and
6e88c7160aa5a1aa7cef38c3f427daee578c42fc for snapshot.

This commit also exposes the API to export WebP images from the libvlc
thumbnailing API.

- - - - -


8 changed files:

- include/vlc/libvlc_picture.h
- lib/picture.c
- modules/codec/avcodec/avcodec.c
- modules/codec/jpeg.c
- modules/codec/png.c
- modules/codec/vpx.c
- src/misc/image.c
- test/src/misc/image.c


Changes:

=====================================
include/vlc/libvlc_picture.h
=====================================
@@ -35,6 +35,7 @@ typedef enum libvlc_picture_type_t
     libvlc_picture_Argb,
     libvlc_picture_Png,
     libvlc_picture_Jpg,
+    libvlc_picture_WebP,
 } libvlc_picture_type_t;
 
 /**


=====================================
lib/picture.c
=====================================
@@ -65,21 +65,15 @@ libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t* input,
     pic->type = type;
     pic->time = libvlc_time_from_vlc_tick( input->date );
     pic->attachment = NULL;
-    vlc_fourcc_t format;
-    switch ( type )
-    {
-        case libvlc_picture_Argb:
-            format = VLC_CODEC_ARGB;
-            break;
-        case libvlc_picture_Jpg:
-            format = VLC_CODEC_JPEG;
-            break;
-        case libvlc_picture_Png:
-            format = VLC_CODEC_PNG;
-            break;
-        default:
-            vlc_assert_unreachable();
-    }
+
+    static const vlc_fourcc_t table[] = {
+        [libvlc_picture_Jpg] = VLC_CODEC_JPEG,
+        [libvlc_picture_Png] = VLC_CODEC_PNG,
+        [libvlc_picture_Argb] = VLC_CODEC_ARGB,
+        [libvlc_picture_WebP] = VLC_CODEC_WEBP,
+    };
+    assert(ARRAY_SIZE(table) > type && table[type] != 0);
+    vlc_fourcc_t format = table[type];
     if ( picture_Export( p_obj, &pic->converted, &pic->fmt,
                          input, format, width, height, crop ) != VLC_SUCCESS )
     {
@@ -100,11 +94,25 @@ static const struct vlc_block_callbacks block_cbs =
     libvlc_picture_block_release,
 };
 
+static bool IsSupportedByLibVLC(vlc_fourcc_t fcc)
+{
+    switch (fcc)
+    {
+        case VLC_CODEC_PNG:
+        case VLC_CODEC_JPEG:
+        case VLC_CODEC_WEBP:
+            return true;
+        default:
+            return false;
+    }
+}
+
 static libvlc_picture_t* libvlc_picture_from_attachment( input_attachment_t* attachment )
 {
     vlc_fourcc_t fcc = image_Mime2Fourcc( attachment->psz_mime );
-    if ( fcc != VLC_CODEC_PNG && fcc != VLC_CODEC_JPEG )
+    if (!IsSupportedByLibVLC(fcc))
         return NULL;
+
     libvlc_picture_t *pic = malloc( sizeof( *pic ) );
     if ( unlikely( pic == NULL ) )
         return NULL;
@@ -127,6 +135,9 @@ static libvlc_picture_t* libvlc_picture_from_attachment( input_attachment_t* att
     case VLC_CODEC_JPEG:
         pic->type = libvlc_picture_Jpg;
         break;
+    case VLC_CODEC_WEBP:
+        pic->type = libvlc_picture_WebP;
+        break;
     default:
         vlc_assert_unreachable();
     }


=====================================
modules/codec/avcodec/avcodec.c
=====================================
@@ -139,6 +139,11 @@ vlc_module_begin ()
     set_capability( "video encoder", 100 )
     set_callback( InitVideoEnc )
 
+    add_submodule()
+    set_description( N_("FFmpeg video encoder") )
+    set_capability( "image encoder", 100 )
+    set_callback( InitVideoEnc )
+
     add_submodule()
     add_shortcut( "ffmpeg" )
     set_section( N_("Encoding") , NULL )


=====================================
modules/codec/jpeg.c
=====================================
@@ -115,15 +115,22 @@ vlc_module_begin()
     set_callbacks(OpenDecoder, CloseDecoder)
     add_shortcut("jpeg")
 
-    /* encoder submodule */
+    /* video encoder submodule */
     add_submodule()
     add_shortcut("jpeg")
     set_section(N_("Encoding"), NULL)
-    set_description(N_("JPEG image encoder"))
+    set_description(N_("JPEG video encoder"))
     set_capability("video encoder", 1000)
     set_callback(OpenEncoder)
     add_integer_with_range(ENC_CFG_PREFIX "quality", 95, 0, 100,
                            ENC_QUALITY_TEXT, ENC_QUALITY_LONGTEXT)
+    /* image encoder submodule */
+    add_submodule()
+    add_shortcut("jpeg")
+    set_section(N_("Encoding"), NULL)
+    set_description(N_("JPEG image encoder"))
+    set_capability("image encoder", 1000)
+    set_callback(OpenEncoder)
 vlc_module_end()
 
 


=====================================
modules/codec/png.c
=====================================
@@ -91,13 +91,21 @@ vlc_module_begin ()
     set_callback( OpenDecoder )
     add_shortcut( "png" )
 
-    /* encoder submodule */
+    /* video encoder submodule */
     add_submodule()
     add_shortcut("png")
     set_section(N_("Encoding"), NULL)
     set_description(N_("PNG video encoder"))
     set_capability("video encoder", 1000)
     set_callback(OpenEncoder)
+
+    /* image encoder submodule */
+    add_submodule()
+    add_shortcut("png")
+    set_section(N_("Encoding"), NULL)
+    set_description(N_("PNG image encoder"))
+    set_capability("image encoder", 1000)
+    set_callback(OpenEncoder)
 vlc_module_end ()
 
 /*****************************************************************************


=====================================
modules/codec/vpx.c
=====================================
@@ -79,6 +79,13 @@ vlc_module_begin ()
     set_capability("video encoder", 60)
     set_description(N_("WebM video encoder"))
     set_callback(OpenEncoder)
+
+    add_submodule()
+    set_shortname("vpx")
+    set_capability("image encoder", 60)
+    set_description(N_("WebP image encoder"))
+    set_callback(OpenEncoder)
+
 #   define ENC_CFG_PREFIX "sout-vpx-"
     add_integer( ENC_CFG_PREFIX "quality-mode", VPX_DL_BEST_QUALITY, QUALITY_MODE_TEXT,
                  QUALITY_MODE_LONGTEXT )


=====================================
src/misc/image.c
=====================================
@@ -753,7 +753,7 @@ static encoder_t *CreateEncoder( vlc_object_t *p_this, const video_format_t *fmt
     p_enc->ops = NULL;
 
     /* Find a suitable decoder module */
-    p_enc->p_module = module_need( p_enc, "video encoder", NULL, false );
+    p_enc->p_module = module_need( p_enc, "image encoder", NULL, false );
     if( !p_enc->p_module )
     {
         msg_Err( p_enc, "no suitable encoder module for fourcc `%4.4s'.\n"


=====================================
test/src/misc/image.c
=====================================
@@ -128,7 +128,7 @@ static int OpenConverter(vlc_object_t *obj)
 /** Inject the mocked modules as a static plugin: **/
 vlc_module_begin()
     set_callback(OpenEncoder)
-    set_capability("video encoder", INT_MAX)
+    set_capability("image encoder", INT_MAX)
 
     add_submodule()
         set_callback(OpenConverter)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4a25b39be3cb2f7477db628be56b391d3f5ebffa...03ec653336026ca7667b5bdb93dbe998965ea85d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4a25b39be3cb2f7477db628be56b391d3f5ebffa...03ec653336026ca7667b5bdb93dbe998965ea85d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list