Re: [FFmpeg-devel] [PATCH v4 8/9] avcodec/cbs_h2645: vvc, do not skip nals for nuh_layer_id > 0

2021-02-05 Thread Andriy Gelman
On Sat, 06. Feb 11:30, Nuo Mi wrote:
> On Mon, Jan 25, 2021 at 10:21 PM Nuo Mi  wrote:
> 
> >
> > On Mon, Jan 25, 2021 at 10:17 PM Nuo Mi  wrote:
> >
> >> ---
> >>  libavcodec/cbs_h2645.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> >> index 6f3abf6b0b..da541407cf 100644
> >> --- a/libavcodec/cbs_h2645.c
> >> +++ b/libavcodec/cbs_h2645.c
> >> @@ -494,8 +494,9 @@ static int
> >> cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
> >>  const H2645NAL *nal = >nals[i];
> >>  AVBufferRef *ref;
> >>  size_t size = nal->size;
> >> +enum AVCodecID codec_id = ctx->codec->codec_id;
> >>
> >> -if (nal->nuh_layer_id > 0)
> >> +if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0)
> >>
> > Hi Mark,
> > Could you explain why we need this for other codecs?
> > thanks
> >
> 
> Hi Mark,
> Any insight on this?

If I remember correctly some of the parameter sets are parsed differently for
nuh_layer_id > 0 layers, which was not supported by cbs.

Just tried it again on a multi-layers stream and cbs errors out. I can forward
you the file if you want.

[trace_headers @ 0x56094c620440] Sequence Parameter Set
[trace_headers @ 0x57c34440] 0   forbidden_zero_bit 
 0 = 0
[trace_headers @ 0x57c34440] 1   nal_unit_type  
11 = 33
[trace_headers @ 0x57c34440] 7   nuh_layer_id   
01 = 1
[trace_headers @ 0x57c34440] 13  nuh_temporal_id_plus1  
   001 = 1
[trace_headers @ 0x57c34440] 16  sps_video_parameter_set_id 
   = 0
[trace_headers @ 0x57c34440] 20  sps_max_sub_layers_minus1  
   111 = 7
[trace_headers @ 0x57c34440] sps_max_sub_layers_minus1 out of range: 7, but 
must be in [0,6].
[trace_headers @ 0x57c34440] Failed to read unit 2 (type 33).
Error initializing bitstream filter: trace_headers
Error initializing output stream 0:0 -- 

-- 
Andriy
___
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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-05 Thread Nuo Mi
On Fri, Feb 5, 2021 at 12:57 AM Derek Buitenhuis 
wrote:

> GIF palette entries are not compressed, and writing 256 entries,
> which can be up to every frame, uses a significant amount of
> space, especially in extreme cases, where palettes can be very
> small.
>
> Example, first six seconds of Tears of Steel, palette generated
> with libimagequant, 320x240 resolution, and with transparency
> optimization + per frame palette:
>
> * Before patch: 186765 bytes
> * After patch: 77901 bytes
>
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavcodec/gif.c | 81 +---
>  1 file changed, 69 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/gif.c b/libavcodec/gif.c
> index de41992851..c52db57edd 100644
> --- a/libavcodec/gif.c
> +++ b/libavcodec/gif.c
> @@ -52,6 +52,7 @@ typedef struct GIFContext {
>  int flags;
>  int image;
>  uint32_t palette[AVPALETTE_COUNT];  ///< local reference palette for
> !pal8
> +size_t palette_count;
>  int palette_loaded;
>  int transparent_index;
>  uint8_t *tmpl;  ///< temporary line buffer
> @@ -62,6 +63,27 @@ enum {
>  GF_TRANSDIFF  = 1<<1,
>  };
>
> +static void shrink_palette(const uint32_t *src, uint32_t *dst, size_t
> *palette_count)
> +{
> +size_t colors_seen = 0;
> +
> +for (size_t i = 0; i < AVPALETTE_COUNT; i++) {
> +int seen = 0;
> +for (size_t c = 0; c < colors_seen; c++) {
> +if (src[i] == dst[c]) {
> +seen = 1;
> +break;
> +}
> +}
> +if (!seen) {
> +dst[colors_seen] = src[i];
> +colors_seen++;
> +}
> +}
> +
> +*palette_count = colors_seen;
> +}
> +
>  static int is_image_translucent(AVCodecContext *avctx,
>  const uint8_t *buf, const int linesize)
>  {
> @@ -83,7 +105,7 @@ static int is_image_translucent(AVCodecContext *avctx,
>  return 0;
>  }
>
> -static int get_palette_transparency_index(const uint32_t *palette)
> +static int get_palette_transparency_index(const uint32_t *palette, int
> palette_count)
>  {
>  int transparent_color_index = -1;
>  unsigned i, smallest_alpha = 0xff;
> @@ -91,7 +113,7 @@ static int get_palette_transparency_index(const
> uint32_t *palette)
>  if (!palette)
>  return -1;
>
> -for (i = 0; i < AVPALETTE_COUNT; i++) {
> +for (i = 0; i < palette_count; i++) {
>  const uint32_t v = palette[i];
>  if (v >> 24 < smallest_alpha) {
>  smallest_alpha = v >> 24;
> @@ -266,6 +288,10 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  int x_start = 0, y_start = 0, trans = s->transparent_index;
>  int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) &&
> s->last_frame && !palette;
>  const uint8_t *ptr;
> +uint32_t shrunk_palette[AVPALETTE_COUNT] = { 0 };
> +size_t shrunk_palette_count;
> +
> +memset(shrunk_palette, 0xff, AVPALETTE_SIZE);

This will memset each frame. Could we avoid it?
Is memset memory between [global_palette_count, 1<<(
av_log2(global_palette_count - 1) + 1)]  enough?




>  if (!s->image && is_image_translucent(avctx, buf, linesize)) {
>  gif_crop_translucent(avctx, buf, linesize, , ,
> _start, _start);
> @@ -277,10 +303,21 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  }
>
>  if (s->image || !avctx->frame_number) { /* GIF header */
> -const uint32_t *global_palette = palette ? palette : s->palette;
> +uint32_t *global_palette;
> +uint32_t shrunk_global_palette[AVPALETTE_COUNT];
> +size_t global_palette_count;
> +unsigned pow2_global_palette_count;
>  const AVRational sar = avctx->sample_aspect_ratio;
>  int64_t aspect = 0;
>
> +if (palette) {
> +shrink_palette(palette, shrunk_global_palette,
> _palette_count);
> +global_palette = shrunk_global_palette;
> +} else {
> +global_palette = s->palette;
> +global_palette_count = s->palette_count;
> +}
> +
>  if (sar.num > 0 && sar.den > 0) {
>  aspect = sar.num * 64LL / sar.den - 15;
>  if (aspect < 0 || aspect > 255)
> @@ -291,17 +328,22 @@ static int gif_image_write_image(AVCodecContext
> *avctx,
>  bytestream_put_le16(bytestream, avctx->width);
>  bytestream_put_le16(bytestream, avctx->height);
>
> -bcid = get_palette_transparency_index(global_palette);
> +bcid = get_palette_transparency_index(global_palette,
> global_palette_count);
>
> -bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256
> entries */
> +pow2_global_palette_count = av_log2(global_palette_count - 1);
> +
> +bytestream_put_byte(bytestream, 0xf0 |
> pow2_global_palette_count); /* flags: global clut, 256 entries */
>
The comment may be misleading, it's not 256 anymore.

>  

Re: [FFmpeg-devel] [PATCH v4 7/9] avformat: add h266/vvc muxer

2021-02-05 Thread Nuo Mi
On Wed, Feb 3, 2021 at 9:57 PM James Almer  wrote:

> On 2/3/2021 10:45 AM, Moritz Barsnick wrote:
> > On Mon, Jan 25, 2021 at 22:15:05 +0800, Nuo Mi wrote:
> >> +.extensions= "hevc,h266,266",
> >
> > Is ".hevc" a valid extension for H.266/VVC?
>
> Most assuredly not, and just a copy paste error.
>
Yes, It's a typo. Thanks for the correction.
Fixed.

>
> >
> > 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 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 v4 8/9] avcodec/cbs_h2645: vvc, do not skip nals for nuh_layer_id > 0

2021-02-05 Thread Nuo Mi
On Mon, Jan 25, 2021 at 10:21 PM Nuo Mi  wrote:

>
> On Mon, Jan 25, 2021 at 10:17 PM Nuo Mi  wrote:
>
>> ---
>>  libavcodec/cbs_h2645.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 6f3abf6b0b..da541407cf 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -494,8 +494,9 @@ static int
>> cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
>>  const H2645NAL *nal = >nals[i];
>>  AVBufferRef *ref;
>>  size_t size = nal->size;
>> +enum AVCodecID codec_id = ctx->codec->codec_id;
>>
>> -if (nal->nuh_layer_id > 0)
>> +if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0)
>>
> Hi Mark,
> Could you explain why we need this for other codecs?
> thanks
>

Hi Mark,
Any insight on this?
 Thanks

 continue;
>>
>>  // Remove trailing zeroes.
>> --
>> 2.25.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] cbs_h2645: Implement replace-PS with a table rather than many functions

2021-02-05 Thread Nuo Mi
On Wed, Feb 3, 2021 at 5:07 AM Mark Thompson  wrote:

> On 30/01/2021 11:01, Nuo Mi wrote:
> > On Wed, Jan 27, 2021 at 9:52 PM Nuo Mi  wrote:
> >> On Wed, Jan 27, 2021 at 7:06 AM Mark Thompson  wrote:
> >>>
> >>> +
> >>> +err = ff_cbs_make_unit_refcounted(ctx, unit);
> >>> +if (err < 0)
> >>> +return err;
> >>> +
> >>> +ref_array =
> >>> + (AVBufferRef**)((uint8_t*)ctx->priv_data +
> >>> ps_type->ref_array_offset);
> >>> +ptr_array = (void**)((uint8_t*)ctx->priv_data +
> >>> ps_type->ptr_array_offset);
> >>> +active= (void**)((uint8_t*)ctx->priv_data +
> >>> ps_type->active_offset);
> >>> +
> >>> +if (ptr_array[id] == *active) {
> >>> +// The old active parameter set is being overwritten, so it
> can't
> >>> +// be active after this point.
> >>> +*active = NULL;
> >>> +}
> >>> +av_buffer_unref(_array[id]);
> >>> +
> >>> +ref_array[id] = av_buffer_ref(unit->content_ref);
> >>> +if (!ref_array[id])
> >>> +return AVERROR(ENOMEM);
> >>>
> >> This happend after ff_cbs_make_unit_refcounted, do we need urnef
> unit->content_ref
> >> before return?
>
> I don't think so?  The content_ref will be freed by the next call to
> fragment_reset/fragment_free, and we don't want to unset it here because
> that would force us to also clear unit->content as well (which doesn't
> matter for reading, but is a very strange side-effect if you are writing).
>
> >>> +ptr_array[id] = ref_array[id]->data;
> >>> +
> >>> +return 0;
> >>> +}
> >>>
> >>> > Hi Mark,
> > Will this fix and merged?
>
> Do you prefer it to what is presently there?
>
> My intent was to suggest it and ask the question given the trouble with
> many versions of this in H.266, not to prescribe a particular answer.

Thanks for the suggestion, I will include the patch and send the new
searials.

>




> - Mark
> ___
> 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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-05 Thread Jean First

Derek Buitenhuis wrote on 04.02.21 19:42:

On 04/02/2021 17:26, Paul B Mahol wrote:

How would that work?
I'm not against if that does not break existing usage.

Somethng like '-no_global_paltte 1' to not use a global
palette, and write a palette each frame. Default would be
off, so curent behavior is maintained.


Please do not negate options. So instead of  '-no_global_palette' just 
use '-global_palette'.

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

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

[FFmpeg-devel] [PATCH] avcodec: add cri parser

2021-02-05 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/Makefile |   1 +
 libavcodec/cri_parser.c | 105 
 libavcodec/parsers.c|   1 +
 3 files changed, 107 insertions(+)
 create mode 100644 libavcodec/cri_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b06b028ae4..116021c0f5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1084,6 +1084,7 @@ OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
 OBJS-$(CONFIG_BMP_PARSER)  += bmp_parser.o
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)+= cavs_parser.o
 OBJS-$(CONFIG_COOK_PARSER) += cook_parser.o
+OBJS-$(CONFIG_CRI_PARSER)  += cri_parser.o
 OBJS-$(CONFIG_DCA_PARSER)  += dca_parser.o dca_exss.o dca.o
 OBJS-$(CONFIG_DIRAC_PARSER)+= dirac_parser.o
 OBJS-$(CONFIG_DNXHD_PARSER)+= dnxhd_parser.o dnxhddata.o
diff --git a/libavcodec/cri_parser.c b/libavcodec/cri_parser.c
new file mode 100644
index 00..9790747a9e
--- /dev/null
+++ b/libavcodec/cri_parser.c
@@ -0,0 +1,105 @@
+/*
+ * CRI parser
+ * Copyright (c) 2021 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
+ */
+
+/**
+ * @file
+ * CRI parser
+ */
+
+#include "libavutil/bswap.h"
+#include "libavutil/common.h"
+
+#include "parser.h"
+
+typedef struct CRIParser {
+ParseContext pc;
+int count;
+int chunk;
+int read_bytes;
+int skip_bytes;
+} CRIParser;
+
+#define KEY (((uint64_t)'\1' << 56) | ((uint64_t)'\0' << 48) | \
+ ((uint64_t)'\0' << 40) | ((uint64_t)'\0' << 32) | \
+ ((uint64_t)'\4' << 24) | ((uint64_t)'\0' << 16) | \
+ ((uint64_t)'\0' <<  8) | ((uint64_t)'\0' <<  0))
+
+static int cri_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+CRIParser *bpc = s->priv_data;
+uint64_t state = bpc->pc.state64;
+int next = END_NOT_FOUND, i = 0;
+
+s->pict_type = AV_PICTURE_TYPE_I;
+s->key_frame = 1;
+s->duration  = 1;
+
+*poutbuf_size = 0;
+*poutbuf = NULL;
+
+for (; i < buf_size; i++) {
+state = (state << 8) | buf[i];
+bpc->read_bytes++;
+
+if (bpc->skip_bytes > 0) {
+bpc->skip_bytes--;
+if (bpc->skip_bytes == 0)
+bpc->read_bytes = 0;
+} else {
+if (state != KEY)
+continue;
+}
+
+if (bpc->skip_bytes == 0 && bpc->read_bytes >= 8) {
+bpc->skip_bytes = av_bswap32(state & 0x);
+bpc->chunk = state >> 32;
+bpc->read_bytes = 0;
+bpc->count++;
+}
+
+if (bpc->chunk == 0x0100 && bpc->skip_bytes == 4 &&
+bpc->read_bytes == 0 && bpc->count > 1) {
+next = i - 7;
+break;
+}
+}
+
+bpc->pc.state64 = state;
+if (ff_combine_frame(>pc, next, , _size) < 0) {
+*poutbuf = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}
+
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+
+return next;
+}
+
+AVCodecParser ff_cri_parser = {
+.codec_ids  = { AV_CODEC_ID_CRI },
+.priv_data_size = sizeof(CRIParser),
+.parser_parse   = cri_parse,
+.parser_close   = ff_parse_close,
+};
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index d3353a6b39..61af22b2d5 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -33,6 +33,7 @@ extern AVCodecParser ff_avs3_parser;
 extern AVCodecParser ff_bmp_parser;
 extern AVCodecParser ff_cavsvideo_parser;
 extern AVCodecParser ff_cook_parser;
+extern AVCodecParser ff_cri_parser;
 extern AVCodecParser ff_dca_parser;
 extern AVCodecParser ff_dirac_parser;
 extern AVCodecParser ff_dnxhd_parser;
-- 
2.17.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] [FFmpeg-cvslog] avcodec: add xbm parser

2021-02-05 Thread James Almer

ffmpeg | branch: master | Paul B Mahol https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog>> | Wed Feb  3 11:58:47 2021 
+0100| [7dfa98665c172a15f2dc6a9424331737360e5138] | committer: Paul B Mahol

avcodec: add xbm parser

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


  Changelog   |   1 +
  libavcodec/Makefile |   1 +
  libavcodec/parsers.c|   1 +
  libavcodec/version.h|   2 +-
  libavcodec/xbm_parser.c | 101 
  5 files changed, 105 insertions(+), 1 deletion(-)

This works with lbw.xbm, but xl.xbm gives the following:

$ cat ../samples/xbm/xl.xbm | ./ffmpeg -i -
[...]
pipe:: Invalid data found when processing input

___
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] avcodec: add photocd parser

2021-02-05 Thread James Almer

On 2/5/2021 3:51 PM, Paul B Mahol wrote:

Signed-off-by: Paul B Mahol 
---
  libavcodec/Makefile |  1 +
  libavcodec/parsers.c|  1 +
  libavcodec/photocd_parser.c | 87 +
  3 files changed, 89 insertions(+)
  create mode 100644 libavcodec/photocd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2ddf021f04..b06b028ae4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1114,6 +1114,7 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER)+= 
mpegvideo_parser.o\
mpeg12.o mpeg12data.o
  OBJS-$(CONFIG_OPUS_PARSER) += opus_parser.o opus.o opustab.o \
opus_rc.o vorbis_data.o
+OBJS-$(CONFIG_PHOTOCD_PARSER)  += photocd_parser.o
  OBJS-$(CONFIG_PNG_PARSER)  += png_parser.o
  OBJS-$(CONFIG_PNM_PARSER)  += pnm_parser.o pnm.o
  OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 93af25ac14..d3353a6b39 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -59,6 +59,7 @@ extern AVCodecParser ff_mpeg4video_parser;
  extern AVCodecParser ff_mpegaudio_parser;
  extern AVCodecParser ff_mpegvideo_parser;
  extern AVCodecParser ff_opus_parser;
+extern AVCodecParser ff_photocd_parser;
  extern AVCodecParser ff_png_parser;
  extern AVCodecParser ff_pnm_parser;
  extern AVCodecParser ff_rv30_parser;
diff --git a/libavcodec/photocd_parser.c b/libavcodec/photocd_parser.c
new file mode 100644
index 00..844327f799
--- /dev/null
+++ b/libavcodec/photocd_parser.c
@@ -0,0 +1,87 @@
+/*
+ * PhotoCD parser
+ * Copyright (c) 2021 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
+ */
+
+/**
+ * @file
+ * PhotoCD parser
+ */
+
+#include "libavutil/common.h"
+
+#include "parser.h"
+
+typedef struct PhotoCDParser {
+ParseContext pc;
+int count;
+} PhotoCDParser;
+
+#define KEY (((uint64_t)'P' << 56) | ((uint64_t)'C' << 48) | \
+ ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \
+ ((uint64_t)'I' << 24) | ((uint64_t)'P' << 16) | \
+ ((uint64_t)'I' <<  8) | ((uint64_t)'\0'<<  0))


You could do something like state == MKBETAG('P', 'C', 'D', '_') and 
(state >> 32) == MKBETAG('I', 'P', 'I', '\0') instead.



+
+static int photocd_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+PhotoCDParser *bpc = s->priv_data;
+uint64_t state = bpc->pc.state64;
+int next = END_NOT_FOUND, i = 0;
+
+s->pict_type = AV_PICTURE_TYPE_I;
+s->key_frame = 1;
+s->duration  = 1;
+
+*poutbuf_size = 0;
+*poutbuf = NULL;
+
+for (; i < buf_size; i++) {


for (int i = 0...


+state = (state << 8) | buf[i];
+
+if (state == KEY)
+bpc->count++;
+
+if (state == KEY && bpc->count >= 2) {
+next = i - (7+2048);
+bpc->count = 0;
+break;
+}
+}


https://0x0.st/-HiX.pcd (Crafted file).

I can reproduce an infinite loop by doing "cat INPUT | ./ffmpeg -i -" 
with the above sample after this patch.



+
+bpc->pc.state64 = state;
+if (ff_combine_frame(>pc, next, , _size) < 0) {
+*poutbuf = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}
+
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+
+return next;
+}
+
+AVCodecParser ff_photocd_parser = {
+.codec_ids  = { AV_CODEC_ID_PHOTOCD },
+.priv_data_size = sizeof(PhotoCDParser),
+.parser_parse   = photocd_parse,
+.parser_close   = ff_parse_close,
+};



___
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 3/3] avformat/mov: simplify size code in probing a bit

2021-02-05 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/mov.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 70f76caff5..8504e97831 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7127,10 +7127,7 @@ static int mov_probe(const AVProbeData *p)
 case MKTAG('p','n','o','t'): /* detect movs with preview pics like 
ew.mov and april.mov */
 case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a 
lot of more junk */
 case MKTAG('f','t','y','p'):
-if (size < 8 &&
-(size != 1 ||
- offset + 12 > (unsigned int)p->buf_size ||
- AV_RB64(p->buf+offset + 8) == 0)) {
+if (size < 8) {
 score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
 } else if (tag == MKTAG('f','t','y','p') &&
(   AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' 
')
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 1/3] avformat/mov: factor size out of probe code

2021-02-05 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/mov.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 8eacf2cc04..9406e42f49 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7108,9 +7108,11 @@ static int mov_probe(const AVProbeData *p)
 /* check file header */
 offset = 0;
 for (;;) {
+int64_t size;
 /* ignore invalid offset */
 if ((offset + 8) > (unsigned int)p->buf_size)
 break;
+size = AV_RB32(p->buf + offset);
 tag = AV_RL32(p->buf + offset + 4);
 switch(tag) {
 /* check for obvious tags */
@@ -7120,8 +7122,8 @@ static int mov_probe(const AVProbeData *p)
 case MKTAG('p','n','o','t'): /* detect movs with preview pics like 
ew.mov and april.mov */
 case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a 
lot of more junk */
 case MKTAG('f','t','y','p'):
-if (AV_RB32(p->buf+offset) < 8 &&
-(AV_RB32(p->buf+offset) != 1 ||
+if (size < 8 &&
+(size != 1 ||
  offset + 12 > (unsigned int)p->buf_size ||
  AV_RB64(p->buf+offset + 8) == 0)) {
 score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
@@ -7133,7 +7135,7 @@ static int mov_probe(const AVProbeData *p)
 } else {
 score = AVPROBE_SCORE_MAX;
 }
-offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
+offset = FFMAX(4, size) + offset;
 break;
 /* those are more common words, so rate then a bit less */
 case MKTAG('e','d','i','w'): /* xdcam files have reverted first tags */
@@ -7142,7 +7144,7 @@ static int mov_probe(const AVProbeData *p)
 case MKTAG('j','u','n','k'):
 case MKTAG('p','i','c','t'):
 score  = FFMAX(score, AVPROBE_SCORE_MAX - 5);
-offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
+offset = FFMAX(4, size) + offset;
 break;
 case MKTAG(0x82,0x82,0x7f,0x7d):
 case MKTAG('s','k','i','p'):
@@ -7150,10 +7152,10 @@ static int mov_probe(const AVProbeData *p)
 case MKTAG('p','r','f','l'):
 /* if we only find those cause probedata is too small at least 
rate them */
 score  = FFMAX(score, AVPROBE_SCORE_EXTENSION);
-offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
+offset = FFMAX(4, size) + offset;
 break;
 default:
-offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
+offset = FFMAX(4, size) + offset;
 }
 }
 if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) {
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 2/3] Support size = 1 and size = 0 special cases in probing

2021-02-05 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/mov.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9406e42f49..70f76caff5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7113,6 +7113,11 @@ static int mov_probe(const AVProbeData *p)
 if ((offset + 8) > (unsigned int)p->buf_size)
 break;
 size = AV_RB32(p->buf + offset);
+if (size == 1 && offset + 16 > (unsigned int)p->buf_size) {
+size = AV_RB64(p->buf+offset + 8);
+} else if (size == 0) {
+size = p->buf_size - offset;
+}
 tag = AV_RL32(p->buf + offset + 4);
 switch(tag) {
 /* check for obvious tags */
-- 
2.17.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] avcodec: add photocd parser

2021-02-05 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/Makefile |  1 +
 libavcodec/parsers.c|  1 +
 libavcodec/photocd_parser.c | 87 +
 3 files changed, 89 insertions(+)
 create mode 100644 libavcodec/photocd_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2ddf021f04..b06b028ae4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1114,6 +1114,7 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER)+= 
mpegvideo_parser.o\
   mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_OPUS_PARSER) += opus_parser.o opus.o opustab.o \
   opus_rc.o vorbis_data.o
+OBJS-$(CONFIG_PHOTOCD_PARSER)  += photocd_parser.o
 OBJS-$(CONFIG_PNG_PARSER)  += png_parser.o
 OBJS-$(CONFIG_PNM_PARSER)  += pnm_parser.o pnm.o
 OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 93af25ac14..d3353a6b39 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -59,6 +59,7 @@ extern AVCodecParser ff_mpeg4video_parser;
 extern AVCodecParser ff_mpegaudio_parser;
 extern AVCodecParser ff_mpegvideo_parser;
 extern AVCodecParser ff_opus_parser;
+extern AVCodecParser ff_photocd_parser;
 extern AVCodecParser ff_png_parser;
 extern AVCodecParser ff_pnm_parser;
 extern AVCodecParser ff_rv30_parser;
diff --git a/libavcodec/photocd_parser.c b/libavcodec/photocd_parser.c
new file mode 100644
index 00..844327f799
--- /dev/null
+++ b/libavcodec/photocd_parser.c
@@ -0,0 +1,87 @@
+/*
+ * PhotoCD parser
+ * Copyright (c) 2021 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
+ */
+
+/**
+ * @file
+ * PhotoCD parser
+ */
+
+#include "libavutil/common.h"
+
+#include "parser.h"
+
+typedef struct PhotoCDParser {
+ParseContext pc;
+int count;
+} PhotoCDParser;
+
+#define KEY (((uint64_t)'P' << 56) | ((uint64_t)'C' << 48) | \
+ ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \
+ ((uint64_t)'I' << 24) | ((uint64_t)'P' << 16) | \
+ ((uint64_t)'I' <<  8) | ((uint64_t)'\0'<<  0))
+
+static int photocd_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+PhotoCDParser *bpc = s->priv_data;
+uint64_t state = bpc->pc.state64;
+int next = END_NOT_FOUND, i = 0;
+
+s->pict_type = AV_PICTURE_TYPE_I;
+s->key_frame = 1;
+s->duration  = 1;
+
+*poutbuf_size = 0;
+*poutbuf = NULL;
+
+for (; i < buf_size; i++) {
+state = (state << 8) | buf[i];
+
+if (state == KEY)
+bpc->count++;
+
+if (state == KEY && bpc->count >= 2) {
+next = i - (7+2048);
+bpc->count = 0;
+break;
+}
+}
+
+bpc->pc.state64 = state;
+if (ff_combine_frame(>pc, next, , _size) < 0) {
+*poutbuf = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}
+
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+
+return next;
+}
+
+AVCodecParser ff_photocd_parser = {
+.codec_ids  = { AV_CODEC_ID_PHOTOCD },
+.priv_data_size = sizeof(PhotoCDParser),
+.parser_parse   = photocd_parse,
+.parser_close   = ff_parse_close,
+};
-- 
2.17.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 v3] ffmpeg: add -fpsmax to clamp output framerate

2021-02-05 Thread Gyan Doshi

Pushed as d99cc1782563672bcdb46fb5ec51135847db8c99

On 05-02-2021 09:39 am, Gyan Doshi wrote:

Will push in 12h if no further changes.

On 03-02-2021 07:42 pm, Gyan Doshi wrote:

Useful when encoding in batch or with aberrant inputs.
---
  doc/ffmpeg.texi  |  7 +++
  fftools/ffmpeg.c |  7 ++-
  fftools/ffmpeg.h |  3 +++
  fftools/ffmpeg_opt.c | 23 ---
  4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 8eb012b7c0..b0d1cf0710 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -759,6 +759,13 @@ If in doubt use @option{-framerate} instead of 
the input option @option{-r}.
  As an output option, duplicate or drop input frames to achieve 
constant output

  frame rate @var{fps}.
  +@item -fpsmax[:@var{stream_specifier}] @var{fps} 
(@emph{output,per-stream})

+Set maximum frame rate (Hz value, fraction or abbreviation).
+
+Clamps output frame rate when output framerate is auto-set and is 
higher than this value.
+Useful in batch processing or when input framerate is wrongly 
detected as very high.
+It cannot be set together with @code{-r}. It is ignored during 
streamcopy.

+
  @item -s[:@var{stream_specifier}] @var{size} 
(@emph{input/output,per-stream})

  Set frame size.
  diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d7c833be63..add5a3e505 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3376,7 +3376,7 @@ static int 
init_output_stream_encode(OutputStream *ost, AVFrame *frame)

  ost->frame_rate = ist->framerate;
  if (ist && !ost->frame_rate.num)
  ost->frame_rate = ist->st->r_frame_rate;
-    if (ist && !ost->frame_rate.num) {
+    if (ist && !ost->frame_rate.num && !ost->max_frame_rate.num) {
  ost->frame_rate = (AVRational){25, 1};
  av_log(NULL, AV_LOG_WARNING,
 "No information "
@@ -3386,6 +3386,11 @@ static int 
init_output_stream_encode(OutputStream *ost, AVFrame *frame)

 ost->file_index, ost->index);
  }
  +    if (ost->max_frame_rate.num &&
+    (av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
+    !ost->frame_rate.den))
+    ost->frame_rate = ost->max_frame_rate;
+
  if (ost->enc->supported_framerates && !ost->force_fps) {
  int idx = av_find_nearest_q_idx(ost->frame_rate, 
ost->enc->supported_framerates);

  ost->frame_rate = ost->enc->supported_framerates[idx];
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5aeceae6b7..423da071dc 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -108,6 +108,8 @@ typedef struct OptionsContext {
  int    nb_audio_sample_rate;
  SpecifierOpt *frame_rates;
  int    nb_frame_rates;
+    SpecifierOpt *max_frame_rates;
+    int    nb_max_frame_rates;
  SpecifierOpt *frame_sizes;
  int    nb_frame_sizes;
  SpecifierOpt *frame_pix_fmts;
@@ -479,6 +481,7 @@ typedef struct OutputStream {
    /* video only */
  AVRational frame_rate;
+    AVRational max_frame_rate;
  int is_cfr;
  int force_fps;
  int top_field_first;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index bf2eb26246..805754953e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -55,6 +55,7 @@ static const char *const 
opt_name_codec_names[]   = {"c", "codec", "

  static const char *const opt_name_audio_channels[] = {"ac", NULL};
  static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
  static const char *const opt_name_frame_rates[] = {"r", NULL};
+static const char *const opt_name_max_frame_rates[]   = 
{"fpsmax", NULL};

  static const char *const opt_name_frame_sizes[] = {"s", NULL};
  static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", 
NULL};

  static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
@@ -1688,7 +1689,7 @@ static OutputStream 
*new_video_stream(OptionsContext *o, AVFormatContext *oc, in

  AVStream *st;
  OutputStream *ost;
  AVCodecContext *video_enc;
-    char *frame_rate = NULL, *frame_aspect_ratio = NULL;
+    char *frame_rate = NULL, *max_frame_rate = NULL, 
*frame_aspect_ratio = NULL;
    ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, 
source_index);

  st  = ost->st;
@@ -1699,8 +1700,21 @@ static OutputStream 
*new_video_stream(OptionsContext *o, AVFormatContext *oc, in
  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", 
frame_rate);

  exit_program(1);
  }
-    if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
-    av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can 
produce invalid output files\n");

+
+    MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
+    if (max_frame_rate && av_parse_video_rate(>max_frame_rate, 
max_frame_rate) < 0) {
+    av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: 
%s\n", max_frame_rate);

+    

Re: [FFmpeg-devel] [PATCH] avfilter/vf_tile: remove extra whitespace in option description

2021-02-05 Thread Paul B Mahol
trivial, so will apply.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter/avfilter: move enable_str expression parsing into avfilter_init_dict()

2021-02-05 Thread Paul B Mahol
Anybody have comments? This fixes crash.
___
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 47/50 v2] doc/examples/vaapi_transcode: use av_packet_alloc() to allocate packets

2021-02-05 Thread James Almer
Signed-off-by: James Almer 
---
 doc/examples/vaapi_transcode.c | 42 ++
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c
index 279d20f636..5a1a704a8e 100644
--- a/doc/examples/vaapi_transcode.c
+++ b/doc/examples/vaapi_transcode.c
@@ -109,28 +109,25 @@ static int open_input_file(const char *filename)
 return ret;
 }
 
-static int encode_write(AVFrame *frame)
+static int encode_write(AVPacket *enc_pkt, AVFrame *frame)
 {
 int ret = 0;
-AVPacket enc_pkt;
 
-av_init_packet(_pkt);
-enc_pkt.data = NULL;
-enc_pkt.size = 0;
+av_packet_unref(enc_pkt);
 
 if ((ret = avcodec_send_frame(encoder_ctx, frame)) < 0) {
 fprintf(stderr, "Error during encoding. Error code: %s\n", 
av_err2str(ret));
 goto end;
 }
 while (1) {
-ret = avcodec_receive_packet(encoder_ctx, _pkt);
+ret = avcodec_receive_packet(encoder_ctx, enc_pkt);
 if (ret)
 break;
 
-enc_pkt.stream_index = 0;
-av_packet_rescale_ts(_pkt, 
ifmt_ctx->streams[video_stream]->time_base,
+enc_pkt->stream_index = 0;
+av_packet_rescale_ts(enc_pkt, 
ifmt_ctx->streams[video_stream]->time_base,
  ofmt_ctx->streams[0]->time_base);
-ret = av_interleaved_write_frame(ofmt_ctx, _pkt);
+ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
 if (ret < 0) {
 fprintf(stderr, "Error during writing data to output file. "
 "Error code: %s\n", av_err2str(ret));
@@ -216,7 +213,7 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec)
 initialized = 1;
 }
 
-if ((ret = encode_write(frame)) < 0)
+if ((ret = encode_write(pkt, frame)) < 0)
 fprintf(stderr, "Error during encoding and writing.\n");
 
 fail:
@@ -230,7 +227,7 @@ fail:
 int main(int argc, char **argv)
 {
 int ret = 0;
-AVPacket dec_pkt;
+AVPacket *dec_pkt;
 AVCodec *enc_codec;
 
 if (argc != 4) {
@@ -246,6 +243,12 @@ int main(int argc, char **argv)
 return -1;
 }
 
+dec_pkt = av_packet_alloc();
+if (!dec_pkt) {
+fprintf(stderr, "Failed to allocate decode packet\n");
+goto end;
+}
+
 if ((ret = open_input_file(argv[1])) < 0)
 goto end;
 
@@ -275,23 +278,21 @@ int main(int argc, char **argv)
 
 /* read all packets and only transcoding video */
 while (ret >= 0) {
-if ((ret = av_read_frame(ifmt_ctx, _pkt)) < 0)
+if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) < 0)
 break;
 
-if (video_stream == dec_pkt.stream_index)
-ret = dec_enc(_pkt, enc_codec);
+if (video_stream == dec_pkt->stream_index)
+ret = dec_enc(dec_pkt, enc_codec);
 
-av_packet_unref(_pkt);
+av_packet_unref(dec_pkt);
 }
 
 /* flush decoder */
-dec_pkt.data = NULL;
-dec_pkt.size = 0;
-ret = dec_enc(_pkt, enc_codec);
-av_packet_unref(_pkt);
+av_packet_unref(dec_pkt);
+ret = dec_enc(dec_pkt, enc_codec);
 
 /* flush encoder */
-ret = encode_write(NULL);
+ret = encode_write(dec_pkt, NULL);
 
 /* write the trailer for output stream */
 av_write_trailer(ofmt_ctx);
@@ -302,5 +303,6 @@ end:
 avcodec_free_context(_ctx);
 avcodec_free_context(_ctx);
 av_buffer_unref(_device_ctx);
+av_packet_free(_pkt);
 return ret;
 }
-- 
2.30.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 47/50] doc/examples/vaapi_transcode: use av_packet_alloc() to allocate packets

2021-02-05 Thread James Almer

On 2/5/2021 1:49 PM, Michael Niedermayer wrote:

On Thu, Feb 04, 2021 at 04:10:02PM -0300, James Almer wrote:

Signed-off-by: James Almer 
---
  doc/examples/vaapi_transcode.c | 45 --
  1 file changed, 26 insertions(+), 19 deletions(-)


maybe i forgot something but this


No, you didn't. This is one of the patches i couldn't test, but since 
it's an example i figured it was important to ensure it's adapted 
alongside the deprecation, so i wrote it blind.


Will try again, but otherwise someone with a vaapi enabled system will 
have to give it a try.



breaks build here

make -j32 doc/examples/vaapi_transcode.o
CC  doc/examples/vaapi_transcode.o
doc/examples/vaapi_transcode.c: In function ‘main’:
doc/examples/vaapi_transcode.c:296:21: warning: passing argument 1 of 
‘av_packet_unref’ from incompatible pointer type [-Wincompatible-pointer-types]
  av_packet_unref(_pkt);
  ^
In file included from ./libavcodec/bsf.h:30:0,
  from ./libavcodec/avcodec.h:44,
  from doc/examples/vaapi_transcode.c:38:
./libavcodec/packet.h:682:6: note: expected ‘AVPacket * {aka struct AVPacket 
*}’ but argument is of type ‘AVPacket ** {aka struct AVPacket **}’
  void av_packet_unref(AVPacket *pkt);
   ^~~
doc/examples/vaapi_transcode.c:300:11: error: too few arguments to function 
‘encode_write’
  ret = encode_write(NULL);
^~~~
doc/examples/vaapi_transcode.c:112:12: note: declared here
  static int encode_write(AVPacket *enc_pkt, AVFrame *frame)
 ^~~~
ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_transcode.o' failed
make: *** [doc/examples/vaapi_transcode.o] Error 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 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 47/50] doc/examples/vaapi_transcode: use av_packet_alloc() to allocate packets

2021-02-05 Thread Michael Niedermayer
On Thu, Feb 04, 2021 at 04:10:02PM -0300, James Almer wrote:
> Signed-off-by: James Almer 
> ---
>  doc/examples/vaapi_transcode.c | 45 --
>  1 file changed, 26 insertions(+), 19 deletions(-)

maybe i forgot something but this 
breaks build here

make -j32 doc/examples/vaapi_transcode.o
CC  doc/examples/vaapi_transcode.o
doc/examples/vaapi_transcode.c: In function ‘main’:
doc/examples/vaapi_transcode.c:296:21: warning: passing argument 1 of 
‘av_packet_unref’ from incompatible pointer type [-Wincompatible-pointer-types]
 av_packet_unref(_pkt);
 ^
In file included from ./libavcodec/bsf.h:30:0,
 from ./libavcodec/avcodec.h:44,
 from doc/examples/vaapi_transcode.c:38:
./libavcodec/packet.h:682:6: note: expected ‘AVPacket * {aka struct AVPacket 
*}’ but argument is of type ‘AVPacket ** {aka struct AVPacket **}’
 void av_packet_unref(AVPacket *pkt);
  ^~~
doc/examples/vaapi_transcode.c:300:11: error: too few arguments to function 
‘encode_write’
 ret = encode_write(NULL);
   ^~~~
doc/examples/vaapi_transcode.c:112:12: note: declared here
 static int encode_write(AVPacket *enc_pkt, AVFrame *frame)
^~~~
ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_transcode.o' failed
make: *** [doc/examples/vaapi_transcode.o] Error 1


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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato


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] libavcodec/gifenc: Only write palette entries that actually used

2021-02-05 Thread Derek Buitenhuis
On 05/02/2021 01:54, Andreas Rheinhardt wrote:
> Could AV_CODEC_FLAG_GLOBAL_HEADER be used for this?

It could, but I don't think it should.

The global header is still written, just not with a global palette.
I think it would be, at best, confusing, especially in terms of
intent.

- Derek 
___
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: add xbm parser

2021-02-05 Thread James Almer

On 2/3/2021 10:10 AM, Paul B Mahol wrote:

Signed-off-by: Paul B Mahol 
---
  libavcodec/Makefile |   1 +
  libavcodec/parsers.c|   1 +
  libavcodec/xbm_parser.c | 101 
  3 files changed, 103 insertions(+)
  create mode 100644 libavcodec/xbm_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ab2e5ad308..2ddf021f04 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1127,6 +1127,7 @@ OBJS-$(CONFIG_VP3_PARSER)  += vp3_parser.o
  OBJS-$(CONFIG_VP8_PARSER)  += vp8_parser.o
  OBJS-$(CONFIG_VP9_PARSER)  += vp9_parser.o
  OBJS-$(CONFIG_WEBP_PARSER) += webp_parser.o
+OBJS-$(CONFIG_XBM_PARSER)  += xbm_parser.o
  OBJS-$(CONFIG_XMA_PARSER)  += xma_parser.o
  
  # bitstream filters

diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index 3156b86b03..93af25ac14 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -72,6 +72,7 @@ extern AVCodecParser ff_vp3_parser;
  extern AVCodecParser ff_vp8_parser;
  extern AVCodecParser ff_vp9_parser;
  extern AVCodecParser ff_webp_parser;
+extern AVCodecParser ff_xbm_parser;
  extern AVCodecParser ff_xma_parser;
  
  #include "libavcodec/parser_list.c"

diff --git a/libavcodec/xbm_parser.c b/libavcodec/xbm_parser.c
new file mode 100644
index 00..30d23200db
--- /dev/null
+++ b/libavcodec/xbm_parser.c
@@ -0,0 +1,101 @@
+/*
+ * XBM parser
+ * Copyright (c) 2021 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
+ */
+
+/**
+ * @file
+ * XBM parser
+ */
+
+#include "libavutil/common.h"
+
+#include "parser.h"
+
+typedef struct XBMParseContext {
+ParseContext pc;
+uint16_t state16;
+int count;
+} XBMParseContext;
+
+#define KEY (((uint64_t)'\n' << 56) | ((uint64_t)'#' << 48) | ((uint64_t)'d' << 40) | ((uint64_t)'e' 
<< 32) | ((uint64_t)'f' << 24) | ('i' << 16) | ('n' << 8) | ('e' << 0))


Please split this line.


+#define END ((';' << 8) | ('\n' << 0))
+
+static int xbm_init(AVCodecParserContext *s)
+{
+XBMParseContext *bpc = s->priv_data;
+
+bpc->count = 1;
+
+return 0;
+}
+
+static int xbm_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+XBMParseContext *bpc = s->priv_data;
+uint64_t state = bpc->pc.state64;
+uint16_t state16 = bpc->state16;
+int next = END_NOT_FOUND, i = 0;
+
+s->pict_type = AV_PICTURE_TYPE_NONE;


The decoder sets every frame to AV_PICTURE_TYPE_I and key_frame = 1, so 
you should do the same here, so the generic lavf code takes it into account.



+s->duration  = 1;
+
+*poutbuf_size = 0;
+*poutbuf = NULL;
+
+for (; i < buf_size; i++) {
+state = (state << 8) | buf[i];
+state16 = (state16 << 8) | buf[i];
+
+if (state == KEY)
+bpc->count++;
+
+if ((state == KEY && bpc->count == 1)) {
+next = i - 6;
+break;
+} else if (state16 == END) {
+next = i + 1;
+bpc->count = 0;
+break;
+}
+}
+
+bpc->pc.state64 = state;
+bpc->state16 = state16;
+if (ff_combine_frame(>pc, next, , _size) < 0) {
+*poutbuf = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}


You could also set s->format and s->width/height if you share some code 
with the decoder (inline within a header preferably) at this point, but 
it's not important.



+
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+
+return next;
+}
+
+AVCodecParser ff_xbm_parser = {
+.codec_ids  = { AV_CODEC_ID_XBM },
+.priv_data_size = sizeof(XBMParseContext),
+.parser_init= xbm_init,
+.parser_parse   = xbm_parse,
+.parser_close   = ff_parse_close,
+};


LGTM if tested otherwise.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] avcodec/g722enc: Validate parameters before using them

2021-02-05 Thread Andreas Rheinhardt
In case trellis is outside of 0..23, an invalid shift and/or a signed
integer overflow happens; furthermore, it can lead to the request to
allocate nonsense amounts of memory. So validate first.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/g722enc.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 9357f170fe..9e2ebf67c5 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -64,19 +64,6 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
 c->band[1].scale_factor = 2;
 c->prev_samples_pos = 22;
 
-if (avctx->trellis) {
-int frontier = 1 << avctx->trellis;
-int max_paths = frontier * FREEZE_INTERVAL;
-int i;
-for (i = 0; i < 2; i++) {
-c->paths[i] = av_mallocz_array(max_paths, sizeof(**c->paths));
-c->node_buf[i] = av_mallocz_array(frontier, 2 * 
sizeof(**c->node_buf));
-c->nodep_buf[i] = av_mallocz_array(frontier, 2 * 
sizeof(**c->nodep_buf));
-if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i])
-return AVERROR(ENOMEM);
-}
-}
-
 if (avctx->frame_size) {
 /* validate frame size */
 if (avctx->frame_size & 1 || avctx->frame_size > MAX_FRAME_SIZE) {
@@ -110,6 +97,18 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
avctx->trellis);
 avctx->trellis = new_trellis;
 }
+if (avctx->trellis) {
+int frontier = 1 << avctx->trellis;
+int max_paths = frontier * FREEZE_INTERVAL;
+
+for (int i = 0; i < 2; i++) {
+c->paths[i] = av_calloc(max_paths, sizeof(**c->paths));
+c->node_buf[i]  = av_calloc(frontier, 2 * 
sizeof(**c->node_buf));
+c->nodep_buf[i] = av_calloc(frontier, 2 * 
sizeof(**c->nodep_buf));
+if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i])
+return AVERROR(ENOMEM);
+}
+}
 }
 
 ff_g722dsp_init(>dsp);
-- 
2.27.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 1/2] avcodec: add xbm parser

2021-02-05 Thread Paul B Mahol
Will apply soon.
___
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] x11grab: capture a window instead of the whole screen

2021-02-05 Thread Paul B Mahol
Looks fine.


On Tue, Jan 26, 2021 at 11:24 AM  wrote:

> In my previous email the patch got mangled by the web mail interface, so I
> am
> sending it again. Sorry for the duplicate.
>
> This patch allows ffmpeg to capture a specific window instead of the whole
> screen. An example:
>
> ffmpeg -f x11grab -window_id 0xa0a -i :0 output.mp4
>
> ---
>   doc/indevs.texi   |  3 +++
>   libavdevice/xcbgrab.c | 19 ---
>   2 files changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/doc/indevs.texi b/doc/indevs.texi
> index 3924d03..0738919 100644
> --- a/doc/indevs.texi
> +++ b/doc/indevs.texi
> @@ -1564,6 +1564,9 @@ With @var{follow_mouse}:
>   ffmpeg -f x11grab -follow_mouse centered -show_region 1 -framerate 25
> -video_size cif -i :0.0 out.mpg
>   @end example
>
> +@item window_id
> +Grab this window, instead of the whole screen.
> +
>   @item video_size
>   Set the video frame size. Default is the full desktop.
>
> diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
> index 95bdc8a..6e4ef5d 100644
> --- a/libavdevice/xcbgrab.c
> +++ b/libavdevice/xcbgrab.c
> @@ -60,6 +60,7 @@ typedef struct XCBGrabContext {
>   AVRational time_base;
>   int64_t frame_duration;
>
> +xcb_window_t window_id;
>   int x, y;
>   int width, height;
>   int frame_size;
> @@ -82,6 +83,7 @@ typedef struct XCBGrabContext {
>   #define OFFSET(x) offsetof(XCBGrabContext, x)
>   #define D AV_OPT_FLAG_DECODING_PARAM
>   static const AVOption options[] = {
> +{ "window_id", "Window to capture", OFFSET(window_id),
> AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, D },

  { "x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, { .i64 =
> 0 }, 0, INT_MAX, D },
>   { "y", "Initial y coordinate.", OFFSET(y), AV_OPT_TYPE_INT, { .i64 =
> 0 }, 0, INT_MAX, D },
>   { "grab_x", "Initial x coordinate.", OFFSET(x), AV_OPT_TYPE_INT, {
> .i64 = 0 }, 0, INT_MAX, D },
> @@ -157,7 +159,7 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket
> *pkt)
>   XCBGrabContext *c = s->priv_data;
>   xcb_get_image_cookie_t iq;
>   xcb_get_image_reply_t *img;
> -xcb_drawable_t drawable = c->screen->root;
> +xcb_drawable_t drawable = c->window_id;
>   xcb_generic_error_t *e = NULL;
>   uint8_t *data;
>   int length;
> @@ -267,7 +269,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s,
> AVPacket *pkt)
>   XCBGrabContext *c = s->priv_data;
>   xcb_shm_get_image_cookie_t iq;
>   xcb_shm_get_image_reply_t *img;
> -xcb_drawable_t drawable = c->screen->root;
> +xcb_drawable_t drawable = c->window_id;
>   xcb_generic_error_t *e = NULL;
>   AVBufferRef *buf;
>   xcb_shm_seg_t segment;
> @@ -566,7 +568,7 @@ static int create_stream(AVFormatContext *s)
>
>   avpriv_set_pts_info(st, 64, 1, 100);
>
> -gc  = xcb_get_geometry(c->conn, c->screen->root);
> +gc  = xcb_get_geometry(c->conn, c->window_id);
>   geo = xcb_get_geometry_reply(c->conn, gc, NULL);
>   if (!geo)
>   return AVERROR_EXTERNAL;
> @@ -745,7 +747,7 @@ static int select_region(AVFormatContext *s)
>   press_position = (xcb_point_t){ press->event_x,
> press->event_y };
>   rectangle.x = press_position.x;
>   rectangle.y = press_position.y;
> -xcb_poly_rectangle(conn, root_window, gc, 1, );
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, );
>   was_pressed = 1;
>   break;
>   }
> @@ -754,14 +756,14 @@ static int select_region(AVFormatContext *s)
>   xcb_motion_notify_event_t *motion =
>   (xcb_motion_notify_event_t *)event;
>   xcb_point_t cursor_position = { motion->event_x,
> motion->event_y };
> -xcb_poly_rectangle(conn, root_window, gc, 1, );
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, );
>   rectangle = rectangle_from_corners(_position,
> _position);
> -xcb_poly_rectangle(conn, root_window, gc, 1, );
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, );
>   }
>   break;
>   }
>   case XCB_BUTTON_RELEASE: {
> -xcb_poly_rectangle(conn, root_window, gc, 1, );
> +xcb_poly_rectangle(conn, c->window_id, gc, 1, );
>   done = 1;
>   break;
>   }
> @@ -825,6 +827,9 @@ static av_cold int xcbgrab_read_header(AVFormatContext
> *s)
>   return AVERROR(EIO);
>   }
>
> +if (c->window_id == 0)
> +c->window_id = c->screen->root;
> +
>   if (c->select_region) {
>   ret = select_region(s);
>   if (ret < 0) {
> --
> 2.29.2
>
> ___
> 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/vf_tile: remove extra whitespace in option description

2021-02-05 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_tile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_tile.c b/libavfilter/vf_tile.c
index 6278f72abb..7e421a9721 100644
--- a/libavfilter/vf_tile.c
+++ b/libavfilter/vf_tile.c
@@ -63,7 +63,7 @@ static const AVOption tile_options[] = {
 { "color",   "set the color of the unused area", OFFSET(rgba_color), 
AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS },
 { "overlap", "set how many frames to overlap for each render", 
OFFSET(overlap),
 AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
-{ "init_padding", " set how many frames to initially pad", 
OFFSET(init_padding),
+{ "init_padding", "set how many frames to initially pad", 
OFFSET(init_padding),
 AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
 { NULL }
 };
-- 
2.17.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] avfilter/avfilter: move enable_str expression parsing into avfilter_init_dict()

2021-02-05 Thread Paul B Mahol
This ensures that needed arrays are always allocated and properly initialized.

Previously if code would use only avfilter_init_dict() to set options for 
filters
it would not allocate arrays for timeline processing thus it would crash if
user supplied enable option for filter(s).

Signed-off-by: Paul B Mahol 
---
 libavfilter/avfilter.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 4c52d83842..d560655f42 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -875,11 +875,6 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 count++;
 }
 
-if (ctx->enable_str) {
-ret = set_enable_expr(ctx, ctx->enable_str);
-if (ret < 0)
-return ret;
-}
 return count;
 }
 
@@ -930,6 +925,12 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary 
**options)
 else if (ctx->filter->init_dict)
 ret = ctx->filter->init_dict(ctx, options);
 
+if (ctx->enable_str) {
+ret = set_enable_expr(ctx, ctx->enable_str);
+if (ret < 0)
+return ret;
+}
+
 return ret;
 }
 
-- 
2.17.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 v2] avformat/concatdec: add support for setting input options

2021-02-05 Thread Moritz Barsnick
On Wed, Feb 03, 2021 at 20:37:35 +0200, Jan Ekström wrote:
>
> +@item @code{input_options @var{key=value:key2=value2}}
> +Input options passed on when reading a specific file, using a :-separated 
> list
> +of key=value pairs. Requires @code{safe} to be non-positive. Global options 
> for
> +all files can be set with the @code{input_options} demuxer option. When using
> +both options on the list of files as well as globally via the demuxer option,
> +the global ones get applied first and the file-specific options are then 
> applied
> +on top of them.
> +

Perhaps it's a good idea to add an example, or add this to one of the
examples.

> +@item input_options
> +Input options to be passed on for all opened inputs using a :-separated list 
> of
> +key=value pairs.

You can also quote the ':' as @code{:}.


> +av_log(avf, AV_LOG_ERROR,
> +   "Line %d: Input options cannot be set in file list in 
> "
> +   " safe mode!\n", line);

There are duplicate spaces in this message.

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".