From patchwork Mon Apr 26 11:01:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Solonsky X-Patchwork-Id: 27428 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6109:0:0:0:0:0 with SMTP id v9csp69736iob; Mon, 26 Apr 2021 05:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJJBZwRHRYsufcOFwVuXGRwcv90BsVNHV46vGIKhpinUYHnatSr61u/DW2mriZm8oyn3w4 X-Received: by 2002:a05:6402:cbb:: with SMTP id cn27mr21361884edb.222.1619441338384; Mon, 26 Apr 2021 05:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619441338; cv=none; d=google.com; s=arc-20160816; b=WGzg0N+8R1tLtCLzcoI+qZ4qW8cNvni/nVINXhOqDjZD+M0TZcbNSV3ErcY8oqVKLl Aul2udrYfyM0q+ITT/X0zBYZ1lv0Chho1KyRz0mYTKkeUYwcyvBEv+2NjvwyytpyNMes i4RpanRSswgupTVY7qnSMMwByK3HJcZBtnr3Anq/Qqxxd78sXy9HlwoAZtsZbB34zJYw a16v1W+OCZiNN9uOULzN9vf3HiM2zAMb/jOyWiF0cjy0NbgA2Q8HKRHHTdsWs5aZeRN9 2FHmkKsdjwMKXZ4Kho1sDxLFFKKMdX1crf12THrbsUjHZRMMfnTNjCeJD7jCGZH+I7mx BxDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=9vedH5HH6CJgPsFfOXi+QCYH0g6frm0MPOP+L/bIkKg=; b=NXYoFhQ/aCbz5hHBM0OLmI8jX3Asy1O0rTsNbK47h0K/5QObTNuHPHe3G5t281uGRt 4E1oMRF2W7G+rlQNuoHqXVidbPY1x48PYp3KLcj4ZzHQayVTj4QqJ+dT3YdloK+n8Ui9 Z25kYs61PVsu/07lzt0YHwuGbL9O5XO3PBqKoQEl9/K1CAd+JnvUmKvd3YQxRTqi8WnI sDjTYLUccQYg8bwW8iXAUeV9mqZwb0pUfPNz82vJ+22a6y9RjEUWrxiX9H1qwa0t3v+L Zee7BLTGDqez4AQzBJmzCQSj84G4wKLPDnomn/XWP20vCF4j2Q6v98EiTfGWNR4fuhw/ Oy9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@castlabs.com header.s=google header.b=IyF45lEB; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=castlabs.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i13si13648349ejy.221.2021.04.26.05.48.57; Mon, 26 Apr 2021 05:48:58 -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; dkim=neutral (body hash did not verify) header.i=@castlabs.com header.s=google header.b=IyF45lEB; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=castlabs.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF76C689CFA; Mon, 26 Apr 2021 15:48:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2BC626804AE for ; Mon, 26 Apr 2021 15:48:47 +0300 (EEST) Received: by mail-wr1-f53.google.com with SMTP id x5so5452978wrv.13 for ; Mon, 26 Apr 2021 05:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=castlabs.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u0b5nCiYp99PYt3hRcTst8u0xhQXFJHLW0+stScmGnk=; b=IyF45lEBUrTGXSQBnj4PTjxW0s5RddNRwJtYu8sC//ZSXUTKMLrqrKa5VMWVkRiH1+ yFqwaw3MT15miEWS1QMPhUUWZqbdro1Rr8ELItts63s1yddud6lRm/JRs1jUH4RE9Vy3 SjGMjV5QogdC8jg+iOM3+sN3a8cCY7IesOXTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u0b5nCiYp99PYt3hRcTst8u0xhQXFJHLW0+stScmGnk=; b=qScqur7+XljQ83CluzHL+zVGJf/cGLsFUGoFvgBSftRLi1YUIvSFDm/R+46abIpKBl p+QhlmgcNLsJPtGuBc80UinzIIG/re+BgM3pYZIhs60wGAcgZR3oPcjFBbCjHkqbBGo0 bDFej5VCPwu4fRufDEkHu9vE8FPFwTxSOms4f+TynNF1w1P3AHk4vu8v0IP+IICO/V27 D7ySQDjMiqiXSb0hcTXFmWF334V17jN4y5a9/vyGhXjlYUs0/fEeoy2TPGpckYIfBYxG 8gIlBNk0VoUijqnLKfSEfCnWNkWiaF03wgXTPB7WIJQhx4aLBy4Of5so5VRi7M6HTYpp LjyA== X-Gm-Message-State: AOAM533A8SiAJMuHF5E/jMvShy/qxLHp3wxxBZ+Gs/scGw5kckrcRA8d uFHL7ibSkaVsTSsRAFrzeNINWGh41MEawQ== X-Received: by 2002:ac2:4158:: with SMTP id c24mr12771414lfi.580.1619434924134; Mon, 26 Apr 2021 04:02:04 -0700 (PDT) Received: from localhost.localdomain ([188.162.12.156]) by smtp.gmail.com with ESMTPSA id x19sm1478912ljh.50.2021.04.26.04.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 04:02:03 -0700 (PDT) From: Alexander Solonsky To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 18:01:44 +0700 Message-Id: <20210426110144.109-1-alexander.solonsky@castlabs.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] allows for independent codec setting per output video stream 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 Cc: Alexander Solonsky Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yzAeaCFJF0mI Sometimes it is useful that output video streams have different gop structure and other settings. Currently one setting used for all and I added a posibility to have it separately --- fftools/cmdutils.c | 22 ++++++++++++++++++++-- fftools/cmdutils.h | 2 ++ fftools/ffmpeg_opt.c | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index fe424b6a4c..4a3520b84b 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -67,7 +67,8 @@ static int init_report(const char *env); AVDictionary *sws_dict; AVDictionary *swr_opts; -AVDictionary *format_opts, *codec_opts, *resample_opts; +AVDictionary *format_opts, *codec_opts, *resample_opts, *codec_opts_aux[MAX_CODEC_OPTS]; +int codec_opts_aux_counter = 0; static FILE *report_file; static int report_file_level = AV_LOG_DEBUG; @@ -86,11 +87,16 @@ void init_opts(void) void uninit_opts(void) { + int i; + av_dict_free(&swr_opts); av_dict_free(&sws_dict); av_dict_free(&format_opts); av_dict_free(&codec_opts); av_dict_free(&resample_opts); + for(i = 0; i < codec_opts_aux_counter; i ++) + av_dict_free(&codec_opts_aux[i]); + } void log_callback_help(void *ptr, int level, const char *fmt, va_list vl) @@ -567,6 +573,10 @@ int opt_default(void *optctx, const char *opt, const char *arg) ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) { av_dict_set(&codec_opts, opt, arg, FLAGS); + av_dict_set(&codec_opts_aux[codec_opts_aux_counter], opt, arg, FLAGS); + if(codec_opts_aux_counter + 1 < MAX_CODEC_OPTS) + codec_opts_aux_counter ++; + // if more streams require separate codec opts - the rest will have to use the latest setting consumed = 1; } if ((o = opt_find(&fc, opt, NULL, 0, @@ -660,6 +670,7 @@ static void finish_group(OptionParseContext *octx, int group_idx, { OptionGroupList *l = &octx->groups[group_idx]; OptionGroup *g; + int i; GROW_ARRAY(l->groups, l->nb_groups); g = &l->groups[l->nb_groups - 1]; @@ -673,6 +684,11 @@ static void finish_group(OptionParseContext *octx, int group_idx, g->format_opts = format_opts; g->resample_opts = resample_opts; + for(i = 0; i < codec_opts_aux_counter; i ++) + g->codec_opts_aux[i] = codec_opts_aux[i]; + + for(i = 0; i < codec_opts_aux_counter; i ++) + codec_opts_aux[i] = NULL; codec_opts = NULL; format_opts = NULL; resample_opts = NULL; @@ -722,7 +738,7 @@ static void init_parse_context(OptionParseContext *octx, void uninit_parse_context(OptionParseContext *octx) { - int i, j; + int i, j, k; for (i = 0; i < octx->nb_groups; i++) { OptionGroupList *l = &octx->groups[i]; @@ -735,6 +751,8 @@ void uninit_parse_context(OptionParseContext *octx) av_dict_free(&l->groups[j].sws_dict); av_dict_free(&l->groups[j].swr_opts); + for (k = 0; k < codec_opts_aux_counter; k ++) + av_dict_free(&l->groups[j].codec_opts_aux[k]); } av_freep(&l->groups); } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 5da9f4c88f..238b80857f 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -308,6 +308,7 @@ typedef struct OptionGroupDef { int flags; } OptionGroupDef; +#define MAX_CODEC_OPTS 16 typedef struct OptionGroup { const OptionGroupDef *group_def; const char *arg; @@ -316,6 +317,7 @@ typedef struct OptionGroup { int nb_opts; AVDictionary *codec_opts; + AVDictionary *codec_opts_aux[MAX_CODEC_OPTS]; AVDictionary *format_opts; AVDictionary *resample_opts; AVDictionary *sws_dict; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 807e783422..a02e05f081 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1474,7 +1474,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e AVIOContext *s = NULL; char *buf = NULL, *arg = NULL, *preset = NULL; - ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc); + ost->encoder_opts = filter_codec_opts(o->g->codec_opts_aux[ost->index], ost->enc->id, oc, st, ost->enc); MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); ost->autoscale = 1;