Page 1 of 1

how to get video size?

Posted: 15 Dec 2011 01:23
by mirswith
I am trying to get the size of a video but everything I have tried does not seem to work. Here is what I am trying (after lots of forum browsing and google searches).

I am listening for the events libvlc_MediaParsedChanged and libvlc_MediaMetaChanged (trying both for now until I can get this). Inside the events I am trying two approaches to get the size, the first is:

Code: Select all

libvlc_media_track_info_t * tracks = NULL; libvlc_media_get_tracks_info(media, &tracks); if( tracks ) { int width = tracks->u.video.i_width; int height = tracks->u.video.i_height; print( "%d x %d", width, height); free(tracks); } else { print("tracks is NULL"); <-- this is what happens. }
The second approach is this:

Code: Select all

libvlc_video_get_size(player, 0, &width, &height); print("%d x %d", width, height); <-- "0 x 0" is what gets printed
I looked through the source and it looks like libvlc_video_get_size is setup to always fail with a #if 0. Even if that was enabled it appears to be getting the window size and not the native video dimensions (is what I need).

For some background I am trying to get the video size so that I can create my OpenGL textures to the appropriate size for the video to be rendered into as opposed to having libvlc scale the video (which I am trying to avoid).

Thanks.

Re: how to get video size?

Posted: 15 Dec 2011 03:22
by Jean-Baptiste Kempf
Did you play before getting the infos?

Re: how to get video size?

Posted: 15 Dec 2011 04:42
by mirswith
Do you mean by calling libvlc_media_player_play? Yah, I have tried that.. I've tried getting the size in the libvlc_MediaPlayerTimeChanged event just to see if I ever received anything valid; never do.

I am wondering if it is because I am setting callbacks with libvlc_video_set_callbacks. All the examples I see that use that send in a pre-determined video size but as mentioned before I want to render the native video size to a texture and to do that I need to know what the actual size is to create my textures with.

Re: how to get video size?

Posted: 15 Dec 2011 07:52
by Rémi Denis-Courmont
The native size is passed to the callback. That is the only correct glitch-free and race-free way to adjust display video in its native resolution.

Re: how to get video size?

Posted: 15 Dec 2011 08:51
by mirswith
Which callback? I noticed there is libvlc_video_set_format_callbacks which looks like what i need however there are two problems with it. 1) it does not accept a void * user data parameter and 2) I get a linking error if I try to use it. I am using the headers from the latest source tree and built a .lib from the 1.1.11 binaries.

Re: how to get video size?

Posted: 15 Dec 2011 12:32
by Rémi Denis-Courmont
set_format_callbacks uses the same opaque pointer as set_callbacks. That's why...

Re: how to get video size?

Posted: 15 Dec 2011 19:11
by mirswith
Is there a solution to use this callback?

Re: how to get video size?

Posted: 15 Dec 2011 21:29
by Rémi Denis-Courmont
Yeah, libvlc 1.2.

Re: how to get video size?

Posted: 15 Dec 2011 21:50
by mirswith
:) ok, i'll check it out. Thanks.

Re: how to get video size?

Posted: 08 Jan 2012 19:49
by Monty811
Hi there,

i have tried to use the "libvlc_video_set_format_callbacks" with VLC 1.2 because I would like to achieve the same with VLC; get the original video size to be able to create a 3D texture with the same (original) size as the video. Then any resizing will be moved from VLC to the graphics card which should be faster...
My problem is that I would only like to get the original size without modifying something. From the documentation I do understand that I also have to pass parameters back to the function but whatever I try it seems to fail and result in an exception (I use the nigthly build for windows, but debugging into it does not work right now...).
My understanding of the parameters of the function is:

Code: Select all

static unsigned formatCallback (void **opaque, char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines) { VLC_InputBase::kVideoBuffer* pVideoBuffer = (VLC_InputBase::kVideoBuffer*) (*opaque); unsigned nWidth = (*width); unsigned nHeight = (*height); (*pitches) = nWidth * 4; (*lines) = nHeight; return 1; }
What am I doing wrong :D ?

Thanks for any help,

Ben

Re: how to get video size?

Posted: 08 Jan 2012 21:51
by Rémi Denis-Courmont
You're not using the chroma parameter. This cannot be correct.