From patchwork Sun Nov 10 19:42:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 16197 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 71B804478B5 for ; Sun, 10 Nov 2019 21:48:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F43368AB1E; Sun, 10 Nov 2019 21:48:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC0C068A877 for ; Sun, 10 Nov 2019 21:48:26 +0200 (EET) Received: by mail-qt1-f193.google.com with SMTP id o3so13330106qtj.8 for ; Sun, 10 Nov 2019 11:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4OJzEDoJWtIbF1PtoLuj+wWu15C6J/YTXT7vUirdJlg=; b=lKmBYRelI7PUXn1x6dxk9Picw+HV2V6XjfEY1aBgevnZ5P4yX/FZ4xSUB6RHQPRicU smefpVc3HZM/8EvjkjwreewKs8U4J8tYneFz9C2dhKTOmjjk0Uwshq9JfQnU/3cr3fAt o4/3YI1QcWWnWvknvXfMe8Prj8O5xw8KzzNQ836BFhkrw8oE9tcwFrTpHXeOiM2UVh2n hG9OjW4SQOb/mP2xDcoVTMPm0zFoZ4674UOn+AVFlKpNQQYL82VRp+MgkRKSHm/JYtEp lDc0GxvkW8F6u2hzIn4DxwCmvztwPF9vTw5M+wmywNkIzqJZtdhHreanq2SxLDmAVlhW N6YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4OJzEDoJWtIbF1PtoLuj+wWu15C6J/YTXT7vUirdJlg=; b=NhwEwfbjvBzcMQkwlJ9z/tHp88DULqfyNgdWY+vRhsheTKmtvZO9aPWwJjiAjyIBUg GUmMaMGqhPBgQgbrmgEEDn096vSwyDlxuvOTHvr84qCg/mK1hDbRxxF7Ge257h9c7lXc HHj+KJ7GAzBPbWU+7/6lNNvbzMXFtnPw2tUcYoUsbrsLCkpM3gvGTz91poT3/PG/Q5S1 CcRC3MLqIXALlUsD+QoMMXrBYMybRGjYV4tLQEpwfqBuDV/qKS7C7uthLTg4Sf6UPgUd r6FOboC9MoqawotEtjN0K2WVrt1I1sIjlwilTEuFOI/hs6oreQ2yeTNlRdUEuTu3nVy4 bSWw== X-Gm-Message-State: APjAAAVyYW0uyo1zAeHE+gV2tGsh3wSybR61UFlDp1xLb5TxewcjrQtu C+SYpwc/fbxkBSNlgQmGsaFDGOni X-Google-Smtp-Source: APXvYqzKyJlXtjNR+Ab3DsGmez6wTlBu0r5MJdA1clGYwEb+LrG8U7RDLTaTrylv2Px0+WDx8XWqGg== X-Received: by 2002:ac8:293a:: with SMTP id y55mr23019783qty.118.1573414951176; Sun, 10 Nov 2019 11:42:31 -0800 (PST) Received: from localhost.localdomain (c-71-232-27-28.hsd1.ma.comcast.net. [71.232.27.28]) by smtp.gmail.com with ESMTPSA id d39sm6838083qtc.23.2019.11.10.11.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 11:42:30 -0800 (PST) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Nov 2019 14:42:10 -0500 Message-Id: <20191110194210.18010-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/v4l2_m2m_enc: Check encoder pix_fmt matches pix_fmt on device X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Fixes #8079 During initialization of a v4l2m2m device, the configured pix_fmt can be different to the pix_fmt of the encoder (i.e. avctx->pix_fmt). For example on the Odroid XU4: ./ffmpeg -f lavfi -i yuvtestsrc -codec:v h264_v4l2m2m out.h264 will configure the v4l2 encoder to pix_fmt nv21, whereas the input frames will be yuv444p. This commit checks that the configured v4l2 pix_fmt on device is the same as avctx->pix_fmt. If they are different it returns an error and suggests a cli input that will fix the problem. This has been tested on RPI4 and Odroid XU4. Signed-off-by: Andriy Gelman --- libavcodec/v4l2_m2m_enc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index 474e6bef89..5c8d49bd2c 100644 --- a/libavcodec/v4l2_m2m_enc.c +++ b/libavcodec/v4l2_m2m_enc.c @@ -30,6 +30,7 @@ #include "libavutil/opt.h" #include "v4l2_context.h" #include "v4l2_m2m.h" +#include "v4l2_fmt.h" #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x @@ -288,6 +289,8 @@ static av_cold int v4l2_encode_init(AVCodecContext *avctx) V4L2Context *capture, *output; V4L2m2mContext *s; V4L2m2mPriv *priv = avctx->priv_data; + enum AVPixelFormat pix_fmt_output; + uint32_t v4l2_fmt_output; int ret; ret = ff_v4l2_m2m_create_context(priv, &s); @@ -316,6 +319,22 @@ static av_cold int v4l2_encode_init(AVCodecContext *avctx) } s->avctx = avctx; + if (V4L2_TYPE_IS_MULTIPLANAR(output->type)) + v4l2_fmt_output = output->format.fmt.pix_mp.pixelformat; + else + v4l2_fmt_output = output->format.fmt.pix.pixelformat; + + /* check configured pix_fmt matches avctx->pix_fmt */ + pix_fmt_output = ff_v4l2_format_v4l2_to_avfmt(v4l2_fmt_output, AV_CODEC_ID_RAWVIDEO); + if (pix_fmt_output != avctx->pix_fmt) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt_output); + av_log(priv, AV_LOG_ERROR, "Pixel format not configured. Encoder requires %s " + " pixel format. On command line add setting:" + " -pix_fmt %s to force correct pixel format.\n", + av_fourcc2str(v4l2_fmt_output), desc->name); + return AVERROR(EINVAL); + } + return v4l2_prepare_encoder(s); }