From patchwork Tue Oct 18 12:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38785 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083085pzb; Tue, 18 Oct 2022 05:39:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VlK5kdLgGR9kznZedPQGymOvwtxIraC3YqqQagmPpSM6Z8u1HaIDlPp689fS+AqpBWXIA X-Received: by 2002:a17:906:4a09:b0:78d:b6bb:ff5f with SMTP id w9-20020a1709064a0900b0078db6bbff5fmr2157809eju.538.1666096768020; Tue, 18 Oct 2022 05:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096768; cv=none; d=google.com; s=arc-20160816; b=iMiO2CesCUCmLTKV+CDndP+pjUjtdF6mrSvBD7jYVkJ2G3QNpuTDdPgzGoahseailA MxksqRRH4wJzLcpo4YOs0onG7+3dwuoNyMTZu/92U8sZmaLIvoZ/gH6akBxgohq4XGTx OwOudSVHlB7Xxowzp+VcPeFz3I9BVR08XEZMc4YFgpBLnDedsAmxSmJMsJJPEb2JXUTp b/f9StzPvgD+mzQJmljEzK0A7IHxxDmxandnE4wDEhgWIIo/g0srMqgrVjjV834zjnyy ozKnWeGu6fHaNQg6pUvu6dt9bZ4CHHRoZ2mVi2Rq2fxh0XwlHE3ZUTouWrsIASTnTmeV sh3Q== 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=iF7HcsGeLsZfH+F2vLzctzEqCyAiPabS0wADMi78Ur0=; b=oeAScfbc85DvnolaWld325KhY1iHdh7JXu6PENZCtno7yTpn112JtuLgsjlHNHGcbL 0A2N7LojUZ5VqFc459QW7N7cWIICSDbbDwsDWAMg84TWNiIPT6q6MDK17KFYF4d/cXbu Jh8UiImika7FfIWPpOQak56ravYY4YDTocvOUQXVm+g8IODlX6RT2SDVLpIIlB2tmtxx oflCQTTM0EmaQUu66OKBKnLVle5sDAqGZH15xTWnTzxHvvcOuOLAl8t+f4E/2OifEJWC YIQqOncY9cV4FHsGIDtJWM+OlZBNLzFHCELYZeSnocKvp9Q33P+lrQyUKPTQSwDiJaUt f0FA== 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 o8-20020a170906974800b0078c39937f73si11417061ejy.798.2022.10.18.05.39.27; Tue, 18 Oct 2022 05:39:28 -0700 (PDT) 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 B1C2968BD6B; Tue, 18 Oct 2022 15:38:29 +0300 (EEST) 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 D350B68BD15 for ; Tue, 18 Oct 2022 15:38:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8C97F2406CA for ; Tue, 18 Oct 2022 14:38:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QqBFlRdP0FyW for ; Tue, 18 Oct 2022 14:38:17 +0200 (CEST) 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 AE3B12405F9 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B99623A18F7 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:52 +0200 Message-Id: <20221018123701.25002-11-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/20] fftools/ffmpeg: factor out copying metadata/chapters from of_open() 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: I/SKdVbPGwM9 This code shares variables like OptionsContext.metadata_*_manual, so it makes sense to group it together. --- fftools/ffmpeg_mux_init.c | 123 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index aa958052d1..cd46f441cf 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1533,6 +1533,70 @@ static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFor return 0; } +static void copy_meta(Muxer *mux, OptionsContext *o) +{ + OutputFile *of = &mux->of; + AVFormatContext *oc = mux->fc; + + /* copy metadata */ + for (int i = 0; i < o->nb_metadata_map; i++) { + char *p; + int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); + + if (in_file_index >= nb_input_files) { + av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); + exit_program(1); + } + copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, + in_file_index >= 0 ? + input_files[in_file_index]->ctx : NULL, o); + } + + /* copy chapters */ + if (o->chapters_input_file >= nb_input_files) { + if (o->chapters_input_file == INT_MAX) { + /* copy chapters from the first input file that has them*/ + o->chapters_input_file = -1; + for (int i = 0; i < nb_input_files; i++) + if (input_files[i]->ctx->nb_chapters) { + o->chapters_input_file = i; + break; + } + } else { + av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", + o->chapters_input_file); + exit_program(1); + } + } + if (o->chapters_input_file >= 0) + copy_chapters(input_files[o->chapters_input_file], of, oc, + !o->metadata_chapters_manual); + + /* copy global metadata by default */ + if (!o->metadata_global_manual && nb_input_files){ + av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, + AV_DICT_DONT_OVERWRITE); + if(o->recording_time != INT64_MAX) + av_dict_set(&oc->metadata, "duration", NULL, 0); + av_dict_set(&oc->metadata, "creation_time", NULL, 0); + av_dict_set(&oc->metadata, "company_name", NULL, 0); + av_dict_set(&oc->metadata, "product_name", NULL, 0); + av_dict_set(&oc->metadata, "product_version", NULL, 0); + } + if (!o->metadata_streams_manual) + for (int i = 0; i < of->nb_streams; i++) { + OutputStream *ost = of->streams[i]; + InputStream *ist; + if (ost->source_index < 0) /* this is true e.g. for attached files */ + continue; + ist = input_streams[ost->source_index]; + av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); + if (ost->enc_ctx) { + av_dict_set(&ost->st->metadata, "encoder", NULL, 0); + } + } +} + static int set_dispositions(OutputFile *of, AVFormatContext *ctx) { int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; @@ -1839,63 +1903,8 @@ int of_open(OptionsContext *o, const char *filename) } oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); - /* copy metadata */ - for (i = 0; i < o->nb_metadata_map; i++) { - char *p; - int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); - - if (in_file_index >= nb_input_files) { - av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); - exit_program(1); - } - copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, - in_file_index >= 0 ? - input_files[in_file_index]->ctx : NULL, o); - } - - /* copy chapters */ - if (o->chapters_input_file >= nb_input_files) { - if (o->chapters_input_file == INT_MAX) { - /* copy chapters from the first input file that has them*/ - o->chapters_input_file = -1; - for (i = 0; i < nb_input_files; i++) - if (input_files[i]->ctx->nb_chapters) { - o->chapters_input_file = i; - break; - } - } else { - av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", - o->chapters_input_file); - exit_program(1); - } - } - if (o->chapters_input_file >= 0) - copy_chapters(input_files[o->chapters_input_file], of, oc, - !o->metadata_chapters_manual); - - /* copy global metadata by default */ - if (!o->metadata_global_manual && nb_input_files){ - av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, - AV_DICT_DONT_OVERWRITE); - if(o->recording_time != INT64_MAX) - av_dict_set(&oc->metadata, "duration", NULL, 0); - av_dict_set(&oc->metadata, "creation_time", NULL, 0); - av_dict_set(&oc->metadata, "company_name", NULL, 0); - av_dict_set(&oc->metadata, "product_name", NULL, 0); - av_dict_set(&oc->metadata, "product_version", NULL, 0); - } - if (!o->metadata_streams_manual) - for (int i = 0; i < of->nb_streams; i++) { - OutputStream *ost = of->streams[i]; - InputStream *ist; - if (ost->source_index < 0) /* this is true e.g. for attached files */ - continue; - ist = input_streams[ost->source_index]; - av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); - if (ost->enc_ctx) { - av_dict_set(&ost->st->metadata, "encoder", NULL, 0); - } - } + /* copy metadata and chapters from input files */ + copy_meta(mux, o); of_add_programs(oc, o); of_add_metadata(of, oc, o);