From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C28BF47403 for ; Wed, 6 Mar 2024 11:08:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CC24868CF38; Wed, 6 Mar 2024 13:05:47 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F7DB68CD22 for ; Wed, 6 Mar 2024 13:05:31 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=IYS70mka; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 70B3D4D41 for ; Wed, 6 Mar 2024 12:05:31 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id sQ2IZTLYpe4v for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=nmJfqXiAPaANJ7kce0Q2AYiK/2K5u0B0MNYeKfo5FHI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IYS70mkaw/ZxUOARHgofVyvEo3bEoe64qwjAQSQMzmQ3zBMIZjL6gZrbJ+MedTUo9 kJBDpkfCiCFml0YGfZ6tRcUhRwmawzYMQP/6nlJUWLhkTiiJqsf0AWfTd9i1hTbQtb +VNeQVasTMgXuZHo8Jitac4gaQ8z91tD+QTiP7vQSGUK9QJzcGxnqXbG+rerNwrfbT ghL6sKnzkyrP1OCfwiROdhcEt3pkCK9cpE+GvJ5KuqZFCcPn+6kWU9BxpMLJAAHCst pKvNAB2RwNn0nBu+XaXdqtzr/6YMK/3lWD4aA9TMsiRfWloQ7uick/Ly47wTP/GUUW j4Wt3Vx/d0Z5Q== 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 mail1.khirnov.net (Postfix) with ESMTPS id 179654D5C for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0B5763A076E for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:13 +0100 Message-ID: <20240306110319.17339-12-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/18] fftools/ffmpeg_enc: merge do_{audio, video}_out into frame_encode() 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: These functions used to be much longer, but now they are only a couple lines each, some of them duplicated between audio and video. --- fftools/ffmpeg_enc.c | 65 +++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f0a17228fe..88635629f7 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -727,24 +727,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, av_assert0(0); } -static int do_audio_out(OutputFile *of, OutputStream *ost, - AVFrame *frame, AVPacket *pkt) -{ - AVCodecContext *enc = ost->enc_ctx; - - if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) { - av_log(ost, AV_LOG_ERROR, - "Audio channel count changed and encoder does not support parameter changes\n"); - return 0; - } - - if (!check_recording_time(ost, frame->pts, frame->time_base)) - return AVERROR_EOF; - - return encode_frame(of, ost, frame, pkt); -} - static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, const AVFrame *frame) { @@ -791,28 +773,6 @@ force_keyframe: return AV_PICTURE_TYPE_I; } -/* May modify/reset frame */ -static int do_video_out(OutputFile *of, OutputStream *ost, - AVFrame *in_picture, AVPacket *pkt) -{ - AVCodecContext *enc = ost->enc_ctx; - - if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base)) - return AVERROR_EOF; - - in_picture->quality = enc->global_quality; - in_picture->pict_type = forced_kf_apply(ost, &ost->kf, in_picture); - -#if FFMPEG_OPT_TOP - if (ost->top_field_first >= 0) { - in_picture->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; - in_picture->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * (!!ost->top_field_first); - } -#endif - - return encode_frame(of, ost, in_picture, pkt); -} - static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) { OutputFile *of = ost->file; @@ -828,11 +788,30 @@ static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) } if (frame) { - return (type == AVMEDIA_TYPE_VIDEO) ? do_video_out(of, ost, frame, pkt) : - do_audio_out(of, ost, frame, pkt); + if (!check_recording_time(ost, frame->pts, frame->time_base)) + return AVERROR_EOF; + + if (type == AVMEDIA_TYPE_VIDEO) { + frame->quality = ost->enc_ctx->global_quality; + frame->pict_type = forced_kf_apply(ost, &ost->kf, frame); + +#if FFMPEG_OPT_TOP + if (ost->top_field_first >= 0) { + frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; + frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * (!!ost->top_field_first); + } +#endif + } else { + if (!(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && + ost->enc_ctx->ch_layout.nb_channels != frame->ch_layout.nb_channels) { + av_log(ost, AV_LOG_ERROR, + "Audio channel count changed and encoder does not support parameter changes\n"); + return 0; + } + } } - return encode_frame(of, ost, NULL, pkt); + return encode_frame(of, ost, frame, pkt); } static void enc_thread_set_name(const OutputStream *ost) -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".