0%

VLC SDK

Recently I am searching for an easy-to-use library of media framework that can be embedded to my own codes. First I have tried ffmpeg and SDL2 libraries, which I found too difficult for me since I have little experience of developing multimedia related applications. Then I found VLC media player after I searched the internet using a key word of “media player library”. I thought maybe it was a good choice and searched related projects in github. There is a very simple demo project called Controlling VLC media player using OpenCV. I was extracted by the word “OpenCV” because I am an engineer in computer vision. After I clicked the link, BINGO! THAT’S ALL I NEED!

Install libvlc

  1. A simple command is used to install libvlc sudo apt-get install libvlc-dev.
  2. One may need to install vlc media player to get the plugins work sudo apt-get install vlc.

Use libvlc

The following code is a simple demo of how to use libvlc to play a video

#include <vlc/vlc.h>
// LibVLC requirements, plays video specified as a command line argument
libvlc_instance_t *instance = libvlc_new(0, NULL);
libvlc_media_t *media = libvlc_media_new_path(instance, argv[1]);    
libvlc_media_player_t *mplayer = libvlc_media_player_new_from_media(media);

while(1)
{
    //something to do while playing video
    //...
}

libvlc_media_release(media);
libvlc_release(instance);

The libvlc will handle the multimedia thread. All we need to do is controlling the player in main thread. More document can be found here.