对于我的问题(http://libav-users.943685.n4.nabble.com/UDP-Stream-Read-Pixelation-Macroblock-Corruption-td4655270.html http://libav-users.943685.n4.nabble.com/UDP-Stream-Read-Pixelation-Macroblock-Corruption-td4655270.html),我试图从其他人设置的多播 UDP 流中捕获。因为我没有能力弄乱源代码,所以我最终从使用 libav 切换到使用 libvlc 作为包装器,并且它工作得很好。以下是对我有用的总结:
流.h:
#include <vlc/vlc.h>
#include <vlc/libvlc.h>
struct ctx {
uchar* frame;
};
流.cpp:
void* lock(void* data, void** p_pixels){
struct ctx* ctx = (struct ctx*)data;
*p_pixels = ctx->frame;
return NULL;
}
void unlock(void* data, void* id, void* const* p_pixels){
struct ctx* ctx = (struct ctx*)data;
uchar* pixels = (uchar*)*p_pixels;
assert(id == NULL);
}
主要.cpp:
struct ctx* context = (struct ctx*)malloc(sizeof(*context));
const char* const vlc_args[] = {"-vvv",
"-q",
"--no-audio"};
libvlc_media_t* media = NULL;
libvlc_media_player_t* media_player = NULL;
libvlc_instance_t* instance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
media = libvlc_media_new_location(instance, "udp://@123.123.123.123:1000");
media_player = libvlc_media_player_new(instance);
libvlc_media_player_set_media(media_player, media);
libvlc_media_release(media);
context->frame = new uchar[height * width * 3];
libvlc_video_set_callbacks(media_player, lock, unlock, NULL, context);
libvlc_video_set_format(media_player, "RV24", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 3);
libvlc_media_player_play(media_player);