在ffmpeg2.81.11和ffmpeg3.0.7上试验。
ffmpeg没有FFERROR_REDO常量定义,但ffmpeg3.0.7上有。 diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
old mode 100644
new mode 100755
index ddf331d..7b4a826
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -79,6 +79,7 @@ struct video_data { int buffers;
volatile int buffers_queued;
+ int buffers_ignore;
void **buf_start;
unsigned int *buf_len;
char *standard;
@@ -519,7 +520,9 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
av_log(ctx, AV_LOG_WARNING,
"Dequeued v4l2 buffer contains corrupted data (%d bytes).\n",
buf.bytesused);
- buf.bytesused = 0;
+ s->buffers_ignore = 8;
+ enqueue_buffer(s, &buf);
+ return FFERROR_REDO;
} else
#endif
{
@@ -529,14 +532,28 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
s->frame_size = buf.bytesused; if (s->frame_size > 0 && buf.bytesused != s->frame_size) {
- av_log(ctx, AV_LOG_ERROR,
+ av_log(ctx, AV_LOG_WARNING,
"Dequeued v4l2 buffer contains %d bytes, but %d were expected. Flags: 0x%08X.\n",
buf.bytesused, s->frame_size, buf.flags);
+ s->buffers_ignore = 8;
enqueue_buffer(s, &buf);
- return AVERROR_INVALIDDATA;
+ return FFERROR_REDO;
}
} +
+ /* if we just encounted some corrupted buffers then we ignore the next few
+ * legitimate buffers because they can arrive at irregular intervals, causing
+ * the timestamps of the input and output streams to be out-of-sync and FFmpeg
+ * to continually emit warnings. */
+ if (s->buffers_ignore) {
+ av_log(ctx, AV_LOG_WARNING,
+ "Ignoring dequeued v4l2 buffer due to earlier corruption.\n");
+ s->buffers_ignore --;
+ enqueue_buffer(s, &buf);
+ return FFERROR_REDO;
+ }
+
/* Image is at s->buff_start[buf.index] */
if (avpriv_atomic_int_get(&s->buffers_queued) == FFMAX(s->buffers / 8, 1)) {
/* when we start getting low on queued buffers, fall back on copying data */
@@ -608,6 +625,7 @@ static int mmap_start(AVFormatContext *ctx)
}
}
s->buffers_queued = s->buffers;
+ s->buffers_ignore = 0; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type) < 0) { 参考自https://patchwork.kernel.org/patch/9324933/

最新文章

  1. 重复安装相同包名APK出现的问题。
  2. android中接口和抽象类的区别
  3. VS2012无法打开文件&ldquo;kernel32.lib&rdquo;问题的解决办法
  4. POJ 3463 有向图求次短路的长度及其方法数
  5. 007医疗项目-模块一:用户的查找:3.用户表查询的Action和Service
  6. .NET概念:.NET程序编译和运行
  7. [Swift 语法点滴]——数组参数
  8. NSSpeechSynthesizer 文字变语音
  9. Lua-C交互函数
  10. HDOJ(HDU) 2156 分数矩阵(嗯、求和)
  11. 《think in python》学习-5
  12. AspectJ给类的属性打桩,进行替换。
  13. codeforces 629D. Babaei and Birthday Cake
  14. sql取指定时间段内的所有月份
  15. 【转】模块(configparser+shutil+logging)
  16. C#常见委托のdelegate定义,Func,Action,Predicate总结
  17. Microsoft Orleans构建高并发、分布式的大型应用程序框架
  18. 金老师的经典著作《一个普通IT人的十年回顾》
  19. headfirst 07
  20. 【多视图几何】TUM 课程 第3章 透视投影

热门文章

  1. 浅谈location对象
  2. poj2262 Goldbach&#39;s Conjecture
  3. 20155201 实验三《Java面向对象程序设计》实验报告
  4. python 计算字典value值的和
  5. 【Docker】Windows下docker环境搭建及解决使用非官方终端时的连接问题
  6. Java 集合-Collections工具类
  7. python学习笔记(日志系统实现)
  8. oracle增加sequence
  9. C primer plus 5 读书笔记2
  10. 几句话概括理查德成熟度模型(RESTful)