Sizing a playback buffer to that of a video
Posted: 04 May 2016 00:54
First time user of LibVLC. I have working code that opens a video file from a URL and renders it into a 256 x 256 buffer via an OpenGL texture.
Now I want to optimize it so the buffer is sized to the actual dimensions of the video.
I realize you don't know the size of the video until after it starts playing so currently, I set an arbitrary size for the video at initialization and defer creation of the buffer until my "lock" method is called. I get the video size and set the format like this:
and create a buffer video_width x video_height x 4 in size. However, the video renders incorrectly - the line pitch is wrong and looks like VLC is still using the value I set at initialization.
Is this the right approach and if so, anyone know what I am doing wrong?
If there is a better way to do this, can you please share details.
Code: Select all
unsigned int texture_width = 256;
unsigned int texture height = 256;
unsigned int texture_depth = 4;
libvlc_video_set_callbacks(media_player, lock, unlock, display, &context);
libvlc_video_set_format(media_player, "RV32", texture_width, texture_height, texture_width * texture_depth);
libvlc_media_player_play(media_player);
I realize you don't know the size of the video until after it starts playing so currently, I set an arbitrary size for the video at initialization and defer creation of the buffer until my "lock" method is called. I get the video size and set the format like this:
Code: Select all
static void* lock(void* data, void** p_pixels)
{
...
...
libvlc_video_get_size(context->mp, 0, &video_width, &video_height);
libvlc_video_set_format(context->mp, "RV32", video_width, video_height, video_width * 4);
...
...
Is this the right approach and if so, anyone know what I am doing wrong?
If there is a better way to do this, can you please share details.