w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Playing a multi-track file/stream using libvlc (ubuntu)

Can you be more specific about what you're trying to do ?

The code in the question does not compile, cannot enumerate tracks in any stream. Below are the minimal changes for that code to become meaningful.

#include <vlc/vlc.h>
#include <unistd.h>
#include <stdlib.h>

int main( int argc, char **argv )
{
    libvlc_instance_t *inst;
    libvlc_media_player_t *mp;
    libvlc_media_t *m;

    if ( argc < 2 )
    {
        fprintf( stderr, "Please provide a file name to open.
" );
        exit( 1 );
    }

    inst = libvlc_new( 0, NULL );
    m = libvlc_media_new_path( inst, argv[1] );
    mp = libvlc_media_player_new_from_media( m );
    libvlc_media_release( m );
    libvlc_media_player_play( mp );

    sleep( 1 );

    libvlc_track_description_t *track_desc =
libvlc_video_get_track_description( mp );
    int numberOfTracks = libvlc_video_get_track_count( mp );

    fprintf( stderr, "numberOfTracks=%d
", numberOfTracks );

    while ( track_desc != NULL )
    {
        int id = track_desc->i_id;

        if ( id == -1 )
        {
            fprintf( stderr, "Not switching to pseudo-track id=%d name=%s
", id, track_desc->psz_name );
        }
        else
        {
            fprintf( stderr, "Switching to video track id=%d name=%s
", id, track_desc->psz_name );
            libvlc_video_set_track( mp, id );
        }

        sleep( 1 );
        track_desc = track_desc->p_next;
    }

    fprintf( stderr, "Finished enumerating tracks. Waiting a little.
" );

    sleep( 10 );

    libvlc_media_player_stop( mp );
    libvlc_media_player_release( mp );
    libvlc_release( inst );


    return 0;
}

Again, can you be more specific about what you're trying to do ?





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.