From patchwork Sun Apr 18 21:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 26959 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp561770yba; Sun, 18 Apr 2021 14:31:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA7gLrwhjEwGUGXJLHc/OULH6jPdJ7KhF0JD7Mm5lTp2KvyGoaWGgM9XRhn1zv4RE70bHQ X-Received: by 2002:a17:906:13d6:: with SMTP id g22mr18854833ejc.475.1618781469973; Sun, 18 Apr 2021 14:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618781469; cv=none; d=google.com; s=arc-20160816; b=L43RanqqBGbqoklca/sWXbLd+IiWWj/CFpzdvgj9RB32k2zRnFTwhq9YMpUeQ/R66y jEPIoF8MBe0zLkqrv1E8faoLLjWsuaEW1TFwOcIbgFEkwBsu/FfUpjq3LKScavetln/v YY1svbYm5ikIc8LLc9XpvkzbuxV4aH9SYZJWIRf8uxqtEW+j2w8B1dFi9qtJgrZzX6+T m6pdIJDrsT5LgNU0wnzh8/BbBpD7HLyANASJLa7U4+mV6KHOH3KKfgSBzU8PDSzEUbkE 29r2/IPPQCnXMsPwKczI7DEAJlVcyxgKA+kTKQvNgXyyv2KJQj4m5ENdB5UsKxNMUbIO GW5g== 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=4Zksyaq6mvWqsSvsGf62E82soZI9zcpzjKXbX6Purk0=; b=yehu/7EalN4eroOs0fq4/jUo+1+A/dwjTokqS1R93sceOoC6Ds63F3KCSA0iCX8QsR Adwxs8Pk7zw5QmGl5NXIiC3rZE4hK2ReMfMBUHldVgwRpChQ+GhVIYAJIltGxVOeemxZ UOJYbUPIqxqyCQJqxYBPPYikVsSDmjgndlYx6E6cPxR6OnkJAT2hC5d8/F9ngo5rMoUN 7sxqN4KZui4HoPe2jg+lDPj4L9dztXSd2eJF083ckw4ipis8AqwAr76JSrWlvF11PrO/ IrRmRVNYpRHzcC6Lc5WUHJ69cknqOzHwZKJBBzq80bvKFt61r5MlxA7OxFcQbzUbcuDt CWhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=JrcLwPL3; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j24si10056034ejk.65.2021.04.18.14.31.09; Sun, 18 Apr 2021 14:31:09 -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=@gmail.com header.s=20161025 header.b=JrcLwPL3; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E4A82680760; Mon, 19 Apr 2021 00:31:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D1086801CD for ; Mon, 19 Apr 2021 00:31:01 +0300 (EEST) Received: by mail-ej1-f51.google.com with SMTP id l4so49848647ejc.10 for ; Sun, 18 Apr 2021 14:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r4bqEAgOZ1S/U7D4r91deKxtlOg39pN/VuC7vasz6os=; b=JrcLwPL3BkY4OOmIoke+ZkV+JMuoqMleNfRwP+RKL9RI8HI23mtE9catM0Q7rLz6DA brFz00ZpbsUpiSzoZma5wSklX16JW/K7XmpXXnz7a7sd7bOkLDJmun4lN62vkdOoij2J am9AUZKz38PfdDcZmwKb3tUqkjjvQe0xp2rnUDXEhA0p5WjXqx37h166UStQ1Y4S/JMX dzou8liqawGBmz45hxML/PDjg0NNpdcm1T6P584FxoaE9VMaNLytQxXD5liRqEm0xjYL mTIc5/fApV2tX6NJls1IcY7Wyh3NJkOX3Wonv37rktsy476pSLM+E+ZcDJMuj+SGL56C UkQA== 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=r4bqEAgOZ1S/U7D4r91deKxtlOg39pN/VuC7vasz6os=; b=bg4E1f3Il+lp8do2nZwD9ewrL7iTEz4T+8gL6pBw9O1Q3inL/thyecYwDMv8eGK5u0 up1DQVBvMN3ubOR2zyOot9zjyOffQIadtHGK4DLEAYyqkeVPtt7xws1d8RUlGzMZ5LGI pckbh0Y0kl+r5I86PmicqVwDieKQtjIYnHj2S2ZfQvuxnywr1LPeZxin0+OD/hmv87QC o3QeY+yWH7UI42al+gXKkba2iL9AiwqMCmkrS6CRGmlL7onS9zKK7U1ZpIN6YFC50V77 3GRGwkAueZTtS3fawMke9AxJStMrBeOO6hA2HXzfEykPKuHe5DG+/Ou9wVW4fFT0Q0xF 710Q== X-Gm-Message-State: AOAM532hSBrQqdHKOQQ7IozNAl6BRAnDky+HurJJg6zlJBx5uuOPkdbx iFLbBYF/axU+BWd55ij2G29qbcmcK3o= X-Received: by 2002:a17:907:760a:: with SMTP id jx10mr19443277ejc.126.1618781460523; Sun, 18 Apr 2021 14:31:00 -0700 (PDT) Received: from mariano (dynamic-adsl-78-14-94-55.clienti.tiscali.it. [78.14.94.55]) by smtp.gmail.com with ESMTPSA id w13sm11020074edc.81.2021.04.18.14.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 14:31:00 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id AD21BBFA60; Sun, 18 Apr 2021 23:30:58 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sun, 18 Apr 2021 23:30:57 +0200 Message-Id: <20210418213058.24475-1-stefasab@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavf/avio: add avio_vprintf() 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: Stefano Sabatini Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: E5swMm/xJ0YZ Content-Length: 3128 This new function makes it possible to use avio_printf() functionality from a function taking a variable list of arguments. --- doc/APIchanges | 3 +++ libavformat/avio.h | 6 ++++++ libavformat/aviobuf.c | 17 +++++++++++++---- libavformat/version.h | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index b41dadee8d..08fec7c234 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2021-04-18 - xxxxxxxxxx - lavf 58.78.100 - avio.h + Add avio_vprintf(), similar to avio_printf(). + 2021-03-21 - xxxxxxxxxx - lavu 56.72.100 - frame.h Deprecated av_get_colorspace_name(). Use av_color_space_name() instead. diff --git a/libavformat/avio.h b/libavformat/avio.h index d022820a6e..24f6839522 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -571,6 +571,12 @@ int64_t avio_size(AVIOContext *s); */ int avio_feof(AVIOContext *s); +/** + * Writes a formatted string to the context taking a va_list. + * @return number of bytes written, < 0 on error. + */ +int avio_vprintf(AVIOContext *s, const char *fmt, va_list ap); + /** * Writes a formatted string to the context. * @return number of bytes written, < 0 on error. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 518cb11129..289da796c8 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1196,15 +1196,12 @@ int avio_closep(AVIOContext **s) return ret; } -int avio_printf(AVIOContext *s, const char *fmt, ...) +int avio_vprintf(AVIOContext *s, const char *fmt, va_list ap) { - va_list ap; AVBPrint bp; av_bprint_init(&bp, 0, INT_MAX); - va_start(ap, fmt); av_vbprintf(&bp, fmt, ap); - va_end(ap); if (!av_bprint_is_complete(&bp)) { av_bprint_finalize(&bp, NULL); s->error = AVERROR(ENOMEM); @@ -1215,6 +1212,18 @@ int avio_printf(AVIOContext *s, const char *fmt, ...) return bp.len; } +int avio_printf(AVIOContext *s, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = avio_vprintf(s, fmt, ap); + va_end(ap); + + return ret; +} + void avio_print_string_array(AVIOContext *s, const char *strings[]) { for(; *strings; strings++) diff --git a/libavformat/version.h b/libavformat/version.h index ced5600034..b6023f9d2e 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 77 +#define LIBAVFORMAT_VERSION_MINOR 78 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From patchwork Sun Apr 18 21:30:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 26973 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp564806yba; Sun, 18 Apr 2021 14:39:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgkGBLHhxLWGbQ7kXXDvhYQHPoi1Hg2B7pCUcHX1e4BrrV7YOmEIuVnBc/2oWkZZ4Foanj X-Received: by 2002:a17:906:ae84:: with SMTP id md4mr19214154ejb.432.1618781960213; Sun, 18 Apr 2021 14:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618781960; cv=none; d=google.com; s=arc-20160816; b=vm7k9WE0xg+5Mt6M1rHfoSyzuNKNKCp1dCAJ1RGbCAvYyCLL0BUEbdHPujjshzFNwh 92c/dDoQDe9sAHU2UicDyMcCIOg/RCbwCBU5SgvsmWxcqzvl55+OoAPFM/LAZFkYAx28 7oJM4cv+qkhZpSu75mADTHEYF8xGnHWDIg7lMtJjbsR9Cdq92Ar+RKfLCKTD6sfI6Wom Zpo5XRwI6EkHoqN0ECHt++eFKLTGpoviUxyIc2iHD6zH+OPgTP3QkXa583uBeePXoigq i2thNzdfCHg9g6FNJqyjpPZVhLMSuC7XdCB4q+dV1uNaHaZk73B6j3hcFvr/ohCUyLVB gXSA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=3BWRRveY7CvCGgMpD22BHMele9CC+TJZX5MP6m+75Bo=; b=Fg13qq3UqrLS5xyHKBTQPk/lmjG1d1K+BbLn4UGrrsgRnm3quSb2m2W7A7iZEoHRf+ Xp6vUnfEm1ifIzmUqpsywltkWLGpdcNtA99cYpwAb3VJJDC0Itf4MYptkn1TvLGoF1nR cDqByzX0jbYZqKIocinIBNgMvK8vs6+Z19iLy8TUE3l5Udra/NaPnMaMhnUTSork6R9m Q9rZy3OSqYzHtx1FRfbY/e0p8lGMU4udfoIIbIiLWzdoyVm6K1fw2xmZMUwylXRYt+9x SpUo3S1hmHSCKdXa+zGB177pjhd/825fhoFo9OC+atKANo4jQG9Ps4mvDSL2URCTfk+k AMkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=hgSvUyfo; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id co3si6871357edb.456.2021.04.18.14.39.19; Sun, 18 Apr 2021 14:39:20 -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=@gmail.com header.s=20161025 header.b=hgSvUyfo; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C2FC680775; Mon, 19 Apr 2021 00:39:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02908680135 for ; Mon, 19 Apr 2021 00:39:10 +0300 (EEST) Received: by mail-ed1-f42.google.com with SMTP id d21so18249898edv.9 for ; Sun, 18 Apr 2021 14:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hWRB2fgMYlQuUddWkkgCoyAZXfVpqGtGyXUdnIEjK20=; b=hgSvUyfoQQwnjLbuLUogKFAXPexSWB/26bPEGPOB0wnfRYucHRWLGh5JBGR1RdBKIs y91QG5z9zUMYmbiX4hj/nVC8ZldJj80RaidnhyT8KYz7w1Tk4ibwLqYgCOU09IBg42ZO 1d1vP4z5pf9oDjkv7npjnWP6Kn4y6oV6aOnwyRe72DMAiBgRLbBttV4cD7KpP3ud73/R jNY3oALX+QQcUbADkor/mtHcYv5zdmbx3AaMQ5uKMFIrMJaOc0YzCiLeVmu/QPMjGQvH /mEKgOx6t3qzED64CbfjSNY0Sghij/asdQbPHIVnTqscab78lpqeq0/C2zt6IjqyAi4j baYw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=hWRB2fgMYlQuUddWkkgCoyAZXfVpqGtGyXUdnIEjK20=; b=scxZ1EPgboe/t86ybkJDXw+XfKr53JCO/D7mTC9GSJsC8sJTPQZtgDri8PUz8YiL08 SbvzGEzWzobOLryShZMK4GLbR+Ufj+fwame2MFc5Hr2areHVAs9PJkRr6CdGAnMd4bAF Jy6rZZ0U1Si8dak2mY0y7EeSOw1CfXcybjgfYwhU8Vx0lgSn+hLv3woDX47k6le57rch X8Ojod6I3VxEpKbF4BxvCk9WUNBG6At5MB0jrgp8eGwgi0YL3tgezHvOlqW+WQep/wAJ gSQln7fES++Onh6wV6tyo0tnJ2DNT1joGb/w/J1ZWsSpgzgDfMt0SSPxRYADfIRmXYF+ tx8w== X-Gm-Message-State: AOAM5319m11ZD79gRZAs9QJmwkRkF1SZo043JQya5zZRRI0alleyM/RI 082B9IMQxsX0yEtTalB2kK+Bl/7e0q4= X-Received: by 2002:a05:6402:1ad9:: with SMTP id ba25mr22108142edb.264.1618781460676; Sun, 18 Apr 2021 14:31:00 -0700 (PDT) Received: from mariano (dynamic-adsl-78-14-94-55.clienti.tiscali.it. [78.14.94.55]) by smtp.gmail.com with ESMTPSA id n11sm9160832ejg.43.2021.04.18.14.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Apr 2021 14:31:00 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id B045ABFA61; Sun, 18 Apr 2021 23:30:58 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sun, 18 Apr 2021 23:30:58 +0200 Message-Id: <20210418213058.24475-2-stefasab@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210418213058.24475-1-stefasab@gmail.com> References: <20210418213058.24475-1-stefasab@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] ffprobe: add -o option 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: Stefano Sabatini Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oOWNBdztK94R Content-Length: 20919 This enables printing to a resource specified with -o OUTPUT. Address issue: http://trac.ffmpeg.org/ticket/8024 --- doc/ffprobe.texi | 7 ++ fftools/ffprobe.c | 174 ++++++++++++++++++++++++++++++---------------- 2 files changed, 120 insertions(+), 61 deletions(-) diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi index d7fab4ff40..f57b46a8fd 100644 --- a/doc/ffprobe.texi +++ b/doc/ffprobe.texi @@ -28,6 +28,9 @@ If a url is specified in input, ffprobe will try to open and probe the url content. If the url cannot be opened or recognized as a multimedia file, a positive exit code is returned. +If no output is specified as output with @option{o} ffprobe will write +to stdout. + ffprobe may be employed both as a standalone application or in combination with a textual filter, which may perform more sophisticated processing, e.g. statistical processing or plotting. @@ -342,6 +345,10 @@ on the specific build. @item -i @var{input_url} Read @var{input_url}. +@item -o @var{output_url} +Write output to @var{output_url}. If not specified, the output is sent +to stdout. + @end table @c man end diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 38462e1ff3..cdec261f29 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -258,6 +258,7 @@ static const OptionDef *options; static const char *input_filename; static const char *print_input_filename; static AVInputFormat *iformat = NULL; +static const char *output_filename = NULL; static struct AVHashContext *hash; @@ -453,6 +454,7 @@ typedef struct Writer { struct WriterContext { const AVClass *class; ///< class of the writer const Writer *writer; ///< the Writer of which this is an instance + AVIOContext *avio; /// the I/O context used to write char *name; ///< name of this writer instance void *priv; ///< private data for use by the filter @@ -530,6 +532,10 @@ static void writer_close(WriterContext **wctx) av_opt_free((*wctx)->priv); av_freep(&((*wctx)->priv)); av_opt_free(*wctx); + if ((*wctx)->avio) { + avio_flush((*wctx)->avio); + avio_close((*wctx)->avio); + } av_freep(wctx); } @@ -543,7 +549,7 @@ static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size) static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, - const struct section *sections, int nb_sections) + const struct section *sections, int nb_sections, const char *url) { int i, ret = 0; @@ -614,6 +620,9 @@ static int writer_open(WriterContext **wctx, const Writer *writer, const char *a } } + if ((ret = avio_open(&(*wctx)->avio, url, AVIO_FLAG_WRITE)) < 0) + goto fail; + for (i = 0; i < SECTION_MAX_NB_LEVELS; i++) av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED); @@ -879,6 +888,25 @@ static void writer_print_integers(WriterContext *wctx, const char *name, av_bprint_finalize(&bp, NULL); } +static inline void writer_w8(WriterContext *wctx, int b) +{ + avio_w8(wctx->avio, b); +} + +static inline void writer_put_str(WriterContext *wctx, const char *str) +{ + avio_put_str(wctx->avio, str); +} + +static inline void writer_printf(WriterContext *wctx, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + avio_vprintf(wctx->avio, fmt, ap); + va_end(ap); +} + #define MAX_REGISTERED_WRITERS_NB 64 static const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1]; @@ -973,7 +1001,7 @@ static void default_print_section_header(WriterContext *wctx) return; if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) - printf("[%s]\n", upcase_string(buf, sizeof(buf), section->name)); + writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name)); } static void default_print_section_footer(WriterContext *wctx) @@ -986,7 +1014,7 @@ static void default_print_section_footer(WriterContext *wctx) return; if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) - printf("[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); + writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); } static void default_print_str(WriterContext *wctx, const char *key, const char *value) @@ -994,8 +1022,8 @@ static void default_print_str(WriterContext *wctx, const char *key, const char * DefaultContext *def = wctx->priv; if (!def->nokey) - printf("%s%s=", wctx->section_pbuf[wctx->level].str, key); - printf("%s\n", value); + writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(wctx, "%s\n", value); } static void default_print_int(WriterContext *wctx, const char *key, long long int value) @@ -1003,8 +1031,8 @@ static void default_print_int(WriterContext *wctx, const char *key, long long in DefaultContext *def = wctx->priv; if (!def->nokey) - printf("%s%s=", wctx->section_pbuf[wctx->level].str, key); - printf("%lld\n", value); + writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(wctx, "%lld\n", value); } static const Writer default_writer = { @@ -1143,11 +1171,11 @@ static void compact_print_section_header(WriterContext *wctx) if (parent_section && compact->has_nested_elems[wctx->level-1] && (section->flags & SECTION_FLAG_IS_ARRAY)) { compact->terminate_line[wctx->level-1] = 0; - printf("\n"); + writer_w8(wctx, '\n'); } if (compact->print_section && !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) - printf("%s%c", section->name, compact->item_sep); + writer_printf(wctx, "%s%c", section->name, compact->item_sep); } } @@ -1158,7 +1186,7 @@ static void compact_print_section_footer(WriterContext *wctx) if (!compact->nested_section[wctx->level] && compact->terminate_line[wctx->level] && !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) - printf("\n"); + writer_w8(wctx, '\n'); } static void compact_print_str(WriterContext *wctx, const char *key, const char *value) @@ -1166,11 +1194,11 @@ static void compact_print_str(WriterContext *wctx, const char *key, const char * CompactContext *compact = wctx->priv; AVBPrint buf; - if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep); + if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep); if (!compact->nokey) - printf("%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx)); + writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx)); av_bprint_finalize(&buf, NULL); } @@ -1178,10 +1206,10 @@ static void compact_print_int(WriterContext *wctx, const char *key, long long in { CompactContext *compact = wctx->priv; - if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep); + if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep); if (!compact->nokey) - printf("%s%s=", wctx->section_pbuf[wctx->level].str, key); - printf("%lld", value); + writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(wctx, "%lld", value); } static const Writer compact_writer = { @@ -1324,7 +1352,7 @@ static void flat_print_section_header(WriterContext *wctx) static void flat_print_int(WriterContext *wctx, const char *key, long long int value) { - printf("%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value); + writer_printf(wctx, "%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value); } static void flat_print_str(WriterContext *wctx, const char *key, const char *value) @@ -1332,11 +1360,11 @@ static void flat_print_str(WriterContext *wctx, const char *key, const char *val FlatContext *flat = wctx->priv; AVBPrint buf; - printf("%s", wctx->section_pbuf[wctx->level].str); + writer_put_str(wctx, wctx->section_pbuf[wctx->level].str); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - printf("%s=", flat_escape_key_str(&buf, key, flat->sep)); + writer_printf(wctx, "%s=", flat_escape_key_str(&buf, key, flat->sep)); av_bprint_clear(&buf); - printf("\"%s\"\n", flat_escape_value_str(&buf, value)); + writer_printf(wctx, "\"%s\"\n", flat_escape_value_str(&buf, value)); av_bprint_finalize(&buf, NULL); } @@ -1406,12 +1434,12 @@ static void ini_print_section_header(WriterContext *wctx) av_bprint_clear(buf); if (!parent_section) { - printf("# ffprobe output\n\n"); + writer_put_str(wctx, "# ffprobe output\n\n"); return; } if (wctx->nb_item[wctx->level-1]) - printf("\n"); + writer_w8(wctx, '\n'); av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str); if (ini->hierarchical || @@ -1426,7 +1454,7 @@ static void ini_print_section_header(WriterContext *wctx) } if (!(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) - printf("[%s]\n", buf->str); + writer_printf(wctx, "[%s]\n", buf->str); } static void ini_print_str(WriterContext *wctx, const char *key, const char *value) @@ -1434,15 +1462,15 @@ static void ini_print_str(WriterContext *wctx, const char *key, const char *valu AVBPrint buf; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - printf("%s=", ini_escape_str(&buf, key)); + writer_printf(wctx, "%s=", ini_escape_str(&buf, key)); av_bprint_clear(&buf); - printf("%s\n", ini_escape_str(&buf, value)); + writer_printf(wctx, "%s\n", ini_escape_str(&buf, value)); av_bprint_finalize(&buf, NULL); } static void ini_print_int(WriterContext *wctx, const char *key, long long int value) { - printf("%s=%lld\n", key, value); + writer_printf(wctx, "%s=%lld\n", key, value); } static const Writer ini_writer = { @@ -1505,7 +1533,7 @@ static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx return dst->str; } -#define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ') +#define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ') static void json_print_section_header(WriterContext *wctx) { @@ -1516,10 +1544,10 @@ static void json_print_section_header(WriterContext *wctx) wctx->section[wctx->level-1] : NULL; if (wctx->level && wctx->nb_item[wctx->level-1]) - printf(",\n"); + writer_put_str(wctx, ",\n"); if (section->flags & SECTION_FLAG_IS_WRAPPER) { - printf("{\n"); + writer_put_str(wctx, "{\n"); json->indent_level++; } else { av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); @@ -1528,17 +1556,17 @@ static void json_print_section_header(WriterContext *wctx) json->indent_level++; if (section->flags & SECTION_FLAG_IS_ARRAY) { - printf("\"%s\": [\n", buf.str); + writer_printf(wctx, "\"%s\": [\n", buf.str); } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) { - printf("\"%s\": {%s", buf.str, json->item_start_end); + writer_printf(wctx, "\"%s\": {%s", buf.str, json->item_start_end); } else { - printf("{%s", json->item_start_end); + writer_printf(wctx, "{%s", json->item_start_end); /* this is required so the parser can distinguish between packets and frames */ if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) { if (!json->compact) JSON_INDENT(); - printf("\"type\": \"%s\"", section->name); + writer_printf(wctx, "\"type\": \"%s\"", section->name); } } av_bprint_finalize(&buf, NULL); @@ -1552,18 +1580,18 @@ static void json_print_section_footer(WriterContext *wctx) if (wctx->level == 0) { json->indent_level--; - printf("\n}\n"); + writer_put_str(wctx, "\n}\n"); } else if (section->flags & SECTION_FLAG_IS_ARRAY) { - printf("\n"); + writer_w8(wctx, '\n'); json->indent_level--; JSON_INDENT(); - printf("]"); + writer_w8(wctx, ']'); } else { - printf("%s", json->item_start_end); + writer_put_str(wctx, json->item_start_end); json->indent_level--; if (!json->compact) JSON_INDENT(); - printf("}"); + writer_w8(wctx, '}'); } } @@ -1573,9 +1601,9 @@ static inline void json_print_item_str(WriterContext *wctx, AVBPrint buf; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - printf("\"%s\":", json_escape_str(&buf, key, wctx)); + writer_printf(wctx, "\"%s\":", json_escape_str(&buf, key, wctx)); av_bprint_clear(&buf); - printf(" \"%s\"", json_escape_str(&buf, value, wctx)); + writer_printf(wctx, " \"%s\"", json_escape_str(&buf, value, wctx)); av_bprint_finalize(&buf, NULL); } @@ -1586,7 +1614,7 @@ static void json_print_str(WriterContext *wctx, const char *key, const char *val wctx->section[wctx->level-1] : NULL; if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) - printf("%s", json->item_sep); + writer_put_str(wctx, json->item_sep); if (!json->compact) JSON_INDENT(); json_print_item_str(wctx, key, value); @@ -1600,12 +1628,12 @@ static void json_print_int(WriterContext *wctx, const char *key, long long int v AVBPrint buf; if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) - printf("%s", json->item_sep); + writer_put_str(wctx, json->item_sep); if (!json->compact) JSON_INDENT(); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - printf("\"%s\": %lld", json_escape_str(&buf, key, wctx), value); + writer_printf(wctx, "\"%s\": %lld", json_escape_str(&buf, key, wctx), value); av_bprint_finalize(&buf, NULL); } @@ -1672,7 +1700,7 @@ static av_cold int xml_init(WriterContext *wctx) return 0; } -#define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') +#define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ') static void xml_print_section_header(WriterContext *wctx) { @@ -1686,8 +1714,8 @@ static void xml_print_section_header(WriterContext *wctx) "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' " "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'"; - printf("\n"); - printf("<%sffprobe%s>\n", + writer_put_str(wctx, "\n"); + writer_printf(wctx, "<%sffprobe%s>\n", xml->fully_qualified ? "ffprobe:" : "", xml->fully_qualified ? qual : ""); return; @@ -1695,20 +1723,20 @@ static void xml_print_section_header(WriterContext *wctx) if (xml->within_tag) { xml->within_tag = 0; - printf(">\n"); + writer_put_str(wctx, ">\n"); } if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { xml->indent_level++; } else { if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) && wctx->level && wctx->nb_item[wctx->level-1]) - printf("\n"); + writer_w8(wctx, '\n'); xml->indent_level++; if (section->flags & SECTION_FLAG_IS_ARRAY) { - XML_INDENT(); printf("<%s>\n", section->name); + XML_INDENT(); writer_printf(wctx, "<%s>\n", section->name); } else { - XML_INDENT(); printf("<%s ", section->name); + XML_INDENT(); writer_printf(wctx, "<%s ", section->name); xml->within_tag = 1; } } @@ -1720,15 +1748,15 @@ static void xml_print_section_footer(WriterContext *wctx) const struct section *section = wctx->section[wctx->level]; if (wctx->level == 0) { - printf("\n", xml->fully_qualified ? "ffprobe:" : ""); + writer_printf(wctx, "\n", xml->fully_qualified ? "ffprobe:" : ""); } else if (xml->within_tag) { xml->within_tag = 0; - printf("/>\n"); + writer_put_str(wctx, "/>\n"); xml->indent_level--; } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { xml->indent_level--; } else { - XML_INDENT(); printf("\n", section->name); + XML_INDENT(); writer_printf(wctx, "\n", section->name); xml->indent_level--; } } @@ -1745,20 +1773,20 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu XML_INDENT(); av_bprint_escape(&buf, key, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - printf("<%s key=\"%s\"", - section->element_name, buf.str); + writer_printf(wctx, "<%s key=\"%s\"", + section->element_name, buf.str); av_bprint_clear(&buf); av_bprint_escape(&buf, value, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - printf(" value=\"%s\"/>\n", buf.str); + writer_printf(wctx, " value=\"%s\"/>\n", buf.str); } else { if (wctx->nb_item[wctx->level]) - printf(" "); + writer_w8(wctx, ' '); av_bprint_escape(&buf, value, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - printf("%s=\"%s\"", key, buf.str); + writer_printf(wctx, "%s=\"%s\"", key, buf.str); } av_bprint_finalize(&buf, NULL); @@ -1767,8 +1795,8 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu static void xml_print_int(WriterContext *wctx, const char *key, long long int value) { if (wctx->nb_item[wctx->level]) - printf(" "); - printf("%s=\"%lld\"", key, value); + writer_w8(wctx, ' '); + writer_printf(wctx, "%s=\"%lld\"", key, value); } static Writer xml_writer = { @@ -3380,6 +3408,25 @@ static int opt_input_file_i(void *optctx, const char *opt, const char *arg) return 0; } +static void opt_output_file(void *optctx, const char *arg) +{ + if (output_filename) { + av_log(NULL, AV_LOG_ERROR, + "Argument '%s' provided as output filename, but '%s' was already specified.\n", + arg, output_filename); + exit_program(1); + } + if (!strcmp(arg, "-")) + arg = "pipe:"; + output_filename = arg; +} + +static int opt_output_file_o(void *optctx, const char *opt, const char *arg) +{ + opt_output_file(optctx, arg); + return 0; +} + static int opt_print_filename(void *optctx, const char *opt, const char *arg) { print_input_filename = arg; @@ -3644,6 +3691,7 @@ static const OptionDef real_options[] = { { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" }, { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" }, { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"}, + { "o", HAS_ARG, {.func_arg = opt_output_file_o}, "write to specified output", "output_file"}, { "print_filename", HAS_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"}, { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info }, "read and decode the streams to fill missing information with heuristics" }, @@ -3771,8 +3819,12 @@ int main(int argc, char **argv) goto end; } + if (!output_filename) { + output_filename = "pipe:"; + } + if ((ret = writer_open(&wctx, w, w_args, - sections, FF_ARRAY_ELEMS(sections))) >= 0) { + sections, FF_ARRAY_ELEMS(sections), output_filename)) >= 0) { if (w == &xml_writer) wctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;