Video playback demo based on LIBVLC (VLC SDK)

Source: Internet
Author: User

As a result of the internship program, a recent study of VLC Media player, which originated from an academic project in École Centrale Paris (Central Polytechnic School), was named VIDEOLAN,VLC VideoLAN Client. Later developed into a non-profit organization composed of volunteers to develop and provide free, open source multimedia solutions.

My job is to use the developer tools provided by the player LIBVLC to implement a feature-customized media player that uses the C + + language.

In the process of exploring several blogs, but also refer to the official introduction of the tutorial, so that the code is not a problem. The problem for me is how to configure the development environment for VLC.

After several toss, finally found a feasible solution, the following steps to explain.

Step 0:

Download the latest software installation package on the VLC official website;

Links: http://www.videolan.org/vlc/index.html

Remember the installation directory and locate the SDK folder;

    

Step 1:

Create a new WIN32 console application (I am under Visual Studio 2012);

    

Simple setup

    

Step 2:

In the Project property settings page, add the Include directory;

    

Create a new row containing the directory;

    

Select the Include folder under the SDK folder;

    

Similarly, add the library directory, the path is the Lib folder under the SDK folder, set as follows;

    

Set additional dependencies;

    

Add two library files vlclib.lib, vlclibcore.lib;

    

    

Step 3:

Create a new source file, type the source code;

1#include <windows.h>2#include <vlc/vlc.h>3#include <time.h>4 5 intMainintargcChar*argv[])6 {7libvlc_instance_t * Vlc_ins =NULL;8libvlc_media_player_t * Vlc_player =NULL;9libvlc_media_t * Vlc_media =NULL;Ten  One     Const Char* vlc_args[] = A     { -         "- I.", -         "Dummy", the         "--ignore-config", -         "--extraintf=logger", -         "--verbose=2",  -     };  +  -     //Create a VLC instance +Vlc_ins = Libvlc_new (sizeof(Vlc_args)/sizeof(vlc_args[0]), Vlc_args); A     if(Vlc_ins! =NULL) at     { -         //Create a VLC player -Vlc_player =libvlc_media_player_new (vlc_ins); -         if(Vlc_player! =NULL) -         { -             //Create a media instance from the file path, here is my test file inVlc_media = Libvlc_media_new_path (Vlc_ins,"G:\\123.HLV"); -             if(Vlc_media! =NULL) to             { +                 //Resolving Media instances - Libvlc_media_parse (vlc_media); the                 //gets the playback length of the media file, returning Ms *libvlc_time_t Duration =libvlc_media_get_duration (vlc_media); $ Panax Notoginseng                 //here is the capture media containing multiple video and audio tracks as well as other types of track information -libvlc_media_track_info_t *media_tracks =NULL; the                 intTrackcount = Libvlc_media_get_tracks_info (Vlc_media, &media_tracks); +                 //This is free memory, but I have a problem with the test, and I haven't studied it carefully . A                 //Free (media_tracks); //crash? the  +                 //set the open media file to the player - Libvlc_media_player_set_media (Vlc_player, vlc_media); $  $                 //because it is a Windows system, it is necessary to set an HWND to the player as a window, here directly using the Desktop window, here is only the test - Libvlc_media_player_set_hwnd (Vlc_player,:: GetDesktopWindow ()); -                 //start playing video the Libvlc_media_player_play (vlc_player); - Wuyi                 //This is just to print some information and exit after 20 seconds . thetime_t Last_time =Time (NULL); -                  while((Time (NULL) < (Last_time + $))) Wu                 { -Sleep (Ten); About                     //get current playback position $libvlc_time_t Play_time =Libvlc_media_player_get_time (vlc_player); -printf"playing time:%lld ms\r", (__int64) (play_time)); -  -                     //get the status of media A                     //libvlc_state_t media_state = libvlc_media_get_state (Vlc_media); +                     //printf ("\nmedia State:%d\n", (int) (media_state)); the                 } -                 //Stop $ libvlc_media_player_stop (vlc_player); the                 //Release the libvlc_media_release (vlc_media); the             } the             //Release - libvlc_media_player_release (vlc_player); in         } the         //Release the libvlc_release (vlc_ins); About     } the     return 0; the}

Reference link 1:http://blog.sina.com.cn/s/blog_62a8419a01014eey.html

Reference link 2:http://www.oschina.net/code/snippet_230937_45237

Reference link 3:https://wiki.videolan.org/libvlc_tutorial/

Step 4:

The "core LIBVLC Error:no plugin found" error occurs when you run the code. Also need to manually import VLC plugin folder;

Go to VLC installation path: C:\Program Files (x86) \videolan\vlc\, copy the plugin folder below to the Debug folder of the VS project;

    

It may also be necessary to copy the Libvlc.dll and Libvlccore.dll in the VLC installation directory to the project debug path, such as the basket frame;

At this point, the setup is complete, the project is running, the local video under the specified path can be played normally.

Video playback demo based on LIBVLC (VLC SDK)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.