[FFmpeg-cvslog] doc/APIchanges: add missing marker for release 5.0

2022-06-16 Thread Gyan Doshi
ffmpeg | branch: master | Gyan Doshi  | Tue Jun 14 15:27:51 
2022 +0530| [557a1a8af27a2666433ca9970a15addcd1d8a506] | committer: Gyan Doshi

doc/APIchanges: add missing marker for release 5.0

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=557a1a8af27a2666433ca9970a15addcd1d8a506
---

 doc/APIchanges | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5857e67ae6..20b944933a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -96,6 +96,8 @@ API changes, most recent first:
 2022-01-26 - af94ab7c7c0 - lavu 57.19.100 - tx.h
   Add AV_TX_FLOAT_RDFT, AV_TX_DOUBLE_RDFT and AV_TX_INT32_RDFT.
 
+ 8< - FFmpeg 5.0 was cut here  8< -
+
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 

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

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


[FFmpeg-cvslog] avfilter: add virtualbass filter

2022-06-16 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Mon May 30 11:36:22 
2022 +0200| [d39f9feddc4c77f578f13cd8375b3860b730fa2b] | committer: Paul B Mahol

avfilter: add virtualbass filter

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d39f9feddc4c77f578f13cd8375b3860b730fa2b
---

 Changelog|   1 +
 doc/filters.texi |  20 +
 libavfilter/Makefile |   1 +
 libavfilter/af_virtualbass.c | 183 +++
 libavfilter/allfilters.c |   1 +
 libavfilter/version.h|   2 +-
 6 files changed, 207 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 64a0c4f358..ef589705c4 100644
--- a/Changelog
+++ b/Changelog
@@ -20,6 +20,7 @@ version 5.1:
 - tiltshelf audio filter
 - QOI image format support
 - ffprobe -o option
+- virtualbass audio filter
 
 
 version 5.0:
diff --git a/doc/filters.texi b/doc/filters.texi
index d65e83d4d0..5abab5de18 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6927,6 +6927,26 @@ Depth of modulation as a percentage. Range is 0.0 - 1.0.
 Default value is 0.5.
 @end table
 
+@section virtualbass
+
+Apply audio Virtual Bass filter.
+
+This filter accepts stereo input and produce stereo with LFE (2.1) channels 
output.
+The newly produced LFE channel have enhanced virtual bass originally obtained 
from both stereo channels.
+This filter outputs front left and front right channels unchanged as available 
in stereo input.
+
+The filter accepts the following options:
+
+@table @option
+@item cutoff
+Set the virtual bass cutoff frequency. Default value is 250 Hz.
+Allowed range is from 100 to 500 Hz.
+
+@item strength
+Set the virtual bass strength. Allowed range is from 0.5 to 3.
+Default value is 3.
+@end table
+
 @section volume
 
 Adjust the input audio volume.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index e0e4d0de2c..7ba1c8a861 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -164,6 +164,7 @@ OBJS-$(CONFIG_SURROUND_FILTER)   += 
af_surround.o
 OBJS-$(CONFIG_TREBLE_FILTER) += af_biquads.o
 OBJS-$(CONFIG_TREMOLO_FILTER)+= af_tremolo.o
 OBJS-$(CONFIG_VIBRATO_FILTER)+= af_vibrato.o 
generate_wave_table.o
+OBJS-$(CONFIG_VIRTUALBASS_FILTER)+= af_virtualbass.o
 OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o
 OBJS-$(CONFIG_VOLUMEDETECT_FILTER)   += af_volumedetect.o
 
diff --git a/libavfilter/af_virtualbass.c b/libavfilter/af_virtualbass.c
new file mode 100644
index 00..950159096b
--- /dev/null
+++ b/libavfilter/af_virtualbass.c
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2022 Paul B Mahol
+ *
+ * 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 "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+
+#include 
+
+typedef struct AudioVirtualBassContext {
+const AVClass *class;
+
+double cutoff;
+double strength;
+
+double a[3], m[3], cf[2];
+} AudioVirtualBassContext;
+
+#define OFFSET(x) offsetof(AudioVirtualBassContext, x)
+#define TFLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption virtualbass_options[] = {
+{ "cutoff",   "set virtual bass cutoff",   OFFSET(cutoff),   
AV_OPT_TYPE_DOUBLE, {.dbl=250},100,500, FLAGS },
+{ "strength", "set virtual bass strength", OFFSET(strength), 
AV_OPT_TYPE_DOUBLE, {.dbl=3},  0.5,  3, TFLAGS },
+{NULL}
+};
+
+AVFILTER_DEFINE_CLASS(virtualbass);
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterChannelLayouts *in_layout = NULL, *out_layout = NULL;
+AVFilterFormats *formats = NULL;
+int ret;
+
+if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBLP )) 
< 0 ||
+(ret = ff_set_common_formats (ctx,  formats)) 
< 0 ||
+(ret = ff_add_channel_layout (&in_layout, 
&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
+(ret = ff_channel_layouts_ref(in_layout, 
&ctx->inputs[0]->outcfg.channel_layouts)) < 0 ||
+(ret = ff_add_channel_layout (&out_layout, 
&(AVChan

[FFmpeg-cvslog] avcodec/mace: fix some style issues

2022-06-16 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Mon Jun  6 17:41:19 
2022 +0200| [afc7679c89fc5bd017b910cfc0a45f8ed080c1d4] | committer: Paul B Mahol

avcodec/mace: fix some style issues

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=afc7679c89fc5bd017b910cfc0a45f8ed080c1d4
---

 libavcodec/mace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 35af4a6aae..110b320031 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -183,14 +183,13 @@ static int16_t read_table(ChannelData *chd, uint8_t val, 
int tab_idx)
 current = - 1 - tabs[tab_idx].tab2[((chd->index & 0x7f0) >> 
4)*tabs[tab_idx].stride + 2*tabs[tab_idx].stride-val-1];
 
 if (( chd->index += tabs[tab_idx].tab1[val]-(chd->index >> 5) ) < 0)
-  chd->index = 0;
+chd->index = 0;
 
 return current;
 }
 
 static void chomp3(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx)
 {
-
 int16_t current = read_table(chd, val, tab_idx);
 
 current = mace_broken_clip_int16(current + chd->level);

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

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


[FFmpeg-cvslog] avfilter/vf_zscale: dissallow too small slices

2022-06-16 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Thu Jun 16 09:53:50 
2022 +0200| [42289d5eaf3e938f0969aaf58c81550c0aed8f5e] | committer: Paul B Mahol

avfilter/vf_zscale: dissallow too small slices

Also change rounding type when calculating slices size.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=42289d5eaf3e938f0969aaf58c81550c0aed8f5e
---

 libavfilter/vf_zscale.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index bb397deea6..44cb4b9c61 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -45,6 +45,7 @@
 #include "libavutil/imgutils.h"
 
 #define ZIMG_ALIGNMENT 64
+#define MIN_TILESIZE 64
 #define MAX_THREADS 64
 
 static const char *const var_names[] = {
@@ -234,7 +235,7 @@ static void slice_params(ZScaleContext *s, int out_h, int 
in_h)
 {
 int slice_size;
 
-slice_size = (out_h + s->nb_threads - 1) / s->nb_threads;
+slice_size = (out_h + (s->nb_threads / 2)) / s->nb_threads;
 if (slice_size % 2)
 slice_size += 1;
 s->out_slice_start[0] = 0;
@@ -829,7 +830,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
 link->dst->inputs[0]->w  = in->width;
 link->dst->inputs[0]->h  = in->height;
 
-s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), 
FFMIN(link->h, outlink->h) / 8), 1, MAX_THREADS);
+s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), 
FFMIN(link->h, outlink->h) / MIN_TILESIZE), 1, MAX_THREADS);
 s->in_colorspace = in->colorspace;
 s->in_trc = in->color_trc;
 s->in_primaries = in->color_primaries;

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

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


[FFmpeg-cvslog] doc: describe QOI image format

2022-06-16 Thread Peter Ross
ffmpeg | branch: master | Peter Ross  | Wed Jun 15 17:36:25 
2022 +1000| [5242ede48da227927b0c20427c893de4cab44397] | committer: Gyan Doshi

doc: describe QOI image format

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5242ede48da227927b0c20427c893de4cab44397
---

 doc/general_contents.texi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 93a90a5e52..987a2f82fb 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -785,6 +785,8 @@ following image formats are supported:
 @tab Photoshop
 @item PTX  @tab   @tab X
 @tab V.Flash PTX format
+@item QOI  @tab X @tab X
+@tab Quite OK Image format
 @item SGI  @tab X @tab X
 @tab SGI RGB image format
 @item Sun Rasterfile  @tab X @tab X

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

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


[FFmpeg-cvslog] avformat/mxfdec: Don't duplicate av_uuid_unparse

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Jun 14 00:20:06 2022 +0200| [8823900b14cf38c3f2b0a9ec1adfb4e26e3ab182] | 
committer: Andreas Rheinhardt

avformat/mxfdec: Don't duplicate av_uuid_unparse

Also don't allocate the string ourselves, let av_dict_set()
do it.

Reviewed-by: Tomas Härdin 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8823900b14cf38c3f2b0a9ec1adfb4e26e3ab182
---

 libavformat/mxfdec.c | 24 +++-
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 6a22c33995..392066b65a 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2118,24 +2118,6 @@ static int mxf_is_intra_only(MXFDescriptor *descriptor)
 &descriptor->essence_codec_ul)->id != 
AV_CODEC_ID_NONE;
 }
 
-static int mxf_uid_to_str(UID uid, char **str)
-{
-int i;
-char *p;
-p = *str = av_mallocz(sizeof(UID) * 2 + 4 + 1);
-if (!p)
-return AVERROR(ENOMEM);
-for (i = 0; i < sizeof(UID); i++) {
-snprintf(p, 2 + 1, "%.2x", uid[i]);
-p += 2;
-if (i == 3 || i == 5 || i == 7 || i == 9) {
-snprintf(p, 1 + 1, "-");
-p++;
-}
-}
-return 0;
-}
-
 static int mxf_umid_to_str(UID ul, UID uid, char **str)
 {
 int i;
@@ -3088,10 +3070,10 @@ static int64_t mxf_timestamp_to_int64(uint64_t 
timestamp)
 } while (0)
 
 #define SET_UID_METADATA(pb, name, var, str) do { \
+char uuid_str[2 * AV_UUID_LEN + 4 + 1]; \
 avio_read(pb, var, 16); \
-if ((ret = mxf_uid_to_str(var, &str)) < 0) \
-return ret; \
-av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \
+av_uuid_unparse(uid, uuid_str); \
+av_dict_set(&s->metadata, name, uuid_str, 0); \
 } while (0)
 
 #define SET_TS_METADATA(pb, name, var, str) do { \

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

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


[FFmpeg-cvslog] avformat/mxfdec: Use ff_data_to_hex() for data->hex conversion

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Jun 14 00:30:06 2022 +0200| [6b5e3590c761aaf8e1ccceee8eadd8d49cf9c0af] | 
committer: Andreas Rheinhardt

avformat/mxfdec: Use ff_data_to_hex() for data->hex conversion

In this case it also stops pretending that the length of
the output string is somehow checked (which is currently
being done by using snprintf that is called with the amount
of space needed instead of the amount of space actually available).

Reviewed-by: Tomas Härdin 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6b5e3590c761aaf8e1ccceee8eadd8d49cf9c0af
---

 libavformat/mxfdec.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 392066b65a..77bde7c3fe 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2120,22 +2120,13 @@ static int mxf_is_intra_only(MXFDescriptor *descriptor)
 
 static int mxf_umid_to_str(UID ul, UID uid, char **str)
 {
-int i;
 char *p;
 p = *str = av_mallocz(sizeof(UID) * 4 + 2 + 1);
 if (!p)
 return AVERROR(ENOMEM);
 snprintf(p, 2 + 1, "0x");
-p += 2;
-for (i = 0; i < sizeof(UID); i++) {
-snprintf(p, 2 + 1, "%.2X", ul[i]);
-p += 2;
-
-}
-for (i = 0; i < sizeof(UID); i++) {
-snprintf(p, 2 + 1, "%.2X", uid[i]);
-p += 2;
-}
+ff_data_to_hex(p + 2, ul, sizeof(UID), 0);
+ff_data_to_hex(p + 2 + 2 * sizeof(UID), uid, sizeof(UID), 0);
 return 0;
 }
 

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

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


[FFmpeg-cvslog] avformat/mxfdec: Offload allocating string to av_dict_set()

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Jun 14 01:12:14 2022 +0200| [9ff0fbbc0ad095f4364b4d86ec7958908c6d737d] | 
committer: Andreas Rheinhardt

avformat/mxfdec: Offload allocating string to av_dict_set()

Reviewed-by: Tomas Härdin 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9ff0fbbc0ad095f4364b4d86ec7958908c6d737d
---

 libavformat/mxfdec.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 77bde7c3fe..400941c348 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2118,16 +2118,12 @@ static int mxf_is_intra_only(MXFDescriptor *descriptor)
 &descriptor->essence_codec_ul)->id != 
AV_CODEC_ID_NONE;
 }
 
-static int mxf_umid_to_str(UID ul, UID uid, char **str)
+static void mxf_umid_to_str(const UID ul, const UID uid,
+char str[2 + sizeof(UID) * 4 + 1])
 {
-char *p;
-p = *str = av_mallocz(sizeof(UID) * 4 + 2 + 1);
-if (!p)
-return AVERROR(ENOMEM);
-snprintf(p, 2 + 1, "0x");
-ff_data_to_hex(p + 2, ul, sizeof(UID), 0);
-ff_data_to_hex(p + 2 + 2 * sizeof(UID), uid, sizeof(UID), 0);
-return 0;
+snprintf(str, 2 + sizeof(UID) * 4 + 1, "0x");
+ff_data_to_hex(str + 2, ul, sizeof(UID), 0);
+ff_data_to_hex(str + 2 + 2 * sizeof(UID), uid, sizeof(UID), 0);
 }
 
 static int mxf_version_to_str(uint16_t major, uint16_t minor, uint16_t 
tertiary,
@@ -2141,13 +2137,11 @@ static int mxf_version_to_str(uint16_t major, uint16_t 
minor, uint16_t tertiary,
 
 static int mxf_add_umid_metadata(AVDictionary **pm, const char *key, 
MXFPackage* package)
 {
-char *str;
-int ret;
+char str[2 + 4 * sizeof(UID) + 1];
 if (!package)
 return 0;
-if ((ret = mxf_umid_to_str(package->package_ul, package->package_uid, 
&str)) < 0)
-return ret;
-av_dict_set(pm, key, str, AV_DICT_DONT_STRDUP_VAL);
+mxf_umid_to_str(package->package_ul, package->package_uid, str);
+av_dict_set(pm, key, str, 0);
 return 0;
 }
 

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

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


[FFmpeg-cvslog] avformat/mxf: Use AVUUID for uids

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Jun 14 00:06:48 2022 +0200| [41365fdf5c9ed96f299939a89dea7e4e257253cf] | 
committer: Andreas Rheinhardt

avformat/mxf: Use AVUUID for uids

This is in preparation for using av_uuid functions directly.

Reviewed-by: Tomas Härdin 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=41365fdf5c9ed96f299939a89dea7e4e257253cf
---

 libavformat/mxf.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index d53a16df51..4d9f5119a3 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -25,8 +25,9 @@
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/rational.h"
+#include "libavutil/uuid.h"
 
-typedef uint8_t UID[16];
+typedef AVUUID UID;
 
 enum MXFMetadataSetType {
 AnyType,

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

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


[FFmpeg-cvslog] avformat/matroskaenc: Reset cur_master_element when discarding master

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Jun 16 19:06:10 2022 +0200| [49a63c6c6609c8ccb6c5c5f7474c9900a7e2cb8f] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Reset cur_master_element when discarding master

Before this patch the muxer writes an invalid file
(namely one in which the Projection master is a child of
the Colour element) if the following conditions are met:
a) The stream contains AVMasteringDisplayMetadata without primaries
and luminance (i.e. useless AVMasteringDisplayMetadata).
b) The stream contains AV_PKT_DATA_SPHERICAL side data.
c) All the colour elements of the stream are equal to default
(i.e. unknown).
Fortunately these conditions are very unlikely to be met.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=49a63c6c6609c8ccb6c5c5f7474c9900a7e2cb8f
---

 libavformat/matroskaenc.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 482b5812e5..297346be84 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -444,15 +444,25 @@ static void ebml_writer_close_master(EbmlWriter *writer)
 av_assert2(writer->current_master_element < writer->nb_elements);
 elem = &writer->elements[writer->current_master_element];
 av_assert2(elem->type == EBML_MASTER);
+av_assert2(elem->priv.master.nb_elements < 0); /* means unset */
 elem->priv.master.nb_elements = writer->nb_elements - 
writer->current_master_element - 1;
+av_assert2(elem->priv.master.containing_master < 0 ||
+   elem->priv.master.containing_master < 
writer->current_master_element);
 writer->current_master_element = elem->priv.master.containing_master;
 }
 
 static void ebml_writer_close_or_discard_master(EbmlWriter *writer)
 {
 av_assert2(writer->nb_elements > 0);
+av_assert2(0 <= writer->current_master_element);
+av_assert2(writer->current_master_element < writer->nb_elements);
 if (writer->current_master_element == writer->nb_elements - 1) {
+const EbmlElement *const elem = &writer->elements[writer->nb_elements 
- 1];
 /* The master element has no children. Discard it. */
+av_assert2(elem->type == EBML_MASTER);
+av_assert2(elem->priv.master.containing_master < 0 ||
+   elem->priv.master.containing_master < 
writer->current_master_element);
+writer->current_master_element = elem->priv.master.containing_master;
 writer->nb_elements--;
 return;
 }

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

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


[FFmpeg-cvslog] avformat/matroskaenc: Convert chapter metadata

2022-06-16 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Jun 15 08:27:58 2022 +0200| [672987b2db9051a4738402751b94133c0d6c405d] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Convert chapter metadata

It is no longer converted since mkv_write_chapters() is called
before mkv_write_tags() which happens since commit
4ebfc13c338423cf48f1a1266c890422367f7775. Given the fact that
chapters can also be written late, mkv_write_chapters() has to
convert the metadata itself.

Fixes ticket #9812.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=672987b2db9051a4738402751b94133c0d6c405d
---

 libavformat/matroskaenc.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 297346be84..c32d4286c1 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2104,7 +2104,7 @@ static int mkv_write_chapters(AVFormatContext *s)
 create_new_ids = mkv_new_chapter_ids_needed(s);
 
 for (unsigned i = 0; i < s->nb_chapters; i++) {
-const AVChapter *c   = s->chapters[i];
+AVChapter *const c   = s->chapters[i];
 int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale);
 int64_t chapterend   = av_rescale_q(c->end,   c->time_base, scale);
 const AVDictionaryEntry *t;
@@ -2132,11 +2132,15 @@ static int mkv_write_chapters(AVFormatContext *s)
 if (ret < 0)
 goto fail;
 
-if (tags && mkv_check_tag(c->metadata, 
MATROSKA_ID_TAGTARGETS_CHAPTERUID)) {
-ret = mkv_write_tag(mkv, c->metadata, tags, NULL,
-MATROSKA_ID_TAGTARGETS_CHAPTERUID, uid);
-if (ret < 0)
-goto fail;
+if (tags) {
+ff_metadata_conv(&c->metadata, ff_mkv_metadata_conv, NULL);
+
+if (mkv_check_tag(c->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID)) 
{
+ret = mkv_write_tag(mkv, c->metadata, tags, NULL,
+MATROSKA_ID_TAGTARGETS_CHAPTERUID, uid);
+if (ret < 0)
+goto fail;
+}
 }
 }
 end_ebml_master(dyn_cp, editionentry);

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

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


[FFmpeg-cvslog] Revert "avdevice/pulse_audio_dec: only set adjust latency flag if fragment_size is not set"

2022-06-16 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Jun 11 19:17:31 
2022 +0200| [b83032899af3fa355f94a7d77a0334fb56e1d919] | committer: Marton 
Balint

Revert "avdevice/pulse_audio_dec: only set adjust latency flag if fragment_size 
is not set"

This reverts commit 7f059a250bb7bcbf7bba537c1a059a5934413035.

Apparently adjusting latency makes a difference even if fragment size is 
specifed.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b83032899af3fa355f94a7d77a0334fb56e1d919
---

 libavdevice/pulse_audio_dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index a33d1afd1f..ed094fd250 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -220,7 +220,7 @@ static av_cold int pulse_read_header(AVFormatContext *s)
 
 ret = pa_stream_connect_record(pd->stream, device, &attr,
 PA_STREAM_INTERPOLATE_TIMING
-| (pd->fragment_size == -1 ? 
PA_STREAM_ADJUST_LATENCY : 0)
+|PA_STREAM_ADJUST_LATENCY
 |PA_STREAM_AUTO_TIMING_UPDATE);
 
 if (ret < 0) {

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

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


[FFmpeg-cvslog] avdevice/pulse_audio_dec: reduce default fragment size

2022-06-16 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Jun 11 19:59:32 
2022 +0200| [b67ca8a7a5f443de5eacac9ed4c5d94dfe685a5b] | committer: Marton 
Balint

avdevice/pulse_audio_dec: reduce default fragment size

Reduces default fragment size from the pulse audio default of 2 sec to 50 ms.
This also has an effect on the size of the returned frames, which will be
around 50 ms as well, making timestamps more accurate.

This should fix the regression in ticket #9776.

Pulseaudio timestamps for monitor sources are still pretty inaccurate for me,
but I don't see how else should we query latencies from the library.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b67ca8a7a5f443de5eacac9ed4c5d94dfe685a5b
---

 doc/indevs.texi   | 4 ++--
 libavdevice/pulse_audio_dec.c | 7 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 9d8020311a..1141da26d1 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -1292,8 +1292,8 @@ Specify the channels in use, by default 2 (stereo) is set.
 Specify the number of bytes per frame, by default it is set to 1024.
 
 @item fragment_size
-Specify the minimal buffering fragment in PulseAudio, it will affect the
-audio latency. By default it is unset.
+Specify the size in bytes of the minimal buffering fragment in PulseAudio, it
+will affect the audio latency. By default it is set to 50 ms amount of data.
 
 @item wallclock
 Set the initial PTS using the current time. Default is 1.
diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index ed094fd250..2355b91776 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -162,7 +162,12 @@ static av_cold int pulse_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 }
 
-attr.fragsize = pd->fragment_size;
+if (pd->fragment_size == -1) {
+// 50 ms fragments/latency by default seem good enough
+attr.fragsize = pa_frame_size(&ss) * (pd->sample_rate / 20);
+} else {
+attr.fragsize = pd->fragment_size;
+}
 
 if (s->url[0] != '\0' && strcmp(s->url, "default"))
 device = s->url;

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

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


[FFmpeg-cvslog] avdevice/pulse_audio_dec: deprecate frame_size option

2022-06-16 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Jun 11 20:13:00 
2022 +0200| [1b3ec3c8ca5f0e2cdaef2a9ccb5950b5a1d89a96] | committer: Marton 
Balint

avdevice/pulse_audio_dec: deprecate frame_size option

It does not do anything. Frame sizes can be controlled by using fragment_size.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1b3ec3c8ca5f0e2cdaef2a9ccb5950b5a1d89a96
---

 doc/indevs.texi   | 2 +-
 libavdevice/pulse_audio_dec.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 1141da26d1..8a198c4b44 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -1289,7 +1289,7 @@ Specify the samplerate in Hz, by default 48kHz is used.
 Specify the channels in use, by default 2 (stereo) is set.
 
 @item frame_size
-Specify the number of bytes per frame, by default it is set to 1024.
+This option does nothing and is deprecated.
 
 @item fragment_size
 Specify the size in bytes of the minimal buffering fragment in PulseAudio, it
diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index 2355b91776..2545462939 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -371,6 +371,7 @@ static int pulse_get_device_list(AVFormatContext *h, 
AVDeviceInfoList *device_li
 
 #define OFFSET(a) offsetof(PulseData, a)
 #define D AV_OPT_FLAG_DECODING_PARAM
+#define DEPR AV_OPT_FLAG_DEPRECATED
 
 static const AVOption options[] = {
 { "server","set PulseAudio server", 
OFFSET(server),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D },
@@ -378,7 +379,7 @@ static const AVOption options[] = {
 { "stream_name",   "set stream description",
OFFSET(stream_name),   AV_OPT_TYPE_STRING, {.str = "record"}, 0, 0, D },
 { "sample_rate",   "set sample rate in Hz", 
OFFSET(sample_rate),   AV_OPT_TYPE_INT,{.i64 = 48000},1, INT_MAX, D },
 { "channels",  "set number of audio channels",  
OFFSET(channels),  AV_OPT_TYPE_INT,{.i64 = 2},1, INT_MAX, D },
-{ "frame_size","set number of bytes per frame", 
OFFSET(frame_size),AV_OPT_TYPE_INT,{.i64 = 1024}, 1, INT_MAX, D },
+{ "frame_size","set number of bytes per frame", 
OFFSET(frame_size),AV_OPT_TYPE_INT,{.i64 = 1024}, 1, INT_MAX, D | 
DEPR },
 { "fragment_size", "set buffering size, affects latency and cpu usage", 
OFFSET(fragment_size), AV_OPT_TYPE_INT,{.i64 = -1},  -1, INT_MAX, D },
 { "wallclock", "set the initial pts using the current time", 
OFFSET(wallclock), AV_OPT_TYPE_INT,{.i64 = 1},   -1, 1, D },
 { NULL },

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

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


[FFmpeg-cvslog] avformat/demux: Count EAGAIN as 100 bytes in relation to read limit in avformat_find_stream_info()

2022-06-16 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Feb  8 20:04:25 2022 +0100| [b0cac7082d8a3ff2d4f039af01b45c48bb578de7] | 
committer: Michael Niedermayer

avformat/demux: Count EAGAIN as 100 bytes in relation to read limit in 
avformat_find_stream_info()

Fixes: Timeout
Fixes: 
43717/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5206008287330304
Fixes: 
45738/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6142535657979904

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b0cac7082d8a3ff2d4f039af01b45c48bb578de7
---

 libavformat/demux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 57720f4311..e121253dfd 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2615,8 +2615,10 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 /* NOTE: A new stream can be added there if no header in file
  * (AVFMTCTX_NOHEADER). */
 ret = read_frame_internal(ic, pkt1);
-if (ret == AVERROR(EAGAIN))
+if (ret == AVERROR(EAGAIN)) {
+read_size += 100;
 continue;
+}
 
 if (ret < 0) {
 /* EOF or error*/

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

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


[FFmpeg-cvslog] avformat/demux: Make read_frame_internal() return AVERREOR(EAGAIN) on stuck empty input parser

2022-06-16 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Feb  8 20:00:53 2022 +0100| [02699490c14e86105104940c009953081f69432c] | 
committer: Michael Niedermayer

avformat/demux: Make read_frame_internal() return AVERREOR(EAGAIN) on stuck 
empty input parser

Fixes: read_frame_internal() which does not return even though both demuxer and 
parser do return
Fixes: 
43717/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5206008287330304

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=02699490c14e86105104940c009953081f69432c
---

 libavformat/demux.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 1620716716..57720f4311 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1235,11 +1235,15 @@ static int read_frame_internal(AVFormatContext *s, 
AVPacket *pkt)
 FFFormatContext *const si = ffformatcontext(s);
 int ret, got_packet = 0;
 AVDictionary *metadata = NULL;
+int empty = 0;
 
 while (!got_packet && !si->parse_queue.head) {
 AVStream *st;
 FFStream *sti;
 
+if (empty > 1)
+return AVERROR(EAGAIN);
+
 /* read next packet */
 ret = ff_read_packet(s, pkt);
 if (ret < 0) {
@@ -1330,6 +1334,8 @@ static int read_frame_internal(AVFormatContext *s, 
AVPacket *pkt)
 }
 got_packet = 1;
 } else if (st->discard < AVDISCARD_ALL) {
+if (pkt->size == 0)
+empty ++;
 if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0)
 return ret;
 st->codecpar->sample_rate = sti->avctx->sample_rate;

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

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


[FFmpeg-cvslog] avformat/aiffdec: avoid integer overflow in get_meta()

2022-06-16 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar 23 01:08:56 2022 +0100| [6a02de21278ec3bea1d2c62665f2629d5a62210f] | 
committer: Michael Niedermayer

avformat/aiffdec: avoid integer overflow in get_meta()

Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 
'int'
Fixes: 
45891/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-6159183893889024

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6a02de21278ec3bea1d2c62665f2629d5a62210f
---

 libavformat/aiffdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index a70899d765..d2dc46e251 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -73,7 +73,7 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 /* Metadata string read */
 static void get_meta(AVFormatContext *s, const char *key, int size)
 {
-uint8_t *str = av_malloc(size+1);
+uint8_t *str = av_malloc(size+1U);
 
 if (str) {
 int res = avio_read(s->pb, str, size);

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

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


[FFmpeg-cvslog] avformat/aaxdec: Check for overlaping segments

2022-06-16 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Wed 
Mar 23 00:57:34 2022 +0100| [c16a0ed2422a86e0f3286f59281d119c4d8d159a] | 
committer: Michael Niedermayer

avformat/aaxdec: Check for overlaping segments

Fixes: Timeout
Fixes: 
45875/clusterfuzz-testcase-minimized-ffmpeg_dem_AAX_fuzzer-6121689903136768

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c16a0ed2422a86e0f3286f59281d119c4d8d159a
---

 libavformat/aaxdec.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index e47ab3ad73..dd1fbde736 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -252,6 +252,10 @@ static int aax_read_header(AVFormatContext *s)
 size  = avio_rb32(pb);
 a->segments[r].start = start + a->data_offset;
 a->segments[r].end   = a->segments[r].start + size;
+if (r &&
+a->segments[r].start < a->segments[r-1].end &&
+a->segments[r].end   > a->segments[r-1].start)
+return AVERROR_INVALIDDATA;
 } else
 return AVERROR_INVALIDDATA;
 }

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

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


[FFmpeg-cvslog] libavcodec/qsvenc: add ROI support to qsv encoder

2022-06-16 Thread Wenbin Chen
ffmpeg | branch: master | Wenbin Chen  | 
Wed Jun  8 13:02:48 2022 +0800| [97141ffeec803c448d81ee4a53cfa2355f79f7ec] | 
committer: Haihao Xiang

libavcodec/qsvenc: add ROI support to qsv encoder

Use The mfxEncoderCtrl parameter to enable ROI. Get side data
"AVRegionOfInterest" and use it to configure "mfxExtEncoderROI" which is
the MediaSDK's ROI configuration.

Signed-off-by: Wenbin Chen 
Signed-off-by: Haihao Xiang 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=97141ffeec803c448d81ee4a53cfa2355f79f7ec
---

 libavcodec/qsv_internal.h |  4 +++
 libavcodec/qsvenc.c   | 85 +++
 2 files changed, 89 insertions(+)

diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index e2aecdcbd6..8131acdae9 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -51,6 +51,9 @@
 #define ASYNC_DEPTH_DEFAULT 4   // internal parallelism
 
 #define QSV_MAX_ENC_PAYLOAD 2   // # of mfxEncodeCtrl payloads supported
+#define QSV_MAX_ENC_EXTPARAM 2
+
+#define QSV_MAX_ROI_NUM 256
 
 #define QSV_MAX_FRAME_EXT_PARAMS 4
 
@@ -83,6 +86,7 @@ typedef struct QSVFrame {
 int num_ext_params;
 
 mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload
+mfxExtBuffer *extparam[QSV_MAX_ENC_EXTPARAM]; ///< used for 
enc_ctrl.ExtParam
 
 int queued;
 int used;
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 03e9e5523d..902bada55b 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1390,15 +1390,29 @@ static void free_encoder_ctrl_payloads(mfxEncodeCtrl* 
enc_ctrl)
 }
 }
 
+static void free_encoder_ctrl_extparam(mfxEncodeCtrl* enc_ctrl)
+{
+if (enc_ctrl) {
+int i;
+for (i = 0; i < enc_ctrl->NumExtParam && i < QSV_MAX_ENC_EXTPARAM; 
i++) {
+if (enc_ctrl->ExtParam[i])
+av_freep(&(enc_ctrl->ExtParam[i]));
+}
+enc_ctrl->NumExtParam = 0;
+}
+}
+
 static void clear_unused_frames(QSVEncContext *q)
 {
 QSVFrame *cur = q->work_frames;
 while (cur) {
 if (cur->used && !cur->surface.Data.Locked) {
 free_encoder_ctrl_payloads(&cur->enc_ctrl);
+free_encoder_ctrl_extparam(&cur->enc_ctrl);
 //do not reuse enc_ctrl from previous frame
 memset(&cur->enc_ctrl, 0, sizeof(cur->enc_ctrl));
 cur->enc_ctrl.Payload = cur->payloads;
+cur->enc_ctrl.ExtParam = cur->extparam;
 if (cur->frame->format == AV_PIX_FMT_QSV) {
 av_frame_unref(cur->frame);
 }
@@ -1436,6 +1450,7 @@ static int get_free_frame(QSVEncContext *q, QSVFrame **f)
 return AVERROR(ENOMEM);
 }
 frame->enc_ctrl.Payload = frame->payloads;
+frame->enc_ctrl.ExtParam = frame->extparam;
 *last = frame;
 
 *f = frame;
@@ -1537,6 +1552,67 @@ static void print_interlace_msg(AVCodecContext *avctx, 
QSVEncContext *q)
 }
 }
 
+static int set_roi_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame,
+   mfxEncodeCtrl *enc_ctrl)
+{
+AVFrameSideData *sd = NULL;
+int mb_size;
+
+if (avctx->codec_id == AV_CODEC_ID_H264)
+mb_size = 16;
+else if (avctx->codec_id == AV_CODEC_ID_H265)
+mb_size = 32;
+else
+return 0;
+
+if (frame)
+sd = av_frame_get_side_data(frame, AV_FRAME_DATA_REGIONS_OF_INTEREST);
+
+if (sd) {
+mfxExtEncoderROI *enc_roi = NULL;
+AVRegionOfInterest *roi;
+uint32_t roi_size;
+int nb_roi, i;
+
+roi = (AVRegionOfInterest *)sd->data;
+roi_size = roi->self_size;
+if (!roi_size || sd->size % roi_size) {
+av_log(avctx, AV_LOG_ERROR, "Invalid ROI Data.\n");
+return AVERROR(EINVAL);
+}
+nb_roi = sd->size / roi_size;
+if (nb_roi > QSV_MAX_ROI_NUM) {
+av_log(avctx, AV_LOG_WARNING, "More ROIs set than "
+"supported by driver (%d > %d).\n",
+nb_roi, QSV_MAX_ROI_NUM);
+nb_roi = QSV_MAX_ROI_NUM;
+}
+
+enc_roi = av_mallocz(sizeof(*enc_roi));
+if (!enc_roi)
+return AVERROR(ENOMEM);
+enc_roi->Header.BufferId = MFX_EXTBUFF_ENCODER_ROI;
+enc_roi->Header.BufferSz = sizeof(*enc_roi);
+enc_roi->NumROI  = nb_roi;
+enc_roi->ROIMode = MFX_ROI_MODE_QP_DELTA;
+for (i = 0; i < nb_roi; i++) {
+roi = (AVRegionOfInterest *)(sd->data + roi_size * i);
+enc_roi->ROI[i].Top= FFALIGN(roi->top, mb_size);
+enc_roi->ROI[i].Bottom = FFALIGN(roi->bottom, mb_size);
+enc_roi->ROI[i].Left   = FFALIGN(roi->left, mb_size);
+enc_roi->ROI[i].Right  = FFALIGN(roi->right, mb_size);
+enc_roi->ROI[i].DeltaQP =
+roi->qoffset.num * 51 / roi->qoffset.den;
+av_log(avctx, AV_LOG_DEBUG, "ROI: (%d,%d)-(%d,%d) -> %+d.\n",
+   roi->top, roi