Skip to content
systemcoding.dev
Media

Create an instance with libvlc_new

Create a libVLC 3.0 engine instance with libvlc_new, check for NULL when plugins are missing, and print the version it loaded.

1 min read
Summarize in AI

Every libVLC 3.0 program starts with an instance, the object that loads the plugins and owns the configuration. libvlc_new(argc, argv) returns NULL if it cannot find them, so check it before anything else.

vlc_new.cc
#include <stdio.h>
#include <vlc/vlc.h>

int main(void) {
    libvlc_instance_t *vlc = libvlc_new(0, NULL);
    if (!vlc) {
        fprintf(stderr, "libvlc_new failed\n");
        return 1;
    }
    printf("libVLC %s\n", libvlc_get_version());
    libvlc_release(vlc);
    return 0;
}
Text
libVLC 3.0.21 Vetinari

Build with gcc vlc_new.c -lvlc. The version string depends on the installed VLC. libvlc_get_version reports the library you linked at run time, which can differ from the headers you compiled against, so print it when a bug only shows on one machine.

The usual cause of a NULL return is a missing plugin directory: a relocated install or a container image that ships libvlc.so without libvlccore and the plugins. Setting VLC_PLUGIN_PATH to the plugin folder fixes that without rebuilding. Create one instance and share it; each instance scans the plugin cache and starts its own threads. Release it only after every media and player created from it has been released.

Taggedclibvlc
Share

More snippets

Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.