Page 1 of 1

Using Video callbacks - "Bad dst image pointers"

Posted: 15 Mar 2016 11:24
by pablocoo
I'm trying to get frames from video stream and use them as OpenCV Mat, but I have encountered a problem. I don't know the resolution my video stream will have so I use

Code: Select all

libvlc_video_set_format_callbacks
but then, after video starts playing, I hear audio, but I'm not getting an image, instead I get errors: Bad dst image pointers. Here's my code:

Code: Select all

struct ctx { unsigned char *pixeldata; std::mutex imagemutex; }; static void *lock(void *data, void **p_pixels) { struct ctx *ctx = reinterpret_cast<struct ctx *>(data); ctx->imagemutex.lock(); *p_pixels = ctx->pixeldata; return NULL; } static void unlock(void *data, void *id, void *const *p_pixels) { struct ctx *ctx = reinterpret_cast<struct ctx *>(data); ctx->imagemutex.unlock(); assert(id == NULL); } unsigned setup(void **opaque, char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines) { struct ctx *callback = reinterpret_cast<struct ctx *>(*opaque); unsigned nWidth = (*width); unsigned nHeight = (*height); (*pitches) = nWidth * 3; (*lines) = nHeight; chroma = (char *)"RV24"; callback->pixeldata = new unsigned char[nWidth*nHeight*3]; return 1; } int main(int argc, char *argv[]) { libvlc_instance_t *vlcInstance; libvlc_media_player_t *_player; libvlc_media_t *_media; 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=2", // Be much more verbose then normal for debugging purpose }; vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); _media = libvlc_media_new_location(vlcInstance , "rtsp://address"); _player = libvlc_media_player_new_from_media(_media); struct ctx *callback = new struct ctx; libvlc_video_set_callbacks(_player, lock, unlock, 0, callback); libvlc_video_set_format_callbacks(_player, setup, 0); libvlc_media_player_play(_player); }
If I won't use

Code: Select all

libvlc_video_set_format_callbacks(_player, setup, 0);
but instead set fixed parameters, eg.

Code: Select all

libvlc_video_set_format(_player, "RV24", 720, 404, 720 * 3);
it works fine. Any idea what might be a problem?

Re: Using Video callbacks - "Bad dst image pointers"

Posted: 15 Mar 2016 12:08
by pablocoo
Wellness IT was a stupid mistake, but I finally managed to fix IT. Instead of:

Code: Select all

chroma = (char *)"RV24";
It has to be:

Code: Select all

char* code = "RV24"; memcpy(chroma, code, 4);
Anyway, I have one more questions. Is there a way to improve stream performance? It is fluid but it uses quite a lot of CPU power. Can I set fps or anything? Not procesu every single frame (which I don't really need?

Oh and I get warnings that plane 0 is not aligned. Can I do something about it?

Re: Using Video callbacks - "Bad dst image pointers"

Posted: 15 Mar 2016 18:09
by RĂ©mi Denis-Courmont
To get better performance, don't change the resolution, and don't change the chroma.