From patchwork Wed Jul 28 12:15:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29083 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp5736576pxb; Wed, 28 Jul 2021 05:15:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnt+JEoKFdUs/qaxmq70MW1hWSbfuFXpE7YGq/SUKysZlX9RsMnOnuxWIMtCnNgBFmzE9L X-Received: by 2002:a17:906:eb4b:: with SMTP id mc11mr2893547ejb.474.1627474545042; Wed, 28 Jul 2021 05:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627474545; cv=none; d=google.com; s=arc-20160816; b=MLuaey8FmBE4Md4kBsZaGfctnoT7j/Iy6LJkYRf7t2S4cySzrNPFpt6ua5P9NELfWU siCG3cbh7Pwt7UC3HhBbmlfltw61mhBWMk12zno5uGsv/v4/+8kV/GTqRbMyKCLCd/hQ Zlf2DXVnHc6d4k44CH0+8JVrnj2qRoIT4DBWNaVtH3GB++B6V86pzVTocuYZHKKsJB5w e42Q3wOQUpDOpmCvDERnU2IwdpyQK7uYfp+L0BLCnu9Z0GxwFViHSZguQYWGWsR/CQwh vyqcPcN6L0V7tIgt1d/O/k28PZqJP1iAK+5nRGcetMhQnZ3XjzDQmBG2yceeY29RTsvs W0rw== 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=WRZFz0NvDLPA3zhnMt0xwd1cYs/XDhmOeY8tJ8RRzlk=; b=wDaeq57fra5zN7WbLVNJNFisfgIIReToJFZvj/fY+Xvo+sSI+7Ij06YfSV4QYI6uSC mmRrrB1hskkSia/tPUqKtVixzx2N+2BNT5VKbonG1No8Da02aGMGBHqpYiIGphkurPNR Xhm0x2Rpxam+bSucgF41YX5NfJyoakmxtnT+4gMiFdwGGtgXHhG8v68DiZ3ryvIVqDhX vyGeGPllzb47wlkaYh//N9TCGlLoFmlZUtis91nxkq9Ozn81eoa32M9fjBkPTULc1pCp ohney3h2+wx10A+CAF/sB7rEgcmMyNAsD7FJlUWVgI6sh9Kl94RxzVED3YFVbK0Wl+01 hQSA== 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 eg26si5947862edb.271.2021.07.28.05.15.44; Wed, 28 Jul 2021 05:15:45 -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 9F67D689EDA; Wed, 28 Jul 2021 15:15:27 +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 7263468081D for ; Wed, 28 Jul 2021 15:15:20 +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 16SCFJ0i030343 for ; Wed, 28 Jul 2021 14:15:20 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id A8EA0E62AD; Wed, 28 Jul 2021 14:15:19 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Jul 2021 14:15:13 +0200 Message-Id: <20210728121517.533173-2-george@nsup.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210728121517.533173-1-george@nsup.org> References: <20210728121517.533173-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]); Wed, 28 Jul 2021 14:15:20 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/5] 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: hl/PyVKenfdo Signed-off-by: Nicolas George --- doc/demuxers.texi | 4 ++++ libavformat/concatdec.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) I intend to refactor the parser some time later. 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 3db1693725..0203b1e6dc 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -51,6 +51,7 @@ typedef struct { int64_t inpoint; int64_t outpoint; AVDictionary *metadata; + AVDictionary *options; int nb_streams; } ConcatFile; @@ -329,6 +330,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) @@ -344,12 +346,21 @@ 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); 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 + @@ -386,6 +397,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); @@ -457,6 +469,29 @@ 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_log(avf, AV_LOG_ERROR, "Line %d: key and val required\n", line); + FAIL(AVERROR_INVALIDDATA); + } + ret = av_dict_set(&file->options, key, val, + AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + if (ret < 0) { + av_freep(&key); + av_freep(&val); + FAIL(ret); + } } else if (!strcmp(keyword, "stream")) { if (!avformat_new_stream(avf, NULL)) FAIL(AVERROR(ENOMEM));