From patchwork Fri Dec 27 21:14:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17007 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 86FD844B0EA for ; Fri, 27 Dec 2019 23:14:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5AEF668AD9A; Fri, 27 Dec 2019 23:14:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A0F768AD08 for ; Fri, 27 Dec 2019 23:14:37 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id F0B63E3E4E; Fri, 27 Dec 2019 22:14:36 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XBW0Pl5qRIJY; Fri, 27 Dec 2019 22:14:34 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3FDC6E1617; Fri, 27 Dec 2019 22:14:32 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Dec 2019 22:14:11 +0100 Message-Id: <20191227211411.30293-8-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20191227211411.30293-1-cus@passwd.hu> References: <20191227211411.30293-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 8/8] avformat/img2enc: add support for specifying protocol options X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- doc/muxers.texi | 11 +++++++++++ libavformat/img2enc.c | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index fb5c9bc4c0..a1f801c28d 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1193,6 +1193,11 @@ overwritten with new images. Default value is 0. @item strftime If set to 1, expand the filename with date and time information from @code{strftime()}. Default value is 0. + +@item protocol_opts @var{options_list} +Set protocol options as a :-separated list of key=value parameters. Values +containing the @code{:} special character must be escaped. + @end table @subsection Examples @@ -1235,6 +1240,12 @@ You can set the file name with current frame's PTS: ffmpeg -f v4l2 -r 1 -i /dev/video0 -copyts -f image2 -frame_pts true %d.jpg" @end example +A more complex example is to publish contents of your desktop directly to a +WebDAV server every second: +@example +ffmpeg -f x11grab -r 1 -framerate 1 -video_size hd1080 -i :0.0 -qscale 6 -update 1 -protocol_opts method=PUT http://example.com/desktop.jpg +@end example + @section matroska Matroska container muxer. diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index 39398f37a3..0ad4ee11d7 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/avassert.h" #include "libavutil/avstring.h" +#include "libavutil/dict.h" #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" @@ -44,6 +45,7 @@ typedef struct VideoMuxData { int frame_pts; const char *muxer; int use_rename; + AVDictionary *protocol_opts; } VideoMuxData; static int write_header(AVFormatContext *s) @@ -133,6 +135,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format); int ret, i; int nb_renames = 0; + AVDictionary *options = NULL; if (img->update) { av_strlcpy(filename, img->path, sizeof(filename)); @@ -161,13 +164,19 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } for (i = 0; i < 4; i++) { + av_dict_copy(&options, img->protocol_opts, 0); snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename); av_strlcpy(img->target[i], filename, sizeof(img->target[i])); - if (s->io_open(s, &pb[i], img->use_rename ? img->tmp[i] : filename, AVIO_FLAG_WRITE, NULL) < 0) { + if (s->io_open(s, &pb[i], img->use_rename ? img->tmp[i] : filename, AVIO_FLAG_WRITE, &options) < 0) { av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->use_rename ? img->tmp[i] : filename); ret = AVERROR(EIO); goto fail; } + if (options) { + av_log(s, AV_LOG_ERROR, "Could not recognize some protocol options\n"); + ret = AVERROR(EINVAL); + goto fail; + } if (!img->split_planes || i+1 >= desc->nb_components) break; @@ -211,6 +220,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) return 0; fail: + av_dict_free(&options); for (i = 0; i < FF_ARRAY_ELEMS(pb); i++) if (pb[i]) ff_format_io_close(s, &pb[i]); @@ -236,6 +246,7 @@ static const AVOption muxoptions[] = { { "strftime", "use strftime for filename", OFFSET(use_strftime), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "frame_pts", "use current frame pts for filename", OFFSET(frame_pts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, + { "protocol_opts", "specify protocol options for the opened files", OFFSET(protocol_opts), AV_OPT_TYPE_DICT, {0}, 0, 0, ENC }, { NULL }, };