I am trying to use libvlc_video_set_callbacks to extract all frames to a custom memory buffer. I am finding that I cannot get all the frames. I know my video has 75 frames (I made the video, and I can use FFmpeg to extract all 75 frames), but I can only ever get 72 frames out with libvlc. I wrote a barebones app to just simply count every time there is a callback made and do nothing else, and the counter gets to 72 and stops. Here's the code:
Code: Select all
#include <vlc/vlc.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
static int frameCount = 1;
char* buf = NULL;
static void* lock(void* userData, void** p_pixels) {
char* buffer = (char* )userData;
*p_pixels = buffer;
cout << "lock no: " << frameCount << endl;
return NULL;
}
static void unlock(void* userData, void* picture, void *const * p_pixels) {
cout << "unlock no: " << frameCount++ << endl;
}
int main(int argc, char *argv[])
{
string fname("path/to/my/movie.mov");
libvlc_instance_t* vlcInstance=libvlc_new(0, NULL);
libvlc_media_t* media = libvlc_media_new_path(vlcInstance, fname.c_str());
libvlc_media_player_t* mediaPlayer = libvlc_media_player_new_from_media(media);
libvlc_media_release(media);
int wd = 2096, ht = 1132;
buf = new char[wd*ht*4];
libvlc_video_set_callbacks(mediaPlayer, lock, unlock, NULL, buf);
libvlc_video_set_format(mediaPlayer, "RV32", wd, ht, 4*wd);
libvlc_media_player_play (mediaPlayer);
while (true) {
;
}
return 0;
}
Anyone got any input on why this might be/what I'm doing wrong/alternatives (apart from just using FFmpeg's 'image2' pipe mechanism)?
Thanks,
Bruce