zoukankan      html  css  js  c++  java
  • ffmpeg采集帧出错不退出的补丁

    在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). ", 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. ", 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. "); + 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/
  • 相关阅读:
    部署phpmyadmin登录不进去
    无法获取快照信息:锁定文件失败
    nginx: [emerg] BIO_new_file("/etc/nginx/ssl_key/server.crt") failed (SSL: error:02001002:syste
    nginx重启失败
    An error occurred (500 Error)
    Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
    clnt_create: RPC: Program not registered
    [error] 2230#2230: *84 client intended to send too large body: 1711341 bytes
    lnmp部署知乎出现403
    easyui下拉框过滤优化
  • 原文地址:https://www.cnblogs.com/xihong2014/p/6723917.html
Copyright © 2011-2022 走看看