使用libvlc播放多轨文件/流(ubuntu)

时间:2013-07-03 15:30:34

标签: c vlc libvlc

我使用的是最新的vlc版本,只要您可以同时在同一窗口或多个窗口中查看它们并不重要。

这就是我的尝试:

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

    inst = libvlc_new(0, NULL);
    m = libvlc_media_new_path(inst, "/tmp/mpt-smart-travels-classical-clip.ts");
    mp = libvlc_media_player_new_from_media(m);
    libvlc_media_release(m);
    libvlc_media_player_play(mp);


    libvlc_track_description_t *videoIDs = libvlc_video_get_track_description(mp); 
    int numberOfTracks = sizeof videoIDs;
    int count = 0;
    int id;
    while (count <= numberOfTracks) {
      id = videoIDs[count];
      libvlc_video_set_track(mp,id);
      count += 1;
      }

    sleep(10);

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


    return 0;
}
  

$ gcc $(pkg-config --cflags libvlc)-c test.c -o test.o

     

$ gcc test.o -o test $(pkg-config --libs libvlc)

一个名为&#39; p_next&#39;的指针可能需要用于获取下一个流的ID。 videolan.org/developers/vlc/doc/doxyge/html/structlibvlc_ 轨道 _description__t.html

1 个答案:

答案 0 :(得分:0)

你能更具体地了解你正在尝试做什么吗?

问题中的代码无法编译,无法枚举任何流中的曲目。 以下是该代码变得有意义的最小变化。

#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.\n" );
        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\n", 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\n", id, track_desc->psz_name );
        }
        else
        {
            fprintf( stderr, "Switching to video track id=%d name=%s\n", 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.\n" );

    sleep( 10 );

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


    return 0;
}

同样,您可以更具体地了解您尝试做什么吗?