From patchwork Fri Sep 11 16:11:04 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: 22289 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 99DCA44924E for ; Fri, 11 Sep 2020 19:18:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7714068BAE7; Fri, 11 Sep 2020 19:18:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 897C86806A5 for ; Fri, 11 Sep 2020 19:18:44 +0300 (EEST) Received: by mail-ed1-f48.google.com with SMTP id l63so10570026edl.9 for ; Fri, 11 Sep 2020 09:18:44 -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=ApqY2GFm7cLyGPwYdGkrLON6omuMlw0vrZ9e2pLJyGM=; b=Wy94XHh43QdRpAMlMz9vvWPTolHPAdoixD/kPsyTpJ972EIxi635bASr6Ts1wwN6MS Rdbwj/XHwHuKWrFcalUXczglKIuWmGpEgkNQn22hQGb5BPnaWUgn+JUtWkNS3vxslMJE lDvNHff0sl2Yaaw0UHn4kL+kYakbAi65SzNTRvRbBjzVl9FgFNS8NZjBVYFgywwbZg/n 0seYYF9H6idAfKCX7SfDDntiQUUzl2VaKGYTJK/44WKs195xiXqOs0pZ/nDLwjUD3brl 7WYgEnbod92QbbxfSI09u8YGr2Xy59s28ds01pQpBhpobZpJ/mqGpwCmjiWf6GY3B7NF oozg== 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=ApqY2GFm7cLyGPwYdGkrLON6omuMlw0vrZ9e2pLJyGM=; b=EqN0graiPV4pDcj7MyJApakh8a1hjOuD89w3b8Nn/zTmYtFMm+HM3nwBAnSy5wH0zn +TuKsPAdtI5XF4wqZ2YJfHQNxayx+zVrsFCGK6gTR/LwBJ91oRfASuMJNbyb1TWC/YVw nVqU9PxWa61tUg9YbH+a8n28hSPzxqHUMYSCHh+B5WhxvN15PfuovNUkNiPlJWUOS1L+ Ed1sQjO5Xc9yvZRV7PxFwd7hO00axMhJIJRJC7faqXTaEUqh/lqE/+lxZ8MM32uZIZ6K C/jwfEgi1BG8uSEpt/0k2j8nzigNV5nEvwQmQmMpObbZDXc9/XPytY45euG3hbqcBxBu 3Jkw== X-Gm-Message-State: AOAM5326USMc4zUaeptGifkJ1775DdcIeSP5g00RH857V9HEaHwS1Fh3 +3Z29Zkg4TCXjT63OLKn4UmK8j58qOM= X-Google-Smtp-Source: ABdhPJziMpXQpzdciStEVQ23KCBExKQfrwnLgrY/kAyk+erOn4pyQF17FAs7kxu/d/FFBCI+2+n/EQ== X-Received: by 2002:ac2:4311:: with SMTP id l17mr566991lfh.457.1599840669602; Fri, 11 Sep 2020 09:11:09 -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.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 09:11:09 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Sep 2020 19:11:04 +0300 Message-Id: <20200911161107.24870-2-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 1/4] ffmpeg: deduplicate init_output_stream usage logic 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" Adds a wrapper function, which handles any errors depending on how fatal a failure would be. --- fftools/ffmpeg.c | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 84306818a2..cb7644de6a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1392,6 +1392,26 @@ static void do_video_stats(OutputStream *ost, int frame_size) static int init_output_stream(OutputStream *ost, char *error, int error_len); +static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal) +{ + int ret = AVERROR_BUG; + char error[1024] = {0}; + + if (ost->initialized) + return 0; + + ret = init_output_stream(ost, 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); + + if (fatal) + exit_program(1); + } + + return ret; +} + static void finish_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -1428,15 +1448,7 @@ static int reap_filters(int flush) continue; filter = ost->filter->filter; - if (!ost->initialized) { - char error[1024] = ""; - ret = init_output_stream(ost, 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); - exit_program(1); - } - } + init_output_stream_wrapper(ost, 1); if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) { return AVERROR(ENOMEM); @@ -1860,7 +1872,6 @@ static void flush_encoders(void) // Maybe we should just let encoding fail instead. if (!ost->initialized) { FilterGraph *fg = ost->filter->graph; - char error[1024] = ""; av_log(NULL, AV_LOG_WARNING, "Finishing stream %d:%d without any data written to it.\n", @@ -1886,12 +1897,7 @@ static void flush_encoders(void) finish_output_stream(ost); } - ret = init_output_stream(ost, 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); - exit_program(1); - } + init_output_stream_wrapper(ost, 1); } if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO) @@ -3669,7 +3675,7 @@ static int transcode_init(void) if (output_streams[i]->filter) continue; - ret = init_output_stream(output_streams[i], error, sizeof(error)); + ret = init_output_stream_wrapper(output_streams[i], 0); if (ret < 0) goto dump_format; } @@ -4580,15 +4586,8 @@ static int transcode_step(void) } if (ost->filter && ost->filter->graph->graph) { - if (!ost->initialized) { - char error[1024] = {0}; - ret = init_output_stream(ost, 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); - exit_program(1); - } - } + init_output_stream_wrapper(ost, 1); + if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0) return ret; if (!ist) From patchwork Fri Sep 11 16:11:05 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: 22288 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 31CE044B89B for ; Fri, 11 Sep 2020 19:16:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 10DF168BAE4; Fri, 11 Sep 2020 19:16:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 75FA568BADA for ; Fri, 11 Sep 2020 19:16:22 +0300 (EEST) Received: by mail-lf1-f68.google.com with SMTP id m5so6408925lfp.7 for ; Fri, 11 Sep 2020 09:16:22 -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=Cs6Eq3ABo49ar1ZHrI9gFtn0XRiDxlqUGVg0vJpR8tQ=; b=WVWrOa0SrfcxGDNyUoWYCpcS7cBVw7nnv1+1ftrE4NQU65846etK7vhNIHf6Bc4p92 yhf1p9F1T1YFR57W6e2UN/hfnKQ4oGowcW8d5JH0TnGTpX4CNTLUTv1cH+mMVwUjx4WF s6oQNruMJzsfSV+P4V7j/VvDtSR8wZ5puG4ucliMqTrsOjwyzaHF/YnUxoKBo9FeW76q 7REZKhDszHBhLnsr6FjkSyTMqDBK6tReJdpc2ltXbnJCbH/MJ75NwwodLYTLhB343q3W DeLa6qf0vdh+7/zANvuT3so1eXUqd6uJkRg0ucD2cchxuYwIp6HyWUijftHaV0fPigDt UbRg== 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=Cs6Eq3ABo49ar1ZHrI9gFtn0XRiDxlqUGVg0vJpR8tQ=; b=QsLuD+SpApjIVIyKEpwnCxwl48pKxsxuKR0QpfGkIs0mLAB28UG4HfDPee1/DEZpwe PbdWbsz812lb/Vk62B/XcLGQUya0dDJ1S7s9S8LKqLIa8ducne+0VoMZlw7jFT2OqIxT jpb688Mqs6pnzBwSXWDglfCvNh72vWJED1Psh6EiVPM7WokdCjam0AKkoIKv7KsiTxOT dvSay3BCQBGGvU5Xg1AX58Z3G9JmB5lR3RPo7QNeb/dO16x44W8YmTXFZCUlxBf9DO2F XNfjRqKZiyfmKftU/7KK6leVwvTR0ThnVuH/u5e+Uw9eWYeB1r2B1dUozbMB7NMd8uFF PdAg== X-Gm-Message-State: AOAM532ZF4N8YrxFTRrDd/2Bx1bRKIdlfQldNy5yuux3bRPnuPiK0v/8 e39BeOONPrRHUQLXt/+FqtBnJuoEvxs= X-Google-Smtp-Source: ABdhPJyQfMlLXR8lxNsqXrYn/N+oILTuXlhochzhg70Irxyp6wqJlvT4YrE22qA5XH+7QXVPorITqw== X-Received: by 2002:a2e:4554:: with SMTP id s81mr1137714lja.121.1599840670604; Fri, 11 Sep 2020 09:11:10 -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.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 09:11:09 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Sep 2020 19:11:05 +0300 Message-Id: <20200911161107.24870-3-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 2/4] ffmpeg: move A/V non-streamcopy initialization to a later point 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" This enables us to utilize AVFrames for initialization parameters further down the line. --- fftools/ffmpeg.c | 63 ++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cb7644de6a..24b8e175a6 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -897,6 +897,28 @@ 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_wrapper(OutputStream *ost, unsigned int fatal) +{ + int ret = AVERROR_BUG; + char error[1024] = {0}; + + if (ost->initialized) + return 0; + + ret = init_output_stream(ost, 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); + + if (fatal) + exit_program(1); + } + + return ret; +} + static void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { @@ -908,6 +930,8 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, pkt.data = NULL; pkt.size = 0; + init_output_stream_wrapper(ost, 1); + if (!check_recording_time(ost)) return; @@ -1057,6 +1081,8 @@ static void do_video_out(OutputFile *of, InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; + init_output_stream_wrapper(ost, 1); + if (ost->source_index >= 0) ist = input_streams[ost->source_index]; @@ -1390,28 +1416,6 @@ static void do_video_stats(OutputStream *ost, int frame_size) } } -static int init_output_stream(OutputStream *ost, char *error, int error_len); - -static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal) -{ - int ret = AVERROR_BUG; - char error[1024] = {0}; - - if (ost->initialized) - return 0; - - ret = init_output_stream(ost, 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); - - if (fatal) - exit_program(1); - } - - return ret; -} - static void finish_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -1448,8 +1452,6 @@ static int reap_filters(int flush) continue; filter = ost->filter->filter; - init_output_stream_wrapper(ost, 1); - if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) { return AVERROR(ENOMEM); } @@ -3669,10 +3671,15 @@ static int transcode_init(void) goto dump_format; } - /* open each encoder */ + /* + * initialize stream copy and subtitle/data streams - encoded AVFrame + * based streams will get initialized when the first AVFrames are + * received via do_{audio,video}_out + */ for (i = 0; i < nb_output_streams; i++) { - // skip streams fed from filtergraphs until we have a frame for them - if (output_streams[i]->filter) + if (!output_streams[i]->stream_copy && + (output_streams[i]->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO || + output_streams[i]->enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO)) continue; ret = init_output_stream_wrapper(output_streams[i], 0); @@ -4586,8 +4593,6 @@ static int transcode_step(void) } if (ost->filter && ost->filter->graph->graph) { - init_output_stream_wrapper(ost, 1); - if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0) return ret; if (!ist) 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; } From patchwork Fri Sep 11 16:11:07 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: 22291 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 9E7D244A058 for ; Fri, 11 Sep 2020 19:19:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8CF2568BAFD; Fri, 11 Sep 2020 19:19:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B776868BAAB for ; Fri, 11 Sep 2020 19:19:28 +0300 (EEST) Received: by mail-lf1-f41.google.com with SMTP id b22so2859290lfs.13 for ; Fri, 11 Sep 2020 09:19:28 -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=oI/WzoRrSxoazDh+Xs3EKY/Q33J/xfva6/R0dV83lC4=; b=tMTIxCZ/qxr1coKLJdOh8JqXw8vlBKUlNX7sMWETHBZTcccnlX1/FDLQfOcrS0zEqf 7kPNnKS8sN5nIBKZBJme8iFMZZakx82oZPKYGt8y+R7r6xq1GIMm62uRYtppsmQY4jNi pxlicywbsJaQiR20/BTFgIn24WsM+PINh6wk5L5t+zVxWfC3KpZdOUSEkDpLsy6WcpCw UV319PZ4AbTtNihpPxoO8+SMYs2iBwGL6QcX4A60UiMm890sAtuYLcHxf5A1dtsr3xWp Vd3UoeWo0Q+tMm11supK3vkQggwTStvLzphKJc/dJRCv75FY83Sbw5XcyiF4zkfEsoOU /v+A== 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=oI/WzoRrSxoazDh+Xs3EKY/Q33J/xfva6/R0dV83lC4=; b=LTE6GFpf85ZuC3FOZquauDHnMa59ur3PPiFJA9zVUJhbSbDdujmRml9Ach/ReDixus roaYNGhZPIi+fxpu0L5RAodbZ6l5En7rMURP7mwkOp3xDKxD2Mbm6hBdoHIgn8fiPNNA Ywd24ep3o+pUUT9U8OdFeH+w+ZW2FBHPpgbjO31QlzPcw9BMR+PtpRoBwlR1i/zzhOOh F3vUF/tgEkZlEctQ2Xby1Y9de6M3qXG8+QAZI+LKW1etGQAVj//4Ss0e/qTaR/c4tvuf N/s43C8Zr7PNEjnYpO3A7ONOyZPTbMOjxpHsYgI3ry+IsNpCHxIzLRXVe+VWEopdJDxR fylA== X-Gm-Message-State: AOAM5339hz2ASRJ5bNdB6C3tiWrWqmpyq4nodehIbsE5xYHh/wSH9pqb Ig37yKH2ProY1zqYlEZaApljpXQWNv8= X-Google-Smtp-Source: ABdhPJwGaB3/hM8XcmW6yllBvDmIpTvTa3Ig/TFcI/bkikXIazOZck9ngrvyvwX2MPpafcLsoH2gJg== X-Received: by 2002:a19:8209:: with SMTP id e9mr476918lfd.254.1599840672460; Fri, 11 Sep 2020 09:11:12 -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.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 09:11:11 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Sep 2020 19:11:07 +0300 Message-Id: <20200911161107.24870-5-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 4/4] ffmpeg: warn if an encoder has to be initialized without an AVFrame 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" This should make it easier to spot such cases. --- fftools/ffmpeg.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 63c8771a01..70e7274d87 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3281,6 +3281,20 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) AVFormatContext *oc = output_files[ost->file_index]->ctx; int j, ret; + if ((enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO || + enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && + !frame) { + const AVCodecDescriptor *description = \ + avcodec_descriptor_get(ost->enc_ctx->codec_id); + + av_log(NULL, AV_LOG_WARNING, + "Initializing %s output stream %d:%d (%s) without an available " + "AVFrame! Possibility of less accurate configuration!\n", + av_get_media_type_string(enc_ctx->codec_type), + ost->file_index, ost->index, + description ? description->name : "no encoder"); + } + set_encoder_id(output_files[ost->file_index], ost); // Muxers use AV_PKT_DATA_DISPLAYMATRIX to signal rotation. On the other