SMEM:使用 format_callback 时错误的 dst 图像指针
SMEM: Bad dst image pointers when using format_callback
我正在尝试从视频流中获取帧并将它们用作 OpenCV Mat,但我遇到了问题。
我不知道我的视频流的分辨率,所以我使用
libvlc_video_set_format_callbacks
但是,在视频开始播放后,我听到了音频,但我没有得到图像,而是出现了错误:
Bad dst image pointers
。
这是我的代码:
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);
}
如果我不使用 libvlc_video_set_format_callbacks(_player, setup, 0);
而是设置固定参数,例如。 libvlc_video_set_format(_player, "RV24", 720, 404, 720 * 3);
效果很好。知道可能是什么问题吗?
实际上这是一个简单而愚蠢的错误。
行:
chroma = (char *)"RV24";
需要替换为:
memcpy(chroma, "RV24", 4);
我正在尝试从视频流中获取帧并将它们用作 OpenCV Mat,但我遇到了问题。
我不知道我的视频流的分辨率,所以我使用
libvlc_video_set_format_callbacks
但是,在视频开始播放后,我听到了音频,但我没有得到图像,而是出现了错误:
Bad dst image pointers
。
这是我的代码:
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);
}
如果我不使用 libvlc_video_set_format_callbacks(_player, setup, 0);
而是设置固定参数,例如。 libvlc_video_set_format(_player, "RV24", 720, 404, 720 * 3);
效果很好。知道可能是什么问题吗?
实际上这是一个简单而愚蠢的错误。 行:
chroma = (char *)"RV24";
需要替换为:
memcpy(chroma, "RV24", 4);