From patchwork Fri Aug 20 15:27:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29644 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1362644iov; Fri, 20 Aug 2021 08:27:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP+ZGCqZHMXs8YSKFAow9PI0Vi5P1kJ2YaqQXKmHWU/v4uZGGredgHTwjjmtvUiwzBqeqS X-Received: by 2002:a17:907:75d0:: with SMTP id jl16mr193814ejc.38.1629473273157; Fri, 20 Aug 2021 08:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629473273; cv=none; d=google.com; s=arc-20160816; b=hefblknBVWWD0p2TEjgbcD4CNquusMMfbmuRVI1H+5jWKa5iib8baCtCrUJ25PGN7X toCinb2qbl+Wbfy73eYCGbWkKJ5jAxYkTWHnV7O3twUjkFy6bt/WtuBd4Kje53KFBldX o458DO0igAvdzp86eeWQ/iPLyIbDR8ygeNqY92P6LMFdccOuZWG8CCVKGVI2/5S7DgJQ dlzSV92R5Muh/ABbmSu2+R7HnATXm3SSE0oAaPpc3cq1/skygoBEfli4ujzpmZx6YdnE 6MH6jgPQlgIreZnIq/La5gOgigXGYmWUY/ec7nNezS2LlCGukttRqPRtJmgFHlqNF7Q9 pO1A== 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=8/6BZaquvGIv9ydct5LJB40dPlg/zp7lYVHasx1EQRI=; b=X7JDaV4ojEQu8hR/gOr1ufyg4Eho4Me703mP82yutCWiVnqTOyugjhqU6pMUSmmds5 9NMuIyPHrr73qzrrpNdgvfxaPo6zhNF3QwOdpXZrJGI3eYIo94pEOcxEDjxxn5mj6yUv tAD8v5f2WmypeotjGGdIz4glfq8Eh0OAEOziO+6GqVtC2uVN8piW5ykG7rq19/u7J2Y8 m1pMSDn0sejNgBGUMcs73DrrY7L4Eh0G1kFEhY55k7s4QNokKGtd6qhfEmS2tspHWCNv ryCH1DotZFkTT7kUerkQ00kXeKZyFZQ8p9mQDpVKGRWtFaOs2EvXTiEXb54NNFCBO1xE T0rA== 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 b6si7815828edu.115.2021.08.20.08.27.52; Fri, 20 Aug 2021 08:27:53 -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 37A8168A306; Fri, 20 Aug 2021 18:27:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B666680BBB for ; Fri, 20 Aug 2021 18:27:32 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17KFRVuf009188 for ; Fri, 20 Aug 2021 17:27:31 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 860C2EB5BC; Fri, 20 Aug 2021 17:27:31 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Aug 2021 17:27:26 +0200 Message-Id: <20210820152728.565116-2-george@nsup.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210820152728.565116-1-george@nsup.org> References: <20210820152728.565116-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Fri, 20 Aug 2021 17:27:31 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/4] lavf/concatdec: support per-file options 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: Pgith/vN5vnL Signed-off-by: Nicolas George --- doc/demuxers.texi | 4 ++++ libavformat/concatdec.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 5f18e4551b..eb3351833a 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -151,6 +151,10 @@ Metadata of the packets of the file. The specified metadata will be set for each file packet. You can specify this directive multiple times to add multiple metadata entries. +@item @code{option @var{key} @var{value}} +Option to access, open and probe the file. +Can be present multiple times. + @item @code{stream} Introduce a stream in the virtual file. All subsequent stream-related directives apply to the last introduced diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index ed6b9d8044..30db456b0e 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -52,6 +52,7 @@ typedef struct { int64_t inpoint; int64_t outpoint; AVDictionary *metadata; + AVDictionary *options; int nb_streams; } ConcatFile; @@ -330,6 +331,7 @@ static int open_file(AVFormatContext *avf, unsigned fileno) { ConcatContext *cat = avf->priv_data; ConcatFile *file = &cat->files[fileno]; + AVDictionary *options = NULL; int ret; if (cat->avf) @@ -345,12 +347,22 @@ static int open_file(AVFormatContext *avf, unsigned fileno) if ((ret = ff_copy_whiteblacklists(cat->avf, avf)) < 0) return ret; - if ((ret = avformat_open_input(&cat->avf, file->url, NULL, NULL)) < 0 || + ret = av_dict_copy(&options, file->options, 0); + if (ret < 0) + return ret; + + if ((ret = avformat_open_input(&cat->avf, file->url, NULL, &options)) < 0 || (ret = avformat_find_stream_info(cat->avf, NULL)) < 0) { av_log(avf, AV_LOG_ERROR, "Impossible to open '%s'\n", file->url); + av_dict_free(&options); avformat_close_input(&cat->avf); return ret; } + if (options) { + av_log(avf, AV_LOG_WARNING, "Unused options for '%s'.\n", file->url); + /* TODO log unused options once we have a proper string API */ + av_dict_free(&options); + } cat->cur_file = file; file->start_time = !fileno ? 0 : cat->files[fileno - 1].start_time + @@ -387,6 +399,7 @@ static int concat_read_close(AVFormatContext *avf) } av_freep(&cat->files[i].streams); av_dict_free(&cat->files[i].metadata); + av_dict_free(&cat->files[i].options); } if (cat->avf) avformat_close_input(&cat->avf); @@ -458,6 +471,26 @@ static int concat_read_header(AVFormatContext *avf) FAIL(AVERROR_INVALIDDATA); } av_freep(&metadata); + } else if (!strcmp(keyword, "option")) { + char *key, *val; + if (cat->safe) { + av_log(avf, AV_LOG_ERROR, "Options not permitted in safe mode.\n"); + FAIL(AVERROR(EPERM)); + } + if (!file) { + av_log(avf, AV_LOG_ERROR, "Line %d: %s without file\n", + line, keyword); + FAIL(AVERROR_INVALIDDATA); + } + if (!(key = av_get_token((const char **)&cursor, SPACE_CHARS)) || + !(val = av_get_token((const char **)&cursor, SPACE_CHARS))) { + av_freep(&key); + FAIL(AVERROR(ENOMEM)); + } + ret = av_dict_set(&file->options, key, val, + AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + if (ret < 0) + FAIL(ret); } else if (!strcmp(keyword, "stream")) { if (!avformat_new_stream(avf, NULL)) FAIL(AVERROR(ENOMEM));