ffmpeg rtsp解码缓冲区太小

时间:2013-01-29 22:51:07

标签: android ffmpeg streaming rtsp

我正在使用ffmpeg在Android上解码rtsp,当图像快速更新或以高分辨率更新时,我会很快看到像素化:

working decoded frame

non working decoded frame

谷歌搜索后,我发现它可能与UDP缓冲区大小有关。然后我在ffmpeg / libavformat / udp.c中使用以下参数重新编译了ffmpeg库

#define UDP_TX_BUF_SIZE 327680
#define UDP_MAX_PKT_SIZE 655360

似乎有所改善,但在某些时候它仍然开始失败。我知道应该增加哪个缓冲区以及如何增加?

1 个答案:

答案 0 :(得分:0)

对于我的问题(http://libav-users.943685.n4.nabble.com/UDP-Stream-Read-Pixelation-Macroblock-Corruption-td4655270.html),我试图从其他人设置的多播UDP流中捕获。因为我没有能力搞乱源代码,所以我最终从使用libav切换到使用libvlc作为包装器,它完美地工作。以下是对我有用的摘要:

stream.h:

#include <vlc/vlc.h>
#include <vlc/libvlc.h>

struct ctx {
   uchar* frame;
};

stream.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);
}

main.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);