Re: [FFmpeg-devel] [PATCH v1] avfilter: add overlay vaapi filter

2019-12-31 Thread Paul B Mahol
On 12/20/19, Xinpeng Sun  wrote:
> Overlay one video on the top of another.
>
> It takes two inputs and has one output. The first input is the "main" video
> on which the
> second input is overlaid. This filter requires same memory layout for all
> the inputs.
>
> An example command to use this filter to overlay an image LOGO at the
> top-left corner of
> the INPUT video and both inputs are yuv420p format:
> FFMPEG -hwaccel vaapi -vaapi_device /dev/dri/renderD128
> -hwaccel_output_format vaapi \
> -i INPUT -i LOGO -filter_complex \
> "[0:v]hwupload[a], [1:v]format=yuv420p, hwupload[b], [a][b]overlay_vaapi,
> hwdownload" \
> OUTPUT
>
> Signed-off-by: Xinpeng Sun 
> Signed-off-by: Zachary Zhou 
> ---
>  configure  |   3 +
>  doc/filters.texi   |  51 
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_overlay_vaapi.c | 432 +
>  5 files changed, 488 insertions(+)
>  create mode 100644 libavfilter/vf_overlay_vaapi.c
>
> diff --git a/configure b/configure
> index eec43c3b06..9969c9e984 100755
> --- a/configure
> +++ b/configure
> @@ -3527,6 +3527,7 @@ openclsrc_filter_deps="opencl"
>  overlay_opencl_filter_deps="opencl"
>  overlay_qsv_filter_deps="libmfx"
>  overlay_qsv_filter_select="qsvvpp"
> +overlay_vaapi_filter_deps="vaapi"
>  owdenoise_filter_deps="gpl"
>  pan_filter_deps="swresample"
>  perspective_filter_deps="gpl"
> @@ -3584,6 +3585,7 @@ tonemap_vaapi_filter_deps="vaapi
> VAProcPipelineParameterBuffer_output_hdr_metada
>  tonemap_opencl_filter_deps="opencl const_nan"
>  transpose_opencl_filter_deps="opencl"
>  transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags"
> +overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
>  unsharp_opencl_filter_deps="opencl"
>  uspp_filter_deps="gpl avcodec"
>  vaguedenoiser_filter_deps="gpl"
> @@ -6587,6 +6589,7 @@ if enabled vaapi; then
>  check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
>  check_struct "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer"
> output_hdr_metadata
>  check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
> +check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
>  check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
>  check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
>  check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 527c6a08b2..d391218529 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -21049,6 +21049,57 @@ To enable compilation of these filters you need to
> configure FFmpeg with
>
>  To use vaapi filters, you need to setup the vaapi device correctly. For
> more information, please read
> @url{https://trac.ffmpeg.org/wiki/Hardware/VAAPI}
>
> +@section overlay_vaapi
> +
> +Overlay one video on the top of another.
> +
> +It takes two inputs and has one output. The first input is the "main" video
> on which the second input is overlaid.
> +This filter requires same memory layout for all the inputs. So, format
> conversion may be needed.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +
> +@item x
> +Set the x coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item y
> +Set the y coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item w
> +Set the width of the overlaid video on the main video.
> +Default value is the width of input overlay video.
> +
> +@item h
> +Set the height of the overlaid video on the main video.
> +Default value is the height of input overlay video.
> +
> +@item alpha
> +Set blocking detection thresholds. Allowed range is 0.0 to 1.0, it
> +need input video has alpha channel.

needs input video that have alpha channel.

> +Default value is @code{0.0}.
> +
> +@end table
> +
> +@subsection Examples
> +
> +@itemize
> +@item
> +Overlay an image LOGO at the top-left corner of the INPUT video. Both
> inputs are yuv420p format.
> +@example
> +-i INPUT -i LOGO -filter_complex "[0:v]hwupload[a], [1:v]format=yuv420p,
> hwupload[b], [a][b]overlay_vaapi, hwdownload" OUTPUT
> +@end example
> +@item
> +Overlay an image LOGO at the offset (200, 100) from the top-left corner of
> the INPUT video.
> +The inputs have same memory layout for color channels, the overlay has
> additional alpha plane, like INPUT is yuv420p, and the LOGO is yuva420p.
> +@example
> +-i INPUT -i LOGO -filter_complex "[0:v]hwupload[a], [1:v]format=yuva420p,
> hwupload[b], [a][b]overlay_vaapi=x=200:y=100:w=400:h=300:alpha=1.0,
> hwdownload" OUTPUT
> +@end example
> +
> +@end itemize
> +
>  @section tonemap_vappi
>
>  Perform HDR(High Dynamic Range) to SDR(Standard Dynamic Range) conversion
> with tone-mapping.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 37d4eee858..ea73fef9aa 100644
> --

Re: [FFmpeg-devel] [PATCH v3 1/1] avdevice/gdigrab: Add use_captureblt option for disable or use CAPTUREBLT flag, when useing the bitblt function with CAPTUREBLT it caused the mouse cursor flicker. mo

2019-12-31 Thread Marton Balint



On Tue, 31 Dec 2019, fgodt wrote:



On 2019/12/31 上午1:37, Calvin Walton wrote:

On Mon, 2019-12-30 at 12:31 +0100, Marton Balint wrote:

On Mon, 30 Dec 2019, fgodt...@hotmail.com wrote:


From: FgoDt 
+@item use_captureblt
+When use gdigrab to capture window or desktop, the mouse cursor
will flicker.

Why? Does this happen with every windows version? This does not seem
like
the right fix. In fact, I dont't see how this can work, because mouse
is
drawn upon the captured video "manually" in paint_mouse_pointer.
Could you
dig deeper what is the main cause of the issue?

I'm guessing that what happens here is that on some OS versions, with
some graphics drivers, the cursor on the *real* display might flicker
while ffmpeg is capturing. I've never actually seen this happen, but if
you have bad/old drivers and have desktop compositing disabled, maybe?
sorry i'm not describe clear. as you say the capture video mouse is 
"manually" paint,


so the flicker is not the video, but windows mouse cursor. the reason is 
CAPTUREBLT flag


use to capture layered window, and the animated cursors or software 
cursor became know


as layered window in Windows. so when we call bitblt with CAPTUREBLT 
windows will hide


cursor do capture , and then reshow the cursor,this will make Windows 
mouse cursor flicker.


if user not capture layered window, without CAPTUREBLT flag does not 
change anything.


see details 
https://docs.microsoft.com/en-us/previous-versions/technet-magazine/dd392008(v=msdn.10)?redirectedfrom=MSDN


This is still not the whole story, if you google deeper you should find 
that this only affects Windows XP and earlier or Windows 7 if Aero is 
disabled.


Considering this, I am not sure if we should add this flag, 
maybe a warning should be printed instead if Aero is disabled.


Regards,
Marton
___
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] [PATCHv2 8/8] avformat/img2enc: add support for specifying protocol options

2019-12-31 Thread Nicolas George
Marton Balint (12019-12-28):
> v2: simplified example
> 
> Signed-off-by: Marton Balint 
> ---
>  doc/muxers.texi   | 11 +++
>  libavformat/img2enc.c | 13 -
>  2 files changed, 23 insertions(+), 1 deletion(-)

image2 is not the only demuxer that opens new streams. I think a generic
solution would be preferable.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
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 6/8] swscale/tests/swscale: remove access of AV_PIX_FMT_NB

2019-12-31 Thread Michael Niedermayer
On Mon, Dec 30, 2019 at 09:54:17PM +0800, quinkbl...@foxmail.com wrote:
> From: Zhao Zhili 
> 
> ---
>  libswscale/tests/swscale.c | 17 +++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
> index 19878a7877..784195f468 100644
> --- a/libswscale/tests/swscale.c
> +++ b/libswscale/tests/swscale.c
> @@ -251,6 +251,18 @@ end:
>  return res;
>  }
>  
> +static int getMaxFmt()
> +{
> +const AVPixFmtDescriptor *desc = NULL;
> +int fmt_max = AV_PIX_FMT_NONE;
> +
> +while ((desc = av_pix_fmt_desc_next(desc))) {
> +int fmt = av_pix_fmt_desc_get_id(desc);
> +fmt_max = FFMAX(fmt, fmt_max);
> +}
> +return fmt_max;
> +}
> +
>  static void selfTest(const uint8_t * const ref[4], int refStride[4],
>   int w, int h,
>   enum AVPixelFormat srcFormat_in,
> @@ -264,9 +276,10 @@ static void selfTest(const uint8_t * const ref[4], int 
> refStride[4],
>  const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 };
>  enum AVPixelFormat srcFormat, dstFormat;
>  const AVPixFmtDescriptor *desc_src, *desc_dst;
> +const int fmt_max = getMaxFmt();
>  
>  for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0;
> - srcFormat < AV_PIX_FMT_NB; srcFormat++) {
> + srcFormat <= fmt_max; srcFormat++) {
>  if (!sws_isSupportedInput(srcFormat) ||
>  !sws_isSupportedOutput(srcFormat))
>  continue;
> @@ -274,7 +287,7 @@ static void selfTest(const uint8_t * const ref[4], int 
> refStride[4],
>  desc_src = av_pix_fmt_desc_get(srcFormat);
>  
>  for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0;
> - dstFormat < AV_PIX_FMT_NB; dstFormat++) {
> + dstFormat <= fmt_max; dstFormat++) {
>  int i, j, k;
>  int res = 0;

Iam not sure this makes sense, formats added after build of the test
would only be rejected in sws_isSupported* in the next line


[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you drop bombs on a foreign country and kill a hundred thousand
innocent people, expect your government to call the consequence
"unprovoked inhuman terrorist attacks" and use it to justify dropping
more bombs and killing more people. The technology changed, the idea is old.


signature.asc
Description: PGP signature
___
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] avfilter: add freezeframes video filter

2019-12-31 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi  |  19 
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_freezeframes.c | 167 ++
 4 files changed, 188 insertions(+)
 create mode 100644 libavfilter/vf_freezeframes.c

diff --git a/doc/filters.texi b/doc/filters.texi
index ba00989987..ca3ddc19eb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11166,6 +11166,25 @@ specified value) or as a difference ratio between 0 
and 1. Default is -60dB, or
 Set freeze duration until notification (default is 2 seconds).
 @end table
 
+@section freezeframes
+
+Freeze video frames.
+
+This filter freeze video frames using frame from 2nd input.
+
+The filter accepts the following options:
+
+@table @option
+@item first
+Set number of first frame from which to start freeze.
+
+@item last
+Set number of last frame from which to end freeze.
+
+@item replace
+Set number of frame from 2nd input which will be used instead of replaced 
frames.
+@end table
+
 @anchor{frei0r}
 @section frei0r
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 8b8a5bd535..58b3077dec 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -254,6 +254,7 @@ OBJS-$(CONFIG_FRAMEPACK_FILTER)  += 
vf_framepack.o
 OBJS-$(CONFIG_FRAMERATE_FILTER)  += vf_framerate.o
 OBJS-$(CONFIG_FRAMESTEP_FILTER)  += vf_framestep.o
 OBJS-$(CONFIG_FREEZEDETECT_FILTER)   += vf_freezedetect.o
+OBJS-$(CONFIG_FREEZEFRAMES_FILTER)   += vf_freezeframes.o
 OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
 OBJS-$(CONFIG_FSPP_FILTER)   += vf_fspp.o
 OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9f2080f857..6270c18ae2 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -239,6 +239,7 @@ extern AVFilter ff_vf_framepack;
 extern AVFilter ff_vf_framerate;
 extern AVFilter ff_vf_framestep;
 extern AVFilter ff_vf_freezedetect;
+extern AVFilter ff_vf_freezeframes;
 extern AVFilter ff_vf_frei0r;
 extern AVFilter ff_vf_fspp;
 extern AVFilter ff_vf_gblur;
diff --git a/libavfilter/vf_freezeframes.c b/libavfilter/vf_freezeframes.c
new file mode 100644
index 00..b6cd5dba68
--- /dev/null
+++ b/libavfilter/vf_freezeframes.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2019 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/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct FreezeFramesContext {
+const AVClass *class;
+int64_t first, last, replace;
+
+AVFrame *replace_frame;
+} FreezeFramesContext;
+
+#define OFFSET(x) offsetof(FreezeFramesContext, x)
+#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
+
+static const AVOption freezeframes_options[] = {
+{ "first",   "set first frame to freeze", OFFSET(first),   
AV_OPT_TYPE_INT64, {.i64=0}, 0, INT64_MAX, FLAGS },
+{ "last","set last frame to freeze",  OFFSET(last),
AV_OPT_TYPE_INT64, {.i64=0}, 0, INT64_MAX, FLAGS },
+{ "replace", "set frame to replace",  OFFSET(replace), 
AV_OPT_TYPE_INT64, {.i64=0}, 0, INT64_MAX, FLAGS },
+{ NULL },
+};
+
+AVFILTER_DEFINE_CLASS(freezeframes);
+
+static int config_output(AVFilterLink *outlink)
+{
+AVFilterContext *ctx = outlink->src;
+AVFilterLink *sourcelink = ctx->inputs[0];
+AVFilterLink *replacelink = ctx->inputs[1];
+
+if (sourcelink->w != replacelink->w || sourcelink->h != replacelink->h) {
+av_log(ctx, AV_LOG_ERROR,
+   "Input frame sizes do not match (%dx%d vs %dx%d).\n",
+   sourcelink->w, sourcelink->h,
+   replacelink->w, replacelink->h);
+return AVERROR(EINVAL);
+}
+
+outlink->w = sourcelink->w;
+outlink->h = sourcelink->h;
+outlink->time_base = sourcelink->time_base;
+outlink->sample_aspect_ratio = sourcelink->sample_aspect_ratio;
+outlink->frame_rate = sourcelink->frame_rate;
+
+return 0;
+}
+
+static int a

Re: [FFmpeg-devel] [PATCH 5/8] swscale/utils: remove access of AV_PIX_FMT_NB

2019-12-31 Thread Michael Niedermayer
On Mon, Dec 30, 2019 at 09:54:16PM +0800, quinkbl...@foxmail.com wrote:
> From: Zhao Zhili 
> 
> ---
>  libswscale/utils.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

will apply

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus


signature.asc
Description: PGP signature
___
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 7/8] avcodec/utils: remove access of AV_SAMPLE_FMT_NB

2019-12-31 Thread Michael Niedermayer
On Mon, Dec 30, 2019 at 09:54:18PM +0800, quinkbl...@foxmail.com wrote:
> From: Zhao Zhili 
> 
> ---
>  libavcodec/utils.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Any man who breaks a law that conscience tells him is unjust and willingly 
accepts the penalty by staying in jail in order to arouse the conscience of 
the community on the injustice of the law is at that moment expressing the 
very highest respect for law. - Martin Luther King Jr


signature.asc
Description: PGP signature
___
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 v2 5/5] avfilter/scale: add animation support

2019-12-31 Thread Gyan Doshi
Width and height expressions in scale and scale2ref filters can now
reference frame index, timestamp and packet position.
---
 libavfilter/vf_scale.c | 64 +++---
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index f47e8fcae4..fac84c51fd 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -54,6 +54,9 @@ static const char *const var_names[] = {
 "vsub",
 "ohsub",
 "ovsub",
+"n",
+"t",
+"pos",
 "main_w",
 "main_h",
 "main_a",
@@ -61,6 +64,9 @@ static const char *const var_names[] = {
 "main_dar", "mdar",
 "main_hsub",
 "main_vsub",
+"main_n",
+"main_t",
+"main_pos",
 NULL
 };
 
@@ -76,6 +82,9 @@ enum var_name {
 VAR_VSUB,
 VAR_OHSUB,
 VAR_OVSUB,
+VAR_N,
+VAR_T,
+VAR_POS,
 VAR_S2R_MAIN_W,
 VAR_S2R_MAIN_H,
 VAR_S2R_MAIN_A,
@@ -83,6 +92,9 @@ enum var_name {
 VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
 VAR_S2R_MAIN_HSUB,
 VAR_S2R_MAIN_VSUB,
+VAR_S2R_MAIN_N,
+VAR_S2R_MAIN_T,
+VAR_S2R_MAIN_POS,
 VARS_NB
 };
 
@@ -184,11 +196,25 @@ static int check_exprs(AVFilterContext *ctx)
  vars_w[VAR_S2R_MAIN_DAR]  || vars_h[VAR_S2R_MAIN_DAR]  ||
  vars_w[VAR_S2R_MDAR]  || vars_h[VAR_S2R_MDAR]  ||
  vars_w[VAR_S2R_MAIN_HSUB] || vars_h[VAR_S2R_MAIN_HSUB] ||
- vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB]) ) {
+ vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB] ||
+ vars_w[VAR_S2R_MAIN_N]|| vars_h[VAR_S2R_MAIN_N]||
+ vars_w[VAR_S2R_MAIN_T]|| vars_h[VAR_S2R_MAIN_T]||
+ vars_w[VAR_S2R_MAIN_POS]  || vars_h[VAR_S2R_MAIN_POS]) ) {
 av_log(ctx, AV_LOG_ERROR, "Expressions with scale2ref variables are 
not valid in scale filter.\n");
 return AVERROR(EINVAL);
 }
 
+if (scale->eval_mode == EVAL_MODE_INIT &&
+(vars_w[VAR_N]|| vars_h[VAR_N]   ||
+ vars_w[VAR_T]|| vars_h[VAR_T]   ||
+ vars_w[VAR_POS]  || vars_h[VAR_POS] ||
+ vars_w[VAR_S2R_MAIN_N]   || vars_h[VAR_S2R_MAIN_N]  ||
+ vars_w[VAR_S2R_MAIN_T]   || vars_h[VAR_S2R_MAIN_T]  ||
+ vars_w[VAR_S2R_MAIN_POS] || vars_h[VAR_S2R_MAIN_POS]) ) {
+av_log(ctx, AV_LOG_ERROR, "Expressions with frame variables 'n', 't', 
'pos' are not valid in init eval_mode.\n");
+return AVERROR(EINVAL);
+}
+
 return 0;
 }
 
@@ -622,6 +648,8 @@ static int scale_slice(AVFilterLink *link, AVFrame 
*out_buf, AVFrame *cur_pic, s
  out,out_stride);
 }
 
+#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts) * av_q2d(tb))
+
 static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
 {
 AVFilterContext *ctx = link->dst;
@@ -643,10 +671,20 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 in->sample_aspect_ratio.den != 
link->sample_aspect_ratio.den ||
 in->sample_aspect_ratio.num != 
link->sample_aspect_ratio.num;
 
-if (frame_changed ||
-(scale->eval_mode == EVAL_MODE_FRAME &&
- ctx->filter == &ff_vf_scale2ref) ) {
+if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) {
 int ret;
+unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
+
+av_expr_count_vars(scale->w_pexpr, vars_w, VARS_NB);
+av_expr_count_vars(scale->h_pexpr, vars_h, VARS_NB);
+
+if (scale->eval_mode == EVAL_MODE_FRAME &&
+!frame_changed &&
+ctx->filter != &ff_vf_scale2ref &&
+!(vars_w[VAR_N] || vars_w[VAR_T] || vars_w[VAR_POS]) &&
+!(vars_h[VAR_N] || vars_h[VAR_T] || vars_h[VAR_POS]) &&
+scale->w && scale->h)
+goto scale;
 
 if (scale->eval_mode == EVAL_MODE_INIT) {
 snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
@@ -663,6 +701,16 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 return ret;
 }
 
+if (ctx->filter == &ff_vf_scale2ref) {
+scale->var_values[VAR_S2R_MAIN_N] = link->frame_count_out;
+scale->var_values[VAR_S2R_MAIN_T] = TS2T(in->pts, link->time_base);
+scale->var_values[VAR_S2R_MAIN_POS] = in->pkt_pos == -1 ? NAN : 
in->pkt_pos;
+} else {
+scale->var_values[VAR_N] = link->frame_count_out;
+scale->var_values[VAR_T] = TS2T(in->pts, link->time_base);
+scale->var_values[VAR_POS] = in->pkt_pos == -1 ? NAN : in->pkt_pos;
+}
+
 link->dst->inputs[0]->format = in->format;
 link->dst->inputs[0]->w  = in->width;
 link->dst->inputs[0]->h  = in->height;
@@ -674,6 +722,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 return ret;
 }
 
+scale:
 if (!scal

[FFmpeg-devel] [PATCH v2 4/5] avfilter/scale: add function to check expressions

2019-12-31 Thread Gyan Doshi
Allows finer identification and logging of invalid expressions and use
of a single list for symbols and their index for both scale and
scale2ref.
---
 libavfilter/vf_scale.c | 97 +-
 1 file changed, 59 insertions(+), 38 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 3c1cbbda89..f47e8fcae4 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -54,6 +54,13 @@ static const char *const var_names[] = {
 "vsub",
 "ohsub",
 "ovsub",
+"main_w",
+"main_h",
+"main_a",
+"main_sar",
+"main_dar", "mdar",
+"main_hsub",
+"main_vsub",
 NULL
 };
 
@@ -69,39 +76,6 @@ enum var_name {
 VAR_VSUB,
 VAR_OHSUB,
 VAR_OVSUB,
-VARS_NB
-};
-
-/**
- * This must be kept in sync with var_names so that it is always a
- * complete list of var_names with the scale2ref specific names
- * appended. scale2ref values must appear in the order they appear
- * in the var_name_scale2ref enum but also be below all of the
- * non-scale2ref specific values.
- */
-static const char *const var_names_scale2ref[] = {
-"in_w",   "iw",
-"in_h",   "ih",
-"out_w",  "ow",
-"out_h",  "oh",
-"a",
-"sar",
-"dar",
-"hsub",
-"vsub",
-"ohsub",
-"ovsub",
-"main_w",
-"main_h",
-"main_a",
-"main_sar",
-"main_dar", "mdar",
-"main_hsub",
-"main_vsub",
-NULL
-};
-
-enum var_name_scale2ref {
 VAR_S2R_MAIN_W,
 VAR_S2R_MAIN_H,
 VAR_S2R_MAIN_A,
@@ -109,7 +83,7 @@ enum var_name_scale2ref {
 VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
 VAR_S2R_MAIN_HSUB,
 VAR_S2R_MAIN_VSUB,
-VARS_S2R_NB
+VARS_NB
 };
 
 enum EvalMode {
@@ -145,7 +119,7 @@ typedef struct ScaleContext {
 char *h_expr;   ///< height expression string
 AVExpr *w_pexpr;
 AVExpr *h_pexpr;
-double var_values[VARS_NB + VARS_S2R_NB];
+double var_values[VARS_NB];
 
 char *flags_str;
 
@@ -173,14 +147,57 @@ AVFilter ff_vf_scale2ref;
 
 static int config_props(AVFilterLink *outlink);
 
+static int check_exprs(AVFilterContext *ctx)
+{
+ScaleContext *scale = ctx->priv;
+unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
+
+if (!scale->w_pexpr && !scale->h_pexpr)
+return AVERROR(EINVAL);
+
+if (scale->w_pexpr)
+av_expr_count_vars(scale->w_pexpr, vars_w, VARS_NB);
+if (scale->h_pexpr)
+av_expr_count_vars(scale->h_pexpr, vars_h, VARS_NB);
+
+if (vars_w[VAR_OUT_W] || vars_w[VAR_OW]) {
+av_log(ctx, AV_LOG_ERROR, "Width expression cannot be 
self-referencing: '%s'.\n", scale->w_expr);
+return AVERROR(EINVAL);
+}
+
+if (vars_h[VAR_OUT_H] || vars_h[VAR_OH]) {
+av_log(ctx, AV_LOG_ERROR, "Height expression cannot be 
self-referencing: '%s'.\n", scale->h_expr);
+return AVERROR(EINVAL);
+}
+
+if ((vars_w[VAR_OUT_H] || vars_w[VAR_OH]) &&
+(vars_h[VAR_OUT_W] || vars_h[VAR_OW])) {
+av_log(ctx, AV_LOG_ERROR, "Circular expressions invalid for width '%s' 
and height '%s'.\n", scale->w_expr, scale->h_expr);
+return AVERROR(EINVAL);
+}
+
+if (ctx->filter != &ff_vf_scale2ref &&
+(vars_w[VAR_S2R_MAIN_W]|| vars_h[VAR_S2R_MAIN_W]||
+ vars_w[VAR_S2R_MAIN_H]|| vars_h[VAR_S2R_MAIN_H]||
+ vars_w[VAR_S2R_MAIN_A]|| vars_h[VAR_S2R_MAIN_A]||
+ vars_w[VAR_S2R_MAIN_SAR]  || vars_h[VAR_S2R_MAIN_SAR]  ||
+ vars_w[VAR_S2R_MAIN_DAR]  || vars_h[VAR_S2R_MAIN_DAR]  ||
+ vars_w[VAR_S2R_MDAR]  || vars_h[VAR_S2R_MDAR]  ||
+ vars_w[VAR_S2R_MAIN_HSUB] || vars_h[VAR_S2R_MAIN_HSUB] ||
+ vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB]) ) {
+av_log(ctx, AV_LOG_ERROR, "Expressions with scale2ref variables are 
not valid in scale filter.\n");
+return AVERROR(EINVAL);
+}
+
+return 0;
+}
+
 static int scale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr 
**pexpr_ptr, const char *var, const char *args)
 {
 ScaleContext *scale = ctx->priv;
 int ret, is_inited = 0;
 char *old_str_expr = NULL;
 AVExpr *old_pexpr = NULL;
-const char scale2ref = ctx->filter == &ff_vf_scale2ref;
-const char *const *names = scale2ref ? var_names_scale2ref : var_names;
 
 if (str_expr) {
 old_str_expr = av_strdup(str_expr);
@@ -195,13 +212,17 @@ static int scale_parse_expr(AVFilterContext *ctx, char 
*str_expr, AVExpr **pexpr
 is_inited = 1;
 }
 
-ret = av_expr_parse(pexpr_ptr, args, names,
+ret = av_expr_parse(pexpr_ptr, args, var_names,
 NULL, NULL, NULL, NULL, 0, ctx);
 if (ret < 0) {
 av_log(ctx, AV_LOG_ERROR, "Cannot parse expression for %s: '%s'\n", 
var, args);
 goto revert;
 }
 
+ret = check_exprs(ctx);
+if (ret < 0)
+goto revert;
+
 if (is_inited && (ret = config_props(ctx->outputs[0])) < 0)
 goto revert;
 
-- 
2.24.1


[FFmpeg-devel] [PATCH v2 3/5] avfilter/scale: separate exprs parse and eval

2019-12-31 Thread Gyan Doshi
Retains parsed expressions which allows for better
error-checking and adding animation support.
---
 libavfilter/scale_eval.c |  69 +-
 libavfilter/vf_scale.c   | 264 +++
 2 files changed, 246 insertions(+), 87 deletions(-)

diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c
index 6c526a97af..dfec081e15 100644
--- a/libavfilter/scale_eval.c
+++ b/libavfilter/scale_eval.c
@@ -54,46 +54,6 @@ enum var_name {
 VARS_NB
 };
 
-/**
- * This must be kept in sync with var_names so that it is always a
- * complete list of var_names with the scale2ref specific names
- * appended. scale2ref values must appear in the order they appear
- * in the var_name_scale2ref enum but also be below all of the
- * non-scale2ref specific values.
- */
-static const char *const var_names_scale2ref[] = {
-"in_w",   "iw",
-"in_h",   "ih",
-"out_w",  "ow",
-"out_h",  "oh",
-"a",
-"sar",
-"dar",
-"hsub",
-"vsub",
-"ohsub",
-"ovsub",
-"main_w",
-"main_h",
-"main_a",
-"main_sar",
-"main_dar", "mdar",
-"main_hsub",
-"main_vsub",
-NULL
-};
-
-enum var_name_scale2ref {
-VAR_S2R_MAIN_W,
-VAR_S2R_MAIN_H,
-VAR_S2R_MAIN_A,
-VAR_S2R_MAIN_SAR,
-VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
-VAR_S2R_MAIN_HSUB,
-VAR_S2R_MAIN_VSUB,
-VARS_S2R_NB
-};
-
 int ff_scale_eval_dimensions(void *log_ctx,
 const char *w_expr, const char *h_expr,
 AVFilterLink *inlink, AVFilterLink *outlink,
@@ -104,16 +64,7 @@ int ff_scale_eval_dimensions(void *log_ctx,
 const char *expr;
 int eval_w, eval_h;
 int ret;
-const char scale2ref = outlink->src->nb_inputs == 2 && 
outlink->src->inputs[1] == inlink;
-double var_values[VARS_NB + VARS_S2R_NB], res;
-const AVPixFmtDescriptor *main_desc;
-const AVFilterLink *main_link;
-const char *const *names = scale2ref ? var_names_scale2ref : var_names;
-
-if (scale2ref) {
-main_link = outlink->src->inputs[0];
-main_desc = av_pix_fmt_desc_get(main_link->format);
-}
+double var_values[VARS_NB], res;
 
 var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
 var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
@@ -128,32 +79,20 @@ int ff_scale_eval_dimensions(void *log_ctx,
 var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
 var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
 
-if (scale2ref) {
-var_values[VARS_NB + VAR_S2R_MAIN_W] = main_link->w;
-var_values[VARS_NB + VAR_S2R_MAIN_H] = main_link->h;
-var_values[VARS_NB + VAR_S2R_MAIN_A] = (double) main_link->w / 
main_link->h;
-var_values[VARS_NB + VAR_S2R_MAIN_SAR] = 
main_link->sample_aspect_ratio.num ?
-(double) main_link->sample_aspect_ratio.num / 
main_link->sample_aspect_ratio.den : 1;
-var_values[VARS_NB + VAR_S2R_MAIN_DAR] = var_values[VARS_NB + 
VAR_S2R_MDAR] =
-var_values[VARS_NB + VAR_S2R_MAIN_A] * var_values[VARS_NB + 
VAR_S2R_MAIN_SAR];
-var_values[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << 
main_desc->log2_chroma_w;
-var_values[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << 
main_desc->log2_chroma_h;
-}
-
 /* evaluate width and height */
 av_expr_parse_and_eval(&res, (expr = w_expr),
-   names, var_values,
+   var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, log_ctx);
 eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = (int) res == 0 ? 
inlink->w : (int) res;
 
 if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),
-  names, var_values,
+  var_names, var_values,
   NULL, NULL, NULL, NULL, NULL, 0, 
log_ctx)) < 0)
 goto fail;
 eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? 
inlink->h : (int) res;
 /* evaluate again the width, as it may depend on the output height */
 if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),
-  names, var_values,
+  var_names, var_values,
   NULL, NULL, NULL, NULL, NULL, 0, 
log_ctx)) < 0)
 goto fail;
 eval_w = (int) res == 0 ? inlink->w : (int) res;
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 5a375fac5d..3c1cbbda89 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -32,6 +32,7 @@
 #include "scale_eval.h"
 #include "video.h"
 #include "libavutil/avstring.h"
+#include "libavutil/eval.h"
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
@@ -41,6 +42,76 @@
 #include "libavutil/avassert.h"
 #include "libswscale/swscale.h"
 
+static const char *const var_names[] = {
+"in_w",   "iw",
+"in_h",   "ih",
+"out_w",  "ow",
+"out_h",  "oh",
+"a",
+"sar",
+"da

Re: [FFmpeg-devel] [PATCH 1/2] tools/target_dec_fuzzer: Stop negative block_align and sampling rate

2019-12-31 Thread Michael Niedermayer
On Sat, Dec 28, 2019 at 09:16:16PM +0100, Michael Niedermayer wrote:
> These are checked for early in avcodec_open2() and do not really test the 
> decoder
> but instead waste resources which could be better spend fuzzing the actual 
> decoder
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_dec_fuzzer.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply so as to improve the fuzzer efficiency


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



signature.asc
Description: PGP signature
___
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 6/8] swscale/tests/swscale: remove access of AV_PIX_FMT_NB

2019-12-31 Thread zhilizhao


> On Dec 31, 2019, at 7:49 PM, Michael Niedermayer  > wrote:
> 
> On Mon, Dec 30, 2019 at 09:54:17PM +0800, quinkbl...@foxmail.com 
>  wrote:
>> From: Zhao Zhili mailto:zhiliz...@tencent.com>>
>> 
>> ---
>> libswscale/tests/swscale.c | 17 +++--
>> 1 file changed, 15 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
>> index 19878a7877..784195f468 100644
>> --- a/libswscale/tests/swscale.c
>> +++ b/libswscale/tests/swscale.c
>> @@ -251,6 +251,18 @@ end:
>> return res;
>> }
>> 
>> +static int getMaxFmt()
>> +{
>> +const AVPixFmtDescriptor *desc = NULL;
>> +int fmt_max = AV_PIX_FMT_NONE;
>> +
>> +while ((desc = av_pix_fmt_desc_next(desc))) {
>> +int fmt = av_pix_fmt_desc_get_id(desc);
>> +fmt_max = FFMAX(fmt, fmt_max);
>> +}
>> +return fmt_max;
>> +}
>> +
>> static void selfTest(const uint8_t * const ref[4], int refStride[4],
>>  int w, int h,
>>  enum AVPixelFormat srcFormat_in,
>> @@ -264,9 +276,10 @@ static void selfTest(const uint8_t * const ref[4], int 
>> refStride[4],
>> const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 };
>> enum AVPixelFormat srcFormat, dstFormat;
>> const AVPixFmtDescriptor *desc_src, *desc_dst;
>> +const int fmt_max = getMaxFmt();
>> 
>> for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0;
>> - srcFormat < AV_PIX_FMT_NB; srcFormat++) {
>> + srcFormat <= fmt_max; srcFormat++) {
>> if (!sws_isSupportedInput(srcFormat) ||
>> !sws_isSupportedOutput(srcFormat))
>> continue;
>> @@ -274,7 +287,7 @@ static void selfTest(const uint8_t * const ref[4], int 
>> refStride[4],
>> desc_src = av_pix_fmt_desc_get(srcFormat);
>> 
>> for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0;
>> - dstFormat < AV_PIX_FMT_NB; dstFormat++) {
>> + dstFormat <= fmt_max; dstFormat++) {
>> int i, j, k;
>> int res = 0;
> 
> Iam not sure this makes sense, formats added after build of the test
> would only be rejected in sws_isSupported* in the next line
> 

(srcFormat < AV_PIX_FMT_NB) means (srcFormat <= AV_PIX_FMT_MAX)
in the context.

Ensure sws_isSupported* can handle invalid (unknown) input is the point of
the test, I guess. Actually, I think it would be better to test

srcFormat <= (fmt_max + 1)

However, it changed the semantics of the original code, and looks like a bug
if takes the code as ‘example’.

> 
> [...]
> 
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> If you drop bombs on a foreign country and kill a hundred thousand
> innocent people, expect your government to call the consequence
> "unprovoked inhuman terrorist attacks" and use it to justify dropping
> more bombs and killing more people. The technology changed, the idea is old.
> ___
> 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 v5] avfilter/buffersrc: deprecate sws_param option

2019-12-31 Thread James Almer
On 12/30/2019 7:25 AM, Nicolas George wrote:
> quinkbl...@foxmail.com (12019-12-30):
>> From: Zhao Zhili 
>>
>> ---
>> Rebase patch on master.
>>
>>  doc/filters.texi|  8 
>>  libavfilter/buffersrc.c | 14 --
>>  libavfilter/version.h   |  5 -
>>  3 files changed, 20 insertions(+), 7 deletions(-)
> 
> Pushed, thanks.
> 
> Regards,

Could the log be changed to verbose instead of warning? Or removed
altogether? It's being printed on pretty much any cli encoding scenario
like "ffmpeg -i input output" and it will confuse users.
___
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 v5] avfilter/buffersrc: deprecate sws_param option

2019-12-31 Thread James Almer
On 12/31/2019 10:05 AM, James Almer wrote:
> On 12/30/2019 7:25 AM, Nicolas George wrote:
>> quinkbl...@foxmail.com (12019-12-30):
>>> From: Zhao Zhili 
>>>
>>> ---
>>> Rebase patch on master.
>>>
>>>  doc/filters.texi|  8 
>>>  libavfilter/buffersrc.c | 14 --
>>>  libavfilter/version.h   |  5 -
>>>  3 files changed, 20 insertions(+), 7 deletions(-)
>>
>> Pushed, thanks.
>>
>> Regards,
> 
> Could the log be changed to verbose instead of warning? Or removed
> altogether? It's being printed on pretty much any cli encoding scenario
> like "ffmpeg -i input output" and it will confuse users.

Or make ffmpeg_filter.c stop using it. That's probably a better
solution, on second thought.
___
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 v5] avfilter/buffersrc: deprecate sws_param option

2019-12-31 Thread zhilizhao


> On Dec 31, 2019, at 9:08 PM, James Almer  wrote:
> 
> On 12/31/2019 10:05 AM, James Almer wrote:
>> On 12/30/2019 7:25 AM, Nicolas George wrote:
>>> quinkbl...@foxmail.com (12019-12-30):
 From: Zhao Zhili 
 
 ---
 Rebase patch on master.
 
 doc/filters.texi|  8 
 libavfilter/buffersrc.c | 14 --
 libavfilter/version.h   |  5 -
 3 files changed, 20 insertions(+), 7 deletions(-)
>>> 
>>> Pushed, thanks.
>>> 
>>> Regards,
>> 
>> Could the log be changed to verbose instead of warning? Or removed
>> altogether? It's being printed on pretty much any cli encoding scenario
>> like "ffmpeg -i input output" and it will confuse users.
> 
> Or make ffmpeg_filter.c stop using it. That's probably a better
> solution, on second thought.


I have a pending patch for it.
http://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/253879.html 



> ___
> 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 v5] avfilter/buffersrc: deprecate sws_param option

2019-12-31 Thread Nicolas George
zhilizhao (12019-12-31):
> I have a pending patch for it.
> http://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/253879.html 
> 

I am about to apply it. It removes flags that used to be passed, but
since nobody noticed they were not taken into account, it was probably
not important.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
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 1/2] fftools/ffmpeg_filter: remove sws_param option from buffersrc

2019-12-31 Thread Nicolas George
quinkbl...@foxmail.com (12019-12-04):
> From: Zhao Zhili 
> 
> The option is deprecated and ignored by buffersrc.
> ---
>  fftools/ffmpeg_filter.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Pushed, thanks.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
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 001/244] Add a new channel layout API

2019-12-31 Thread Nicolas George
Anton Khirnov (12019-12-29):
> Maybe I missed something, but I am not aware of the UB-ness of signed
> overflow being a practical problem. Typically, your computation will
> return a meaningless result. You would get a similarly meaningless
> result from the analogous perfectly well-defined unsigned computation.
> 
> to be clear: I am not objecting against fixing UB, but clarifying my
> 'theoretical gain' comment above.

It seems you have missed some of the drama that happened on this list
recently. Michael and others have been intent on fixing the UB caused by
integer overflows, including cases that I personally find futile.

But I do not consider this case futile: a channel number will typically
be used as an array index, and an invalid value will cause an invalid
memory access and a segmentation fault, or an exploitable memory
corruption.

What makes signed overflows, which are UB, worse than unsigned
overflows, which are completely specified, is that you cannot guard
against it. For example, if your write:

if (ch < 0 || ch >= nb_channels)
return AVERROR_BUG;

you think you are safe, but if the compiler detects that ch cannot be
negative without overflow, it will silently discard the ch<0 test. Then,
if the overflows does happen, there is no protection against invalid
memory access.

And this is not theoretical: I have seen entire blogs and twitter
accounts dedicated to posting examples of actual cases where an
optimizing compiler produces very unintuitive code because there is a
tiny UB in the middle.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
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 v2 2/2] avcodec/libvpxenc: add a way to explicitly set temporal layer id

2019-12-31 Thread Moritz Barsnick
On Tue, Dec 17, 2019 at 14:42:21 -0800, Wonkap Jang wrote:
> +memset(&layer_id, 0, sizeof(vpx_svc_layer_id_t));

ffmpeg coding tends to prefer sizeof(variable) over sizeof(type).

Cheers,
Moritz
___
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] avformat/dtsdec: make S16LE discrimination sharper

2019-12-31 Thread Michael Niedermayer
Both S16LE as well as DTS can have lots of 0 bytes in silent segments
Using these results in error. Thus this patch skips 0 bytes in
comparission.

Fixes Ticket6561

Signed-off-by: Michael Niedermayer 
---
 libavformat/dtsdec.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index ab59a56dfc..0215ee18bd 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -37,6 +37,7 @@ static int dts_probe(const AVProbeData *p)
 int exss_markers = 0, exss_nextpos = 0;
 int sum, max, pos, ret, i;
 int64_t diff = 0;
+int diffcount = 1;
 uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
 
 for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {
@@ -47,8 +48,12 @@ static int dts_probe(const AVProbeData *p)
 bufp = buf = p->buf + pos;
 state = (state << 16) | bytestream_get_be16(&bufp);
 
-if (pos >= 4)
-diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));
+if (pos >= 4) {
+if (AV_RL16(buf) || AV_RL16(buf-4)) {
+diff += FFABS(((int16_t)AV_RL16(buf)) - 
(int16_t)AV_RL16(buf-4));
+diffcount ++;
+}
+}
 
 /* extension substream (EXSS) */
 if (state == DCA_SYNCWORD_SUBSTREAM) {
@@ -121,7 +126,7 @@ static int dts_probe(const AVProbeData *p)
 
 if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
 markers[max] * 4 > sum * 3 &&
-diff / p->buf_size > 200)
+diff / diffcount > 600)
 return AVPROBE_SCORE_EXTENSION + 1;
 
 return 0;
-- 
2.24.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 001/244] Add a new channel layout API

2019-12-31 Thread Nicolas George
Anton Khirnov (12019-12-29):
> In the API namespace (function names) or the parameter names? For the
> latter, it can be changed at any time without problem and I don't really
> care much. For the former, the header is called channel_layout and I'd
> lean towards keeping that aligned with the namespace. Not a very strong
> opinion though.

I meant both, but of course the names of the public symbols (and the name
of the header, which is not set in marble) are what we are stuck with
and requires careful planning. I do not insist on it, but it is
something to consider.

In fact, I just noticed that you used chlayout at some places in the
public API instead of channel_layout.

> Hmm, this was apparently added by Vittorio so I'm not sure, but would
> assume it refers to AV_CHAN_SILENCE.

It will need to be clarified before it's done.

> I am aware that it is different, but making the struct dynamic would
> make using it significantly more cumbersome. Given how long we have
> lived with the bitmask, I do not expect there to be a significant need
> to add more fields to it.

The bitmask was constraining, but it was very simple: we can accept to
be constrained as the cost of simplicity. This new API is not very
simple: if it is constraining, the it is not worth it.

> Plus, it can still be extended by adding a new AV_CHANNEL_ORDER types
> and a corresponding new union member.

Not all extensions can be done like that.

> Given that a copy of this struct is embedded in every single frame, I'd
> rather not add extensive dynamically allocated metadata to it. Those
> should rather appear in some higher level API.

What higher level API? Maybe we need to reconsider embedding the
structure in every single frame, and possibly using reference counting
instead.

> They also can (and are, in the patchset) used as
> (AVChannelLayout)AV_CHANNEL_LAYOUT_FOO
> 
> We might want to add a macro for that.

Ok. Or just mention it in the doc.

> That still requires error checks and adds considerable complexity.

This is not true, please have a look at the API I have proposed, since I
have posted it on the mailing-list:

https://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254901.html

As you can see, all the complexity is inside the implementation. For the
code that uses the API, it actually makes things simpler.

In particular, with your version, error checking must be done twice:
once in av_channel_layout_describe() and once when calling it. With
AVWriter, the first one is unnecessary.

> There is no hiding from the fact that the string size is not bounded, so
> either you make up an arbitrary limit and hope it's enough (and have it
> fail for special cases), or you do dynamic allocation with error checks.

All that is taken care of by the API and hidden from the user.

> Yes. The point of the API is to provide a logical mapping between
> audio channels and their indices in a stream. That way, the callers that
> only read the channel layout do not (typically) need to know how exactly
> it is stored.
> 
> This function is the canonical way of answering the question 'what
> semantics does n-th channel in this stream have?', so the callers don't
> need to handle ORDER_NATIVE vs ORDER_CUSTOM, or do any messing with
> bitmasks.

Ok. But my point is: is the question "what semantics does n-th channel
in this stream have?" really relevant?

(Similar with strings: the question "what is the n-th character" is
hardly ever relevant, but people keep asking it and implementing APIs to
answer it.)

> I do not agree. Duplicated channels in a layout are expected to be a
> fringe thing and how you handle them highly depends on the specific use
> case. I expect a typical caller will want to disregard that possibility
> and just take the first channel of each semantics.
> So I do not believe a dedicated function for this makes sense. We could
> always add something later though, if it turns out to be necessary.

I think you are making a mistake. I think that as soon as it will be
technically possible, we will see cases with duplicated channels. And I
know that some filters will do exactly that as soon as they are ported
to this new API.

Therefore, I insist, we need a clean user interface to handle duplicated
channels.

> Again, yes. E.g. you are decoding an audio stream with multiple channels
> and want to know which is the 'front left' one. This function gives you
> the canonical answer to that.

Same as above: I do not insist, but I doubt that "which one is the front
left" is a very interesting question.

> It turns out to be useful in flacenc, matroskaenc and mlpdec
> conversions. And of course can be potentially useful to the callers.
> Since we are not deprecating the AV_CH_FOO macros, I do not see a
> problem with having it public.

Ok.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/h264_ps: Provide more details with "Truncated VUI" Message

2019-12-31 Thread Michael Niedermayer
On Sun, Dec 15, 2019 at 11:00:29PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/h264_ps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Observe your enemies, for they first find out your faults. -- Antisthenes


signature.asc
Description: PGP signature
___
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 2/4] avformat/mpeg: Remove secondary packet for reading VobSub

2019-12-31 Thread Andreas Rheinhardt
On Tue, Dec 24, 2019 at 1:58 AM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> Andreas Rheinhardt:
> > Andreas Rheinhardt:
> >> Andreas Rheinhardt:
> >>> Andreas Rheinhardt:
>  When vobsub_read_packet() reads a packet, it uses a dedicated AVPacket
>  to get the subtitle timing and position from an FFDemuxSubtitlesQueue
>  (which has been filled with this data during reading the idx file in
>  vobsub_read_header); afterwards the actual subtitle data is read into
>  the packet destined for output and the timing and position are copied
>  to this packet. Afterwards, the local packet is unreferenced.
> 
>  This can be simplified: Simply use the output packet to get the timing
>  and position from the FFDemuxSubtitlesQueue. The packet's size will be
>  zero afterwards, so that it can be directly used to read the actual
>  subtitle data. This makes copying the packet fields as well as
>  unreferencing the local packet unecessary and also removes an instance
>  of usage of sizeof(AVPacket) in libavformat.
> 
>  The only difference is that the returned packet will already be
> flagged
>  as a keyframe. This currently only happens in compute_pkt_fields().
> 
>  Signed-off-by: Andreas Rheinhardt 
>  ---
>   libavformat/mpeg.c | 23 +++
>   1 file changed, 7 insertions(+), 16 deletions(-)
> 
>  diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
>  index bd182e4429..7daa72f7ce 100644
>  --- a/libavformat/mpeg.c
>  +++ b/libavformat/mpeg.c
>  @@ -912,7 +912,6 @@ static int vobsub_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>   FFDemuxSubtitlesQueue *q;
>   AVIOContext *pb = vobsub->sub_ctx->pb;
>   int ret, psize, total_read = 0, i;
>  -AVPacket idx_pkt = { 0 };
> 
>   int64_t min_ts = INT64_MAX;
>   int sid = 0;
>  @@ -927,24 +926,22 @@ static int vobsub_read_packet(AVFormatContext
> *s, AVPacket *pkt)
>   }
>   }
>   q = &vobsub->q[sid];
>  -ret = ff_subtitles_queue_read_packet(q, &idx_pkt);
>  +/* The returned packet will have size zero,
>  + * so that it can be directly used with av_grow_packet. */
>  +ret = ff_subtitles_queue_read_packet(q, pkt);
>   if (ret < 0)
>   return ret;
> 
>   /* compute maximum packet size using the next packet position.
> This is
>    * useful when the len in the header is non-sense */
>   if (q->current_sub_idx < q->nb_subs) {
>  -psize = q->subs[q->current_sub_idx].pos - idx_pkt.pos;
>  +psize = q->subs[q->current_sub_idx].pos - pkt->pos;
>   } else {
>   int64_t fsize = avio_size(pb);
>  -psize = fsize < 0 ? 0x : fsize - idx_pkt.pos;
>  +psize = fsize < 0 ? 0x : fsize - pkt->pos;
>   }
> 
>  -avio_seek(pb, idx_pkt.pos, SEEK_SET);
>  -
>  -av_init_packet(pkt);
>  -pkt->size = 0;
>  -pkt->data = NULL;
>  +avio_seek(pb, pkt->pos, SEEK_SET);
> 
>   do {
>   int n, to_read, startcode;
>  @@ -968,7 +965,7 @@ static int vobsub_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>   total_read += pkt_size;
> 
>   /* the current chunk doesn't match the stream index
> (unlikely) */
>  -if ((startcode & 0x1f) !=
> s->streams[idx_pkt.stream_index]->id)
>  +if ((startcode & 0x1f) != s->streams[pkt->stream_index]->id)
>   break;
> 
>   ret = av_grow_packet(pkt, to_read);
>  @@ -980,16 +977,10 @@ static int vobsub_read_packet(AVFormatContext
> *s, AVPacket *pkt)
>   pkt->size -= to_read - n;
>   } while (total_read < psize);
> 
>  -pkt->pts = pkt->dts = idx_pkt.pts;
>  -pkt->pos = idx_pkt.pos;
>  -pkt->stream_index = idx_pkt.stream_index;
>  -
>  -av_packet_unref(&idx_pkt);
>   return 0;
> 
>   fail:
>   av_packet_unref(pkt);
>  -av_packet_unref(&idx_pkt);
>   return ret;
>   }
> 
> 
> >>> Ping.
> >>>
> >>> - Andreas
> >>>
> >> Another ping for the three unmerged patches of this patchset.
> >>
> >> - Andreas
> >>
> > Another ping for the two unmerged patches of this patchset; and also
> > for the other patch fixing uninitialized reads in the vobsub demuxer:
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2019-October/251961.html
> >
> > - Andreas
> >
> Ping.
>
> - Andreas
>

Ping.

- Andreas
___
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 v2 6/7] avcodec/utils: Fix ff_add_cpb_side_data() add twice

2019-12-31 Thread Moritz Barsnick
On Thu, Dec 19, 2019 at 17:43:26 +0100, Nicolas Gaullier wrote:
> +return (AVCPBProperties  *)avctx->coded_side_data[i].data;

Nit:  ^^ two spaces

Moritz
___
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 1/2] avcodec/twinvqdec: Correct overflow in block align check

2019-12-31 Thread Michael Niedermayer
On Tue, Dec 03, 2019 at 10:23:54PM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 538976288 * 8 cannot be represented in type 
> 'int'
> Fixes: 
> 19126/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TWINVQ_fuzzer-5687464110325760
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/twinvqdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch


signature.asc
Description: PGP signature
___
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 5/6] tools/target_dec_fuzzer: Support fuzzing error detection

2019-12-31 Thread Michael Niedermayer
On Tue, Dec 03, 2019 at 04:07:32PM +0100, Michael Niedermayer wrote:
> On Sat, Nov 30, 2019 at 12:59:20AM +0100, Michael Niedermayer wrote:
> > This should increase coverage
> > 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  tools/target_dec_fuzzer.c | 6 ++
> >  1 file changed, 6 insertions(+)
> 
> will apply this and the other coverage increasing patch so we get increased
> coverage

will apply the rest of the patchset as well

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


signature.asc
Description: PGP signature
___
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 1/3] avcodec/cook: Use 3 stage VLC decoding for channel_coupling

2019-12-31 Thread Michael Niedermayer
On Mon, Nov 25, 2019 at 11:47:15PM +0100, Michael Niedermayer wrote:
> Fixes: shift exponent -1 is negative
> Fixes: out of array read
> Fixes: 
> 19028/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_COOK_fuzzer-5759766471376896
> Fixes: 
> 19037/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_COOK_fuzzer-5734106625474560
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cook.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

You can kill me, but you cannot change the truth.


signature.asc
Description: PGP signature
___
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 2/3] avcodec/ffwavesynth: Fix undefined overflow in wavesynth_synth_sample()

2019-12-31 Thread Michael Niedermayer
On Mon, Nov 25, 2019 at 11:47:16PM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 2147464192 + 21176 cannot be represented in 
> type 'int'
> Fixes: 
> 19042/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFWAVESYNTH_fuzzer-5719828090585088
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ffwavesynth.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

will apply

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange


signature.asc
Description: PGP signature
___
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 1/5] avcodec: Replace show_bits_long() by show_bits() where possible

2019-12-31 Thread Michael Niedermayer
On Sun, Nov 24, 2019 at 04:45:02PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/golomb.h| 2 +-
>  libavcodec/ivi.c   | 2 +-
>  libavcodec/mpeg4audio.c| 2 +-
>  libavcodec/mpeg4videodec.c | 4 ++--
>  4 files changed, 5 insertions(+), 5 deletions(-)

will apply pacthset

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

You can kill me, but you cannot change the truth.


signature.asc
Description: PGP signature
___
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 v2 3/5] avfilter/scale: separate exprs parse and eval

2019-12-31 Thread Gyan Doshi
Retains parsed expressions which allows for better
error-checking and adding animation support.
---

First version was rebased incorrectly in scale_eval_dimensions

 libavfilter/scale_eval.c |  69 +-
 libavfilter/vf_scale.c   | 264 +++
 2 files changed, 246 insertions(+), 87 deletions(-)

diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c
index 6c526a97af..dfec081e15 100644
--- a/libavfilter/scale_eval.c
+++ b/libavfilter/scale_eval.c
@@ -54,46 +54,6 @@ enum var_name {
 VARS_NB
 };
 
-/**
- * This must be kept in sync with var_names so that it is always a
- * complete list of var_names with the scale2ref specific names
- * appended. scale2ref values must appear in the order they appear
- * in the var_name_scale2ref enum but also be below all of the
- * non-scale2ref specific values.
- */
-static const char *const var_names_scale2ref[] = {
-"in_w",   "iw",
-"in_h",   "ih",
-"out_w",  "ow",
-"out_h",  "oh",
-"a",
-"sar",
-"dar",
-"hsub",
-"vsub",
-"ohsub",
-"ovsub",
-"main_w",
-"main_h",
-"main_a",
-"main_sar",
-"main_dar", "mdar",
-"main_hsub",
-"main_vsub",
-NULL
-};
-
-enum var_name_scale2ref {
-VAR_S2R_MAIN_W,
-VAR_S2R_MAIN_H,
-VAR_S2R_MAIN_A,
-VAR_S2R_MAIN_SAR,
-VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
-VAR_S2R_MAIN_HSUB,
-VAR_S2R_MAIN_VSUB,
-VARS_S2R_NB
-};
-
 int ff_scale_eval_dimensions(void *log_ctx,
 const char *w_expr, const char *h_expr,
 AVFilterLink *inlink, AVFilterLink *outlink,
@@ -104,16 +64,7 @@ int ff_scale_eval_dimensions(void *log_ctx,
 const char *expr;
 int eval_w, eval_h;
 int ret;
-const char scale2ref = outlink->src->nb_inputs == 2 && 
outlink->src->inputs[1] == inlink;
-double var_values[VARS_NB + VARS_S2R_NB], res;
-const AVPixFmtDescriptor *main_desc;
-const AVFilterLink *main_link;
-const char *const *names = scale2ref ? var_names_scale2ref : var_names;
-
-if (scale2ref) {
-main_link = outlink->src->inputs[0];
-main_desc = av_pix_fmt_desc_get(main_link->format);
-}
+double var_values[VARS_NB], res;
 
 var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
 var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
@@ -128,32 +79,20 @@ int ff_scale_eval_dimensions(void *log_ctx,
 var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
 var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
 
-if (scale2ref) {
-var_values[VARS_NB + VAR_S2R_MAIN_W] = main_link->w;
-var_values[VARS_NB + VAR_S2R_MAIN_H] = main_link->h;
-var_values[VARS_NB + VAR_S2R_MAIN_A] = (double) main_link->w / 
main_link->h;
-var_values[VARS_NB + VAR_S2R_MAIN_SAR] = 
main_link->sample_aspect_ratio.num ?
-(double) main_link->sample_aspect_ratio.num / 
main_link->sample_aspect_ratio.den : 1;
-var_values[VARS_NB + VAR_S2R_MAIN_DAR] = var_values[VARS_NB + 
VAR_S2R_MDAR] =
-var_values[VARS_NB + VAR_S2R_MAIN_A] * var_values[VARS_NB + 
VAR_S2R_MAIN_SAR];
-var_values[VARS_NB + VAR_S2R_MAIN_HSUB] = 1 << 
main_desc->log2_chroma_w;
-var_values[VARS_NB + VAR_S2R_MAIN_VSUB] = 1 << 
main_desc->log2_chroma_h;
-}
-
 /* evaluate width and height */
 av_expr_parse_and_eval(&res, (expr = w_expr),
-   names, var_values,
+   var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, log_ctx);
 eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = (int) res == 0 ? 
inlink->w : (int) res;
 
 if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr),
-  names, var_values,
+  var_names, var_values,
   NULL, NULL, NULL, NULL, NULL, 0, 
log_ctx)) < 0)
 goto fail;
 eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? 
inlink->h : (int) res;
 /* evaluate again the width, as it may depend on the output height */
 if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr),
-  names, var_values,
+  var_names, var_values,
   NULL, NULL, NULL, NULL, NULL, 0, 
log_ctx)) < 0)
 goto fail;
 eval_w = (int) res == 0 ? inlink->w : (int) res;
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 5a375fac5d..582b34ce09 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -32,6 +32,7 @@
 #include "scale_eval.h"
 #include "video.h"
 #include "libavutil/avstring.h"
+#include "libavutil/eval.h"
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
@@ -41,6 +42,76 @@
 #include "libavutil/avassert.h"
 #include "libswscale/swscale.h"
 
+static const char *const var_names[] = {
+"in_w",   "iw",
+"in_h",   "ih",
+"o

[FFmpeg-devel] [PATCH v2 4/5] avfilter/scale: add function to check expressions

2019-12-31 Thread Gyan Doshi
Allows finer identification and logging of invalid expressions and use
of a single list for symbols and their index for both scale and
scale2ref.
---
Rebased upon the correct rebase of v2 3/5

 libavfilter/vf_scale.c | 113 -
 1 file changed, 67 insertions(+), 46 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 582b34ce09..f47e8fcae4 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -54,6 +54,13 @@ static const char *const var_names[] = {
 "vsub",
 "ohsub",
 "ovsub",
+"main_w",
+"main_h",
+"main_a",
+"main_sar",
+"main_dar", "mdar",
+"main_hsub",
+"main_vsub",
 NULL
 };
 
@@ -69,39 +76,6 @@ enum var_name {
 VAR_VSUB,
 VAR_OHSUB,
 VAR_OVSUB,
-VARS_NB
-};
-
-/**
- * This must be kept in sync with var_names so that it is always a
- * complete list of var_names with the scale2ref specific names
- * appended. scale2ref values must appear in the order they appear
- * in the var_name_scale2ref enum but also be below all of the
- * non-scale2ref specific values.
- */
-static const char *const var_names_scale2ref[] = {
-"in_w",   "iw",
-"in_h",   "ih",
-"out_w",  "ow",
-"out_h",  "oh",
-"a",
-"sar",
-"dar",
-"hsub",
-"vsub",
-"ohsub",
-"ovsub",
-"main_w",
-"main_h",
-"main_a",
-"main_sar",
-"main_dar", "mdar",
-"main_hsub",
-"main_vsub",
-NULL
-};
-
-enum var_name_scale2ref {
 VAR_S2R_MAIN_W,
 VAR_S2R_MAIN_H,
 VAR_S2R_MAIN_A,
@@ -109,7 +83,7 @@ enum var_name_scale2ref {
 VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
 VAR_S2R_MAIN_HSUB,
 VAR_S2R_MAIN_VSUB,
-VARS_S2R_NB
+VARS_NB
 };
 
 enum EvalMode {
@@ -145,7 +119,7 @@ typedef struct ScaleContext {
 char *h_expr;   ///< height expression string
 AVExpr *w_pexpr;
 AVExpr *h_pexpr;
-double var_values[VARS_NB + VARS_S2R_NB];
+double var_values[VARS_NB];
 
 char *flags_str;
 
@@ -173,14 +147,57 @@ AVFilter ff_vf_scale2ref;
 
 static int config_props(AVFilterLink *outlink);
 
+static int check_exprs(AVFilterContext *ctx)
+{
+ScaleContext *scale = ctx->priv;
+unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
+
+if (!scale->w_pexpr && !scale->h_pexpr)
+return AVERROR(EINVAL);
+
+if (scale->w_pexpr)
+av_expr_count_vars(scale->w_pexpr, vars_w, VARS_NB);
+if (scale->h_pexpr)
+av_expr_count_vars(scale->h_pexpr, vars_h, VARS_NB);
+
+if (vars_w[VAR_OUT_W] || vars_w[VAR_OW]) {
+av_log(ctx, AV_LOG_ERROR, "Width expression cannot be 
self-referencing: '%s'.\n", scale->w_expr);
+return AVERROR(EINVAL);
+}
+
+if (vars_h[VAR_OUT_H] || vars_h[VAR_OH]) {
+av_log(ctx, AV_LOG_ERROR, "Height expression cannot be 
self-referencing: '%s'.\n", scale->h_expr);
+return AVERROR(EINVAL);
+}
+
+if ((vars_w[VAR_OUT_H] || vars_w[VAR_OH]) &&
+(vars_h[VAR_OUT_W] || vars_h[VAR_OW])) {
+av_log(ctx, AV_LOG_ERROR, "Circular expressions invalid for width '%s' 
and height '%s'.\n", scale->w_expr, scale->h_expr);
+return AVERROR(EINVAL);
+}
+
+if (ctx->filter != &ff_vf_scale2ref &&
+(vars_w[VAR_S2R_MAIN_W]|| vars_h[VAR_S2R_MAIN_W]||
+ vars_w[VAR_S2R_MAIN_H]|| vars_h[VAR_S2R_MAIN_H]||
+ vars_w[VAR_S2R_MAIN_A]|| vars_h[VAR_S2R_MAIN_A]||
+ vars_w[VAR_S2R_MAIN_SAR]  || vars_h[VAR_S2R_MAIN_SAR]  ||
+ vars_w[VAR_S2R_MAIN_DAR]  || vars_h[VAR_S2R_MAIN_DAR]  ||
+ vars_w[VAR_S2R_MDAR]  || vars_h[VAR_S2R_MDAR]  ||
+ vars_w[VAR_S2R_MAIN_HSUB] || vars_h[VAR_S2R_MAIN_HSUB] ||
+ vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB]) ) {
+av_log(ctx, AV_LOG_ERROR, "Expressions with scale2ref variables are 
not valid in scale filter.\n");
+return AVERROR(EINVAL);
+}
+
+return 0;
+}
+
 static int scale_parse_expr(AVFilterContext *ctx, char *str_expr, AVExpr 
**pexpr_ptr, const char *var, const char *args)
 {
 ScaleContext *scale = ctx->priv;
 int ret, is_inited = 0;
 char *old_str_expr = NULL;
 AVExpr *old_pexpr = NULL;
-const char scale2ref = ctx->filter == &ff_vf_scale2ref;
-const char *const *names = scale2ref ? var_names_scale2ref : var_names;
 
 if (str_expr) {
 old_str_expr = av_strdup(str_expr);
@@ -195,13 +212,17 @@ static int scale_parse_expr(AVFilterContext *ctx, char 
*str_expr, AVExpr **pexpr
 is_inited = 1;
 }
 
-ret = av_expr_parse(pexpr_ptr, args, names,
+ret = av_expr_parse(pexpr_ptr, args, var_names,
 NULL, NULL, NULL, NULL, 0, ctx);
 if (ret < 0) {
 av_log(ctx, AV_LOG_ERROR, "Cannot parse expression for %s: '%s'\n", 
var, args);
 goto revert;
 }
 
+ret = check_exprs(ctx);
+if (ret < 0)
+goto revert;
+
 if (is_inited && (ret = config_props(ctx->outputs[0])) < 

[FFmpeg-devel] [PATCH v2 5/5] avfilter/scale: add animation support

2019-12-31 Thread Gyan Doshi
Width and height expressions in scale and scale2ref filters can now
reference frame index, timestamp and packet position.
---
Rebased upon correct rebase of v2 3/5

 libavfilter/vf_scale.c | 64 +++---
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index f47e8fcae4..fac84c51fd 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -54,6 +54,9 @@ static const char *const var_names[] = {
 "vsub",
 "ohsub",
 "ovsub",
+"n",
+"t",
+"pos",
 "main_w",
 "main_h",
 "main_a",
@@ -61,6 +64,9 @@ static const char *const var_names[] = {
 "main_dar", "mdar",
 "main_hsub",
 "main_vsub",
+"main_n",
+"main_t",
+"main_pos",
 NULL
 };
 
@@ -76,6 +82,9 @@ enum var_name {
 VAR_VSUB,
 VAR_OHSUB,
 VAR_OVSUB,
+VAR_N,
+VAR_T,
+VAR_POS,
 VAR_S2R_MAIN_W,
 VAR_S2R_MAIN_H,
 VAR_S2R_MAIN_A,
@@ -83,6 +92,9 @@ enum var_name {
 VAR_S2R_MAIN_DAR, VAR_S2R_MDAR,
 VAR_S2R_MAIN_HSUB,
 VAR_S2R_MAIN_VSUB,
+VAR_S2R_MAIN_N,
+VAR_S2R_MAIN_T,
+VAR_S2R_MAIN_POS,
 VARS_NB
 };
 
@@ -184,11 +196,25 @@ static int check_exprs(AVFilterContext *ctx)
  vars_w[VAR_S2R_MAIN_DAR]  || vars_h[VAR_S2R_MAIN_DAR]  ||
  vars_w[VAR_S2R_MDAR]  || vars_h[VAR_S2R_MDAR]  ||
  vars_w[VAR_S2R_MAIN_HSUB] || vars_h[VAR_S2R_MAIN_HSUB] ||
- vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB]) ) {
+ vars_w[VAR_S2R_MAIN_VSUB] || vars_h[VAR_S2R_MAIN_VSUB] ||
+ vars_w[VAR_S2R_MAIN_N]|| vars_h[VAR_S2R_MAIN_N]||
+ vars_w[VAR_S2R_MAIN_T]|| vars_h[VAR_S2R_MAIN_T]||
+ vars_w[VAR_S2R_MAIN_POS]  || vars_h[VAR_S2R_MAIN_POS]) ) {
 av_log(ctx, AV_LOG_ERROR, "Expressions with scale2ref variables are 
not valid in scale filter.\n");
 return AVERROR(EINVAL);
 }
 
+if (scale->eval_mode == EVAL_MODE_INIT &&
+(vars_w[VAR_N]|| vars_h[VAR_N]   ||
+ vars_w[VAR_T]|| vars_h[VAR_T]   ||
+ vars_w[VAR_POS]  || vars_h[VAR_POS] ||
+ vars_w[VAR_S2R_MAIN_N]   || vars_h[VAR_S2R_MAIN_N]  ||
+ vars_w[VAR_S2R_MAIN_T]   || vars_h[VAR_S2R_MAIN_T]  ||
+ vars_w[VAR_S2R_MAIN_POS] || vars_h[VAR_S2R_MAIN_POS]) ) {
+av_log(ctx, AV_LOG_ERROR, "Expressions with frame variables 'n', 't', 
'pos' are not valid in init eval_mode.\n");
+return AVERROR(EINVAL);
+}
+
 return 0;
 }
 
@@ -622,6 +648,8 @@ static int scale_slice(AVFilterLink *link, AVFrame 
*out_buf, AVFrame *cur_pic, s
  out,out_stride);
 }
 
+#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts) * av_q2d(tb))
+
 static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
 {
 AVFilterContext *ctx = link->dst;
@@ -643,10 +671,20 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 in->sample_aspect_ratio.den != 
link->sample_aspect_ratio.den ||
 in->sample_aspect_ratio.num != 
link->sample_aspect_ratio.num;
 
-if (frame_changed ||
-(scale->eval_mode == EVAL_MODE_FRAME &&
- ctx->filter == &ff_vf_scale2ref) ) {
+if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) {
 int ret;
+unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
+
+av_expr_count_vars(scale->w_pexpr, vars_w, VARS_NB);
+av_expr_count_vars(scale->h_pexpr, vars_h, VARS_NB);
+
+if (scale->eval_mode == EVAL_MODE_FRAME &&
+!frame_changed &&
+ctx->filter != &ff_vf_scale2ref &&
+!(vars_w[VAR_N] || vars_w[VAR_T] || vars_w[VAR_POS]) &&
+!(vars_h[VAR_N] || vars_h[VAR_T] || vars_h[VAR_POS]) &&
+scale->w && scale->h)
+goto scale;
 
 if (scale->eval_mode == EVAL_MODE_INIT) {
 snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
@@ -663,6 +701,16 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 return ret;
 }
 
+if (ctx->filter == &ff_vf_scale2ref) {
+scale->var_values[VAR_S2R_MAIN_N] = link->frame_count_out;
+scale->var_values[VAR_S2R_MAIN_T] = TS2T(in->pts, link->time_base);
+scale->var_values[VAR_S2R_MAIN_POS] = in->pkt_pos == -1 ? NAN : 
in->pkt_pos;
+} else {
+scale->var_values[VAR_N] = link->frame_count_out;
+scale->var_values[VAR_T] = TS2T(in->pts, link->time_base);
+scale->var_values[VAR_POS] = in->pkt_pos == -1 ? NAN : in->pkt_pos;
+}
+
 link->dst->inputs[0]->format = in->format;
 link->dst->inputs[0]->w  = in->width;
 link->dst->inputs[0]->h  = in->height;
@@ -674,6 +722,7 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, 
AVFrame **frame_out)
 retu

Re: [FFmpeg-devel] [PATCH] Adding a flag to give user the option to have ffmpeg fail instead of warn when mismatches are found in rtmp url stream or application names.

2019-12-31 Thread William Martin
I doesn't look like there are any blockers on this patch request - could
someone go ahead and merge it?

On Sat, Sep 28, 2019 at 2:55 AM Reino Wijnsma  wrote:

> On 2019-09-27T19:37:40+0200, William Martin 
> wrote:
> > On Wed, Sep 25, 2019 at 2:36 PM Reino Wijnsma 
> wrote:
> >> On 2019-09-25T20:57:08+0200, William Martin <
> unique.will.mar...@gmail.com>
> >> wrote:
> >>> +av_log(s, AV_LOG_ERROR, "App field don't match up: %s <->
> %s. "
> >> Although I'm not a native English speaker, since "field" isn't plural,
> I'm pretty confident "don't" should be "doesn't".
> >>
> >> -- Reino
> >
> > Hi Reino - good point. Though, that was an existing log message that I
> did
> > not modify. Should the old typo be addressed in a separate patch, or
> should
> > I update it here?
> >
> I believe that's good practise here, yes. However, I'm not a FFmpeg coder,
> so someone else would to correct me otherwise.
>
> Please don't top-post on this mailinglist!
>
> -- Reino
> ___
> 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] [PATCHv2 8/8] avformat/img2enc: add support for specifying protocol options

2019-12-31 Thread Michael Niedermayer
On Tue, Dec 31, 2019 at 12:37:02PM +0100, Nicolas George wrote:
> Marton Balint (12019-12-28):
> > v2: simplified example
> > 
> > Signed-off-by: Marton Balint 
> > ---
> >  doc/muxers.texi   | 11 +++
> >  libavformat/img2enc.c | 13 -
> >  2 files changed, 23 insertions(+), 1 deletion(-)
> 
> image2 is not the only demuxer that opens new streams. I think a generic
> solution would be preferable.

i also had a slightly ungood feeling about the patch but didnt
had time to think more about it. a more generic solution like with
child AVClasses or something would be interresting but as said i didnt
had time to think about this ...

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus


signature.asc
Description: PGP signature
___
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 00/20] Matroska muxer patches

2019-12-31 Thread Andreas Rheinhardt
Hello,

this patchset is about the Matroska muxer. It consists partially of
patches from my earlier patchset [1] that is currently blocked by the
webm_chunk muxer [2].

One focus of this patchset is about improving writing Cues; in
particular, an assert that is triggered if the reserved space for
writing Cues in front exceeds the needed space by one byte is fixed.

Furthermore, the checks involved in writing SeekHeads were fixed. This
goes beyond what was done in the earlier patchset.

- Andreas

[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-November/252578.html
[2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254783.html

Andreas Rheinhardt (20):
  avformat/matroskaenc: Fix ReferenceBlock timestamp
  avformat/matroskaenc: Improve writing Projection
  avformat/matroskaenc: Remove useless AVIOContext
  avformat/matroskaenc: Adapt documentation of put_ebml_num
  avformat/matroskaenc: Check return value of ff_isom_write_hvcc()
  avformat/matroskaenc: Check functions that can fail
  avformat/matroskaenc: Avoid allocations for SeekHead
  avformat/matroskaenc: Improve calculating EBML ID size
  avformat/matroskaenc: Check for failure when writing SeekHead
  avformat/matroskaenc: Avoid unnecessary seek
  avformat/matroskaenc: Cosmetics
  avformat/matroskaenc: Avoid allocation for Cues
  avformat/aviobuf: Add function to reset dynamic buffer
  avformat/matroskadec: Simplify writing Cues
  avformat/matroskaenc: Write level 1 elements in one go
  avformat/matroskaenc: Remove unused function parameter
  avformat/matroskaenc: Check that Cluster has been opened
  avformat/matroskaenc: Don't fail if reserved Cues space doesn't
suffice
  avformat/matroskaenc: Fix edge case of writing Cues at the beginning
  avformat/matroskaenc: Avoid seek when writing Cues at the front

 doc/muxers.texi  |   4 +-
 libavformat/avio_internal.h  |   7 +
 libavformat/aviobuf.c|  11 +
 libavformat/matroskaenc.c| 516 ---
 tests/fate/matroska.mak  |   2 +-
 tests/fate/wavpack.mak   |   4 +-
 tests/ref/fate/aac-autobsf-adtstoasc |   4 +-
 tests/ref/fate/binsub-mksenc |   2 +-
 tests/ref/fate/rgb24-mkv |   4 +-
 tests/ref/lavf/mka   |   4 +-
 tests/ref/lavf/mkv   |   4 +-
 tests/ref/lavf/mkv_attachment|   4 +-
 tests/ref/seek/lavf-mkv  |  44 +--
 13 files changed, 286 insertions(+), 324 deletions(-)

-- 
2.20.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 02/20] avformat/matroskaenc: Improve writing Projection

2019-12-31 Thread Andreas Rheinhardt
The Matroska Projection master element has such a small maximum length
that it can always be written with a length field of length one.
So it is unnecessary to first write the element into a dynamic buffer to
get the accurate length in order not to waste bytes on the length field.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 48 +--
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 9cf840c9be..bbf9b55e78 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -947,10 +947,8 @@ static int mkv_write_video_projection(AVFormatContext *s, 
AVIOContext *pb,
   AVStream *st)
 {
 AVIOContext b;
-AVIOContext *dyn_cp;
+ebml_master projection;
 int side_data_size = 0;
-int ret, projection_size;
-uint8_t *projection_ptr;
 uint8_t private[20];
 
 const AVSphericalMapping *spherical =
@@ -960,62 +958,58 @@ static int mkv_write_video_projection(AVFormatContext *s, 
AVIOContext *pb,
 if (!side_data_size)
 return 0;
 
-ret = avio_open_dyn_buf(&dyn_cp);
-if (ret < 0)
-return ret;
+if (spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR  &&
+spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR_TILE &&
+spherical->projection != AV_SPHERICAL_CUBEMAP) {
+av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
+return 0;
+}
+
+// Maximally 4 8-byte elements with id-length 2 + 1 byte length field
+// and the private data of the AV_SPHERICAL_EQUIRECTANGULAR_TILE case
+projection = start_ebml_master(pb, MATROSKA_ID_VIDEOPROJECTION,
+   4 * (2 + 1 + 8) + (2 + 1 + 20));
 
 switch (spherical->projection) {
 case AV_SPHERICAL_EQUIRECTANGULAR:
-put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPROJECTIONTYPE,
   MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
 break;
 case AV_SPHERICAL_EQUIRECTANGULAR_TILE:
 ffio_init_context(&b, private, 20, 1, NULL, NULL, NULL, NULL);
-put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPROJECTIONTYPE,
   MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
 avio_wb32(&b, 0); // version + flags
 avio_wb32(&b, spherical->bound_top);
 avio_wb32(&b, spherical->bound_bottom);
 avio_wb32(&b, spherical->bound_left);
 avio_wb32(&b, spherical->bound_right);
-put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
+put_ebml_binary(pb, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
 private, avio_tell(&b));
 break;
 case AV_SPHERICAL_CUBEMAP:
 ffio_init_context(&b, private, 12, 1, NULL, NULL, NULL, NULL);
-put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONTYPE,
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPROJECTIONTYPE,
   MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP);
 avio_wb32(&b, 0); // version + flags
 avio_wb32(&b, 0); // layout
 avio_wb32(&b, spherical->padding);
-put_ebml_binary(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
+put_ebml_binary(pb, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
 private, avio_tell(&b));
 break;
-default:
-av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
-goto end;
 }
 
 if (spherical->yaw)
-put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEYAW,
+put_ebml_float(pb, MATROSKA_ID_VIDEOPROJECTIONPOSEYAW,
(double) spherical->yaw   / (1 << 16));
 if (spherical->pitch)
-put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH,
+put_ebml_float(pb, MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH,
(double) spherical->pitch / (1 << 16));
 if (spherical->roll)
-put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOPROJECTIONPOSEROLL,
+put_ebml_float(pb, MATROSKA_ID_VIDEOPROJECTIONPOSEROLL,
(double) spherical->roll  / (1 << 16));
 
-end:
-projection_size = avio_close_dyn_buf(dyn_cp, &projection_ptr);
-if (projection_size) {
-ebml_master projection = start_ebml_master(pb,
-   MATROSKA_ID_VIDEOPROJECTION,
-   projection_size);
-avio_write(pb, projection_ptr, projection_size);
-end_ebml_master(pb, projection);
-}
-av_freep(&projection_ptr);
+end_ebml_master(pb, projection);
 
 return 0;
 }
-- 
2.20.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 subjec

[FFmpeg-devel] [PATCH 01/20] avformat/matroskaenc: Fix ReferenceBlock timestamp

2019-12-31 Thread Andreas Rheinhardt
In order to indicate that the frames in a BlockGroup are not keyframes,
one has to add a ReferenceBlock element containing the timestamp of a
referenced Block that has already been written. The timestamp ought to be
relative to the timestamp of the Block it is attached to. Yet the
Matroska muxer used the relative timestamp of the preceding Block of the
track, i.e. the timestamp of the preceding block relative to the
timestamp of the Cluster containing said block (that need not be the
Cluster containing the current Block). This has been fixed.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 469b604de6..9cf840c9be 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2167,9 +2167,9 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 av_free(data);
 
 if (blockid == MATROSKA_ID_BLOCK && !keyframe) {
-put_ebml_sint(pb, MATROSKA_ID_BLOCKREFERENCE, track->last_timestamp);
+put_ebml_sint(pb, MATROSKA_ID_BLOCKREFERENCE, track->last_timestamp - 
ts);
 }
-track->last_timestamp = ts - mkv->cluster_pts;
+track->last_timestamp = ts;
 
 if (discard_padding) {
 put_ebml_sint(pb, MATROSKA_ID_DISCARDPADDING, discard_padding);
-- 
2.20.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 11/20] avformat/matroskaenc: Cosmetics

2019-12-31 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 8040c8311c..6dd731eb90 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -449,7 +449,6 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 {
 AVIOContext *dyn_cp;
 mkv_seekhead *seekhead = &mkv->seekhead;
-ebml_master seekentry;
 int64_t remaining, ret64;
 int i, ret;
 
@@ -465,8 +464,8 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 
 for (i = 0; i < seekhead->num_entries; i++) {
 mkv_seekhead_entry *entry = &seekhead->entries[i];
-
-seekentry = start_ebml_master(dyn_cp, MATROSKA_ID_SEEKENTRY, 
MAX_SEEKENTRY_SIZE);
+ebml_master seekentry = start_ebml_master(dyn_cp, 
MATROSKA_ID_SEEKENTRY,
+  MAX_SEEKENTRY_SIZE);
 
 put_ebml_id(dyn_cp, MATROSKA_ID_SEEKID);
 put_ebml_num(dyn_cp, ebml_id_size(entry->elementid), 0);
@@ -478,7 +477,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 end_ebml_master_crc32(pb, &dyn_cp, mkv);
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
-put_ebml_void(pb, remaining);
+put_ebml_void(pb, remaining);
 
 seek:
 if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0)
-- 
2.20.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 06/20] avformat/matroskaenc: Check functions that can fail

2019-12-31 Thread Andreas Rheinhardt
Sometimes it has not been checked whether opening the dynamic buffer for
writing Tags fails; this might have led to segfaults.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 8cea829b31..7857656309 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1557,7 +1557,9 @@ static int mkv_write_tag_targets(AVFormatContext *s, 
uint32_t elementid,
 ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_TAGS, 
avio_tell(s->pb));
 if (ret < 0) return ret;
 
-start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
+ret = start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, 
MATROSKA_ID_TAGS);
+if (ret < 0)
+return ret;
 }
 pb = mkv->tags_bc;
 
@@ -1653,7 +1655,10 @@ static int mkv_write_tags(AVFormatContext *s)
 if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
 continue;
 
-mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, 
&tag_target);
+ret = mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID,
+i + 1, &tag_target);
+if (ret < 0)
+return ret;
 pb = mkv->tags_bc;
 
 tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 0);
-- 
2.20.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 03/20] avformat/matroskaenc: Remove useless AVIOContext

2019-12-31 Thread Andreas Rheinhardt
Write a few numbers directly via AV_WB32 instead of using an AVIOContext
(that is initialized only for this very purpose) to write these numbers
at known offsets into a fixed buffer.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index bbf9b55e78..d51c8cbebf 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -946,7 +946,6 @@ static int mkv_write_video_color(AVIOContext *pb, 
AVCodecParameters *par, AVStre
 static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb,
   AVStream *st)
 {
-AVIOContext b;
 ebml_master projection;
 int side_data_size = 0;
 uint8_t private[20];
@@ -976,26 +975,24 @@ static int mkv_write_video_projection(AVFormatContext *s, 
AVIOContext *pb,
   MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
 break;
 case AV_SPHERICAL_EQUIRECTANGULAR_TILE:
-ffio_init_context(&b, private, 20, 1, NULL, NULL, NULL, NULL);
 put_ebml_uint(pb, MATROSKA_ID_VIDEOPROJECTIONTYPE,
   MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR);
-avio_wb32(&b, 0); // version + flags
-avio_wb32(&b, spherical->bound_top);
-avio_wb32(&b, spherical->bound_bottom);
-avio_wb32(&b, spherical->bound_left);
-avio_wb32(&b, spherical->bound_right);
+AV_WB32(private , 0); // version + flags
+AV_WB32(private +  4, spherical->bound_top);
+AV_WB32(private +  8, spherical->bound_bottom);
+AV_WB32(private + 12, spherical->bound_left);
+AV_WB32(private + 16, spherical->bound_right);
 put_ebml_binary(pb, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
-private, avio_tell(&b));
+private, 20);
 break;
 case AV_SPHERICAL_CUBEMAP:
-ffio_init_context(&b, private, 12, 1, NULL, NULL, NULL, NULL);
 put_ebml_uint(pb, MATROSKA_ID_VIDEOPROJECTIONTYPE,
   MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP);
-avio_wb32(&b, 0); // version + flags
-avio_wb32(&b, 0); // layout
-avio_wb32(&b, spherical->padding);
+AV_WB32(private, 0); // version + flags
+AV_WB32(private + 4, 0); // layout
+AV_WB32(private + 8, spherical->padding);
 put_ebml_binary(pb, MATROSKA_ID_VIDEOPROJECTIONPRIVATE,
-private, avio_tell(&b));
+private, 12);
 break;
 }
 
-- 
2.20.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 05/20] avformat/matroskaenc: Check return value of ff_isom_write_hvcc()

2019-12-31 Thread Andreas Rheinhardt
The Matroska muxer currently does not check the return value of
ff_isom_write_hvcc(), the function used to write mp4-style
HEVC-extradata as Matroska also uses it. This was intentionally done in
7a5356c72 to allow remuxing from mpeg-ts.

But if ff_isom_write_hvcc() fails, it has not output anything and the
file ends up without CodecPrivate and, if the input was Annex B, with
Annex B data, which is against the spec. So check the return value
again.

The underlying issue of not having extradata seems to have been fixed by
the introduction of the extract_extradata bitstream filter.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 76c38b8d09..8cea829b31 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -748,9 +748,8 @@ static int mkv_write_native_codecprivate(AVFormatContext 
*s, AVIOContext *pb,
 return ff_isom_write_avcc(dyn_cp, par->extradata,
   par->extradata_size);
 case AV_CODEC_ID_HEVC:
-ff_isom_write_hvcc(dyn_cp, par->extradata,
-   par->extradata_size, 0);
-return 0;
+return ff_isom_write_hvcc(dyn_cp, par->extradata,
+  par->extradata_size, 0);
 case AV_CODEC_ID_AV1:
 if (par->extradata_size)
 return ff_isom_write_av1c(dyn_cp, par->extradata,
-- 
2.20.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 04/20] avformat/matroskaenc: Adapt documentation of put_ebml_num

2019-12-31 Thread Andreas Rheinhardt
to its actual behaviour: That it uses the least amount of bytes unless
overridden.

The current documentation leaves it undefined how many bytes will be used
when no number to use has been given explicitly. But several estimates
(used to write EBML Master elements with a small length field) require
this number to be the least amount of bytes to work. Therefore change
the documentation; and remove a comment about writing length fields
indicating "unkown length". It has been outdated since 0580a122.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d51c8cbebf..76c38b8d09 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -218,7 +218,7 @@ static int ebml_num_size(uint64_t num)
  * Write a number in EBML variable length format.
  *
  * @param bytes The number of bytes that need to be used to write the number.
- *  If zero, any number of bytes can be used.
+ *  If zero, the minimal number of bytes will be used.
  */
 static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
 {
@@ -228,10 +228,9 @@ static void put_ebml_num(AVIOContext *pb, uint64_t num, 
int bytes)
 av_assert0(num < (1ULL << 56) - 1);
 
 if (bytes == 0)
-// don't care how many bytes are used, so use the min
 bytes = needed_bytes;
-// the bytes needed to write the given size would exceed the bytes
-// that we need to use, so write unknown size. This shouldn't happen.
+// The bytes needed to write the given size must not exceed
+// the bytes that we ought to use.
 av_assert0(bytes >= needed_bytes);
 
 num |= 1ULL << bytes * 7;
-- 
2.20.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 12/20] avformat/matroskaenc: Avoid allocation for Cues

2019-12-31 Thread Andreas Rheinhardt
Up until now, the Matroska muxer would allocate a structure containing
three members: The segment offset, a pointer to an array containing Cue
(index) entries and a counter for said array. It is unnecessary to
allocate it separately and it is unnecessary to contain the segment
offset in said structure, as it duplicates another field contained in
the MatroskaMuxContext. This commit implements the corresponding
changes.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 39 +++
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 6dd731eb90..2c4d3c338f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -88,7 +88,6 @@ typedef struct mkv_cuepoint {
 } mkv_cuepoint;
 
 typedef struct mkv_cues {
-int64_t segment_offset;
 mkv_cuepoint*entries;
 int num_entries;
 } mkv_cues;
@@ -139,7 +138,7 @@ typedef struct MatroskaMuxContext {
 int64_t duration_offset;
 int64_t duration;
 mkv_seekheadseekhead;
-mkv_cues*cues;
+mkv_cuescues;
 mkv_track   *tracks;
 mkv_attachments *attachments;
 
@@ -398,10 +397,7 @@ static void mkv_deinit(AVFormatContext *s)
 ffio_free_dyn_buf(&mkv->tracks_bc);
 ffio_free_dyn_buf(&mkv->tags_bc);
 
-if (mkv->cues) {
-av_freep(&mkv->cues->entries);
-av_freep(&mkv->cues);
-}
+av_freep(&mkv->cues.entries);
 if (mkv->attachments) {
 av_freep(&mkv->attachments->entries);
 av_freep(&mkv->attachments);
@@ -486,19 +482,10 @@ seek:
 return 0;
 }
 
-static mkv_cues *mkv_start_cues(int64_t segment_offset)
-{
-mkv_cues *cues = av_mallocz(sizeof(mkv_cues));
-if (!cues)
-return NULL;
-
-cues->segment_offset = segment_offset;
-return cues;
-}
-
-static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t 
ts,
+static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int tracknum, 
int64_t ts,
 int64_t cluster_pos, int64_t relative_pos, int64_t 
duration)
 {
+mkv_cues *cues = &mkv->cues;
 mkv_cuepoint *entries = cues->entries;
 
 if (ts < 0)
@@ -512,7 +499,7 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int 
tracknum, int64_t ts
 cues->entries[cues->num_entries].pts   = ts;
 cues->entries[cues->num_entries].stream_idx= stream;
 cues->entries[cues->num_entries].tracknum  = tracknum;
-cues->entries[cues->num_entries].cluster_pos   = cluster_pos - 
cues->segment_offset;
+cues->entries[cues->num_entries].cluster_pos   = cluster_pos - 
mkv->segment_offset;
 cues->entries[cues->num_entries].relative_pos  = relative_pos;
 cues->entries[cues->num_entries++].duration= duration;
 
@@ -1931,11 +1918,6 @@ static int mkv_write_header(AVFormatContext *s)
 return ret;
 }
 
-mkv->cues = mkv_start_cues(mkv->segment_offset);
-if (!mkv->cues) {
-return AVERROR(ENOMEM);
-}
-
 if (s->metadata_header_padding > 0) {
 if (s->metadata_header_padding == 1)
 s->metadata_header_padding++;
@@ -2346,7 +2328,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, 
AVPacket *pkt, int add_
 if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
 mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == 
AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) {
-ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, 
mkv->cluster_pos, relative_packet_pos, -1);
+ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts,
+   mkv->cluster_pos, relative_packet_pos, -1);
 if (ret < 0) return ret;
 }
 } else {
@@ -2371,7 +2354,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 
 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
-ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts,
+ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts,
mkv->cluster_pos, relative_packet_pos, 
duration);
 if (ret < 0)
 return ret;
@@ -2501,14 +2484,14 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
-if (mkv->cues->num_entries) {
+if (mkv->cues.num_entries) {
 if (mkv->reserve_cues_space) {
 int64_t cues_end;
 
 currentpos = avio_tell(pb);
 avio_seek(pb, mkv->cues_pos, SEEK_SET);
 
-cuespos  = mkv_write_cues(s, mkv->cues, mkv->tracks, 
s->nb_streams);
+cuespos  = mkv_write_cues(s, &mkv->cues, mkv->tracks, 
s->nb_streams);
 cues_end = avio_tell(pb);
 if (cues_end > cue

[FFmpeg-devel] [PATCH 14/20] avformat/matroskadec: Simplify writing Cues

2019-12-31 Thread Andreas Rheinhardt
When the Matroska muxer writes the Cues (the index), it groups index
entries with the same timestamp into the same CuePoint to save space.
But given Matroska's variable-length length fields, it either needs
to have an upper bound of the final size of the CuePoint before writing it
or the CuePoint has to be assembled in a different buffer, so that after
having assembled the CuePoint (when the real size is known), the CuePoint's
header can be written and its data copied after it.

The first of these approaches is the currently used one. This entails
finding out the number of entries in a CuePoint before starting the
CuePoint and therefore means that the list is read at least twice.
Furthermore, a worst-case upper-bound for the length of a single entry
was used, so that sometimes bytes are wasted on length fields.

This commit switches to the second approach. This is no longer more
expensive than the current approach if one only resets the dynamic
buffer used to write the CuePoint's content instead of opening a new
buffer for every CuePoint: Writing the trailer of a file with 540.000
CuePoints improved actually from 219054414 decicycles to 2164379394
decicycles (based upon 50 iterations).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 74 +--
 1 file changed, 33 insertions(+), 41 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 2c4d3c338f..6f0760fa69 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -170,12 +170,8 @@ typedef struct MatroskaMuxContext {
  * offset, 4 bytes for target EBML ID */
 #define MAX_SEEKENTRY_SIZE 21
 
-/** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint 
max
- * and one 1-byte uint for the track number (this assumes MAX_TRACKS to be <= 
255) */
-#define MAX_CUETRACKPOS_SIZE 35
-
-/** per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max */
-#define MAX_CUEPOINT_CONTENT_SIZE(num_tracks) 10 + MAX_CUETRACKPOS_SIZE * 
num_tracks
+/** 4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max) */
+#define MAX_CUETRACKPOS_SIZE 40
 
 /** Seek preroll value for opus */
 #define OPUS_SEEK_PREROLL 8000
@@ -509,58 +505,54 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int 
stream, int tracknum, i
 static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track 
*tracks, int num_tracks)
 {
 MatroskaMuxContext *mkv = s->priv_data;
-AVIOContext *dyn_cp, *pb = s->pb;
+AVIOContext *dyn_cp, *pb = s->pb, *cuepoint;
 int64_t currentpos;
-int i, j, ret;
+int ret;
 
 currentpos = avio_tell(pb);
 ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
 if (ret < 0)
 return ret;
 
-for (i = 0; i < cues->num_entries; i++) {
-ebml_master cuepoint, track_positions;
-mkv_cuepoint *entry = &cues->entries[i];
-uint64_t pts = entry->pts;
-int ctp_nb = 0;
-
-// Calculate the number of entries, so we know the element size
-for (j = 0; j < num_tracks; j++)
-tracks[j].has_cue = 0;
-for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
-int idx = entry[j].stream_idx;
+ret = avio_open_dyn_buf(&cuepoint);
+if (ret < 0) {
+ffio_free_dyn_buf(&dyn_cp);
+return ret;
+}
 
-av_assert0(idx >= 0 && idx < num_tracks);
-if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type 
!= AVMEDIA_TYPE_SUBTITLE)
-continue;
-tracks[idx].has_cue = 1;
-ctp_nb ++;
-}
+for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
+ entry < end;) {
+uint64_t pts = entry->pts;
+uint8_t *buf;
+int size;
 
-cuepoint = start_ebml_master(dyn_cp, MATROSKA_ID_POINTENTRY, 
MAX_CUEPOINT_CONTENT_SIZE(ctp_nb));
-put_ebml_uint(dyn_cp, MATROSKA_ID_CUETIME, pts);
+put_ebml_uint(cuepoint, MATROSKA_ID_CUETIME, pts);
 
 // put all the entries from different tracks that have the exact same
 // timestamp into the same CuePoint
-for (j = 0; j < num_tracks; j++)
+for (int j = 0; j < num_tracks; j++)
 tracks[j].has_cue = 0;
-for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
-int idx = entry[j].stream_idx;
+do {
+ebml_master track_positions;
+int idx = entry->stream_idx;
 
+av_assert0(idx >= 0 && idx < num_tracks);
 if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type 
!= AVMEDIA_TYPE_SUBTITLE)
 continue;
 tracks[idx].has_cue = 1;
-track_positions = start_ebml_master(dyn_cp, 
MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);
-put_ebml_uint(dyn_cp, MATROSKA_ID_CUETRACK   , 
entry[j].tracknum   );
-put_ebml_uint(dyn_cp, MATROSKA_ID_CUECLUSTE

[FFmpeg-devel] [PATCH 07/20] avformat/matroskaenc: Avoid allocations for SeekHead

2019-12-31 Thread Andreas Rheinhardt
Up until e7ddafd5, the Matroska muxer wrote two SeekHeads: One at the
beginning referencing the main level 1 elements (i.e. not the Clusters)
and one at the end, referencing the Clusters. This second SeekHead was
useless and has therefore been removed. Yet the SeekHead-related
functions and structures are still geared towards this usecase: They
are built around an allocated array of variable size that gets
reallocated every time an element is added to it although the maximum
number of Seek entries is a small compile-time constant, so that one should
rather include the array in the SeekHead structure itself; and said
structure should be contained in the MatroskaMuxContext instead of being
allocated separately.

The earlier code reserved space for a SeekHead with 10 entries, although
we currently write at most 6. Reducing said number implied that every
Matroska/Webm file will be 84 bytes smaller and required to adapt
several FATE tests; furthermore, the reserved amount overestimated the
amount needed for for the SeekHead's length field and how many bytes
need to be reserved to write a EBML Void element, bringing the total
reduction to 89 bytes.

Signed-off-by: Andreas Rheinhardt 
---
Slightly changed since last time: The five bytes mentioned at the end of
the commit message have been stripped away, too.

 libavformat/matroskaenc.c| 119 ---
 tests/fate/matroska.mak  |   2 +-
 tests/fate/wavpack.mak   |   4 +-
 tests/ref/fate/aac-autobsf-adtstoasc |   4 +-
 tests/ref/fate/binsub-mksenc |   2 +-
 tests/ref/fate/rgb24-mkv |   4 +-
 tests/ref/lavf/mka   |   4 +-
 tests/ref/lavf/mkv   |   4 +-
 tests/ref/lavf/mkv_attachment|   4 +-
 tests/ref/seek/lavf-mkv  |  44 +-
 10 files changed, 71 insertions(+), 120 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 7857656309..25ad337844 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -57,6 +57,10 @@
 #include "libavcodec/mpeg4audio.h"
 #include "libavcodec/internal.h"
 
+/* Level 1 elements we create a SeekHead entry for:
+ * Info, Tracks, Chapters, Attachments, Tags and Cues */
+#define MAX_SEEKHEAD_ENTRIES 6
+
 typedef struct ebml_master {
 int64_t pos;///< absolute offset in the containing 
AVIOContext where the master's elements start
 int sizebytes;  ///< how many bytes were reserved for 
the size
@@ -69,11 +73,9 @@ typedef struct mkv_seekhead_entry {
 
 typedef struct mkv_seekhead {
 int64_t filepos;
-int64_t segment_offset; ///< the file offset to the 
beginning of the segment
-int reserved_size;  ///< -1 if appending to file
-int max_entries;
-mkv_seekhead_entry  *entries;
+mkv_seekhead_entry  entries[MAX_SEEKHEAD_ENTRIES];
 int num_entries;
+int reserved_size;
 } mkv_seekhead;
 
 typedef struct mkv_cuepoint {
@@ -136,7 +138,7 @@ typedef struct MatroskaMuxContext {
 int64_t cluster_pts;
 int64_t duration_offset;
 int64_t duration;
-mkv_seekhead*seekhead;
+mkv_seekheadseekhead;
 mkv_cues*cues;
 mkv_track   *tracks;
 mkv_attachments *attachments;
@@ -396,10 +398,6 @@ static void mkv_deinit(AVFormatContext *s)
 ffio_free_dyn_buf(&mkv->tracks_bc);
 ffio_free_dyn_buf(&mkv->tags_bc);
 
-if (mkv->seekhead) {
-av_freep(&mkv->seekhead->entries);
-av_freep(&mkv->seekhead);
-}
 if (mkv->cues) {
 av_freep(&mkv->cues->entries);
 av_freep(&mkv->cues);
@@ -412,61 +410,33 @@ static void mkv_deinit(AVFormatContext *s)
 }
 
 /**
- * Initialize a mkv_seekhead element to be ready to index level 1 Matroska
- * elements. If a maximum number of elements is specified, enough space
- * will be reserved at the current file location to write a seek head of
- * that size.
- *
- * @param segment_offset The absolute offset to the position in the file
- *   where the segment begins.
- * @param numelements The maximum number of elements that will be indexed
- *by this seek head, 0 if unlimited.
+ * Initialize the SeekHead element to be ready to index level 1 Matroska
+ * elements. Enough space to write MAX_SEEKHEAD_ENTRIES SeekHead entries
+ * will be reserved at the current file location.
  */
-static mkv_seekhead *mkv_start_seekhead(AVIOContext *pb, int64_t 
segment_offset,
-int numelements)
+static void mkv_start_seekhead(MatroskaMuxContext *mkv, AVIOContext *pb)
 {
-mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead));
-if (!new_seekhead)
-return NULL;
-
-new_seekhead->segment_offset = segment_offset;
-
-if (numelements > 0) {
-new_seekhead-

[FFmpeg-devel] [PATCH 09/20] avformat/matroskaenc: Check for failure when writing SeekHead

2019-12-31 Thread Andreas Rheinhardt
mkv_write_seekhead() would up until now try to seek to the position where
the SeekHead ought to be written, write the SeekHead and seek back. The
first of these seeks was checked as was writing, yet the seek back was
unchecked. Moreover the return value of mkv_write_seekhead() was unchecked
(the ordinary return value was the position where the SeekHead was written).

This commit changes this: Everything is checked. In the unseekable case
(where the first seek may nevertheless work when it happens in the buffer)
a failure at the first seek is not considered an error. In any case,
failure to seek back is an error.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 52 ++-
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index cecf7589e5..c7948fb643 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -436,31 +436,35 @@ static void mkv_add_seekhead_entry(MatroskaMuxContext 
*mkv, uint32_t elementid,
 }
 
 /**
- * Write the SeekHead to the file at the location reserved for it.
+ * Write the SeekHead to the file at the location reserved for it
+ * and seek back to the initial position. When error_on_seek_failure
+ * is not set, failure to seek to the position designated for the
+ * SeekHead is not considered an error; failure to seek back afterwards
+ * is always an error.
  *
- * @return The file offset where the seekhead was written,
- * -1 if an error occurred.
+ * @return 0 on success, < 0 on error.
  */
-static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv)
+static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv,
+  int error_on_seek_failure)
 {
 AVIOContext *dyn_cp;
 mkv_seekhead *seekhead = &mkv->seekhead;
 ebml_master seekentry;
-int64_t currentpos, remaining;
-int i;
+int64_t currentpos, remaining, ret64;
+int i, ret;
 
 currentpos = avio_tell(pb);
 
-if (avio_seek(pb, seekhead->filepos, SEEK_SET) < 0) {
-currentpos = -1;
-goto fail;
-}
-
-if (start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD) < 0) {
-currentpos = -1;
-goto fail;
+if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0) {
+if (error_on_seek_failure)
+return ret64;
+goto seek_back;
 }
 
+ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
+if (ret < 0)
+return ret;
+
 for (i = 0; i < seekhead->num_entries; i++) {
 mkv_seekhead_entry *entry = &seekhead->entries[i];
 
@@ -477,13 +481,12 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv)
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
-avio_seek(pb, currentpos, SEEK_SET);
 
-currentpos = seekhead->filepos;
+seek_back:
+if ((ret64 = avio_seek(pb, currentpos, SEEK_SET)) < 0)
+return ret64;
 
-fail:
-
-return currentpos;
+return 0;
 }
 
 static mkv_cues *mkv_start_cues(int64_t segment_offset)
@@ -1925,8 +1928,11 @@ static int mkv_write_header(AVFormatContext *s)
 if (ret < 0)
 return ret;
 
-if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
-mkv_write_seekhead(pb, mkv);
+if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
+ret = mkv_write_seekhead(pb, mkv, 0);
+if (ret < 0)
+return ret;
+}
 
 mkv->cues = mkv_start_cues(mkv->segment_offset);
 if (!mkv->cues) {
@@ -2527,7 +2533,9 @@ static int mkv_write_trailer(AVFormatContext *s)
 mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos);
 }
 
-mkv_write_seekhead(pb, mkv);
+ret = mkv_write_seekhead(pb, mkv, 1);
+if (ret < 0)
+return ret;
 
 // update the duration
 av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
-- 
2.20.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 08/20] avformat/matroskaenc: Improve calculating EBML ID size

2019-12-31 Thread Andreas Rheinhardt
When the Matroska muxer writes an EBML ID, it calculates the length of
said ID before; and it does this as if this were a number that needs to
be encoded as EBML number: The formula used is (av_log2(id + 1) - 1) / 7
+ 1. But the constants used already contain the VINT_MARKER (the leading
bit indicating the length of the EBML number) and therefore the algorithm
used makes no sense. Instead the position of the most significant byte
set gives the desired length.

The algorithm used until now worked because EBML numbers are subject to
restrictions: If the EBML number takes up k bytes, then the bit 1 << (7
* k) is set and av_log2(id) is 7 * k. So the current algorithm produces
the correct result unless the EBML ID is of the form 7 * k - 1 because
of the "id + 1". But contrary to encoding lengths as EBML number (where
the + 1 exists to avoid the encodings reserved for unknown length),
such EBML numbers are simply forbidden as EBML IDs and as such none of
them were ever written.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 25ad337844..cecf7589e5 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -183,7 +183,7 @@ typedef struct MatroskaMuxContext {
 
 static int ebml_id_size(uint32_t id)
 {
-return (av_log2(id + 1) - 1) / 7 + 1;
+return (av_log2(id) + 7U) / 8;
 }
 
 static void put_ebml_id(AVIOContext *pb, uint32_t id)
-- 
2.20.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 13/20] avformat/aviobuf: Add function to reset dynamic buffer

2019-12-31 Thread Andreas Rheinhardt
Resetting a dynamic buffer means to keep the AVIOContext and the
internal buffer used by the dynamic buffer. This is done in order to
save (re)allocations when one has a workflow where one opens and closes
dynamic buffers in sequence.

Signed-off-by: Andreas Rheinhardt 
---
This function might also be beneficial in the mpegts muxer when
converting AAC to ADTS (currently a new dynamic buffer is opened for
every packet) or in the nut muxer. Besides the application in this very
patchset, there is another way that this can be used in the Matroska
muxer: By not reallocating the buffer used for writing packets one can
improve speed on platforms where realloc is slow (namely Windows). A
patch for this comes soon.

 libavformat/avio_internal.h |  7 +++
 libavformat/aviobuf.c   | 11 +++
 2 files changed, 18 insertions(+)

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index eb628ac493..c575df8035 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -171,6 +171,13 @@ int ffio_open_whitelist(AVIOContext **s, const char *url, 
int flags,
  */
 int ffio_close_null_buf(AVIOContext *s);
 
+/**
+ * Reset a dynamic buffer.
+ *
+ * Resets everything, but keeps the allocated buffer for later use.
+ */
+void ffio_reset_dyn_buf(AVIOContext *s);
+
 /**
  * Free a dynamic buffer.
  *
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 70e1d2ca10..d44ee0fa35 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1461,6 +1461,17 @@ int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
 return d->size;
 }
 
+void ffio_reset_dyn_buf(AVIOContext *s)
+{
+DynBuffer *d = s->opaque;
+int max_packet_size = s->max_packet_size;
+
+ffio_init_context(s, d->io_buffer, d->io_buffer_size, 1, d, NULL,
+  s->write_packet, s->seek);
+s->max_packet_size = max_packet_size;
+d->pos = d->size = 0;
+}
+
 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
 {
 DynBuffer *d;
-- 
2.20.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 16/20] avformat/matroskaenc: Remove unused function parameter

2019-12-31 Thread Andreas Rheinhardt
end_ebml_master_crc32_preliminary() has a MatroskaMuxContext as
parameter that isn't used at all. So remove it.
Furthermore it doesn't close its dynamic buffer; it just uses the
underlying buffer and therefore it only needs a pointer to the
dynamic buffer, not a pointer to a pointer.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index f9509129c8..c0979feb88 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -361,11 +361,11 @@ static void end_ebml_master_crc32(AVIOContext *pb, 
AVIOContext **dyn_cp,
 /**
 * Complete ebml master without destroying the buffer, allowing for later 
updates
 */
-static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext 
**dyn_cp, MatroskaMuxContext *mkv,
+static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext 
*dyn_cp,
   uint32_t id, int64_t *pos)
 {
 uint8_t *buf;
-int size = avio_get_dyn_buf(*dyn_cp, &buf);
+int size = avio_get_dyn_buf(dyn_cp, &buf);
 
 *pos = avio_tell(pb);
 
@@ -1389,7 +1389,7 @@ static int mkv_write_tracks(AVFormatContext *s)
 }
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
-end_ebml_master_crc32_preliminary(pb, &mkv->tracks_bc, mkv,
+end_ebml_master_crc32_preliminary(pb, mkv->tracks_bc,
   MATROSKA_ID_TRACKS, 
&mkv->tracks_pos);
 else
 end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS);
@@ -1644,7 +1644,7 @@ static int mkv_write_tags(AVFormatContext *s)
 
 if (mkv->tags_bc) {
 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
-end_ebml_master_crc32_preliminary(s->pb, &mkv->tags_bc, mkv,
+end_ebml_master_crc32_preliminary(s->pb, mkv->tags_bc,
   MATROSKA_ID_TAGS, 
&mkv->tags_pos);
 else
 end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
@@ -1881,7 +1881,7 @@ static int mkv_write_header(AVFormatContext *s)
 }
 }
 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
-end_ebml_master_crc32_preliminary(s->pb, &mkv->info_bc, mkv,
+end_ebml_master_crc32_preliminary(s->pb, mkv->info_bc,
   MATROSKA_ID_INFO, &mkv->info_pos);
 else
 end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO);
-- 
2.20.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 18/20] avformat/matroskaenc: Don't fail if reserved Cues space doesn't suffice

2019-12-31 Thread Andreas Rheinhardt
When the user opted to write the Cues at the beginning, the Cues were
simply written without checking in advance whether enough space has been
reserved for them. If it wasn't enough, the data following the space
reserved for the Cues was simply overwritten, corrupting the file.

This commit changes this by checking whether enough space has been
reserved for the Cues before outputting anything. If it isn't enough,
the Cues will be output at the end as usual.

Signed-off-by: Andreas Rheinhardt 
---
 doc/muxers.texi   |  4 +-
 libavformat/matroskaenc.c | 79 ---
 2 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 5d7ff1ab3b..9eca32c1ca 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1314,8 +1314,8 @@ index at the beginning of the file.
 
 If this option is set to a non-zero value, the muxer will reserve a given 
amount
 of space in the file header and then try to write the cues there when the 
muxing
-finishes. If the available space does not suffice, muxing will fail. A safe 
size
-for most use cases should be about 50kB per hour of video.
+finishes. If the reserved space does not suffice, the Cues will be written at
+the end. A safe size for most use cases should be about 50kB per hour of video.
 
 Note that cues are only written if the output is seekable and this option will
 have no effect if it is not.
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d7aa832eb3..4e739d245b 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -503,23 +503,15 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int 
stream, int tracknum, i
 return 0;
 }
 
-static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track 
*tracks, int num_tracks)
+static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
+ mkv_cues *cues, mkv_track *tracks, int num_tracks)
 {
-MatroskaMuxContext *mkv = s->priv_data;
-AVIOContext *dyn_cp, *pb = s->pb, *cuepoint;
-int64_t currentpos;
+AVIOContext *cuepoint;
 int ret;
 
-currentpos = avio_tell(pb);
-ret = start_ebml_master_crc32(&dyn_cp, mkv);
-if (ret < 0)
-return ret;
-
 ret = avio_open_dyn_buf(&cuepoint);
-if (ret < 0) {
-ffio_free_dyn_buf(&dyn_cp);
+if (ret < 0)
 return ret;
-}
 
 for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
  entry < end;) {
@@ -538,7 +530,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 int idx = entry->stream_idx;
 
 av_assert0(idx >= 0 && idx < num_tracks);
-if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type 
!= AVMEDIA_TYPE_SUBTITLE)
+if (tracks[idx].has_cue && streams[idx]->codecpar->codec_type != 
AVMEDIA_TYPE_SUBTITLE)
 continue;
 tracks[idx].has_cue = 1;
 track_positions = start_ebml_master(cuepoint, 
MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);
@@ -554,9 +546,8 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 ffio_reset_dyn_buf(cuepoint);
 }
 ffio_free_dyn_buf(&cuepoint);
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
 
-return currentpos;
+return 0;
 }
 
 static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, 
AVCodecParameters *par)
@@ -2457,7 +2448,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb = s->pb;
-int64_t currentpos, cuespos;
+int64_t currentpos;
 int ret;
 
 // check if we have an audio packet cached
@@ -2480,33 +2471,45 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
+int64_t ret64;
+
 if (mkv->cues.num_entries) {
-if (mkv->reserve_cues_space) {
-int64_t cues_end;
-
-currentpos = avio_tell(pb);
-avio_seek(pb, mkv->cues_pos, SEEK_SET);
-
-cuespos  = mkv_write_cues(s, &mkv->cues, mkv->tracks, 
s->nb_streams);
-cues_end = avio_tell(pb);
-if (cues_end > cuespos + mkv->reserve_cues_space) {
-av_log(s, AV_LOG_ERROR,
-   "Insufficient space reserved for cues: %d "
-   "(needed: %" PRId64 ").\n",
-   mkv->reserve_cues_space, cues_end - cuespos);
-return AVERROR(EINVAL);
-}
+AVIOContext *cues;
+uint64_t size;
 
-if (cues_end < cuespos + mkv->reserve_cues_space)
-put_ebml_void(pb, mkv->reserve_cues_space -
-  (cues_end - cuespos));
+ret = start_ebml_master_crc32(&cues, mkv);
+if (ret < 

[FFmpeg-devel] [PATCH 19/20] avformat/matroskaenc: Fix edge case of writing Cues at the beginning

2019-12-31 Thread Andreas Rheinhardt
The Matroska muxer has the ability to write the Cues (the index) at the
beginning of the file (in front of the Cluster): The user inputs the
amount of space that should be reserved at the beginning of the file and
if this is sufficient, the Cues will be written there and the part of the
reserved space not used up by the Cues will be filled with a "Void"
element.

There is just one problem with this: One can not fill a single byte this
way, because said Void element is minimally two bytes long (one byte ID,
one byte length field). Up until now, if one reserved one byte more than
needed, one would run into an assert when writing the Void element.

There are two solutions for this: Error out if it happens. Or adjust the
length field of the Cues in order to ensure that the above situation
can't happen (i.e. write the length on one byte more than necessary).
The first solution is very unsatisfactory, as enough space has been
reserved. Therefore this commit implements the second solution.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 42 +--
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 4e739d245b..24317d3819 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -339,14 +339,15 @@ static int start_ebml_master_crc32(AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv
 }
 
 static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp,
-  MatroskaMuxContext *mkv, uint32_t id)
+  MatroskaMuxContext *mkv, uint32_t id,
+  int length_size)
 {
 uint8_t *buf, crc[4];
 int size, skip = 0;
 
 put_ebml_id(pb, id);
 size = avio_close_dyn_buf(*dyn_cp, &buf);
-put_ebml_num(pb, size, 0);
+put_ebml_num(pb, size, length_size);
 if (mkv->write_crc) {
 skip = 6; /* Skip reserved 6-byte long void element from the dynamic 
buffer. */
 AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, 
buf + skip, size - skip) ^ UINT32_MAX);
@@ -467,7 +468,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);
 end_ebml_master(dyn_cp, seekentry);
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD, 0);
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
@@ -1383,7 +1384,7 @@ static int mkv_write_tracks(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(pb, mkv->tracks_bc,
   MATROSKA_ID_TRACKS, 
&mkv->tracks_pos);
 else
-end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS);
+end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS, 0);
 
 return 0;
 }
@@ -1439,7 +1440,7 @@ static int mkv_write_chapters(AVFormatContext *s)
 end_ebml_master(dyn_cp, chapteratom);
 }
 end_ebml_master(dyn_cp, editionentry);
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS, 0);
 
 mkv->wrote_chapters = 1;
 return 0;
@@ -1638,7 +1639,7 @@ static int mkv_write_tags(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(s->pb, mkv->tags_bc,
   MATROSKA_ID_TAGS, 
&mkv->tags_pos);
 else
-end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
+end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 
0);
 }
 return 0;
 }
@@ -1734,7 +1735,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 mkv->attachments->entries[mkv->attachments->num_entries].stream_idx = 
i;
 mkv->attachments->entries[mkv->attachments->num_entries++].fileuid  = 
fileuid;
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS, 0);
 
 return 0;
 }
@@ -1875,7 +1876,7 @@ static int mkv_write_header(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(s->pb, mkv->info_bc,
   MATROSKA_ID_INFO, &mkv->info_pos);
 else
-end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO);
+end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO, 0);
 pb = s->pb;
 
 ret = mkv_write_tracks(s);
@@ -2157,7 +2158,7 @@ static void mkv_end_cluster(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 
-end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv, MATROSKA_ID_CLUSTER);
+end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv, MATROSKA_ID_CLUSTER, 
0);
 mkv->cluster_pos = -1;
 avio_flush(s->pb);
 }
@@

[FFmpeg-devel] [PATCH 15/20] avformat/matroskaenc: Write level 1 elements in one go

2019-12-31 Thread Andreas Rheinhardt
Up until now, writing level 1 elements proceeded as follows: First, the
element id was written to the ordinary output AVIOContext and a dynamic
buffer was opened for the content of the level 1 element in
start_ebml_master_crc32(). Then this buffer was actually used and after it
was closed (in end_ebml_master_crc32()), the size field corresponding to
the buffer's size was written, after which the actual data was written.

This commit changes this: Nothing is written to the main AVIOContext any
more in start_ebml_master_crc32(). end_ebml_master_crc32() now writes
both the id, the length field as well as the data. This implies that
one can start a level 1 element in memory without outputting anything.
This is done to enable to test whether enough space has been reserved
for the Cues (if space has been reserved for them) before writing them.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 60 +--
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 6f0760fa69..f9509129c8 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -325,26 +325,26 @@ static void end_ebml_master(AVIOContext *pb, ebml_master 
master)
 avio_seek(pb, pos, SEEK_SET);
 }
 
-static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv,
-   uint32_t elementid)
+static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext 
*mkv)
 {
 int ret;
 
 if ((ret = avio_open_dyn_buf(dyn_cp)) < 0)
 return ret;
 
-put_ebml_id(pb, elementid);
 if (mkv->write_crc)
 put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size 
calculations using avio_tell() take it into account */
 
 return 0;
 }
 
-static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv)
+static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp,
+  MatroskaMuxContext *mkv, uint32_t id)
 {
 uint8_t *buf, crc[4];
 int size, skip = 0;
 
+put_ebml_id(pb, id);
 size = avio_close_dyn_buf(*dyn_cp, &buf);
 put_ebml_num(pb, size, 0);
 if (mkv->write_crc) {
@@ -362,13 +362,14 @@ static void end_ebml_master_crc32(AVIOContext *pb, 
AVIOContext **dyn_cp, Matrosk
 * Complete ebml master without destroying the buffer, allowing for later 
updates
 */
 static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext 
**dyn_cp, MatroskaMuxContext *mkv,
-  int64_t *pos)
+  uint32_t id, int64_t *pos)
 {
 uint8_t *buf;
 int size = avio_get_dyn_buf(*dyn_cp, &buf);
 
 *pos = avio_tell(pb);
 
+put_ebml_id(pb, id);
 put_ebml_num(pb, size, 0);
 avio_write(pb, buf, size);
 }
@@ -450,7 +451,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 goto seek;
 }
 
-ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
+ret = start_ebml_master_crc32(&dyn_cp, mkv);
 if (ret < 0)
 return ret;
 
@@ -466,7 +467,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);
 end_ebml_master(dyn_cp, seekentry);
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
@@ -510,7 +511,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 int ret;
 
 currentpos = avio_tell(pb);
-ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
+ret = start_ebml_master_crc32(&dyn_cp, mkv);
 if (ret < 0)
 return ret;
 
@@ -553,7 +554,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 ffio_reset_dyn_buf(cuepoint);
 }
 ffio_free_dyn_buf(&cuepoint);
-end_ebml_master_crc32(pb, &dyn_cp, mkv);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
 
 return currentpos;
 }
@@ -1373,7 +1374,7 @@ static int mkv_write_tracks(AVFormatContext *s)
 
 mkv_add_seekhead_entry(mkv, MATROSKA_ID_TRACKS, avio_tell(pb));
 
-ret = start_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, 
MATROSKA_ID_TRACKS);
+ret = start_ebml_master_crc32(&mkv->tracks_bc, mkv);
 if (ret < 0)
 return ret;
 
@@ -1388,9 +1389,10 @@ static int mkv_write_tracks(AVFormatContext *s)
 }
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
-end_ebml_master_crc32_preliminary(pb, &mkv->tracks_bc, mkv, 
&mkv->tracks_pos);
+end_ebml_master_crc32_preliminary(pb, &mkv->tracks_bc, mkv,
+  MATROSKA_ID_TRACKS, 
&mkv->

[FFmpeg-devel] [PATCH 20/20] avformat/matroskaenc: Avoid seek when writing Cues at the front

2019-12-31 Thread Andreas Rheinhardt
When the Cues are written in front of the Cluster, the muxer would seek
to the beginning (to where the Cues ought to be written) and write the
Cues; afterwards it would seek back to the end of the file only to seek
to the beginning once again to update several elements there. This
commit removes the seek to the end.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 24317d3819..95d97a10c5 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2449,7 +2449,6 @@ static int mkv_write_trailer(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb = s->pb;
-int64_t currentpos;
 int ret;
 
 // check if we have an audio packet cached
@@ -2472,11 +2471,14 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
-int64_t ret64;
+int64_t endpos, ret64;
+
+endpos = avio_tell(pb);
 
 if (mkv->cues.num_entries) {
 AVIOContext *cues;
 uint64_t size;
+int64_t cuespos = endpos;
 int length_size = 0;
 
 ret = start_ebml_master_crc32(&cues, mkv);
@@ -2499,7 +2501,7 @@ static int mkv_write_trailer(AVFormatContext *s)
mkv->reserve_cues_space, size);
 mkv->reserve_cues_space = 0;
 } else {
-currentpos = avio_tell(pb);
+cuespos = mkv->cues_pos;
 if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) {
 ffio_free_dyn_buf(&cues);
 return ret64;
@@ -2515,17 +2517,15 @@ static int mkv_write_trailer(AVFormatContext *s)
 }
 }
 }
-mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, avio_tell(pb));
+mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos);
 end_ebml_master_crc32(pb, &cues, mkv, MATROSKA_ID_CUES, 
length_size);
 if (mkv->reserve_cues_space) {
 if (size < mkv->reserve_cues_space)
 put_ebml_void(pb, mkv->reserve_cues_space - size);
-avio_seek(pb, currentpos, SEEK_SET);
-}
+} else
+endpos = avio_tell(pb);
 }
 
-currentpos = avio_tell(pb);
-
 ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos);
 if (ret < 0)
 return ret;
@@ -2571,7 +2571,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 end_ebml_master_crc32(pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 0);
 }
 
-avio_seek(pb, currentpos, SEEK_SET);
+avio_seek(pb, endpos, SEEK_SET);
 }
 
 if (!mkv->is_live) {
-- 
2.20.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 17/20] avformat/matroskaenc: Check that Cluster has been opened

2019-12-31 Thread Andreas Rheinhardt
before setting the field indicating that a Cluster has been opened.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c0979feb88..d7aa832eb3 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2306,10 +2306,10 @@ static int mkv_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt, int add_
 }
 
 if (mkv->cluster_pos == -1) {
-mkv->cluster_pos = avio_tell(s->pb);
 ret = start_ebml_master_crc32(&mkv->cluster_bc, mkv);
 if (ret < 0)
 return ret;
+mkv->cluster_pos = avio_tell(s->pb);
 put_ebml_uint(mkv->cluster_bc, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, 
ts));
 mkv->cluster_pts = FFMAX(0, ts);
 av_log(s, AV_LOG_DEBUG,
-- 
2.20.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 10/20] avformat/matroskaenc: Avoid unnecessary seek

2019-12-31 Thread Andreas Rheinhardt
When writing the SeekHead (a form of index) at the end of the muxing
process, mkv_write_seekhead() would first seek to the position where the
SeekHead ought to be written, then write it there and seek back to the
original position afterwards. Which means: To the end of the file.
Afterwards, a seek to the beginning of the file is performed to update
further values. This of course means that the second seek in
mkv_write_seekhead() was unnecessary.

This has been changed: A new parameter was added to mkv_write_seekhead()
containing the destination for the second seek, effectively eliminating
the seek to the end of the file after writing the SeekHead.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c7948fb643..8040c8311c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -437,28 +437,26 @@ static void mkv_add_seekhead_entry(MatroskaMuxContext 
*mkv, uint32_t elementid,
 
 /**
  * Write the SeekHead to the file at the location reserved for it
- * and seek back to the initial position. When error_on_seek_failure
+ * and seek to destpos afterwards. When error_on_seek_failure
  * is not set, failure to seek to the position designated for the
- * SeekHead is not considered an error; failure to seek back afterwards
- * is always an error.
+ * SeekHead is not considered an error; failure to seek to destpos
+ * afterwards is always an error.
  *
  * @return 0 on success, < 0 on error.
  */
 static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv,
-  int error_on_seek_failure)
+  int error_on_seek_failure, int64_t destpos)
 {
 AVIOContext *dyn_cp;
 mkv_seekhead *seekhead = &mkv->seekhead;
 ebml_master seekentry;
-int64_t currentpos, remaining, ret64;
+int64_t remaining, ret64;
 int i, ret;
 
-currentpos = avio_tell(pb);
-
 if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0) {
 if (error_on_seek_failure)
 return ret64;
-goto seek_back;
+goto seek;
 }
 
 ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
@@ -482,8 +480,8 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
 
-seek_back:
-if ((ret64 = avio_seek(pb, currentpos, SEEK_SET)) < 0)
+seek:
+if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0)
 return ret64;
 
 return 0;
@@ -1929,7 +1927,7 @@ static int mkv_write_header(AVFormatContext *s)
 return ret;
 
 if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
-ret = mkv_write_seekhead(pb, mkv, 0);
+ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb));
 if (ret < 0)
 return ret;
 }
@@ -2533,16 +2531,16 @@ static int mkv_write_trailer(AVFormatContext *s)
 mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos);
 }
 
-ret = mkv_write_seekhead(pb, mkv, 1);
+currentpos = avio_tell(pb);
+
+ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos);
 if (ret < 0)
 return ret;
 
 // update the duration
 av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
-currentpos = avio_tell(pb);
 avio_seek(mkv->info_bc, mkv->duration_offset, SEEK_SET);
 put_ebml_float(mkv->info_bc, MATROSKA_ID_DURATION, mkv->duration);
-avio_seek(pb, mkv->info_pos, SEEK_SET);
 end_ebml_master_crc32(pb, &mkv->info_bc, mkv);
 
 // write tracks master
-- 
2.20.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 02/20] avformat/matroskaenc: Improve writing Projection

2019-12-31 Thread Carl Eugen Hoyos
Am Mi., 1. Jan. 2020 um 01:59 Uhr schrieb Andreas Rheinhardt
:
>
> The Matroska Projection master element has such a small maximum length
> that it can always be written with a length field of length one.
> So it is unnecessary to first write the element into a dynamic buffer to
> get the accurate length in order not to waste bytes on the length field.

"Improve" or "Simplify"?
___
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 05/20] avformat/matroskaenc: Check return value of ff_isom_write_hvcc()

2019-12-31 Thread myp...@gmail.com
On Wed, Jan 1, 2020 at 8:59 AM Andreas Rheinhardt
 wrote:
>
> The Matroska muxer currently does not check the return value of
> ff_isom_write_hvcc(), the function used to write mp4-style
> HEVC-extradata as Matroska also uses it. This was intentionally done in
> 7a5356c72 to allow remuxing from mpeg-ts.
>
> But if ff_isom_write_hvcc() fails, it has not output anything and the
> file ends up without CodecPrivate and, if the input was Annex B, with
> Annex B data, which is against the spec. So check the return value
> again.
>
> The underlying issue of not having extradata seems to have been fixed by
> the introduction of the extract_extradata bitstream filter.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskaenc.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 76c38b8d09..8cea829b31 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -748,9 +748,8 @@ static int mkv_write_native_codecprivate(AVFormatContext 
> *s, AVIOContext *pb,
>  return ff_isom_write_avcc(dyn_cp, par->extradata,
>par->extradata_size);
>  case AV_CODEC_ID_HEVC:
> -ff_isom_write_hvcc(dyn_cp, par->extradata,
> -   par->extradata_size, 0);
> -return 0;
> +return ff_isom_write_hvcc(dyn_cp, par->extradata,
> +  par->extradata_size, 0);
>  case AV_CODEC_ID_AV1:
>  if (par->extradata_size)
>  return ff_isom_write_av1c(dyn_cp, par->extradata,
> --
> 2.20.1
LGTM
___
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 V1 01/12] lavc/bsf: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/bsf.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index c1653cd..8e1af60 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -517,8 +517,8 @@ static int bsf_parse_single(const char *str, AVBSFList 
*bsf_lst)
 
 ret = av_bsf_list_append2(bsf_lst, bsf_name, &bsf_options);
 
-av_dict_free(&bsf_options);
 end:
+av_dict_free(&bsf_options);
 av_free(buf);
 return ret;
 }
-- 
1.7.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 V1 06/12] lavc/libx265: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libx265.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 963c28f..3836049 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -262,8 +262,8 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 break;
 }
 }
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 if (ctx->params->rc.vbvBufferSize && avctx->rc_initial_buffer_occupancy > 
1000 &&
-- 
1.7.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 V1 09/12] lavf/dashenc: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavformat/dashenc.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 8c28fb6..c37678d 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1305,8 +1305,10 @@ static int dash_init(AVFormatContext *s)
 
 if (c->format_options_str) {
 ret = av_dict_parse_string(&opts, c->format_options_str, "=", ":", 
0);
-if (ret < 0)
+if (ret < 0) {
+av_dict_free(&opts);
 return ret;
+}
 }
 
 if (os->segment_type == SEGMENT_TYPE_MP4) {
-- 
1.7.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 V1 02/12] lavc/libkvazaar: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index a89ca7f..02bcae3 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
entry->key, entry->value);
 }
 }
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 ctx->encoder = enc = api->encoder_open(cfg);
-- 
1.7.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 V1 04/12] lavc/libvpxenc: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libvpxenc.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 721a052..e9b3793 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -768,9 +768,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
"Error parsing option '%s = %s'.\n",
en->key, en->value);
 }
-
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 dump_enc_cfg(avctx, &enccfg);
-- 
1.7.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 V1 05/12] lavc/libx264: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libx264.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index bfd91bb..b982ba7 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -903,9 +903,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
"Error parsing option '%s = %s'.\n",
 en->key, en->value);
 }
-
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 // update AVCodecContext with x264 parameters
-- 
1.7.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 V1 03/12] lavc/librav1e: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/librav1e.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index a5aedd5..13ebe53 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -254,8 +254,8 @@ static av_cold int librav1e_encode_init(AVCodecContext 
*avctx)
 if (parse_ret < 0)
 av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: 
%s.\n", en->key, en->value);
 }
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 rret = rav1e_config_parse_int(cfg, "width", avctx->width);
-- 
1.7.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 V1 08/12] lavfi/coreimage: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_coreimage.m |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libavfilter/vf_coreimage.m b/libavfilter/vf_coreimage.m
index 323a28c..4ed5ba7 100644
--- a/libavfilter/vf_coreimage.m
+++ b/libavfilter/vf_coreimage.m
@@ -486,6 +486,7 @@ static av_cold int init(AVFilterContext *fctx)
 av_log(ctx, AV_LOG_DEBUG, "Filter_string: %s\n", ctx->filter_string);
 ret = av_dict_parse_string(&filter_dict, ctx->filter_string, "@", "#", 
AV_DICT_MULTIKEY); // parse filter_name:all_filter_options
 if (ret) {
+av_dict_free(&filter_dict);
 av_log(ctx, AV_LOG_ERROR, "Parsing of filters failed.\n");
 return AVERROR(EIO);
 }
@@ -507,6 +508,7 @@ static av_cold int init(AVFilterContext *fctx)
 if (strncmp(f->value, "default", 7)) { // not default
 ret = av_dict_parse_string(&filter_options, f->value, "=", 
"@", 0); // parse option_name:option_value
 if (ret) {
+av_dict_free(&filter_options);
 av_log(ctx, AV_LOG_ERROR, "Parsing of filter options for 
\"%s\" failed.\n", f->key);
 return AVERROR(EIO);
 }
-- 
1.7.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 V1 10/12] lavf/hlsenc: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavformat/hlsenc.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 6551e1c..df19545 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -856,6 +856,7 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
*vs)
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
+av_dict_free(&hls->format_options);
 av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n",
hls->format_options_str);
 return ret;
@@ -2781,6 +2782,7 @@ static int hls_init(AVFormatContext *s)
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
+av_dict_free(&hls->format_options);
 av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n", hls->format_options_str);
 goto fail;
 }
-- 
1.7.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 V1 11/12] libavutil/opt: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavutil/opt.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 60161d4..a482feb 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -452,8 +452,10 @@ static int set_string_dict(void *obj, const AVOption *o, 
const char *val, uint8_
 
 if (val) {
 int ret = av_dict_parse_string(&options, val, "=", ":", 0);
-if (ret < 0)
+if (ret < 0) {
+av_dict_free(&options);
 return ret;
+}
 }
 
 av_dict_free((AVDictionary **)dst);
@@ -2006,8 +2008,10 @@ int av_opt_is_set_to_default(void *obj, const AVOption 
*o)
 AVDictionaryEntry *en1 = NULL;
 AVDictionaryEntry *en2 = NULL;
 ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
-if (ret < 0)
+if (ret < 0) {
+av_dict_free(&dict1);
 return ret;
+}
 do {
 en1 = av_dict_get(dict1, "", en1, AV_DICT_IGNORE_SUFFIX);
 en2 = av_dict_get(dict2, "", en2, AV_DICT_IGNORE_SUFFIX);
-- 
1.7.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 V1 12/12] tools/aviocat: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 tools/aviocat.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/tools/aviocat.c b/tools/aviocat.c
index 816ab70..0fdf39b 100644
--- a/tools/aviocat.c
+++ b/tools/aviocat.c
@@ -53,6 +53,7 @@ int main(int argc, char **argv)
 i++;
 } else if (!strcmp(argv[i], "-oi") && i + 1 < argc) {
 if (av_dict_parse_string(&in_opts, argv[i + 1], "=", ":", 0) < 0) {
+av_dict_free(&in_opts);
 fprintf(stderr, "Cannot parse option string %s\n",
 argv[i + 1]);
 return usage(argv[0], 1);
@@ -60,6 +61,7 @@ int main(int argc, char **argv)
 i++;
 } else if (!strcmp(argv[i], "-oo") && i + 1 < argc) {
 if (av_dict_parse_string(&out_opts, argv[i + 1], "=", ":", 0) < 0) 
{
+av_dict_free(&out_opts);
 fprintf(stderr, "Cannot parse option string %s\n",
 argv[i + 1]);
 return usage(argv[0], 1);
-- 
1.7.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 V1] lavfi/buffersrc: Remove redundancy free after ff_filter_frame fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

ff_filter_frame always free the frame in case of error, so we don't
need to free the frame after ff_filter_frame fail.

Signed-off-by: Jun Zhao 
---
 libavfilter/buffersrc.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index 64940d9..bf30f54 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -240,10 +240,8 @@ static int av_buffersrc_add_frame_internal(AVFilterContext 
*ctx,
 }
 
 ret = ff_filter_frame(ctx->outputs[0], copy);
-if (ret < 0) {
-av_frame_free(©);
+if (ret < 0)
 return ret;
-}
 
 if ((flags & AV_BUFFERSRC_FLAG_PUSH)) {
 ret = push_frame(ctx->graph);
-- 
1.7.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 V1 07/12] lavc/libxavs2: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread Jun Zhao
From: Jun Zhao 

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao 
---
 libavcodec/libxavs2.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
index 2f8460a..91afeeb 100644
--- a/libavcodec/libxavs2.c
+++ b/libavcodec/libxavs2.c
@@ -100,8 +100,8 @@ static av_cold int xavs2_init(AVCodecContext *avctx)
 while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
 xavs2_opt_set2(en->key, "%s", en->value);
 }
-av_dict_free(&dict);
 }
+av_dict_free(&dict);
 }
 
 /* Rate control */
-- 
1.7.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 V1 02/12] lavc/libkvazaar: fix memory leak after av_dict_parse_string fail

2019-12-31 Thread James Almer
On 1/1/2020 2:20 AM, Jun Zhao wrote:
> From: Jun Zhao 
> 
> In case of failure, all the successfully set entries are stored in
> *pm. We need to manually free the created dictionary to avoid
> memory leak.
> 
> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/libkvazaar.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> index a89ca7f..02bcae3 100644
> --- a/libavcodec/libkvazaar.c
> +++ b/libavcodec/libkvazaar.c
> @@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
> entry->key, entry->value);
>  }
>  }
> -av_dict_free(&dict);
>  }
> +av_dict_free(&dict);
>  }
>  
>  ctx->encoder = enc = api->encoder_open(cfg);

There's a patchset by Marton Balint changing this code in all the same
modules as in this patchset, by replacing it all with a simple
av_dict_copy() call.

http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
and every following patch.
___
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 V1] libavcodec/aacdec: fix HE-AAC decoder dirty date (for sbr) when flush

2019-12-31 Thread Jun Zhao
From: qoroliang 

aac decoder only do the window overlapping data buffer flush but
without sbr related buffer flush, that will cause dirty data in
the first output frame after flush.

Signed-off-by: qoroliang 
---
 libavcodec/aacdec_template.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index bb11de3..8f8dc24 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -507,7 +507,13 @@ static void flush(AVCodecContext *avctx)
 ChannelElement *che = ac->che[type][i];
 if (che) {
 for (j = 0; j <= 1; j++) {
+// LTP buffer related data buffer
+// or windowing overlapping
 memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved));
+memset(che->ch[j].coeffs, 0, sizeof(che->ch[j].coeffs));
+// sbr context should be reseted and function pointers 
should be applied too
+memset(&che->sbr, 0, sizeof(che->sbr));
+AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &che->sbr, type);
 }
 }
 }
-- 
1.7.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 02/20] avformat/matroskaenc: Improve writing Projection

2019-12-31 Thread Andreas Rheinhardt
On Wed, Jan 1, 2020 at 4:53 AM Carl Eugen Hoyos  wrote:

> Am Mi., 1. Jan. 2020 um 01:59 Uhr schrieb Andreas Rheinhardt
> :
> >
> > The Matroska Projection master element has such a small maximum length
> > that it can always be written with a length field of length one.
> > So it is unnecessary to first write the element into a dynamic buffer to
> > get the accurate length in order not to waste bytes on the length field.
>
> "Improve" or "Simplify"?
>
>
Both are applicable.

- Andreas
___
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 5/7] avformat/matroskadec: Use AV_DICT_DONT_STRDUP_VAL to save av_strdup

2019-12-31 Thread Andreas Rheinhardt
On Sun, Nov 10, 2019 at 5:07 AM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> This will likely also fix CID 1452562, a false positive resulting from
> Coverity thinking that av_dict_set() automatically frees its key and
> value parameters (even without the AV_DICT_DONT_STRDUP_* flags).
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index c224c3447a..56863eb08e 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2413,8 +2413,8 @@ static int matroska_parse_tracks(AVFormatContext *s)
>
>  if (key_id_base64) {
>  /* export encryption key id as base64 metadata tag */
> -av_dict_set(&st->metadata, "enc_key_id", key_id_base64, 0);
> -av_freep(&key_id_base64);
> +av_dict_set(&st->metadata, "enc_key_id", key_id_base64,
> +AV_DICT_DONT_STRDUP_VAL);
>  }
>
>  if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") &&
> @@ -4142,8 +4142,8 @@ static int webm_dash_manifest_cues(AVFormatContext
> *s, int64_t init_range)
>  }
>  end += ret;
>  }
> -av_dict_set(&s->streams[0]->metadata, CUE_TIMESTAMPS, buf, 0);
> -av_free(buf);
> +av_dict_set(&s->streams[0]->metadata, CUE_TIMESTAMPS,
> +buf, AV_DICT_DONT_STRDUP_VAL);
>
>  return 0;
>  }
> @@ -4168,8 +4168,8 @@ static int
> webm_dash_manifest_read_header(AVFormatContext *s)
>  if (!matroska->is_live) {
>  buf = av_asprintf("%g", matroska->duration);
>  if (!buf) return AVERROR(ENOMEM);
> -av_dict_set(&s->streams[0]->metadata, DURATION, buf, 0);
> -av_free(buf);
> +av_dict_set(&s->streams[0]->metadata, DURATION,
> +buf, AV_DICT_DONT_STRDUP_VAL);
>
>  // initialization range
>  // 5 is the offset of Cluster ID.
> --
> 2.20.1
>
>
Ping.

- Andreas
___
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] configure: bump year

2019-12-31 Thread Gyan Doshi
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 43dc409fe6..965b4c71b8 100755
--- a/configure
+++ b/configure
@@ -7456,7 +7456,7 @@ cat > $TMPH 

Re: [FFmpeg-devel] [PATCH] configure: bump year

2019-12-31 Thread myp...@gmail.com
On Wed, Jan 1, 2020 at 2:46 PM Gyan Doshi  wrote:
>
> ---
>  configure | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 43dc409fe6..965b4c71b8 100755
> --- a/configure
> +++ b/configure
> @@ -7456,7 +7456,7 @@ cat > $TMPH <  #define FFMPEG_CONFIG_H
>  #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
>  #define FFMPEG_LICENSE "$(c_escape $license)"
> -#define CONFIG_THIS_YEAR 2019
> +#define CONFIG_THIS_YEAR 2020
>  #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
>  #define AVCONV_DATADIR "$(eval c_escape $datadir)"
>  #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
> --
> 2.24.1
>
Ha, new year, LGTM
___
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".