[UPDATED WITH PARTIAL ANSWER]
Here is my code:
void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) {
// Locking
imageMutex.lock();
videoBuffer = (uint8_t *)malloc(size);
*pp_pixel_buffer = videoBuffer;
}
void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer
, int width, int height, int pixel_pitch, int size, int64_t pts) {
// Unlocking
imageMutex.unlock();
Mat img = Mat(Size(width,height), CV_8UC3, p_pixel_buffer);
//cvtColor(img,img,CV_RGB2BGR);
}
int main(int argc, char ** argv)
{
libvlc_instance_t * inst;
char smem_options[1000];
sprintf(smem_options
, "#transcode{vcodec=RV24}:smem{"
"video-prerender-callback=%lld,"
"video-postrender-callback=%lld,"
"video-data=%lld,"
"no-time-sync},"
, (long long int)(intptr_t)(void*)&cbVideoPrerender
, (long long int)(intptr_t)(void*)&cbVideoPostrender //This would normally be useful data, 100 is just test data
, (long long int)200 //Test data
);
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=1", // Be verbose
"--sout", smem_options // Stream to memory
};
// We launch VLC
inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
...
return 0;
}
QUESTION UPDATED
I checked my two callback functions seem correctly executed.
_What kind of data does RV32 exactly output ? Does it fit the CV_8U3C (unsigned 8bits int 3 channel required here?
_Do I need to add a step to my Mat class ? (step – Number of bytes each matrix row occupies)
UPDATED2
I changed RV32 to RV24 which makes more sense. I add cvtColor cause the Mat matrix seems to need BGR pixel and not RGB but still the image is not display correctly.
_Is there a vcodec which would give me a YUV format as output so I can test the pixel data before trying to output an opencv::Mat img ?
[EDIT OUTPUT IMG] (By changing vlc type to CV_8UC4 four channel (dont know why) we can almost see the frame but in really poor quality why is that ?
[SOLUTION]
I found out that the images at the beginning of my video were of poor quality that's why my Mat imshow() showed me such ugly thing the code above should work now (Apperently no need for cvtColor)
libvlc_video_set_format( mp, "RV24", W,H, W * 3 );
– berak