From patchwork Sun Oct 22 11:56:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 44312 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1b28:b0:15d:8365:d4b8 with SMTP id ch40csp845102pzb; Sun, 22 Oct 2023 04:56:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPSC5NC9Qd/SBplTcnMuiy8/4V0ExmzzgtpjGodNh3p0M4qji09W1JjJHrHEwTLOtLhZ8b X-Received: by 2002:a17:907:9710:b0:9a1:e0b1:e919 with SMTP id jg16-20020a170907971000b009a1e0b1e919mr6783511ejc.4.1697975798155; Sun, 22 Oct 2023 04:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697975798; cv=none; d=google.com; s=arc-20160816; b=QLif9wpLWLaL33pVB77kdF8zb/Qy9xMdjQG7EAie3yGjuU1DlGenaGZ3Xs9vuQBvRH RzCJ1NmoAtqC1KiwnUeGu+xdWooxJWwjG8x7p8dLLrMuNcHSYLNPo7Z44mg4uFNyY/Zq cqgmG4C+yWd+ZETB4dZySSchtA4eSo18nvLbdfWNgKp+nOD+GHpFt4Q48tKgUrdnUQoq jbEQ62h8K0gP+tZWwahpSq9CMGTmHe2QNCnrJvbSYC6RJZ3fRiSkYR3vru1GS8E9IRv5 y4tElP/dnUGpXuJPACgdAfVgO73IUnLwxWZ9Y0Q3toqTDEY+KRDZe61Cw/sCms0aDO+P ZDNg== 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:message-id:date:to:from :delivered-to; bh=TrqmGPK5dVnJbLgKUXqm+72dycMhmtFwt9oOSJy1Ino=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=xPV7IniBNVS266KT/38aWMcdBBWoEV4z1gsDd2Hf0vfDtkYcn3f6VfwLTIMx10uEnQ 2kgY3PNr7JxIYKpXaKPRrT09ysgz5tCcwIfIgDB6xkZep+aEf5jiRMOoF+1hMB20DLFG qEk1PnBuIZS7kbmhQEL1mJxvXKuJ8Xz7oMqzDBTVaIxgzOFdnDwPhYoXoRzhAUbztcBP oJHLAPpBFTPxfpidM52Ve3zNon5qLKFHQF7Qd5DfDKZAuF5+dQSWypMBTfGwJIKFkax/ rjcXHPPIc3sCTW0DvS6ZgTrRKXbTeukfEIiec/8lHxp/1/Pp5Rq4FH7iVcP1yDbsJVxq fo6A== 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 v5-20020a1709063bc500b009b2ca10970fsi2381430ejf.531.2023.10.22.04.56.37; Sun, 22 Oct 2023 04:56:38 -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 DB18B68C79C; Sun, 22 Oct 2023 14:56:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67CD068C79C for ; Sun, 22 Oct 2023 14:56:26 +0300 (EEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4SCxcS0svZz9sWc for ; Sun, 22 Oct 2023 13:56:24 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Oct 2023 17:26:08 +0530 Message-Id: <20231022115608.766-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avfilter/vidstab: add option for file format specification 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: PWa6HZTKZk5Y The vidstab library added support in Nov 2020 for writing/reading the transforms data in binary in addition to ASCII. The library default was changed to binary format but no changes were made to the AVfilters resulting in data file for writing or reading being always opened as text. This effectively broke the filters. Option added to vidstabdetect to specify file format and open files in both filters with the correct attributes. --- doc/filters.texi | 13 +++++++++++++ libavfilter/vf_vidstabdetect.c | 15 ++++++++++++++- libavfilter/vf_vidstabtransform.c | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index f5032ddf74..cc5d0d3f12 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are counted starting from 1. Show fields and transforms in the resulting frames. It accepts an integer in the range 0-2. Default value is 0, which disables any visualization. + +@item fileformat +Format for the transforms data file to be written. +Acceptable values are + +@table @samp +@item ascii +Human-readable plain text + +@item binary +Binary format, roughly 40% smaller than @code{ascii}. (@emph{default}) +@end table + @end table @subsection Examples diff --git a/libavfilter/vf_vidstabdetect.c b/libavfilter/vf_vidstabdetect.c index a2c6d89503..aa050afab9 100644 --- a/libavfilter/vf_vidstabdetect.c +++ b/libavfilter/vf_vidstabdetect.c @@ -40,6 +40,7 @@ typedef struct StabData { VSMotionDetectConfig conf; char *result; + int fileformat; FILE *f; } StabData; @@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = { {"show", "0: draw nothing; 1,2: show fields and transforms", OFFSETC(show), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, FLAGS}, {"tripod", "virtual tripod mode (if >0): motion is compared to a reference" " reference frame (frame # is the value)", OFFSETC(virtualTripod), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS}, +#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION + { "fileformat", "transforms data file format", OFFSET(fileformat), AV_OPT_TYPE_INT, {.i64 = BINARY_SERIALIZATION_MODE}, ASCII_SERIALIZATION_MODE, BINARY_SERIALIZATION_MODE, FLAGS, "file_format"}, + { "ascii", "ASCII text", 0, AV_OPT_TYPE_CONST, {.i64 = ASCII_SERIALIZATION_MODE }, 0, 0, FLAGS, "file_format"}, + { "binary", "binary", 0, AV_OPT_TYPE_CONST, {.i64 = BINARY_SERIALIZATION_MODE}, 0, 0, FLAGS, "file_format"}, +#endif {NULL} }; @@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink) VSFrameInfo fi; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR; + const char *file_mode = "w"; + +#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION + md->serializationMode = s->fileformat; + if (s->fileformat == BINARY_SERIALIZATION_MODE) + file_mode = "wb"; +#endif vsFrameInfoInit(&fi, inlink->w, inlink->h, ff_av2vs_pixfmt(ctx, inlink->format)); @@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink) av_log(ctx, AV_LOG_INFO, " show = %d\n", s->conf.show); av_log(ctx, AV_LOG_INFO, " result = %s\n", s->result); - s->f = avpriv_fopen_utf8(s->result, "w"); + s->f = avpriv_fopen_utf8(s->result, file_mode); if (s->f == NULL) { av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", s->result); return AVERROR(EINVAL); diff --git a/libavfilter/vf_vidstabtransform.c b/libavfilter/vf_vidstabtransform.c index 8a66a463b4..f49d302b80 100644 --- a/libavfilter/vf_vidstabtransform.c +++ b/libavfilter/vf_vidstabtransform.c @@ -193,7 +193,7 @@ static int config_input(AVFilterLink *inlink) av_log(ctx, AV_LOG_INFO, " zoomspeed = %g\n", tc->conf.zoomSpeed); av_log(ctx, AV_LOG_INFO, " interpol = %s\n", getInterpolationTypeName(tc->conf.interpolType)); - f = avpriv_fopen_utf8(tc->input, "r"); + f = avpriv_fopen_utf8(tc->input, "rb"); if (!f) { int ret = AVERROR(errno); av_log(ctx, AV_LOG_ERROR, "cannot open input file %s\n", tc->input);