Page 1 of 1

Extract all frames from video

Posted: 09 May 2013 04:10
by blamond
Hi,

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; }
The mechanism works fine, but it's missing frames.

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

Re: Extract all frames from video

Posted: 09 May 2013 04:19
by blamond
Update:

I just tried it with a .mxf video containing a .mpg 'essence' and the counter recorded all frames (266 this time)

I then tried it again on the same .mpg I used to create the .mxf file and the counter stopped at 262

Frustrating...

Input appreciated!

Re: Extract all frames from video

Posted: 19 May 2013 21:10
by erwan10
Have you checked the logs about frames being dropped ?

The following parameters are enabled by default. Maybe, setting them to disabled will help.

--drop-late-frames, --no-drop-late-frames
Drop late frames (default enabled)
This drops frames that are late (arrive to the video output after
their intended display date). (default enabled)
--skip-frames, --no-skip-frames
Skip frames (default enabled)
Enables framedropping on MPEG2 stream. Framedropping occurs when your
computer is not powerful enough (default enabled)