How to read multiple video tracks in memory ?

This forum is about all development around libVLC.
jacques.vlc
New Cone
New Cone
Posts: 2
Joined: 21 May 2015 12:02

How to read multiple video tracks in memory ?

Postby jacques.vlc » 21 May 2015 12:44

Hello, i'm using libvlc 2.0.8 on Ubuntu and I'm trying to read a file with 2 video tracks. The goal is to recompose the frame from track 1 with the frame from track 2.

Right now I'm able to select which track to read with libvlc_video_set_track and save frames in memory by setting my own callbacks with libvlc_video_set_callbacks

My question is how can I read both tracks at the same time ?

Do I have to set different callbacks for each track or are they handled by one callback ? I tried both cases without success.

1. Different callbacks for each track (pseudo code):

Code: Select all

libvlc_video_set_track(0) libvlc_video_set_callbacks(lock_cb0, display_cb_0, unlock_cb0) libvlc_video_set_track(1) libvlc_video_set_callbacks(lock_cb1, display_cb_1, unlock_cb1)
It seems like only the last set of callbacks are taken into account.

2. One set of callbacks for both tracks (pseudo code):

Code: Select all

display_cb(void *opaque, void *picture) { print libvlc_video_get_track() // always returns the same track id. myfifo.push(picture) }
Although libvlc_video_get_track always returns the same track id, the frames stored in myfifo are actually from track 1 and 2. So how can I know exactly where the decoded frame came from ?

Any help is appreciated, thanks !

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: How to read multiple video tracks in memory ?

Postby Rémi Denis-Courmont » 21 May 2015 13:11

1. The whole point of selecting a track is to play only that track. Don't do that.
2. You have to use the format (setup) callback if you need to match buffers from the same output. Outputs and buffers are not directly mapped to tracks.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

jacques.vlc
New Cone
New Cone
Posts: 2
Joined: 21 May 2015 12:02

Re: How to read multiple video tracks in memory ?

Postby jacques.vlc » 21 May 2015 21:06

Thanks for the help !

So If I understand correctly I should define a callback like this ?

Code: Select all

unsigned my_setup_cb(void **opaque, char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines) { int track_id = libvlc_video_format_cb_get_track_id(opaque); // Returns the track ID of the current decoded frame ? if( track_id == 0 ) do_something(); else do_something_else(); ... }
libvlc_video_format_cb_get_track_id is not defined in my version of libvlc but I found that info here : http://vlc-devel.videolan.narkive.com/J ... p-callback
So I may have to update my libvlc.

Then call libvlc_video_set_format_callbacks instead of libvlc_video_set_format

Is that correct ?
By the way, I don't really know what should opaque be ?
opaque : pointer to the private pointer passed to libvlc_video_set_callbacks() [IN/OUT]

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: How to read multiple video tracks in memory ?

Postby Rémi Denis-Courmont » 21 May 2015 22:03

Again, if you want to map lock, unlock and display callbacks to a given video output instance, then you need the setup callback. There exists no mappings between track ID and output instance, for various reasons.

The first parameter to setup is a pointer to a void pointer. The initial void pointer value is that which you passed to libvlc_video_set_callbacks(), but you can change it so that each output has its own private data.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 41 guests