From patchwork Thu Jan 20 16:05:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33725 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5974127iog; Thu, 20 Jan 2022 08:05:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxU+IgVfFXD0NzHjqiIVrCgNbeiTS4xhju+Md8x1LpQ5G1U9adJ6prQl/KDMbLxUfY3TMo X-Received: by 2002:aa7:cd99:: with SMTP id x25mr37465461edv.249.1642694740716; Thu, 20 Jan 2022 08:05:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642694740; cv=none; d=google.com; s=arc-20160816; b=BItp1xvDd4vqoviNDdB7rilnWxhRCn/eRewFFfZyMVkSsx7irsounMs8BGClB/WM7t PmlNiFXp0nvFLg6GBtQH+uxq4Iq+Gari8xWuHAf9AMz8xLecf9x43A9mnVhp1JLosRXF TZybvVqj6bkDn/mMOgaVXly5NOxZGCLdHzGW3mGaPay3sU1pkxMa8G36nAWLv8eskecz i6NQ6ziTbBVOC2D5jxpUP3eH6mRzicGkD0g/QS/Zm52juZ4IcA1WIQ8+78lBIif/k+ek ZJ6vSFuTtmK4N6v7KmnkkmhNUPvtkPSIjjTxx8cHExcgcEqBARXNkusqKa8yp3OGWdDg ARdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=FN+Gof5djazFSbQEvQdLyADkGpXHT0aQGg5FVtVHllc=; b=DeLqGFZsPenFJv8tNEGqQzeCWC2umkzfGmymxXCCSYPV4mIE9ySsr3MC4zbx4ZlGss Bzpf4EP/VQQVqNa25/RJS/Xo5CEHvUdkvY8D+0MtXaEb9VGoig2JMg1TRRKRxE5CuFja 6KWw5gmtZqOC52vUoTXPdvPTZBPi0fZbWVyfsIdNHtpn6lIaTbYjWIxSh70OTk8kFhIS 7z71D0nJRJ834BkHDWQbTON+q7FxppBhegg/XluM6GqRU3xF7Kiz5Y/BmZsNY67gUP53 bn93le9tN/3bmUbPnbAp+idWrtUbVLprUmSUGtogT4a/RNa4bdDT5DlmBbKH6IfscJ5Z Pcqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dn17si3032339ejc.531.2022.01.20.08.05.40; Thu, 20 Jan 2022 08:05:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 900C168B1D0; Thu, 20 Jan 2022 18:05:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C04068B09E for ; Thu, 20 Jan 2022 18:05:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7515A24017C for ; Thu, 20 Jan 2022 17:05:14 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id J1lZe-NZjRjn for ; Thu, 20 Jan 2022 17:05:12 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id EB307240179 for ; Thu, 20 Jan 2022 17:05:12 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 241F13A067C; Thu, 20 Jan 2022 17:05:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jan 2022 17:05:04 +0100 Message-Id: <20220120160506.32698-1-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/encode: factor audio/video-specific parts out of ff_encode_preinit() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2mbDq07gyXBD --- libavcodec/encode.c | 127 ++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 52 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 618be0573d..6543dda5bd 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -406,15 +406,67 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * return 0; } -int ff_encode_preinit(AVCodecContext *avctx) +static int encode_preinit_video(AVCodecContext *avctx) { + const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); int i; - if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { - av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n"); - return AVERROR(EINVAL); + if (avctx->codec->pix_fmts) { + for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) + if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) + break; + if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) { + char buf[128]; + snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt); + av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n", + (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf)); + return AVERROR(EINVAL); + } + if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || + avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P || + avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P || + avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P || + avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P) + avctx->color_range = AVCOL_RANGE_JPEG; + } + + if ( avctx->bits_per_raw_sample < 0 + || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) { + av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n", + avctx->bits_per_raw_sample, pixdesc->comp[0].depth); + avctx->bits_per_raw_sample = pixdesc->comp[0].depth; + } + if (avctx->width <= 0 || avctx->height <= 0) { + av_log(avctx, AV_LOG_ERROR, "dimensions not set\n"); + return AVERROR(EINVAL); + } + + if (avctx->hw_frames_ctx) { + AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; + if (frames_ctx->format != avctx->pix_fmt) { + av_log(avctx, AV_LOG_ERROR, + "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n"); + return AVERROR(EINVAL); + } + if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE && + avctx->sw_pix_fmt != frames_ctx->sw_format) { + av_log(avctx, AV_LOG_ERROR, + "Mismatching AVCodecContext.sw_pix_fmt (%s) " + "and AVHWFramesContext.sw_format (%s)\n", + av_get_pix_fmt_name(avctx->sw_pix_fmt), + av_get_pix_fmt_name(frames_ctx->sw_format)); + return AVERROR(EINVAL); + } + avctx->sw_pix_fmt = frames_ctx->sw_format; } + return 0; +} + +static int encode_preinit_audio(AVCodecContext *avctx) +{ + int i; + if (avctx->codec->sample_fmts) { for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) @@ -434,24 +486,6 @@ int ff_encode_preinit(AVCodecContext *avctx) return AVERROR(EINVAL); } } - if (avctx->codec->pix_fmts) { - for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) - if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) - break; - if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) { - char buf[128]; - snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt); - av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n", - (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf)); - return AVERROR(EINVAL); - } - if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P) - avctx->color_range = AVCOL_RANGE_JPEG; - } if (avctx->codec->supported_samplerates) { for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) @@ -500,19 +534,26 @@ int ff_encode_preinit(AVCodecContext *avctx) avctx->channels); return AVERROR(EINVAL); } - if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) { - const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); - if ( avctx->bits_per_raw_sample < 0 - || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) { - av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n", - avctx->bits_per_raw_sample, pixdesc->comp[0].depth); - avctx->bits_per_raw_sample = pixdesc->comp[0].depth; - } - if (avctx->width <= 0 || avctx->height <= 0) { - av_log(avctx, AV_LOG_ERROR, "dimensions not set\n"); - return AVERROR(EINVAL); - } + + return 0; +} + +int ff_encode_preinit(AVCodecContext *avctx) +{ + int ret = 0; + + if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { + av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n"); + return AVERROR(EINVAL); } + + switch (avctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: ret = encode_preinit_video(avctx); break; + case AVMEDIA_TYPE_AUDIO: ret = encode_preinit_audio(avctx); break; + } + if (ret < 0) + return ret; + if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO) && avctx->bit_rate>0 && avctx->bit_rate<1000) { av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate); @@ -531,24 +572,6 @@ int ff_encode_preinit(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->hw_frames_ctx) { - AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; - if (frames_ctx->format != avctx->pix_fmt) { - av_log(avctx, AV_LOG_ERROR, - "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n"); - return AVERROR(EINVAL); - } - if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE && - avctx->sw_pix_fmt != frames_ctx->sw_format) { - av_log(avctx, AV_LOG_ERROR, - "Mismatching AVCodecContext.sw_pix_fmt (%s) " - "and AVHWFramesContext.sw_format (%s)\n", - av_get_pix_fmt_name(avctx->sw_pix_fmt), - av_get_pix_fmt_name(frames_ctx->sw_format)); - return AVERROR(EINVAL); - } - avctx->sw_pix_fmt = frames_ctx->sw_format; - } if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; From patchwork Thu Jan 20 16:05:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33724 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5973892iog; Thu, 20 Jan 2022 08:05:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyT3HRtKefob5ht642FlkrJ1tRn/ol4h+M/4DSC25GrQEpGD2GxrMXvo/dUdjdf6cxl0dDO X-Received: by 2002:a17:907:72c5:: with SMTP id du5mr18199840ejc.210.1642694728086; Thu, 20 Jan 2022 08:05:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642694728; cv=none; d=google.com; s=arc-20160816; b=M1FoCBBpPgenL/FeBMviUDdZ1cpvF3VNI+x5jJ9cjTJHK2HxA0+e1s8UkTaCJa8YjG Hfge9EhAg2TMw0x5Sim3ok/UhI8Q9OiInb1Wo7cjglXPfznZHl6bPL8vIoyhiO29gMBT 4DrAO4QgxTGvzKaczTDjSVOGBsPAjOL8oVDKeybUvpAyBUh5nggRvaze7hTzjuB4+r0r sMx1a7Q6Fw2GB1fqvvDBzvRcYG1oFqGY/SyGMQfXWVob/8gZLAjQJDPkvlQCXseoLr8n 2H+cFGxwJxK3jTf4v8w8/IjZ/OeK0V+pYCNjbv+IdEhFMFkdVX1bB0XA/F9aieBvT/yQ pC2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=4oEtUCVkcnKTE5DiPB3vlxsp+Fc6QGYWafbhs25oRDA=; b=g83DPrfGnQjKwPs8RI7N0PBX2quJ08Y42SxHb+MSB+n5jYB1A41gctAD+0DiylWSQ5 UgzMglcg2MkgwXmfj92Z8+GrPNSOPLmJNI+N8dDdF1xa0QXifKpnvH03TcclI+tgob2y 6GQr4HzYuEbzL+T09bLZEgV8GyioVmktGHgA33xklm9jzlgMc1olPFDbirXb3+3CXrmv Bli4UmyInrZXPK1ClEfS7cHbOnkGQbdvpApxHrKW34G8so/PxcN84dMz/WC28hRTJPkV Jaq8fChDYP/unYmcGhEX2GeZZljYcEzrB3iVNhJS5DP+oBsYQSMq92SlAZxiqoi5N83a 2DRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hq6si2611058ejc.42.2022.01.20.08.05.26; Thu, 20 Jan 2022 08:05:28 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 62D3068B1BC; Thu, 20 Jan 2022 18:05:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F5CD68B194 for ; Thu, 20 Jan 2022 18:05:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 43AF02404FE for ; Thu, 20 Jan 2022 17:05:14 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tkxPXhoSgrc0 for ; Thu, 20 Jan 2022 17:05:13 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id F07D524017C for ; Thu, 20 Jan 2022 17:05:12 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 261D73A0631; Thu, 20 Jan 2022 17:05:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jan 2022 17:05:05 +0100 Message-Id: <20220120160506.32698-2-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220120160506.32698-1-anton@khirnov.net> References: <20220120160506.32698-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/encode: reindent X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fv07nac75TNt --- libavcodec/encode.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 6543dda5bd..b6f81d1458 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -408,7 +408,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * static int encode_preinit_video(AVCodecContext *avctx) { - const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); + const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); int i; if (avctx->codec->pix_fmts) { @@ -430,16 +430,16 @@ static int encode_preinit_video(AVCodecContext *avctx) avctx->color_range = AVCOL_RANGE_JPEG; } - if ( avctx->bits_per_raw_sample < 0 - || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) { - av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n", - avctx->bits_per_raw_sample, pixdesc->comp[0].depth); - avctx->bits_per_raw_sample = pixdesc->comp[0].depth; - } - if (avctx->width <= 0 || avctx->height <= 0) { - av_log(avctx, AV_LOG_ERROR, "dimensions not set\n"); - return AVERROR(EINVAL); - } + if ( avctx->bits_per_raw_sample < 0 + || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) { + av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n", + avctx->bits_per_raw_sample, pixdesc->comp[0].depth); + avctx->bits_per_raw_sample = pixdesc->comp[0].depth; + } + if (avctx->width <= 0 || avctx->height <= 0) { + av_log(avctx, AV_LOG_ERROR, "dimensions not set\n"); + return AVERROR(EINVAL); + } if (avctx->hw_frames_ctx) { AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; From patchwork Thu Jan 20 16:05:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5974390iog; Thu, 20 Jan 2022 08:05:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJL1BLMViE5k3RO7/TY+yzuwwAQojJeJ4G6Bbeisb0boU5UT8lHrmfBMgywurRbGr376hj X-Received: by 2002:a50:fe89:: with SMTP id d9mr37068737edt.252.1642694754823; Thu, 20 Jan 2022 08:05:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642694754; cv=none; d=google.com; s=arc-20160816; b=YCNUPKYSUQIx2b0Yrt0wvXo3FUhedkNVwAmOqdSPA9S0CqCbz2TwgjaDnopFR8Z8rX Lc7fX+mS5VzMIqiPvUqEpxtwTFPNAJSkLBn6Ch/2nO9uavSBsZkwNz6s+TJFQ1V9BoGd d4Wo1qbU6UzvcDjnSsoAFFmkMGUX2cLty7g1pX8QrIG1t0gJzUQb1a2SbdL99VZF4s2n xh9Dg2f/0IxIzrZnFc/bKrPO9MjBZXHlbpLCDrYlKKkPhdic//N80BS3KqXGCGKNXGly eOVaToFNgUO41mPSkxqmxUEloOcIOfW9JGWk+EqT7iLnGhhcQXcPYfOmXYGOkW6gsDEU Dxpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=5JJSzstBNHpcgbLIICpj3cRc26O6hLZkRhiOGM96Wpo=; b=WmDIWwpq2gJOSGFrrDu5K6aJU5AnHH+V/gWXrfZwbMVHA8Dj/p9MyewI399MmPrsem B3yHHhIpplihA7ctNwGPilEUINdNF62I7ghM7izqCwA5aIyo7VCzCykX+/gC+iq7/xUZ HbnS9c7blDZ+NRLFY3NHizwwOL4jKcsltwhpcVTA4QAfVaA2zdJ2q1+nRTNHmXcGNRJ6 zbw+xUcjQX5jsayulR8CaQJH5jcbNLmyFE/PoWGuDpyHpRRi8ZKEmDonV5Ruu+GFj7IF T+EN4duG6koOtjcuvL7hlPqnhZ530vpZ4p1J2qwqiuj/yfIeyelmio6Ibvx1Ojx3IjgE MUgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b2si2030244edx.83.2022.01.20.08.05.54; Thu, 20 Jan 2022 08:05:54 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DBC068B1DD; Thu, 20 Jan 2022 18:05:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9200168B19F for ; Thu, 20 Jan 2022 18:05:15 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9D808240179 for ; Thu, 20 Jan 2022 17:05:14 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6zxZvNwuxRqG for ; Thu, 20 Jan 2022 17:05:14 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2AF0124017E for ; Thu, 20 Jan 2022 17:05:13 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2ACE73A0743; Thu, 20 Jan 2022 17:05:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jan 2022 17:05:06 +0100 Message-Id: <20220120160506.32698-3-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220120160506.32698-1-anton@khirnov.net> References: <20220120160506.32698-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/encode: pick a sane default for bits_per_raw_sample if it's not set X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZLqqpur4VxlS Fixes #9563. --- libavcodec/encode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index b6f81d1458..44ab81af3f 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -535,6 +535,9 @@ static int encode_preinit_audio(AVCodecContext *avctx) return AVERROR(EINVAL); } + if (!avctx->bits_per_raw_sample) + avctx->bits_per_raw_sample = 8 * av_get_bytes_per_sample(avctx->sample_fmt); + return 0; }