From patchwork Wed Aug 3 13:58:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp457519pzb; Wed, 3 Aug 2022 06:59:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v+ZqU8dtoreSGUQvCyaskLqv3Dyyzh8p8+MsYv5SthdnrdIzg9DZGB6o23/JFgS0hoSP2x X-Received: by 2002:a05:6402:2804:b0:439:83c2:8be2 with SMTP id h4-20020a056402280400b0043983c28be2mr26518179ede.292.1659535158547; Wed, 03 Aug 2022 06:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659535158; cv=none; d=google.com; s=arc-20160816; b=MBpWJKvlIm+IwA9aUTPPNDAClVMRhGk+joN460CgpyjLTajNdovuVq9X264LNaIlxI kIYc2/mR9k7gB4ipjZQtTvoyd5rXM+czT2qzwETtGjoFZq6Hztrk57N3JSOGDdlHV+PT NQq/9WRGYJ2wEn3KvKr77/naYAwnI5ZMWEadL3uy1W8oG5Ynsn2iVX8W7Lg1QXx4ma6k 1M8/NuA5idivyf7rY6lBBGjJ8P6XC95udrBg1xY39CM+kfaxNs/Srvz1wx3D5NYXRGTa 9Y3DXW4mVLn58cpjGVEipkcewbVPTVXMWp1JGWFxVGuzxRS7z41Byj8rWMx69VYkn0J4 HzWw== 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=XsB/W9SCpuDuFY4LdTRFuCDLsuWC9cAO24odP/Onz8I=; b=KNm9w9wVGJ4gAKrbJ2RCe/dtkSFFh3C8VABtK8OKckCktBlVCZ0QMfG0Fl8D6xEI+B 3da/Utd4O7/eP+J55TPl8C8wUoVFylUOWKWDbTrBnYQ3mjvhh+KI1l7JFKFdamHzb3um 8ajT6OrYsk5zMkQaKlx8ziKuLOkJ6yx+vi5iSsv3toMHUQmr5Yfe+wH3Pg7sSjeq/flz bQs0dbTivWZ/wiahybAyXKOMZD81BWTQpTIWYhCm+PV/BECzJ88xcl4Qvep/IgSV88SI xbrUX0OskI11hPZ52yvI/Igbj8VcfXzV8EQaOj9kOmsiwaWqmoQslIUHmKisagJUOGEI 0tJQ== 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 cr12-20020a170906d54c00b007307fd1b9bbsi8926664ejc.589.2022.08.03.06.59.18; Wed, 03 Aug 2022 06:59:18 -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 6439868B7AE; Wed, 3 Aug 2022 16:59:04 +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 6E85A68B4DC for ; Wed, 3 Aug 2022 16:58:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 050C12400F5 for ; Wed, 3 Aug 2022 15:58:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hGMV47hkPNw8 for ; Wed, 3 Aug 2022 15:58:55 +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 A88AA24017E for ; Wed, 3 Aug 2022 15:58:54 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id E144A3A03FD; Wed, 3 Aug 2022 15:58:51 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Aug 2022 15:58:21 +0200 Message-Id: <20220803135844.16662-2-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220803135844.16662-1-anton@khirnov.net> References: <20220803135844.16662-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs out of open_output_file() 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: ViRz0FLLqXQJ --- fftools/ffmpeg_opt.c | 135 ++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 0d5323ea73..ccab98406e 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2784,6 +2784,75 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o) } } +static void of_add_programs(AVFormatContext *oc, const OptionsContext *o) +{ + /* process manually set programs */ + for (int i = 0; i < o->nb_program; i++) { + const char *p = o->program[i].u.str; + int progid = i+1; + AVProgram *program; + + while(*p) { + const char *p2 = av_get_token(&p, ":"); + const char *to_dealloc = p2; + char *key; + if (!p2) + break; + + if(*p) p++; + + key = av_get_token(&p2, "="); + if (!key || !*p2) { + av_freep(&to_dealloc); + av_freep(&key); + break; + } + p2++; + + if (!strcmp(key, "program_num")) + progid = strtol(p2, NULL, 0); + av_freep(&to_dealloc); + av_freep(&key); + } + + program = av_new_program(oc, progid); + + p = o->program[i].u.str; + while(*p) { + const char *p2 = av_get_token(&p, ":"); + const char *to_dealloc = p2; + char *key; + if (!p2) + break; + if(*p) p++; + + key = av_get_token(&p2, "="); + if (!key) { + av_log(NULL, AV_LOG_FATAL, + "No '=' character in program string %s.\n", + p2); + exit_program(1); + } + if (!*p2) + exit_program(1); + p2++; + + if (!strcmp(key, "title")) { + av_dict_set(&program->metadata, "title", p2, 0); + } else if (!strcmp(key, "program_num")) { + } else if (!strcmp(key, "st")) { + int st_num = strtol(p2, NULL, 0); + av_program_add_stream_index(oc, progid, st_num); + } else { + av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key); + exit_program(1); + } + av_freep(&to_dealloc); + av_freep(&key); + } + } +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -3073,71 +3142,7 @@ static int open_output_file(OptionsContext *o, const char *filename) } } - /* process manually set programs */ - for (i = 0; i < o->nb_program; i++) { - const char *p = o->program[i].u.str; - int progid = i+1; - AVProgram *program; - - while(*p) { - const char *p2 = av_get_token(&p, ":"); - const char *to_dealloc = p2; - char *key; - if (!p2) - break; - - if(*p) p++; - - key = av_get_token(&p2, "="); - if (!key || !*p2) { - av_freep(&to_dealloc); - av_freep(&key); - break; - } - p2++; - - if (!strcmp(key, "program_num")) - progid = strtol(p2, NULL, 0); - av_freep(&to_dealloc); - av_freep(&key); - } - - program = av_new_program(oc, progid); - - p = o->program[i].u.str; - while(*p) { - const char *p2 = av_get_token(&p, ":"); - const char *to_dealloc = p2; - char *key; - if (!p2) - break; - if(*p) p++; - - key = av_get_token(&p2, "="); - if (!key) { - av_log(NULL, AV_LOG_FATAL, - "No '=' character in program string %s.\n", - p2); - exit_program(1); - } - if (!*p2) - exit_program(1); - p2++; - - if (!strcmp(key, "title")) { - av_dict_set(&program->metadata, "title", p2, 0); - } else if (!strcmp(key, "program_num")) { - } else if (!strcmp(key, "st")) { - int st_num = strtol(p2, NULL, 0); - av_program_add_stream_index(oc, progid, st_num); - } else { - av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key); - exit_program(1); - } - av_freep(&to_dealloc); - av_freep(&key); - } - } + of_add_programs(oc, o); /* process manually set metadata */ for (i = 0; i < o->nb_metadata; i++) {