【问题标题】:Too small ffmpeg rtsp decoding bufferffmpeg rtsp 解码缓冲区太小
【发布时间】:2013-01-13 15:36:56
【问题描述】:

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

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

#define UDP_TX_BUF_SIZE 327680
#define UDP_MAX_PKT_SIZE 655360

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

【问题讨论】:

标签: android ffmpeg streaming rtsp


【解决方案1】:

对于我的问题 (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;
};

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

【讨论】:

  • 非常感谢。我将其标记为已回答,但我更希望在 ffmpeg 中进行修复。
  • 我记得我花了很多时间寻找与您提到的类似的 libav/ffmpeg 修复程序,但最终没有任何效果。如果您有能力使用源代码,我建议您使用数据包大小来查看是否有任何东西。
  • 您可以使用live555库接收rtsp数据包然后将其传递给ffmpeg,它对rtsp的支持比ffmpeg好得多
  • 这是很好的反馈。谢谢。它可能解释了为什么 mplayer 给出了清晰的输出 - 我在 mplayer 的日志中看到 555。
  • 其实我刚刚发现VLC也是用Live555的!
猜你喜欢
  • 2015-05-18
  • 2018-06-27
  • 1970-01-01
  • 2016-09-22
  • 1970-01-01
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多