[FFmpeg-devel] [PATCH] avfilter: add filmgrain filter

2022-02-18 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_filmgrain.c | 489 +
 3 files changed, 491 insertions(+)
 create mode 100644 libavfilter/vf_filmgrain.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 56d33e6480..39d98881bb 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -283,6 +283,7 @@ OBJS-$(CONFIG_FIELDHINT_FILTER)  += 
vf_fieldhint.o
 OBJS-$(CONFIG_FIELDMATCH_FILTER) += vf_fieldmatch.o
 OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o
 OBJS-$(CONFIG_FILLBORDERS_FILTER)+= vf_fillborders.o
+OBJS-$(CONFIG_FILMGRAIN_FILTER)  += vf_filmgrain.o
 OBJS-$(CONFIG_FIND_RECT_FILTER)  += vf_find_rect.o lavfutils.o
 OBJS-$(CONFIG_FLOODFILL_FILTER)  += vf_floodfill.o
 OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index f5caee3a62..20e889880f 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -266,6 +266,7 @@ extern const AVFilter ff_vf_fieldhint;
 extern const AVFilter ff_vf_fieldmatch;
 extern const AVFilter ff_vf_fieldorder;
 extern const AVFilter ff_vf_fillborders;
+extern const AVFilter ff_vf_filmgrain;
 extern const AVFilter ff_vf_find_rect;
 extern const AVFilter ff_vf_flip_vulkan;
 extern const AVFilter ff_vf_floodfill;
diff --git a/libavfilter/vf_filmgrain.c b/libavfilter/vf_filmgrain.c
new file mode 100644
index 00..c87118dad0
--- /dev/null
+++ b/libavfilter/vf_filmgrain.c
@@ -0,0 +1,489 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/random_seed.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+#define STRETCH_3D (-1.f / 6.f)
+#define SQUISH_3D  (1.f / 3.f)
+#define NORM_3D(1.f / 103.f)
+
+typedef struct Contribution3 {
+float dx, dy, dz;
+int xsb, ysb, zsb;
+struct Contribution3 *next;
+} Contribution3;
+
+typedef struct OpenSimplexNoise {
+uint8_t perm[256];
+uint8_t perm3D[256];
+
+Contribution3 *lookup3D[2048];
+Contribution3 *contributions3D[24];
+} OpenSimplexNoise;
+
+typedef struct ThreadData {
+AVFrame *in, *out;
+int plane;
+float strength;
+} ThreadData;
+
+typedef struct FilmGrainContext {
+const AVClass *class;
+
+int depth;
+int nb_planes;
+int linesize[4];
+int planewidth[4];
+int planeheight[4];
+
+float size;
+float speed;
+float strength;
+float bias;
+int planes;
+
+int64_t seed[4];
+
+int (*grain_plane_slice)(AVFilterContext *ctx, ThreadData *td, int jobnr, 
int nb_jobs, int p, int max);
+
+OpenSimplexNoise osn[4];
+} FilmGrainContext;
+
+#define OFFSET(x) offsetof(FilmGrainContext, x)
+#define FLAGS 
AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
+
+static const AVOption filmgrain_options[] = {
+{ "size", "set grain size",OFFSET(size), 
AV_OPT_TYPE_FLOAT, {.dbl=1600},20, 6400,FLAGS },
+{ "strength", "set grain strength",OFFSET(strength), 
AV_OPT_TYPE_FLOAT, {.dbl=.25}, 0,  1,   FLAGS },
+{ "speed","set grain change speed",OFFSET(speed),
AV_OPT_TYPE_FLOAT, {.dbl=1},   0,  10,  FLAGS },
+{ "bias", "set grain bias",OFFSET(bias), 
AV_OPT_TYPE_FLOAT, {.dbl=0},  -1,  1,   FLAGS },
+{ "planes",   "set planes to filter",  OFFSET(planes),   AV_OPT_TYPE_INT,  
 {.i64=1},   0,  0xF, FLAGS },
+{ "0seed","set random seed #0",OFFSET(seed[0]),  
AV_OPT_TYPE_INT64, {.i64=-1}, -1,  UINT_MAX, FLAGS },
+{ "1seed","set random seed #1",OFFSET(seed[1]),  
AV_OPT_TYPE_INT64, {.i64=-1}, -1,  UINT_MAX, FLAGS },
+{ "2seed","set random seed #2",OFFSET(seed[2]),  
AV_OPT_TYPE_INT64, {.i64=-1}, -1,  UINT_MAX, FLAGS },
+{ "3seed","set random seed #3",OFFSET(seed[3]),  
AV_OPT_TYPE_INT64, {.i64=-1}, -1,  UINT_MAX, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(filmgrain);
+
+static const enum AVPixelFormat pixel_fmts[] =

[FFmpeg-devel] [PATCH] avfilter/vf_fps: only give frame as soon as possible if really requested by output

2022-02-18 Thread Paul B Mahol
Fixes OOM in #9081.

Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_fps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 99e679441e..1a68d519fb 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -351,7 +351,7 @@ static int activate(AVFilterContext *ctx)
 if (s->frames_count > 0) {
 ret = write_frame(ctx, s, outlink, &again);
 /* Couldn't generate a frame, so schedule us to perform another step */
-if (again)
+if (again && ff_outlink_frame_wanted(outlink))
 ff_filter_set_ready(ctx, 100);
 return ret;
 }
-- 
2.33.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/5] avformat/mov: reindent after previous commit

2022-02-18 Thread Clément Bœsch
---
 libavformat/mov.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 919dd940c0..09cc4e8ad7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8570,12 +8570,12 @@ static int mov_seek_stream(AVFormatContext *s, AVStream 
*st, int64_t timestamp,
 return ret;
 
 for (;;) {
-sample = av_index_search_timestamp(st, timestamp, flags);
-av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", 
st->index, timestamp, sample);
-if (sample < 0 && sti->nb_index_entries && timestamp < 
sti->index_entries[0].timestamp)
-sample = 0;
-if (sample < 0) /* not sure what to do */
-return AVERROR_INVALIDDATA;
+sample = av_index_search_timestamp(st, timestamp, flags);
+av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", 
st->index, timestamp, sample);
+if (sample < 0 && sti->nb_index_entries && timestamp < 
sti->index_entries[0].timestamp)
+sample = 0;
+if (sample < 0) /* not sure what to do */
+return AVERROR_INVALIDDATA;
 
 if (!sample || can_seek_to_key_sample(st, sample, timestamp))
 break;
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/5] avformat/mov: fix seeking with HEVC open GOP files

2022-02-18 Thread Clément Bœsch
This was tested with medias recorded from an iPhone XR and an iPhone 13.

Here is how a typical stream looks like in coding order:

┌┬─┬─┬──┐
│ sample | PTS | DTS | keyframe |
├┼─┼─┼──┤
┊┊ ┊ ┊  ┊
│   53   │ 560 │ 510 │No│
│   54   │ 540 │ 520 │No│
│   55   │ 530 │ 530 │No│
│   56   │ 550 │ 540 │No│
│   57   │ 600 │ 550 │Yes   │
│ * 58   │ 580 │ 560 │No│
│ * 59   │ 570 │ 570 │No│
│ * 60   │ 590 │ 580 │No│
│   61   │ 640 │ 590 │No│
│   62   │ 620 │ 600 │No│
┊┊ ┊ ┊  ┊

In composition/display order:

┌┬─┬─┬──┐
│ sample | PTS | DTS | keyframe |
├┼─┼─┼──┤
┊┊ ┊ ┊  ┊
│   55   │ 530 │ 530 │No│
│   54   │ 540 │ 520 │No│
│   56   │ 550 │ 540 │No│
│   53   │ 560 │ 510 │No│
│ * 59   │ 570 │ 570 │No│
│ * 58   │ 580 │ 560 │No│
│ * 60   │ 590 │ 580 │No│
│   57   │ 600 │ 550 │Yes   │
│   63   │ 610 │ 610 │No│
│   62   │ 620 │ 600 │No│
┊┊ ┊ ┊  ┊

Sample/frame 58, 59 and 60 are B-frames which actually depends on the
key frame (57). Here the key frame is not an IDR but a "CRA" (Clean
Random Access).

Initially, I thought I could rely on the sdtp box (independent and
disposable samples), but unfortunately:

sdtp[54] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 
sample_has_redundancy:0
sdtp[55] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 
sample_has_redundancy:0
sdtp[56] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 
sample_has_redundancy:0
sdtp[57] is_leading:0 sample_depends_on:2 sample_is_depended_on:0 
sample_has_redundancy:0
sdtp[58] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 
sample_has_redundancy:0
sdtp[59] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 
sample_has_redundancy:0
sdtp[60] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 
sample_has_redundancy:0
sdtp[61] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 
sample_has_redundancy:0
sdtp[62] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 
sample_has_redundancy:0

The information that might have been useful here would have been
is_leading, but all the samples are set to 0 so this was unusable.

Instead, we need to rely on sgpd/sbgp tables. In my case the video track
contained 3 sgpd tables with the following grouping types: tscl, sync
and tsas. In the sync table we have the following 2 entries (only):

sgpd.sync[1]: sync nal_unit_type:0x14
sgpd.sync[2]: sync nal_unit_type:0x15

(The count starts at 1 because 0 carries the undefined semantic, we'll
see that later in the reference table).

The NAL unit types presented here correspond to:

libavcodec/hevc.h:HEVC_NAL_IDR_N_LP   = 20,
libavcodec/hevc.h:HEVC_NAL_CRA_NUT= 21,

In parallel, the sbgp sync table contains the following:

┌┬───┬─┐
│ id │ count │ gdi │
├┼───┼─┤
│  0 │   1   │  1  │
│  1 │   56  │  0  │
│  2 │   1   │  2  │
│  3 │   59  │  0  │
│  4 │   1   │  2  │
│  5 │   59  │  0  │
│  6 │   1   │  2  │
│  7 │   59  │  0  │
│  8 │   1   │  2  │
│  9 │   59  │  0  │
│ 10 │   1   │  2  │
│ 11 │   11  │  0  │
└┴───┴─┘

The gdi column (group description index) directly refers to the index in
the sgpd.sync table. This means the first frame is an IDR, then we have
batches of undefined frames interlaced with CRA frames. No IDR ever
appears again (tried on a 30+ seconds sample).

With that information, we can build an heuristic using the presentation
order.

A few things needed to be introduced in this commit:

1. min_sample_duration is extracted from the stts: we need the minimal
   step between sample in order to PTS-step backward to a valid point
2. In order to avoid a loop over the ctts table systematically during a
   seek, we build an expanded list of sample offsets which will be used
   to translate from DTS to PTS
3. An open_key_samples index to keep track of all the non-IDR key
   frames; for now it only supports HEVC CRA frames. We should probably
   add BLA frames as well, but I don't have any sample so I prefered to
   leave that for later

It is entirely possible I missed something obvious in my approach, but I
couldn't come up with a better solution. Also, as mentioned in the diff,
we could optimize is_open_key_sample(), but the linear scaling overhead
should be fine for now since it only happens in seek events.

Fixing this issue prevents sending broken packets to the decoder. With
FFmpeg hevc decoder the frames are skipped, with VideoToolbox the frames
are glitching.
---
 libavformat/isom.h |

[FFmpeg-devel] [PATCH 3/5] avformat/mov: add parsing for the sgpd sync box

2022-02-18 Thread Clément Bœsch
sgpd means Sample Group Description Box.

For now, only the sync grouping type is parsed, but the function can
easily be adjusted to support other flavours.

The sbgp (Sample to Group Box) sync_group table built in previous commit
contains references to this table through the group_description_index
field.
---
 libavformat/isom.h |  2 ++
 libavformat/mov.c  | 59 ++
 2 files changed, 61 insertions(+)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index e326f4f27f..bbe395ee4b 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -220,6 +220,8 @@ typedef struct MOVStreamContext {
 MOVSbgp *rap_group;
 unsigned int sync_group_count;
 MOVSbgp *sync_group;
+uint8_t *sgpd_sync;
+uint32_t sgpd_sync_count;
 
 int nb_frames_for_fps;
 int64_t duration_for_fps;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index ebc397e573..6b22d8c5f8 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3130,6 +3130,62 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_sgpd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+MOVStreamContext *sc;
+uint8_t version;
+uint32_t grouping_type;
+uint32_t default_length;
+av_unused uint32_t default_group_description_index;
+uint32_t entry_count;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams - 1];
+sc = st->priv_data;
+
+version = avio_r8(pb); /* version */
+avio_rb24(pb); /* flags */
+grouping_type = avio_rl32(pb);
+
+/*
+ * This function only supports "sync" boxes, but the code is able to parse
+ * other boxes (such as "tscl", "tsas" and "stsa")
+ */
+if (grouping_type != MKTAG('s','y','n','c'))
+return 0;
+
+default_length = version >= 1 ? avio_rb32(pb) : 0;
+default_group_description_index = version >= 2 ? avio_rb32(pb) : 0;
+entry_count = avio_rb32(pb);
+
+av_freep(&sc->sgpd_sync);
+sc->sgpd_sync_count = entry_count;
+sc->sgpd_sync = av_calloc(entry_count, sizeof(*sc->sgpd_sync));
+if (!sc->sgpd_sync)
+return AVERROR(ENOMEM);
+
+for (uint32_t i = 0; i < entry_count && !pb->eof_reached; i++) {
+uint32_t description_length = default_length;
+if (version >= 1 && default_length == 0)
+description_length = avio_rb32(pb);
+if (grouping_type == MKTAG('s','y','n','c')) {
+const uint8_t nal_unit_type = avio_r8(pb) & 0x3f;
+sc->sgpd_sync[i] = nal_unit_type;
+description_length -= 1;
+}
+avio_skip(pb, description_length);
+}
+
+if (pb->eof_reached) {
+av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SGPD atom\n");
+return AVERROR_EOF;
+}
+
+return 0;
+}
+
 static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -4375,6 +4431,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 av_freep(&sc->elst_data);
 av_freep(&sc->rap_group);
 av_freep(&sc->sync_group);
+av_freep(&sc->sgpd_sync);
 
 return 0;
 }
@@ -7253,6 +7310,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('c','m','o','v'), mov_read_cmov },
 { MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */
 { MKTAG('d','v','c','1'), mov_read_dvc1 },
+{ MKTAG('s','g','p','d'), mov_read_sgpd },
 { MKTAG('s','b','g','p'), mov_read_sbgp },
 { MKTAG('h','v','c','C'), mov_read_glbl },
 { MKTAG('u','u','i','d'), mov_read_uuid },
@@ -7713,6 +7771,7 @@ static int mov_read_close(AVFormatContext *s)
 av_freep(&sc->elst_data);
 av_freep(&sc->rap_group);
 av_freep(&sc->sync_group);
+av_freep(&sc->sgpd_sync);
 av_freep(&sc->display_matrix);
 av_freep(&sc->index_ranges);
 
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/5] avformat/mov: add support for sync group in sbgp box

2022-02-18 Thread Clément Bœsch
---
 libavformat/isom.h | 2 ++
 libavformat/mov.c  | 5 +
 2 files changed, 7 insertions(+)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 625dea8421..e326f4f27f 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -218,6 +218,8 @@ typedef struct MOVStreamContext {
 int start_pad;///< amount of samples to skip due to enc-dec delay
 unsigned int rap_group_count;
 MOVSbgp *rap_group;
+unsigned int sync_group_count;
+MOVSbgp *sync_group;
 
 int nb_frames_for_fps;
 int64_t duration_for_fps;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index aade052b7a..ebc397e573 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3152,6 +3152,9 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (grouping_type == MKTAG('r','a','p',' ')) {
 tablep = &sc->rap_group;
 table_count = &sc->rap_group_count;
+} else if (grouping_type == MKTAG('s','y','n','c')) {
+tablep = &sc->sync_group;
+table_count = &sc->sync_group_count;
 } else {
 return 0;
 }
@@ -4371,6 +4374,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 av_freep(&sc->stps_data);
 av_freep(&sc->elst_data);
 av_freep(&sc->rap_group);
+av_freep(&sc->sync_group);
 
 return 0;
 }
@@ -7708,6 +7712,7 @@ static int mov_read_close(AVFormatContext *s)
 av_freep(&sc->stps_data);
 av_freep(&sc->elst_data);
 av_freep(&sc->rap_group);
+av_freep(&sc->sync_group);
 av_freep(&sc->display_matrix);
 av_freep(&sc->index_ranges);
 
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/5] avformat/mov: prepare sbgp parsing for other grouping types

2022-02-18 Thread Clément Bœsch
---
 libavformat/mov.c | 30 +++---
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 5e26267810..aade052b7a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3137,6 +3137,8 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 unsigned int i, entries;
 uint8_t version;
 uint32_t grouping_type;
+MOVSbgp *table, **tablep;
+int *table_count;
 
 if (c->fc->nb_streams < 1)
 return 0;
@@ -3146,28 +3148,34 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 version = avio_r8(pb); /* version */
 avio_rb24(pb); /* flags */
 grouping_type = avio_rl32(pb);
-if (grouping_type != MKTAG( 'r','a','p',' '))
-return 0; /* only support 'rap ' grouping */
+
+if (grouping_type == MKTAG('r','a','p',' ')) {
+tablep = &sc->rap_group;
+table_count = &sc->rap_group_count;
+} else {
+return 0;
+}
+
 if (version == 1)
 avio_rb32(pb); /* grouping_type_parameter */
 
 entries = avio_rb32(pb);
 if (!entries)
 return 0;
-if (sc->rap_group)
-av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP atom\n");
-av_free(sc->rap_group);
-sc->rap_group_count = 0;
-sc->rap_group = av_malloc_array(entries, sizeof(*sc->rap_group));
-if (!sc->rap_group)
+if (*tablep)
+av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP %s atom\n", 
av_fourcc2str(grouping_type));
+av_freep(tablep);
+table = av_malloc_array(entries, sizeof(*table));
+if (!table)
 return AVERROR(ENOMEM);
+*tablep = table;
 
 for (i = 0; i < entries && !pb->eof_reached; i++) {
-sc->rap_group[i].count = avio_rb32(pb); /* sample_count */
-sc->rap_group[i].index = avio_rb32(pb); /* group_description_index */
+table[i].count = avio_rb32(pb); /* sample_count */
+table[i].index = avio_rb32(pb); /* group_description_index */
 }
 
-sc->rap_group_count = i;
+*table_count = i;
 
 if (pb->eof_reached) {
 av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SBGP atom\n");
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] HEVC open GOP support in MOV/MP4

2022-02-18 Thread Clément Bœsch
Motivated by glitchy seeking issues with iPhone encoded files.


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/avisynth: fix frameprop version check

2022-02-18 Thread Stephen Hutchinson

On 2/16/22 7:49 PM, Stephen Hutchinson wrote:

Trying to be clever about determining between interface version 8
and 8.1 ended up with pre-8.1 versions of AviSynth+ segfaulting.

The amount of time between interface version 8.1 and 9 is small,
so just restrict the frameprop awareness to version 9 and call it
a day.
---
  libavformat/avisynth.c | 23 ++-
  1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8bc39869a3..b345f5efe2 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -502,24 +502,13 @@ static int avisynth_create_stream_video(AVFormatContext 
*s, AVStream *st)
  /* Read AviSynth+'s frame properties to set additional info.
   *
   * Due to a bug preventing the C interface from accessing frame
- * properties in earlier versions of interface version 8, only
- * enable this if we detect version 8.1 at the minimum. */
+ * properties in earlier versions of interface version 8, and
+ * previous attempts at being clever resulting in pre-8 versions
+ * of AviSynth+ segfaulting, only enable this if we detect
+ * version 9 at the minimum.  Technically, 8.1 works, but the time
+ * distance between 8.1 and 9 is very small, so just restrict it to 9. */
  
-if (!avs_library.avs_get_env_property) {

-av_log(s, AV_LOG_TRACE, "%s\n",
-   "avs_get_env_property does not exist in AviSynth library; frame 
properties won't be checked.");
-frameprop = false;
-} else {
-if (avs_library.avs_get_env_property(avs->env, 
AVS_AEP_INTERFACE_BUGFIX)) {
-av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.1 or higher, 
reading frame properties.");
-frameprop = true;
-} else {
-av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.0, need 8.1+ 
to read frame properties.");
-frameprop = false;
-}
-}
-
-if (frameprop = true) {
+if (avs_library.avs_get_version(avs->clip) >= 9) {
  
  frame  = avs_library.avs_get_frame(avs->clip, framedata);

  avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);


Pushed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread Martin Storsjö

On Thu, 17 Feb 2022, nil-admir...@mailo.com wrote:


if the path later is going to end up in a codepath that expects it to be UTF8 
(please do check!), then we should go that way instead


I checked. datadir ends up in (cmdutils.c:2104)

   base[2] = datadir;

and base[*] are later used in (cmdutils.c:2112 or 2116)

   snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
i != 1 ? "" : "/.ffmpeg", preset_name);
   f = fopen(filename, "r");

On Windows fopen expects ANSI encoded strings, so we cannot change the 
encoding to UTF-8 without rewriting the rest of the function.


Ok, well maybe we should change that too, to use wchar paths (or 
utf8->whcar routines?). But maybe those are libavutil internals that 
cmdutils shouldn't use?


If we stick with this form, with ansi paths, it would be good to leave a 
comment at the call to wchartoansi(), to explain why that doesn't use 
UTF-8 like everything else.


// Martin

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 6/6] fftools: Use UTF-8 on Windows

2022-02-18 Thread nihil-admirari
---
 fftools/fftools.manifest | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
index 30b7d8f..d1ac1e4 100644
--- a/fftools/fftools.manifest
+++ b/fftools/fftools.manifest
@@ -3,8 +3,10 @@
 
   
   
-http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";
+ 
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings";>
   true
+  UTF-8
 
   
 
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 4/6] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
---
 fftools/cmdutils.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15..ea78897 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -62,6 +62,7 @@
 #endif
 #ifdef _WIN32
 #include 
+#include "compat/w32dlfcn.h"
 #endif
 
 static int init_report(const char *env);
@@ -2065,6 +2066,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 {
 FILE *f = NULL;
 int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
 const char *base[3] = { getenv("FFMPEG_DATADIR"),
 getenv("HOME"),
 FFMPEG_DATADIR, };
@@ -2074,19 +2078,31 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 f = fopen(filename, "r");
 } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
 base[2] = NULL;
 
-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoansi(datadir_w, &datadir))
+datadir = NULL;
+av_free(datadir_w);
+
+if (datadir)
 {
-for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+char *ls;
+for (ls = datadir; *ls; ls++)
 if (*ls == '\\') *ls = '/';
 
 if (ls = strrchr(datadir, '/'))
 {
-*ls = 0;
-strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - 
strlen(datadir));
-base[2] = datadir;
+const int datadir_len = ls - datadir;
+const int desired_size = datadir_len + strlen("/ffpresets") + 
1;
+char *new_datadir = av_realloc_array(
+datadir, desired_size, sizeof *datadir);
+if (new_datadir) {
+datadir = new_datadir;
+datadir[datadir_len] = 0;
+strncat(datadir, "/ffpresets",  desired_size - 1 - 
datadir_len);
+base[2] = datadir;
+}
 }
 }
 #endif
@@ -2106,6 +2122,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 }
 }
 
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+av_free(datadir);
+#endif
 return f;
 }
 
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 3/6] compat/w32dlfcn.h: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
Also replaces a call to LoadLibraryExA with LoadLibraryExW
since ANSI functions do not support long paths.
---
 compat/w32dlfcn.h | 74 ++-
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index 52a94ef..a8ac780 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -25,6 +25,30 @@
 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
 #include "libavutil/wchar_filename.h"
 #endif
+
+static inline wchar_t *get_module_filename(const HMODULE module)
+{
+wchar_t *path = NULL;
+int path_size = 0, path_len = 0;
+
+do {
+path_size = path_size ? 1.5 * path_size : MAX_PATH;
+wchar_t *new_path = av_realloc_array(path, path_size, sizeof *path);
+if (!new_path) {
+av_free(path);
+return NULL;
+}
+path = new_path;
+path_len = GetModuleFileNameW(module, path, path_size);
+} while (path_len && path_size <= 32768 && path_size <= path_len);
+
+if (!path_len) {
+av_free(path);
+return NULL;
+}
+return path;
+}
+
 /**
  * Safe function used to open dynamic libs. This attempts to improve program 
security
  * by removing the current directory from the dll search path. Only dll's 
found in the
@@ -34,28 +58,50 @@
  */
 static inline HMODULE win32_dlopen(const char *name)
 {
+wchar_t *name_w = NULL;
+if (utf8towchar(name, &name_w))
+name_w = NULL;
 #if _WIN32_WINNT < 0x0602
 // Need to check if KB2533623 is available
 if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), 
"SetDefaultDllDirectories")) {
 HMODULE module = NULL;
-wchar_t *path = NULL, *name_w = NULL;
-DWORD pathlen;
-if (utf8towchar(name, &name_w))
+wchar_t *path = NULL, *new_path = NULL;
+DWORD pathlen, pathsize, namelen;
+if (!name_w)
 goto exit;
-path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+namelen = wcslen(name_w);
 // Try local directory first
-pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
-pathlen = wcsrchr(path, '\\') - path;
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+path = get_module_filename(NULL);
+if (!path)
 goto exit;
-path[pathlen] = '\\';
+new_path = wcsrchr(path, '\\');
+if (!new_path)
+goto exit;
+pathlen = new_path - path;
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 if (module == NULL) {
 // Next try System32 directory
-pathlen = GetSystemDirectoryW(path, MAX_PATH);
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
 goto exit;
+if (pathlen + namelen + 2 > pathsize) {
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
+// The buffer might have been not enough for system directory
+// in the first place.
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
+goto exit;
+}
 path[pathlen] = '\\';
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -73,15 +119,17 @@ exit:
 #   define LOAD_LIBRARY_SEARCH_SYSTEM320x0800
 #endif
 #if HAVE_WINRT
-wchar_t *name_w = NULL;
 int ret;
-if (utf8towchar(name, &name_w))
+if (!name_w)
 return NULL;
 ret = LoadPackagedLibrary(name_w, 0);
 av_free(name_w);
 return ret;
 #else
-return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
+/* filename may be be in CP_ACP */
+if (!name_w)
+return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR 
| LOAD_LIBRARY_SEARCH_SYSTEM32);
+return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
 #endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 2/6] libavformat/avisynth.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
---
 libavformat/avisynth.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8bc3986..219f307 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -36,6 +36,7 @@
 /* Platform-specific directives. */
 #ifdef _WIN32
   #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
   #undef EXTERN_C
   #define AVISYNTH_LIB "avisynth"
 #else
@@ -806,8 +807,7 @@ static int avisynth_open_file(AVFormatContext *s)
 AVS_Value arg, val;
 int ret;
 #ifdef _WIN32
-char filename_ansi[MAX_PATH * 4];
-wchar_t filename_wc[MAX_PATH * 4];
+char *filename_ansi = NULL;
 #endif
 
 if (ret = avisynth_context_create(s))
@@ -815,10 +815,12 @@ static int avisynth_open_file(AVFormatContext *s)
 
 #ifdef _WIN32
 /* Convert UTF-8 to ANSI code page */
-MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
-WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
-MAX_PATH * 4, NULL, NULL);
+if (utf8toansi(s->url, &filename_ansi)) {
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
 arg = avs_new_value_string(filename_ansi);
+av_free(filename_ansi);
 #else
 arg = avs_new_value_string(s->url);
 #endif
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 5/6] fftools: Enable long path support on Windows (fixes #8885)

2022-02-18 Thread nihil-admirari
---
 fftools/Makefile |  5 +
 fftools/fftools.manifest | 10 ++
 fftools/manifest.rc  |  3 +++
 3 files changed, 18 insertions(+)
 create mode 100644 fftools/fftools.manifest
 create mode 100644 fftools/manifest.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index da42078..b221155 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -11,6 +11,11 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
 
 OBJS-ffmpeg+= fftools/ffmpeg_opt.o 
fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
 
+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
new file mode 100644
index 000..30b7d8f
--- /dev/null
+++ b/fftools/fftools.manifest
@@ -0,0 +1,10 @@
+
+
+
+  
+  
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+  true
+
+  
+
diff --git a/fftools/manifest.rc b/fftools/manifest.rc
new file mode 100644
index 000..e436fa7
--- /dev/null
+++ b/fftools/manifest.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fftools.manifest"
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 1/6] libavutil/wchar_filename.h: Add wchartoansi and utf8toansi

2022-02-18 Thread nihil-admirari
These functions are going to be used in libavformat/avisynth.c
and fftools/cmdutils.c when replacing MAX_PATH-sized buffers
with dynamically sized ones.
---
 libavutil/wchar_filename.h | 37 +
 1 file changed, 37 insertions(+)

diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index 90f0824..32260a4 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -40,6 +40,43 @@ static inline int utf8towchar(const char *filename_utf8, 
wchar_t **filename_w)
 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
 return 0;
 }
+
+av_warn_unused_result
+static inline int wchartoansi(const wchar_t *filename_w, char **filename)
+{
+const int num_chars = WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+  NULL, 0, NULL, NULL);
+if (num_chars <= 0) {
+*filename = NULL;
+return 0;
+}
+*filename = (char *)av_calloc(num_chars, sizeof(char));
+if (!*filename) {
+errno = ENOMEM;
+return -1;
+}
+WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+*filename, num_chars, NULL, NULL);
+return 0;
+}
+
+av_warn_unused_result
+static inline int utf8toansi(const char *filename_utf8, char **filename)
+{
+wchar_t *filename_w = NULL;
+int ret = -1;
+if (utf8towchar(filename_utf8, &filename_w))
+return -1;
+
+if (!filename_w) {
+*filename = NULL;
+return 0;
+}
+
+ret = wchartoansi(filename_w, filename);
+av_free(filename_w);
+return ret;
+}
 #endif
 
 #endif /* AVUTIL_WCHAR_FILENAME_H */
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 5/5] fftools: Enable long path support on Windows (fixes #8885)

2022-02-18 Thread nil-admirari
> Generally UTF-8 codepage should not be needed, because unicode windows 
functions should be used everywhere, right?

No. FFmpeg does not seem to use WinAPI ANSI functions explicitly, but it still 
uses ordinary stdlib functions (fopen etc.) instead of their wide equivalents. 
See https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293169.html.

> And use simple fftools/fftools.manifest and fftools/manifest.rc as filenames, 
> because 
later other things might be put there, not only utf8/longpath support.

Done in https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293204.html.

> I'd perfer if you enable UTF8 codepage in a separate patch.

Done in https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293207.html.

Actually, UTF-8 codepage was already absent in the fourth version of this 
patch: https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293168.html. 
Microsoft documentation 
(https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests) 
says that manifests can be added to DLLs too, and does not say whether 
longPathAware and activeCodePage apply to the process or to individual DLLs 
loaded into it. Thus I wasn't sure whether ANSI-encoded strings passed to 
external APIs will be decoded correctly. Unfortunately, if it were that 
longPathAware is per DLL, manifests would need to be added to avformat.dll 
etc., so I decided to test how things actually work. It turned out that 
longPathAware and activeCodePage are applied per process, which means that all 
externally loaded libraries will have CP_ACP set to CP_UTF8, which means that 
there should be no problem in using activeCodePage in FFmpeg.

For some reason, fifth version of patches ended up being sent as separate 
messages. Only the second part 
(https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293206.html) is a 
reply to the first 
(https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293205.html). It's a 
strange email glitch. I swear I used git send-email to send these patches.



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 6/6] fftools: Use UTF-8 on Windows

2022-02-18 Thread nihil-admirari
---
 fftools/fftools.manifest | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
index 30b7d8f..d1ac1e4 100644
--- a/fftools/fftools.manifest
+++ b/fftools/fftools.manifest
@@ -3,8 +3,10 @@
 
   
   
-http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";
+ 
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings";>
   true
+  UTF-8
 
   
 
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 2/6] libavformat/avisynth.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
---
 libavformat/avisynth.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8bc3986..219f307 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -36,6 +36,7 @@
 /* Platform-specific directives. */
 #ifdef _WIN32
   #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
   #undef EXTERN_C
   #define AVISYNTH_LIB "avisynth"
 #else
@@ -806,8 +807,7 @@ static int avisynth_open_file(AVFormatContext *s)
 AVS_Value arg, val;
 int ret;
 #ifdef _WIN32
-char filename_ansi[MAX_PATH * 4];
-wchar_t filename_wc[MAX_PATH * 4];
+char *filename_ansi = NULL;
 #endif
 
 if (ret = avisynth_context_create(s))
@@ -815,10 +815,12 @@ static int avisynth_open_file(AVFormatContext *s)
 
 #ifdef _WIN32
 /* Convert UTF-8 to ANSI code page */
-MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
-WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
-MAX_PATH * 4, NULL, NULL);
+if (utf8toansi(s->url, &filename_ansi)) {
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
 arg = avs_new_value_string(filename_ansi);
+av_free(filename_ansi);
 #else
 arg = avs_new_value_string(s->url);
 #endif
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 1/6] libavutil/wchar_filename.h: Add wchartoansi and utf8toansi

2022-02-18 Thread nihil-admirari
These functions are going to be used in libavformat/avisynth.c
and fftools/cmdutils.c when replacing MAX_PATH-sized buffers
with dynamically sized ones.
---
 libavutil/wchar_filename.h | 37 +
 1 file changed, 37 insertions(+)

diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index 90f0824..32260a4 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -40,6 +40,43 @@ static inline int utf8towchar(const char *filename_utf8, 
wchar_t **filename_w)
 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
 return 0;
 }
+
+av_warn_unused_result
+static inline int wchartoansi(const wchar_t *filename_w, char **filename)
+{
+const int num_chars = WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+  NULL, 0, NULL, NULL);
+if (num_chars <= 0) {
+*filename = NULL;
+return 0;
+}
+*filename = (char *)av_calloc(num_chars, sizeof(char));
+if (!*filename) {
+errno = ENOMEM;
+return -1;
+}
+WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+*filename, num_chars, NULL, NULL);
+return 0;
+}
+
+av_warn_unused_result
+static inline int utf8toansi(const char *filename_utf8, char **filename)
+{
+wchar_t *filename_w = NULL;
+int ret = -1;
+if (utf8towchar(filename_utf8, &filename_w))
+return -1;
+
+if (!filename_w) {
+*filename = NULL;
+return 0;
+}
+
+ret = wchartoansi(filename_w, filename);
+av_free(filename_w);
+return ret;
+}
 #endif
 
 #endif /* AVUTIL_WCHAR_FILENAME_H */
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 5/6] fftools: Enable long path support on Windows (fixes #8885)

2022-02-18 Thread nihil-admirari
---
 fftools/Makefile |  5 +
 fftools/fftools.manifest | 10 ++
 fftools/manifest.rc  |  3 +++
 3 files changed, 18 insertions(+)
 create mode 100644 fftools/fftools.manifest
 create mode 100644 fftools/manifest.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index da42078..b221155 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -11,6 +11,11 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
 
 OBJS-ffmpeg+= fftools/ffmpeg_opt.o 
fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
 
+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
new file mode 100644
index 000..30b7d8f
--- /dev/null
+++ b/fftools/fftools.manifest
@@ -0,0 +1,10 @@
+
+
+
+  
+  
+http://schemas.microsoft.com/SMI/2016/WindowsSettings";>
+  true
+
+  
+
diff --git a/fftools/manifest.rc b/fftools/manifest.rc
new file mode 100644
index 000..689f8b2
--- /dev/null
+++ b/fftools/manifest.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "long_paths.manifest"
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 4/6] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
---
 fftools/cmdutils.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15..ea78897 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -62,6 +62,7 @@
 #endif
 #ifdef _WIN32
 #include 
+#include "compat/w32dlfcn.h"
 #endif
 
 static int init_report(const char *env);
@@ -2065,6 +2066,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 {
 FILE *f = NULL;
 int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
 const char *base[3] = { getenv("FFMPEG_DATADIR"),
 getenv("HOME"),
 FFMPEG_DATADIR, };
@@ -2074,19 +2078,31 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 f = fopen(filename, "r");
 } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
 base[2] = NULL;
 
-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoansi(datadir_w, &datadir))
+datadir = NULL;
+av_free(datadir_w);
+
+if (datadir)
 {
-for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+char *ls;
+for (ls = datadir; *ls; ls++)
 if (*ls == '\\') *ls = '/';
 
 if (ls = strrchr(datadir, '/'))
 {
-*ls = 0;
-strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - 
strlen(datadir));
-base[2] = datadir;
+const int datadir_len = ls - datadir;
+const int desired_size = datadir_len + strlen("/ffpresets") + 
1;
+char *new_datadir = av_realloc_array(
+datadir, desired_size, sizeof *datadir);
+if (new_datadir) {
+datadir = new_datadir;
+datadir[datadir_len] = 0;
+strncat(datadir, "/ffpresets",  desired_size - 1 - 
datadir_len);
+base[2] = datadir;
+}
 }
 }
 #endif
@@ -2106,6 +2122,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 }
 }
 
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+av_free(datadir);
+#endif
 return f;
 }
 
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 3/6] compat/w32dlfcn.h: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-18 Thread nihil-admirari
Also replaces a call to LoadLibraryExA with LoadLibraryExW
since ANSI functions do not support long paths.
---
 compat/w32dlfcn.h | 74 ++-
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index 52a94ef..a8ac780 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -25,6 +25,30 @@
 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
 #include "libavutil/wchar_filename.h"
 #endif
+
+static inline wchar_t *get_module_filename(const HMODULE module)
+{
+wchar_t *path = NULL;
+int path_size = 0, path_len = 0;
+
+do {
+path_size = path_size ? 1.5 * path_size : MAX_PATH;
+wchar_t *new_path = av_realloc_array(path, path_size, sizeof *path);
+if (!new_path) {
+av_free(path);
+return NULL;
+}
+path = new_path;
+path_len = GetModuleFileNameW(module, path, path_size);
+} while (path_len && path_size <= 32768 && path_size <= path_len);
+
+if (!path_len) {
+av_free(path);
+return NULL;
+}
+return path;
+}
+
 /**
  * Safe function used to open dynamic libs. This attempts to improve program 
security
  * by removing the current directory from the dll search path. Only dll's 
found in the
@@ -34,28 +58,50 @@
  */
 static inline HMODULE win32_dlopen(const char *name)
 {
+wchar_t *name_w = NULL;
+if (utf8towchar(name, &name_w))
+name_w = NULL;
 #if _WIN32_WINNT < 0x0602
 // Need to check if KB2533623 is available
 if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), 
"SetDefaultDllDirectories")) {
 HMODULE module = NULL;
-wchar_t *path = NULL, *name_w = NULL;
-DWORD pathlen;
-if (utf8towchar(name, &name_w))
+wchar_t *path = NULL, *new_path = NULL;
+DWORD pathlen, pathsize, namelen;
+if (!name_w)
 goto exit;
-path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+namelen = wcslen(name_w);
 // Try local directory first
-pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
-pathlen = wcsrchr(path, '\\') - path;
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+path = get_module_filename(NULL);
+if (!path)
 goto exit;
-path[pathlen] = '\\';
+new_path = wcsrchr(path, '\\');
+if (!new_path)
+goto exit;
+pathlen = new_path - path;
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 if (module == NULL) {
 // Next try System32 directory
-pathlen = GetSystemDirectoryW(path, MAX_PATH);
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
 goto exit;
+if (pathlen + namelen + 2 > pathsize) {
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
+// The buffer might have been not enough for system directory
+// in the first place.
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
+goto exit;
+}
 path[pathlen] = '\\';
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -73,15 +119,17 @@ exit:
 #   define LOAD_LIBRARY_SEARCH_SYSTEM320x0800
 #endif
 #if HAVE_WINRT
-wchar_t *name_w = NULL;
 int ret;
-if (utf8towchar(name, &name_w))
+if (!name_w)
 return NULL;
 ret = LoadPackagedLibrary(name_w, 0);
 av_free(name_w);
 return ret;
 #else
-return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
+/* filename may be be in CP_ACP */
+if (!name_w)
+return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR 
| LOAD_LIBRARY_SEARCH_SYSTEM32);
+return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
 #endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
-- 
2.32.0



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: Added siti filter

2022-02-18 Thread Paul B Mahol
On Sat, Feb 12, 2022 at 11:55 AM Thilo Borgmann 
wrote:

> Am 31.01.22 um 12:55 schrieb James Almer:
> >
> >
> > On 1/31/2022 8:53 AM, Anton Khirnov wrote:
> >> Quoting Thilo Borgmann (2022-01-18 14:58:07)
> > Violations of code style.
> >>>
> >>> Enhanced.
> >>
> >> Not enough. There are still many remaining, e.g.
> >> * opening brace of a function definition should be on its own line
> >> * the context should generally be the first argument
> >> * unsigned char* should be uint8_t*
> >> * mixed declarations and code (the compiler should warn about that)
> >
> > I think someone said that clang (or some versions) is apparently not
> warning about this, hence why so many of these end up being missed in
> reviews or even by the patch author.
>
> This and all of Anton's comments in v3. Also removed some more obviously
> useless doubles.
>

Why it uses doubles in so many places?
Is there any real benefit in that, except extra slowdown?



>
> Thanks,
> Thilo___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavfilter: zscale performance optimization >4x

2022-02-18 Thread Paul B Mahol
On Fri, Feb 18, 2022 at 12:48:10PM -0300, James Almer wrote:
> 
> 
> On 2/18/2022 12:24 PM, Victoria Zhislina wrote:
> > By ffmpeg threading support implementation via frame slicing and doing
> > zimg_filter_graph_build that used to take 30-60% of each frame processig
> > only if necessary (some parameters changed)
> > the performance increase vs original version
> > in video downscale and color conversion  >4x is seen
> > on 64 cores Intel Xeon, 3x on i7-6700K (4 cores with HT)
> > 
> > Signed-off-by: Victoria Zhislina 
> > ---
> >   libavfilter/vf_zscale.c | 787 
> >   1 file changed, 475 insertions(+), 312 deletions(-)
> > 
> > diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
> > index 1288c5efc1..ea2565025f 100644
> > --- a/libavfilter/vf_zscale.c
> > +++ b/libavfilter/vf_zscale.c
> > @@ -1,6 +1,7 @@
> >   /*
> >* Copyright (c) 2015 Paul B Mahol
> > - *
> > + * 2022 Victoria Zhislina, Intel
> > +
> >* This file is part of FFmpeg.
> >*
> >* FFmpeg is free software; you can redistribute it and/or
> > @@ -44,6 +45,8 @@
> >   #include "libavutil/imgutils.h"
> >   #define ZIMG_ALIGNMENT 32
> > +#define MIN_TILESIZE 64
> > +#define MAX_THREADS 64
> >   static const char *const var_names[] = {
> >   "in_w",   "iw",
> > @@ -113,13 +116,17 @@ typedef struct ZScaleContext {
> >   int force_original_aspect_ratio;
> > -void *tmp;
> > -size_t tmp_size;
> > +void *tmp[MAX_THREADS]; //separate for each thread;
> > +int nb_threads;
> > +int slice_h;
> >   zimg_image_format src_format, dst_format;
> >   zimg_image_format alpha_src_format, alpha_dst_format;
> > +zimg_image_format src_format_tmp, dst_format_tmp;
> > +zimg_image_format alpha_src_format_tmp, alpha_dst_format_tmp;
> >   zimg_graph_builder_params alpha_params, params;
> > -zimg_filter_graph *alpha_graph, *graph;
> > +zimg_graph_builder_params alpha_params_tmp, params_tmp;
> > +zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS];
> >   enum AVColorSpace in_colorspace, out_colorspace;
> >   enum AVColorTransferCharacteristic in_trc, out_trc;
> > @@ -128,10 +135,181 @@ typedef struct ZScaleContext {
> >   enum AVChromaLocation in_chromal, out_chromal;
> >   } ZScaleContext;
> > +
> > +typedef struct ThreadData {
> > +const AVPixFmtDescriptor *desc, *odesc;
> > +AVFrame *in, *out;
> > +} ThreadData;
> > +
> > +static int convert_chroma_location(enum AVChromaLocation chroma_location)
> > +{
> > +switch (chroma_location) {
> > +case AVCHROMA_LOC_UNSPECIFIED:
> > +case AVCHROMA_LOC_LEFT:
> > +return ZIMG_CHROMA_LEFT;
> > +case AVCHROMA_LOC_CENTER:
> > +return ZIMG_CHROMA_CENTER;
> > +case AVCHROMA_LOC_TOPLEFT:
> > +return ZIMG_CHROMA_TOP_LEFT;
> > +case AVCHROMA_LOC_TOP:
> > +return ZIMG_CHROMA_TOP;
> > +case AVCHROMA_LOC_BOTTOMLEFT:
> > +return ZIMG_CHROMA_BOTTOM_LEFT;
> > +case AVCHROMA_LOC_BOTTOM:
> > +return ZIMG_CHROMA_BOTTOM;
> > +}
> > +return ZIMG_CHROMA_LEFT;
> > +}
> > +
> > +static int convert_matrix(enum AVColorSpace colorspace)
> > +{
> > +switch (colorspace) {
> > +case AVCOL_SPC_RGB:
> > +return ZIMG_MATRIX_RGB;
> > +case AVCOL_SPC_BT709:
> > +return ZIMG_MATRIX_709;
> > +case AVCOL_SPC_UNSPECIFIED:
> > +return ZIMG_MATRIX_UNSPECIFIED;
> > +case AVCOL_SPC_FCC:
> > +return ZIMG_MATRIX_FCC;
> > +case AVCOL_SPC_BT470BG:
> > +return ZIMG_MATRIX_470BG;
> > +case AVCOL_SPC_SMPTE170M:
> > +return ZIMG_MATRIX_170M;
> > +case AVCOL_SPC_SMPTE240M:
> > +return ZIMG_MATRIX_240M;
> > +case AVCOL_SPC_YCGCO:
> > +return ZIMG_MATRIX_YCGCO;
> > +case AVCOL_SPC_BT2020_NCL:
> > +return ZIMG_MATRIX_2020_NCL;
> > +case AVCOL_SPC_BT2020_CL:
> > +return ZIMG_MATRIX_2020_CL;
> > +case AVCOL_SPC_CHROMA_DERIVED_NCL:
> > +return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
> > +case AVCOL_SPC_CHROMA_DERIVED_CL:
> > +return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
> > +case AVCOL_SPC_ICTCP:
> > +return ZIMG_MATRIX_ICTCP;
> > +}
> > +return ZIMG_MATRIX_UNSPECIFIED;
> > +}
> > +
> > +static int convert_trc(enum AVColorTransferCharacteristic color_trc)
> > +{
> > +switch (color_trc) {
> > +case AVCOL_TRC_UNSPECIFIED:
> > +return ZIMG_TRANSFER_UNSPECIFIED;
> > +case AVCOL_TRC_BT709:
> > +return ZIMG_TRANSFER_709;
> > +case AVCOL_TRC_GAMMA22:
> > +return ZIMG_TRANSFER_470_M;
> > +case AVCOL_TRC_GAMMA28:
> > +return ZIMG_TRANSFER_470_BG;
> > +case AVCOL_TRC_SMPTE170M:
> > +return ZIMG_TRANSFER_601;
> > +case AVCOL_TRC_SMPTE240M:
> > +return ZIMG_TRANSFER_240M;
> > +case AVCOL_TRC_LINEAR:
> > +return ZIMG_TRANSFER_LINEAR;
> > +case AVCOL_TRC_LOG:
> > +return ZIMG_TRANSFER_LOG_100;
> > +

Re: [FFmpeg-devel] [PATCH] libavfilter: zscale performance optimization >4x

2022-02-18 Thread James Almer




On 2/18/2022 12:24 PM, Victoria Zhislina wrote:

By ffmpeg threading support implementation via frame slicing and doing
zimg_filter_graph_build that used to take 30-60% of each frame processig
only if necessary (some parameters changed)
the performance increase vs original version
in video downscale and color conversion  >4x is seen
on 64 cores Intel Xeon, 3x on i7-6700K (4 cores with HT)

Signed-off-by: Victoria Zhislina 
---
  libavfilter/vf_zscale.c | 787 
  1 file changed, 475 insertions(+), 312 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 1288c5efc1..ea2565025f 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -1,6 +1,7 @@
  /*
   * Copyright (c) 2015 Paul B Mahol
- *
+ * 2022 Victoria Zhislina, Intel
+
   * This file is part of FFmpeg.
   *
   * FFmpeg is free software; you can redistribute it and/or
@@ -44,6 +45,8 @@
  #include "libavutil/imgutils.h"
  
  #define ZIMG_ALIGNMENT 32

+#define MIN_TILESIZE 64
+#define MAX_THREADS 64
  
  static const char *const var_names[] = {

  "in_w",   "iw",
@@ -113,13 +116,17 @@ typedef struct ZScaleContext {
  
  int force_original_aspect_ratio;
  
-void *tmp;

-size_t tmp_size;
+void *tmp[MAX_THREADS]; //separate for each thread;
+int nb_threads;
+int slice_h;
  
  zimg_image_format src_format, dst_format;

  zimg_image_format alpha_src_format, alpha_dst_format;
+zimg_image_format src_format_tmp, dst_format_tmp;
+zimg_image_format alpha_src_format_tmp, alpha_dst_format_tmp;
  zimg_graph_builder_params alpha_params, params;
-zimg_filter_graph *alpha_graph, *graph;
+zimg_graph_builder_params alpha_params_tmp, params_tmp;
+zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS];
  
  enum AVColorSpace in_colorspace, out_colorspace;

  enum AVColorTransferCharacteristic in_trc, out_trc;
@@ -128,10 +135,181 @@ typedef struct ZScaleContext {
  enum AVChromaLocation in_chromal, out_chromal;
  } ZScaleContext;
  
+

+typedef struct ThreadData {
+const AVPixFmtDescriptor *desc, *odesc;
+AVFrame *in, *out;
+} ThreadData;
+
+static int convert_chroma_location(enum AVChromaLocation chroma_location)
+{
+switch (chroma_location) {
+case AVCHROMA_LOC_UNSPECIFIED:
+case AVCHROMA_LOC_LEFT:
+return ZIMG_CHROMA_LEFT;
+case AVCHROMA_LOC_CENTER:
+return ZIMG_CHROMA_CENTER;
+case AVCHROMA_LOC_TOPLEFT:
+return ZIMG_CHROMA_TOP_LEFT;
+case AVCHROMA_LOC_TOP:
+return ZIMG_CHROMA_TOP;
+case AVCHROMA_LOC_BOTTOMLEFT:
+return ZIMG_CHROMA_BOTTOM_LEFT;
+case AVCHROMA_LOC_BOTTOM:
+return ZIMG_CHROMA_BOTTOM;
+}
+return ZIMG_CHROMA_LEFT;
+}
+
+static int convert_matrix(enum AVColorSpace colorspace)
+{
+switch (colorspace) {
+case AVCOL_SPC_RGB:
+return ZIMG_MATRIX_RGB;
+case AVCOL_SPC_BT709:
+return ZIMG_MATRIX_709;
+case AVCOL_SPC_UNSPECIFIED:
+return ZIMG_MATRIX_UNSPECIFIED;
+case AVCOL_SPC_FCC:
+return ZIMG_MATRIX_FCC;
+case AVCOL_SPC_BT470BG:
+return ZIMG_MATRIX_470BG;
+case AVCOL_SPC_SMPTE170M:
+return ZIMG_MATRIX_170M;
+case AVCOL_SPC_SMPTE240M:
+return ZIMG_MATRIX_240M;
+case AVCOL_SPC_YCGCO:
+return ZIMG_MATRIX_YCGCO;
+case AVCOL_SPC_BT2020_NCL:
+return ZIMG_MATRIX_2020_NCL;
+case AVCOL_SPC_BT2020_CL:
+return ZIMG_MATRIX_2020_CL;
+case AVCOL_SPC_CHROMA_DERIVED_NCL:
+return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
+case AVCOL_SPC_CHROMA_DERIVED_CL:
+return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
+case AVCOL_SPC_ICTCP:
+return ZIMG_MATRIX_ICTCP;
+}
+return ZIMG_MATRIX_UNSPECIFIED;
+}
+
+static int convert_trc(enum AVColorTransferCharacteristic color_trc)
+{
+switch (color_trc) {
+case AVCOL_TRC_UNSPECIFIED:
+return ZIMG_TRANSFER_UNSPECIFIED;
+case AVCOL_TRC_BT709:
+return ZIMG_TRANSFER_709;
+case AVCOL_TRC_GAMMA22:
+return ZIMG_TRANSFER_470_M;
+case AVCOL_TRC_GAMMA28:
+return ZIMG_TRANSFER_470_BG;
+case AVCOL_TRC_SMPTE170M:
+return ZIMG_TRANSFER_601;
+case AVCOL_TRC_SMPTE240M:
+return ZIMG_TRANSFER_240M;
+case AVCOL_TRC_LINEAR:
+return ZIMG_TRANSFER_LINEAR;
+case AVCOL_TRC_LOG:
+return ZIMG_TRANSFER_LOG_100;
+case AVCOL_TRC_LOG_SQRT:
+return ZIMG_TRANSFER_LOG_316;
+case AVCOL_TRC_IEC61966_2_4:
+return ZIMG_TRANSFER_IEC_61966_2_4;
+case AVCOL_TRC_BT2020_10:
+return ZIMG_TRANSFER_2020_10;
+case AVCOL_TRC_BT2020_12:
+return ZIMG_TRANSFER_2020_12;
+case AVCOL_TRC_SMPTE2084:
+return ZIMG_TRANSFER_ST2084;
+case AVCOL_TRC_ARIB_STD_B67:
+return ZIMG_TRANSFER_ARIB_B67;
+case AVCOL_TRC_IEC61966_2_1:
+return ZIMG_TRANSFER_IEC_61966_2_1;
+}
+return ZIMG_TRANSFER_UNSPECIFIED;
+}
+
+

Re: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV option

2022-02-18 Thread Wu Jianhua
> 29 Jan 2022, 13:34 by toqsxw at outlook.com:

>> Ping.
>>
>>> From: Wu, Jianhua
>>> Sent: 2022年1月21日 19:42
>>> To: ffmpeg-devel at ffmpeg.org
>>> Cc: Wu, Jianhua
>>> Subject: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV 
>>> option
>>>
>>> [PATCH 1/5] avfilter/vf_gblur_vulkan: add sizeV option [PATCH 2/5] 
>>> avfilter:add shader_vulkan filter [PATCH 3/5] avfilter/vf_blend_vulkan: add 
>>> multiply blend mode [PATCH 4/5] avutil/vulkan: don't use strlen as loop 
>>> >condition [PATCH 5/5] avfilter/scale_vulkan: use RET for checking return 
>>> value
>>>
>>> Patches attached.
>>>
>>
>> Hi there,
>>
>> Any update?
>>
>
> Sorry, haven't forgotten, but been busy with FFTs lately.
> Will try to review and test the patches soon.

Hi there,

I'm sorry for bothering you. If there is any update on this
thread, please do let me know. 

Thanks,
Jianhua

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavfilter: zscale performance optimization >4x

2022-02-18 Thread Victoria Zhislina
By ffmpeg threading support implementation via frame slicing and doing
zimg_filter_graph_build that used to take 30-60% of each frame processig
only if necessary (some parameters changed)
the performance increase vs original version
in video downscale and color conversion  >4x is seen
on 64 cores Intel Xeon, 3x on i7-6700K (4 cores with HT)

Signed-off-by: Victoria Zhislina 
---
 libavfilter/vf_zscale.c | 787 
 1 file changed, 475 insertions(+), 312 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 1288c5efc1..ea2565025f 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2015 Paul B Mahol
- *
+ * 2022 Victoria Zhislina, Intel
+ 
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -44,6 +45,8 @@
 #include "libavutil/imgutils.h"
 
 #define ZIMG_ALIGNMENT 32
+#define MIN_TILESIZE 64
+#define MAX_THREADS 64
 
 static const char *const var_names[] = {
 "in_w",   "iw",
@@ -113,13 +116,17 @@ typedef struct ZScaleContext {
 
 int force_original_aspect_ratio;
 
-void *tmp;
-size_t tmp_size;
+void *tmp[MAX_THREADS]; //separate for each thread;
+int nb_threads;
+int slice_h;
 
 zimg_image_format src_format, dst_format;
 zimg_image_format alpha_src_format, alpha_dst_format;
+zimg_image_format src_format_tmp, dst_format_tmp;
+zimg_image_format alpha_src_format_tmp, alpha_dst_format_tmp;
 zimg_graph_builder_params alpha_params, params;
-zimg_filter_graph *alpha_graph, *graph;
+zimg_graph_builder_params alpha_params_tmp, params_tmp;
+zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS];
 
 enum AVColorSpace in_colorspace, out_colorspace;
 enum AVColorTransferCharacteristic in_trc, out_trc;
@@ -128,10 +135,181 @@ typedef struct ZScaleContext {
 enum AVChromaLocation in_chromal, out_chromal;
 } ZScaleContext;
 
+
+typedef struct ThreadData {
+const AVPixFmtDescriptor *desc, *odesc;
+AVFrame *in, *out;
+} ThreadData;
+
+static int convert_chroma_location(enum AVChromaLocation chroma_location)
+{
+switch (chroma_location) {
+case AVCHROMA_LOC_UNSPECIFIED:
+case AVCHROMA_LOC_LEFT:
+return ZIMG_CHROMA_LEFT;
+case AVCHROMA_LOC_CENTER:
+return ZIMG_CHROMA_CENTER;
+case AVCHROMA_LOC_TOPLEFT:
+return ZIMG_CHROMA_TOP_LEFT;
+case AVCHROMA_LOC_TOP:
+return ZIMG_CHROMA_TOP;
+case AVCHROMA_LOC_BOTTOMLEFT:
+return ZIMG_CHROMA_BOTTOM_LEFT;
+case AVCHROMA_LOC_BOTTOM:
+return ZIMG_CHROMA_BOTTOM;
+}
+return ZIMG_CHROMA_LEFT;
+}
+
+static int convert_matrix(enum AVColorSpace colorspace)
+{
+switch (colorspace) {
+case AVCOL_SPC_RGB:
+return ZIMG_MATRIX_RGB;
+case AVCOL_SPC_BT709:
+return ZIMG_MATRIX_709;
+case AVCOL_SPC_UNSPECIFIED:
+return ZIMG_MATRIX_UNSPECIFIED;
+case AVCOL_SPC_FCC:
+return ZIMG_MATRIX_FCC;
+case AVCOL_SPC_BT470BG:
+return ZIMG_MATRIX_470BG;
+case AVCOL_SPC_SMPTE170M:
+return ZIMG_MATRIX_170M;
+case AVCOL_SPC_SMPTE240M:
+return ZIMG_MATRIX_240M;
+case AVCOL_SPC_YCGCO:
+return ZIMG_MATRIX_YCGCO;
+case AVCOL_SPC_BT2020_NCL:
+return ZIMG_MATRIX_2020_NCL;
+case AVCOL_SPC_BT2020_CL:
+return ZIMG_MATRIX_2020_CL;
+case AVCOL_SPC_CHROMA_DERIVED_NCL:
+return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
+case AVCOL_SPC_CHROMA_DERIVED_CL:
+return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
+case AVCOL_SPC_ICTCP:
+return ZIMG_MATRIX_ICTCP;
+}
+return ZIMG_MATRIX_UNSPECIFIED;
+}
+
+static int convert_trc(enum AVColorTransferCharacteristic color_trc)
+{
+switch (color_trc) {
+case AVCOL_TRC_UNSPECIFIED:
+return ZIMG_TRANSFER_UNSPECIFIED;
+case AVCOL_TRC_BT709:
+return ZIMG_TRANSFER_709;
+case AVCOL_TRC_GAMMA22:
+return ZIMG_TRANSFER_470_M;
+case AVCOL_TRC_GAMMA28:
+return ZIMG_TRANSFER_470_BG;
+case AVCOL_TRC_SMPTE170M:
+return ZIMG_TRANSFER_601;
+case AVCOL_TRC_SMPTE240M:
+return ZIMG_TRANSFER_240M;
+case AVCOL_TRC_LINEAR:
+return ZIMG_TRANSFER_LINEAR;
+case AVCOL_TRC_LOG:
+return ZIMG_TRANSFER_LOG_100;
+case AVCOL_TRC_LOG_SQRT:
+return ZIMG_TRANSFER_LOG_316;
+case AVCOL_TRC_IEC61966_2_4:
+return ZIMG_TRANSFER_IEC_61966_2_4;
+case AVCOL_TRC_BT2020_10:
+return ZIMG_TRANSFER_2020_10;
+case AVCOL_TRC_BT2020_12:
+return ZIMG_TRANSFER_2020_12;
+case AVCOL_TRC_SMPTE2084:
+return ZIMG_TRANSFER_ST2084;
+case AVCOL_TRC_ARIB_STD_B67:
+return ZIMG_TRANSFER_ARIB_B67;
+case AVCOL_TRC_IEC61966_2_1:
+return ZIMG_TRANSFER_IEC_61966_2_1;
+}
+return ZIMG_TRANSFER_UNSPECIFIED;
+}
+
+static int convert_primaries(enum AVColorPrimaries color_primaries)
+{
+switch (

[FFmpeg-devel] [PATCH] swscale: Take the destination range into account for yuv->rgb->yuv conversions

2022-02-18 Thread Martin Storsjö
The range parameters need to be set up before calling
sws_init_context (which selects which fastpaths can be used;
this gets called by sws_getContext); solely passing them via
sws_setColorspaceDetails isn't enough.

This fixes producing full range YUV range output when doing
YUV->YUV conversions between different YUV color spaces.

Signed-off-by: Martin Storsjö 
---
 libswscale/utils.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 7c8e1bbdde..34f7f0b869 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1037,11 +1037,16 @@ int sws_setColorspaceDetails(struct SwsContext *c, 
const int inv_table[4],
  srcRange, table, dstRange,
  brightness, contrast, saturation);
 
-c->cascaded_context[1] = sws_getContext(tmp_width, tmp_height, 
tmp_format,
-dstW, dstH, c->dstFormat,
-c->flags, NULL, NULL, 
c->param);
+c->cascaded_context[1] = sws_alloc_set_opts(tmp_width, tmp_height, 
tmp_format,
+dstW, dstH, 
c->dstFormat,
+c->flags, c->param);
 if (!c->cascaded_context[1])
 return -1;
+c->cascaded_context[1]->srcRange = srcRange;
+c->cascaded_context[1]->dstRange = dstRange;
+ret = sws_init_context(c->cascaded_context[1], NULL , NULL);
+if (ret < 0)
+return ret;
 sws_setColorspaceDetails(c->cascaded_context[1], inv_table,
  srcRange, table, dstRange,
  0, 1 << 16, 1 << 16);
-- 
2.32.0 (Apple Git-132)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API

2022-02-18 Thread James Almer




On 2/16/2022 3:15 PM, Anton Khirnov wrote:

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index b89a680883..3ebd279df7 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int 
st_index, void *log_ctx)
  {
  AVCodecParameters *dec_par = st->st->codecpar;
  char buf[256];
-int64_t chl = av_get_default_channel_layout(dec_par->channels);
+AVChannelLayout chl = { 0 };
  
-if (!chl) {

+av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels);
+
+if (!KNOWN(&chl)) {
  av_log(log_ctx, AV_LOG_ERROR,
 "Channel layout is not set in stream %d, and could not "
 "be guessed from the number of channels (%d)\n",
-   st_index, dec_par->channels);
+   st_index, dec_par->ch_layout.nb_channels);
  return AVERROR(EINVAL);

Should this still be an error? Unspec layouts should now be properly
supported by (almost?) everything.


Probably, but making it no longer abort if a native channel layout can't 
be guessed is a behavior change that I'd rather leave for a different 
patch, if you don't mind.




-- Anton Khirnov ___ 
ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org 
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit 
link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject 
"unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avcodec/openh264: return (DE|EN)CODER_NOT_FOUND if version check fails

2022-02-18 Thread Andreas Schneider
Signed-off-by: Andreas Schneider 
---
 libavcodec/libopenh264dec.c | 2 +-
 libavcodec/libopenh264enc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264dec.c b/libavcodec/libopenh264dec.c
index 7f5e85402a..97d3630df6 100644
--- a/libavcodec/libopenh264dec.c
+++ b/libavcodec/libopenh264dec.c
@@ -56,7 +56,7 @@ static av_cold int svc_decode_init(AVCodecContext *avctx)
 WelsTraceCallback callback_function;
 
 if ((err = ff_libopenh264_check_version(avctx)) < 0)
-return err;
+return AVERROR_DECODER_NOT_FOUND;
 
 if (WelsCreateDecoder(&s->decoder)) {
 av_log(avctx, AV_LOG_ERROR, "Unable to create decoder\n");
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 7c0501a2eb..7649e7b025 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -137,7 +137,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 AVCPBProperties *props;
 
 if ((err = ff_libopenh264_check_version(avctx)) < 0)
-return err;
+return AVERROR_ENCODER_NOT_FOUND;
 
 if (WelsCreateSVCEncoder(&s->encoder)) {
 av_log(avctx, AV_LOG_ERROR, "Unable to create encoder\n");
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavfilter: zscale performance optimization >4x

2022-02-18 Thread Paul B Mahol
On Thu, Feb 10, 2022 at 01:08:04PM +0300, Victoria Zhislina wrote:
> By ffmpeg threading support implementation via frame slicing and doing
> zimg_filter_graph_build that used to take 30-60% of each frame processig
> only if necessary (some parameters changed)
> the performance increase vs original version
> in video downscale and color conversion  >4x is seen
> on 64 cores Intel Xeon, 3x on i7-6700K (4 cores with HT)
> 
> Signed-off-by: Victoria Zhislina 
> ---
>  libavfilter/vf_zscale.c | 786 
>  1 file changed, 475 insertions(+), 311 deletions(-)
> 
> diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
> index 1288c5efc1..ce4c0b2c76 100644
> --- a/libavfilter/vf_zscale.c
> +++ b/libavfilter/vf_zscale.c
> @@ -1,6 +1,7 @@
>  /*
>   * Copyright (c) 2015 Paul B Mahol
> - *
> + * * 2022 Victoria Zhislina, Intel - performance optimization

Just name, please, without extra stuff, see line above.

> + 
>   * This file is part of FFmpeg.
>   *
>   * FFmpeg is free software; you can redistribute it and/or
> @@ -44,6 +45,8 @@
>  #include "libavutil/imgutils.h"
>  
>  #define ZIMG_ALIGNMENT 32
> +#define MIN_TILESIZE 64
> +#define MAX_THREADS 64
>  
>  static const char *const var_names[] = {
>  "in_w",   "iw",
> @@ -113,13 +116,17 @@ typedef struct ZScaleContext {
>  
>  int force_original_aspect_ratio;
>  
> -void *tmp;
> -size_t tmp_size;
> +void *tmp[MAX_THREADS]; //separate for each thread;
> + int nb_threads;

Sorry, but tab characters are generally forbidden in FFmpeg source code.

> +int slice_h;
>  
>  zimg_image_format src_format, dst_format;
>  zimg_image_format alpha_src_format, alpha_dst_format;
> +zimg_image_format src_format_tmp, dst_format_tmp;
> +zimg_image_format alpha_src_format_tmp, alpha_dst_format_tmp;
>  zimg_graph_builder_params alpha_params, params;
> -zimg_filter_graph *alpha_graph, *graph;
> +zimg_graph_builder_params alpha_params_tmp, params_tmp;
> +zimg_filter_graph *alpha_graph[MAX_THREADS], *graph[MAX_THREADS];
>  
>  enum AVColorSpace in_colorspace, out_colorspace;
>  enum AVColorTransferCharacteristic in_trc, out_trc;
> @@ -128,10 +135,181 @@ typedef struct ZScaleContext {
>  enum AVChromaLocation in_chromal, out_chromal;
>  } ZScaleContext;
>  
> +
> +typedef struct ThreadData {
> +const AVPixFmtDescriptor *desc, *odesc;
> +AVFrame *in, *out;
> +} ThreadData;
> +
> +static int convert_chroma_location(enum AVChromaLocation chroma_location)
> +{
> +switch (chroma_location) {
> +case AVCHROMA_LOC_UNSPECIFIED:
> +case AVCHROMA_LOC_LEFT:
> +return ZIMG_CHROMA_LEFT;
> +case AVCHROMA_LOC_CENTER:
> +return ZIMG_CHROMA_CENTER;
> +case AVCHROMA_LOC_TOPLEFT:
> +return ZIMG_CHROMA_TOP_LEFT;
> +case AVCHROMA_LOC_TOP:
> +return ZIMG_CHROMA_TOP;
> +case AVCHROMA_LOC_BOTTOMLEFT:
> +return ZIMG_CHROMA_BOTTOM_LEFT;
> +case AVCHROMA_LOC_BOTTOM:
> +return ZIMG_CHROMA_BOTTOM;
> +}
> +return ZIMG_CHROMA_LEFT;
> +}
> +
> +static int convert_matrix(enum AVColorSpace colorspace)
> +{
> +switch (colorspace) {
> +case AVCOL_SPC_RGB:
> +return ZIMG_MATRIX_RGB;
> +case AVCOL_SPC_BT709:
> +return ZIMG_MATRIX_709;
> +case AVCOL_SPC_UNSPECIFIED:
> +return ZIMG_MATRIX_UNSPECIFIED;
> +case AVCOL_SPC_FCC:
> +return ZIMG_MATRIX_FCC;
> +case AVCOL_SPC_BT470BG:
> +return ZIMG_MATRIX_470BG;
> +case AVCOL_SPC_SMPTE170M:
> +return ZIMG_MATRIX_170M;
> +case AVCOL_SPC_SMPTE240M:
> +return ZIMG_MATRIX_240M;
> +case AVCOL_SPC_YCGCO:
> +return ZIMG_MATRIX_YCGCO;
> +case AVCOL_SPC_BT2020_NCL:
> +return ZIMG_MATRIX_2020_NCL;
> +case AVCOL_SPC_BT2020_CL:
> +return ZIMG_MATRIX_2020_CL;
> +case AVCOL_SPC_CHROMA_DERIVED_NCL:
> +return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
> +case AVCOL_SPC_CHROMA_DERIVED_CL:
> +return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
> +case AVCOL_SPC_ICTCP:
> +return ZIMG_MATRIX_ICTCP;
> +}
> +return ZIMG_MATRIX_UNSPECIFIED;
> +}
> +
> +static int convert_trc(enum AVColorTransferCharacteristic color_trc)
> +{
> +switch (color_trc) {
> +case AVCOL_TRC_UNSPECIFIED:
> +return ZIMG_TRANSFER_UNSPECIFIED;
> +case AVCOL_TRC_BT709:
> +return ZIMG_TRANSFER_709;
> +case AVCOL_TRC_GAMMA22:
> +return ZIMG_TRANSFER_470_M;
> +case AVCOL_TRC_GAMMA28:
> +return ZIMG_TRANSFER_470_BG;
> +case AVCOL_TRC_SMPTE170M:
> +return ZIMG_TRANSFER_601;
> +case AVCOL_TRC_SMPTE240M:
> +return ZIMG_TRANSFER_240M;
> +case AVCOL_TRC_LINEAR:
> +return ZIMG_TRANSFER_LINEAR;
> +case AVCOL_TRC_LOG:
> +return ZIMG_TRANSFER_LOG_100;
> +case AVCOL_TRC_LOG_SQRT:
> +return ZIMG_TRANSFER_LOG_316;
> +case AVCOL_TRC_IEC61966_2_4:
> +return ZIMG_TRANSFER_I

[FFmpeg-devel] [PATCH] avfilter/framepool: fix adjustment that can crash filtering

2022-02-18 Thread Paul B Mahol
Fixes #9551.

Signed-off-by: Paul B Mahol 
---
 libavfilter/framepool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/framepool.c b/libavfilter/framepool.c
index 7c63807df3..aab408d355 100644
--- a/libavfilter/framepool.c
+++ b/libavfilter/framepool.c
@@ -96,7 +96,7 @@ FFFramePool *ff_frame_pool_video_init(AVBufferRef* 
(*alloc)(size_t size),
 if (i == 1 || i == 2)
 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
 
-pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h + 16 + 16 - 
1,
+pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h + 16 + 16 - 
0,
  alloc);
 if (!pool->pools[i])
 goto fail;
-- 
2.33.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".