From patchwork Fri Sep 11 16:11:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 22290 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 AB37044A058 for ; Fri, 11 Sep 2020 19:19:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B74C68BAF0; Fri, 11 Sep 2020 19:19:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F2E7468B976 for ; Fri, 11 Sep 2020 19:18:56 +0300 (EEST) Received: by mail-lj1-f171.google.com with SMTP id r24so12955100ljm.3 for ; Fri, 11 Sep 2020 09:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ldxFN34BJie0PcXjHCQ6QAZ7/D0DYtWJs7Ov5RUxd+o=; b=BYhY/sdS/xbc/DOBC9K3B/3D/HyZDRccb3Jjr0fh2MYR4qhKkOMy/qMPyizo4Zsics CIe8VZ8EYCo0dlNGVnPcKop2lHNLfmxLfKQTCuDttjFF8gwuPCsW4YuvMYv6ej+voIJF kmXKXAXvktFTx70L8GDHTaec5bYKy41J8c62jzRuo/mC6FgJMSWKlAHUjyB3KLsnOjac LaSQJ9kW+2lHLBMsXNo72iUxsbVrxT4MURwU+Vmhg1tGY1aFzbi8gFfZG6G+6j4n9icR VGEr5ihERWldLJE25H4whTzTYszdEQa3GoqzQp083MoATMWNnbNOOI4jhMO0NG6zlKbo 64Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ldxFN34BJie0PcXjHCQ6QAZ7/D0DYtWJs7Ov5RUxd+o=; b=NIAoW2Gm+wwUy9ar61QiRscGgQ5cmJ6JbXAY3bGp9kmO9KXMQnCTLSTEZ+19hc9AQ8 m8DDi86ZMNgpx0iaF4YG92BoyiDxosa2U1NQSXmro0UMLJu/i99MWHzk14U5Eksa/PCx 56heTqfhQ9SadHeJ29x+0tzukuV+xqTH5zkeSCQEG8fzZj7Q9aGYM9G+FM4hZ7g3HvdE 9j95XO+p/4/aIsMc6eoLrh+AnZn88iA0fMvwVjzSh0X+j59531Z3PnLo3AZiSR2oXUnR IH2YYh31s1XG/ADWywsMgTl7UqP4ngEwdd1S9oFJeMvoO84H2PBJI52Bfdwf+6rioKIE v6rA== X-Gm-Message-State: AOAM530Ng0c7sVbTn5qRpvTxeKMZ+CazXSaCxEMbZmT6iUA9/EqK4oz0 xRrh8/Ik26da2lO1NfeQKUhraAbY2hI= X-Google-Smtp-Source: ABdhPJwo7m/3OaNLZ3FgwSxpNTv7N/+Wra0BBcrupkZDpwF26N+bpDM4k3izQY9AiDaBONalcmGV4g== X-Received: by 2002:a19:3fd5:: with SMTP id m204mr459558lfa.233.1599840671554; Fri, 11 Sep 2020 09:11:11 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id 193sm134285lfb.212.2020.09.11.09.11.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 09:11:10 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Sep 2020 19:11:06 +0300 Message-Id: <20200911161107.24870-4-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911161107.24870-1-jeebjp@gmail.com> References: <20200911161107.24870-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] ffmpeg: pass decoded or filtered AVFrame to output stream initialization 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Additionally, reap the first rewards by being able to set the color related encoding values based on the passed AVFrame. --- fftools/ffmpeg.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 24b8e175a6..63c8771a01 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -897,9 +897,11 @@ static int check_recording_time(OutputStream *ost) return 1; } -static int init_output_stream(OutputStream *ost, char *error, int error_len); +static int init_output_stream(OutputStream *ost, AVFrame *frame, + char *error, int error_len); -static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal) +static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame, + unsigned int fatal) { int ret = AVERROR_BUG; char error[1024] = {0}; @@ -907,7 +909,7 @@ static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal) if (ost->initialized) return 0; - ret = init_output_stream(ost, error, sizeof(error)); + ret = init_output_stream(ost, frame, error, sizeof(error)); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n", ost->file_index, ost->index, error); @@ -930,7 +932,7 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, pkt.data = NULL; pkt.size = 0; - init_output_stream_wrapper(ost, 1); + init_output_stream_wrapper(ost, frame, 1); if (!check_recording_time(ost)) return; @@ -1081,7 +1083,7 @@ static void do_video_out(OutputFile *of, InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; - init_output_stream_wrapper(ost, 1); + init_output_stream_wrapper(ost, next_picture, 1); if (ost->source_index >= 0) ist = input_streams[ost->source_index]; @@ -1899,7 +1901,7 @@ static void flush_encoders(void) finish_output_stream(ost); } - init_output_stream_wrapper(ost, 1); + init_output_stream_wrapper(ost, NULL, 1); } if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO) @@ -3271,7 +3273,7 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba enc_ctx->time_base = default_time_base; } -static int init_output_stream_encode(OutputStream *ost) +static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) { InputStream *ist = get_input_stream(ost); AVCodecContext *enc_ctx = ost->enc_ctx; @@ -3368,6 +3370,23 @@ static int init_output_stream_encode(OutputStream *ost) enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth); + if (frame) { + if (!av_dict_get(ost->encoder_opts, "color_range", NULL, 0)) + enc_ctx->color_range = frame->color_range; + + if (!av_dict_get(ost->encoder_opts, "color_primaries", NULL, 0)) + enc_ctx->color_primaries = frame->color_primaries; + + if (!av_dict_get(ost->encoder_opts, "color_trc", NULL, 0)) + enc_ctx->color_trc = frame->color_trc; + + if (!av_dict_get(ost->encoder_opts, "colorspace", NULL, 0)) + enc_ctx->colorspace = frame->colorspace; + + if (!av_dict_get(ost->encoder_opts, "chroma_sample_location", NULL, 0)) + enc_ctx->chroma_sample_location = frame->chroma_location; + } + enc_ctx->framerate = ost->frame_rate; ost->st->avg_frame_rate = ost->frame_rate; @@ -3425,7 +3444,8 @@ static int init_output_stream_encode(OutputStream *ost) return 0; } -static int init_output_stream(OutputStream *ost, char *error, int error_len) +static int init_output_stream(OutputStream *ost, AVFrame *frame, + char *error, int error_len) { int ret = 0; @@ -3434,7 +3454,7 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) AVCodecContext *dec = NULL; InputStream *ist; - ret = init_output_stream_encode(ost); + ret = init_output_stream_encode(ost, frame); if (ret < 0) return ret; @@ -3682,7 +3702,7 @@ static int transcode_init(void) output_streams[i]->enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO)) continue; - ret = init_output_stream_wrapper(output_streams[i], 0); + ret = init_output_stream_wrapper(output_streams[i], NULL, 0); if (ret < 0) goto dump_format; }