Re: [FFmpeg-devel] [PATCH v15 1/2] lavc/svt_hevc: add libsvt hevc encoder wrapper

2019-07-29 Thread Limin Wang
On Mon, Jul 29, 2019 at 03:50:36PM +0800, Jing Sun wrote:
> Signed-off-by: Zhengxu Huang 
> Signed-off-by: Hassene Tmar 
> Signed-off-by: Jun Zhao 
> Signed-off-by: Jing Sun 
> ---
>  configure|   4 +
>  libavcodec/Makefile  |   1 +
>  libavcodec/allcodecs.c   |   1 +
>  libavcodec/libsvt_hevc.c | 501 
> +++
>  libavcodec/version.h |   2 +-
>  5 files changed, 508 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libsvt_hevc.c
> 
> diff --git a/configure b/configure
> index 7cea9d4..8f2f065 100755
> --- a/configure
> +++ b/configure
> @@ -264,6 +264,7 @@ External library support:
>--enable-libspeexenable Speex de/encoding via libspeex [no]
>--enable-libsrt  enable Haivision SRT protocol via libsrt [no]
>--enable-libssh  enable SFTP protocol via libssh [no]
> +  --enable-libsvthevc  enable HEVC encoding via svt [no]
>--enable-libtensorflow   enable TensorFlow as a DNN module backend
> for DNN based filters like sr [no]
>--enable-libtesseractenable Tesseract, needed for ocr filter [no]
> @@ -1787,6 +1788,7 @@ EXTERNAL_LIBRARY_LIST="
>  libspeex
>  libsrt
>  libssh
> +libsvthevc
>  libtensorflow
>  libtesseract
>  libtheora
> @@ -3180,6 +3182,7 @@ libshine_encoder_select="audio_frame_queue"
>  libspeex_decoder_deps="libspeex"
>  libspeex_encoder_deps="libspeex"
>  libspeex_encoder_select="audio_frame_queue"
> +libsvt_hevc_encoder_deps="libsvthevc"
>  libtheora_encoder_deps="libtheora"
>  libtwolame_encoder_deps="libtwolame"
>  libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
> @@ -6226,6 +6229,7 @@ enabled libsoxr   && require libsoxr soxr.h 
> soxr_create -lsoxr
>  enabled libssh&& require_pkg_config libssh libssh libssh/sftp.h 
> sftp_init
>  enabled libspeex  && require_pkg_config libspeex speex speex/speex.h 
> speex_decoder_init
>  enabled libsrt&& require_pkg_config libsrt "srt >= 1.3.0" 
> srt/srt.h srt_socket
> +enabled libsvthevc&& require_pkg_config libsvthevc SvtHevcEnc 
> EbApi.h EbInitHandle
>  enabled libtensorflow && require libtensorflow tensorflow/c/c_api.h 
> TF_Version -ltensorflow
>  enabled libtesseract  && require_pkg_config libtesseract tesseract 
> tesseract/capi.h TessBaseAPICreate
>  enabled libtheora && require libtheora theora/theoraenc.h 
> th_info_init -ltheoraenc -ltheoradec -logg
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index edccd73..7eb13de 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -991,6 +991,7 @@ OBJS-$(CONFIG_LIBOPUS_ENCODER)+= libopusenc.o 
> libopus.o \
>  OBJS-$(CONFIG_LIBSHINE_ENCODER)   += libshine.o
>  OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
>  OBJS-$(CONFIG_LIBSPEEX_ENCODER)   += libspeexenc.o
> +OBJS-$(CONFIG_LIBSVT_HEVC_ENCODER)+= libsvt_hevc.o
>  OBJS-$(CONFIG_LIBTHEORA_ENCODER)  += libtheoraenc.o
>  OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o
>  OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index d2f9a39..d8788a7 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -707,6 +707,7 @@ extern AVCodec ff_librsvg_decoder;
>  extern AVCodec ff_libshine_encoder;
>  extern AVCodec ff_libspeex_encoder;
>  extern AVCodec ff_libspeex_decoder;
> +extern AVCodec ff_libsvt_hevc_encoder;
>  extern AVCodec ff_libtheora_encoder;
>  extern AVCodec ff_libtwolame_encoder;
>  extern AVCodec ff_libvo_amrwbenc_encoder;
> diff --git a/libavcodec/libsvt_hevc.c b/libavcodec/libsvt_hevc.c
> new file mode 100644
> index 000..d9ac04c
> --- /dev/null
> +++ b/libavcodec/libsvt_hevc.c
> @@ -0,0 +1,501 @@
> +/*
> +* Scalable Video Technology for HEVC encoder library plugin
> +*
> +* Copyright (c) 2019 Intel Corporation
> +*
> +* 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 this program; if not, write to the Free Software
> +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> +*/
> +
> +#include "EbErrorCodes.h"
> +#include "EbTime.h"
> +#include "EbApi.h"
> +
> +#include "libavutil/common.h"
> +#include "libavutil/frame.h"
> +#include "libavutil/opt.h"
> +
> +#include "internal.h"
> +#include "a

Re: [FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg: support variable dimension encode

2019-07-29 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of James Almer
> Sent: Tuesday, July 30, 2019 00:44
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg: support variable
> dimension encode
> 
> On 7/29/2019 11:44 AM, Linjie Fu wrote:
> > Flush encoders when dimension change happens, reset draining to resume
> > encode.
> >
> > If encoder doesn't support variable dimension, stop encoding and
> > report errors.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  fftools/ffmpeg.c| 13 +
> >  libavcodec/encode.c |  4 
> >  2 files changed, 17 insertions(+)
> >
> > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> > index 5d52430..8ceeaaa 100644
> > --- a/fftools/ffmpeg.c
> > +++ b/fftools/ffmpeg.c
> > @@ -130,6 +130,7 @@ static void do_video_stats(OutputStream *ost, int
> frame_size);
> >  static BenchmarkTimeStamps get_benchmark_time_stamps(void);
> >  static int64_t getmaxrss(void);
> >  static int ifilter_has_all_input_formats(FilterGraph *fg);
> > +static void flush_encoders(void);
> >
> >  static int run_as_daemon  = 0;
> >  static int nb_frames_dup = 0;
> > @@ -1067,6 +1068,18 @@ static void do_video_out(OutputFile *of,
> >  InputStream *ist = NULL;
> >  AVFilterContext *filter = ost->filter->filter;
> >
> > +/* flush encoders in dynamic resolution encode */
> > +if (next_picture && (enc->width != next_picture->width ||
> > + enc->height != next_picture->height)) {
> > +flush_encoders();
> > +
> > +if (!(enc->codec->capabilities &
> AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
> > +av_log(NULL, AV_LOG_ERROR, "Dynamic resolution encode "
> > +"is not supported by %s.\n", enc->codec->name);
> > +goto error;
> > +}
> > +}
> > +
> >  if (ost->source_index >= 0)
> >  ist = input_streams[ost->source_index];
> >
> > diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> > index d12c425..9303bc9 100644
> > --- a/libavcodec/encode.c
> > +++ b/libavcodec/encode.c
> > @@ -389,6 +389,10 @@ int attribute_align_arg
> avcodec_send_frame(AVCodecContext *avctx, const AVFrame
> >  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
> >  return AVERROR(EINVAL);
> >
> > +/* reset draining when encoder is flushed in variable dimensions
> encoding */
> > +if (frame)
> > +avctx->internal->draining = 0;
> 
> This is an API change that can break some workflows.
> 
> avcodec_flush_buffers() is the public function meant to flush an
> AVCodecContext.
> 

Thanks for the hint, updated.

- linjie
___
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/4] fftools/ffmpeg: support variable dimension encode

2019-07-29 Thread Linjie Fu
Flush encoders when dimension change happens.

Signed-off-by: Linjie Fu 
---
 fftools/ffmpeg.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d52430..cb3adb2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -130,6 +130,7 @@ static void do_video_stats(OutputStream *ost, int 
frame_size);
 static BenchmarkTimeStamps get_benchmark_time_stamps(void);
 static int64_t getmaxrss(void);
 static int ifilter_has_all_input_formats(FilterGraph *fg);
+static void flush_encoders(void);
 
 static int run_as_daemon  = 0;
 static int nb_frames_dup = 0;
@@ -1067,6 +1068,19 @@ static void do_video_out(OutputFile *of,
 InputStream *ist = NULL;
 AVFilterContext *filter = ost->filter->filter;
 
+/* flush encoders in dynamic resolution encode */
+if (next_picture && (enc->width != next_picture->width ||
+ enc->height != next_picture->height)) {
+flush_encoders();
+avcodec_flush_buffers(enc);
+
+if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
+av_log(NULL, AV_LOG_ERROR, "Dynamic resolution encode "
+"is not supported by %s.\n", enc->codec->name);
+goto error;
+}
+}
+
 if (ost->source_index >= 0)
 ist = input_streams[ost->source_index];
 
-- 
2.7.4

___
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 2/4] avc/avcodec: add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag

2019-07-29 Thread Linjie Fu
Add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag to indicate whether encoder
supports variable dimension encoding.

Signed-off-by: Linjie Fu 
---
[v2]: update API changes.
 doc/APIchanges   | 3 +++
 fftools/cmdutils.c   | 2 ++
 libavcodec/avcodec.h | 5 +
 libavcodec/rawenc.c  | 1 +
 libavcodec/version.h | 2 +-
 5 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 07331b1..2e855f2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-07-xx - xx - lavc 58.55.101 - avcodec.h
+  Add AV_CODEC_CAP_VARIABLE_DIMENSIONS
+
  8< - FFmpeg 4.2 was cut here  8< -
 
 2019-06-21 - a30e44098a - lavu 56.30.100 - frame.h
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 9cfbc45..25ea1c6 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1424,6 +1424,8 @@ static void print_codec(const AVCodec *c)
 printf("hardware ");
 if (c->capabilities & AV_CODEC_CAP_HYBRID)
 printf("hybrid ");
+if (c->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)
+printf("multidimension ");
 if (!c->capabilities)
 printf("none");
 printf("\n");
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271..a7704ea 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1092,6 +1092,11 @@ typedef struct RcOverride{
 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
 
 /**
+ * Codec supports variable dimensions in encoding.
+ */
+#define AV_CODEC_CAP_VARIABLE_DIMENSIONS (1 << 21)
+
+/**
  * Pan Scan area.
  * This specifies the area which should be displayed.
  * Note there may be multiple such areas for one frame.
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index d181b74..486c0d7 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -92,4 +92,5 @@ AVCodec ff_rawvideo_encoder = {
 .id = AV_CODEC_ID_RAWVIDEO,
 .init   = raw_encode_init,
 .encode2= raw_encode,
+.capabilities   = AV_CODEC_CAP_VARIABLE_DIMENSIONS,
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 43c8cdb..e70ebc0 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  55
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.7.4

___
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] avcodec: add a WavPack DSD decoder

2019-07-29 Thread David Bryant
On 7/28/19 10:27 AM, Paul B Mahol wrote:
> On Sun, Jul 28, 2019 at 6:02 AM David Bryant  wrote:
>
>> On 7/24/19 12:26 AM, Paul B Mahol wrote:
>>> On 7/23/19, David Bryant  wrote:
 On 7/23/19 12:47 AM, Paul B Mahol wrote:
> On 7/23/19, David Bryant  wrote:
>> On 7/21/19 11:23 PM, Paul B Mahol wrote:
>>> On 7/22/19, David Bryant  wrote:
 Hi,

 As I promised late last year, here is a patch to add a WavPack DSD
 decoder.

 Thanks!

 -David Bryant


>>> Please correct me if I'm wrong, but why this uses new codec id?
>>> Apparently is also copies some logic from other files.
>> Yes, I created a new codec ID for WavPack DSD. It would be possible to
>> just
>> piggyback on the existing WavPack codec by silently
>> decimating the DSD to PCM, but that seemed weird and wrong to me. For
>> one
>> thing, the user would have no idea that the file was
>> actually DSD and not high sample-rate PCM.
>>
>> Also, since regular WavPack has threading enabled but WavPack DSD
>> can't
>> (because of the dsd2pcm conversion) I would have to turn
>> off threading for all WavPack (unless there's some way of making that
>> conditional at runtime). It would also mean that regular
>> WavPack would be dependent on the dsd2pcm component even if DSD was
>> not
>> required (not everyone needs DSD). And of course I was
>> looking closely at the only other DSD codec in FFmpeg (DST) which has
>> its
>> own codec ID.
>>
>> Because regular WavPack PCM and DSD share the same block format and
>> metadata
>> structure, there is a little code that is shared
>> between the two codecs (although they are no longer identical because
>> of
>> the
>> threading difference). Is this a problem? I could
>> combine the two codecs into one file and sprinkle in a few
>> conditionals,
>> but
>> I don't think it would be as clean or clear (but
>> might save a little duplicate code).
>>
>> That's my thinking, but obviously I am not as familiar with the FFmpeg
>> philosophy as you guys.
> Looking carefully at dsd2pcm code in your patch, it appears it would
> work only with 1 or 2 channels.
> Is this correct?
 Individual WavPack blocks can only be 1 or 2 channels. Multichannel
>> files
 contains sequences of blocks which ends up creating
 multiple frame contexts. This was originally implemented for PCM WavPack
 years ago and so it "just works" for DSD WavPack
 because I didn't touch any of that.

 I have tested this extensively with multichannel DSD files and it works
 great, including seeking.
>>> Than I fail to see why it could not work for multi-threading too.
>> Really? Because I just looked back at the FFmpeg devel archives (May 2016)
>> and you supplied the patch for the DST codec, the
>> only other DSD compression codec in existence before my recent
>> development. And dstdec.c does not enable multi-threading
>> because, of course, you get clicks. This seems like an unlikely oversight
>> since DST is a well-documented CPU hog and would
>> benefit greatly from multi-threading.
>>
> You are right, it can not use frame-multi-threading. But can use
> slice-multi-threading as each channel is independent.
> Thanks for pointing this for DST, I will implement this slice-threading
> soon, unless someone beat me first.

My thought was that the CPU-hungry DSD decoding would be multi-threaded, but 
each thread would have to wait when it got to the
dsd2pcm step to make sure the previous had finished, and then it would copy the 
dsd2pcm-specific context from the previous
thread. So there would be dsd2pcm contexts allocated for each thread, but the 
actual content would be copied from one to the
next. Or you could just always use the dsd2pcm contexts from the "first" 
thread, if it was possible to access that. I would need
to look at it a lot more to be sure.


> ___
> 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] Extract QP from h264 encoded videos

2019-07-29 Thread James Almer
On 7/29/2019 11:19 PM, Juan De León wrote:
> On Mon, Jul 29, 2019 at 12:48 PM Mark Thompson  wrote:
> 
>> This doesn't belong in the commit message.
>>
>> What does belong here would be some commentary on why you want this
>> feature.
>>
> Here is the, somewhat outdated, design document, this should explain it.
> https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
> 
> In short the purpose is to implement an API to extract QP and calculate min
> max and average.
> 
>> +int x, y;
>>
>> How do these values interact with cropping?
> 
> I'm not sure I understand, could you elaborate?
> 
>> +AVQuantizationParams *qp_arr;
>>
>> Side-data is reference counted, so how is this pointer managed?  More
>> genrally, it would probably help to explain exactly how this is allocated
>> and who will be responsible for freeing it.
>>
> The idea is to allocate the memory, for AVQuantizationParamsArray and the
> necessary number of AVQuantizationParams, in a single buffer that can be
> freed when the side data is freed.

Side data, or more specifically, any AVBufferRef, must be a flat array.
You can't have pointers to some other allocated buffer within them since
you can't really control their lifetime.
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
I tried to fix all you suggested, please have a look and let me know what you 
think.

design doc: 
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  42 
 libavutil/quantization_params.h | 114 
 4 files changed, 164 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be1a9c3a9c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.h \
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b64fd9c02c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data is stored as AVQuantizationParamsArray type, described in
+ * libavuitl/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..fc51b55eee
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,42 @@
+/*
+ * 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/quantization_params.h"
+#include "libavutil/mem.h"
+
+static const char* const QP_NAMES_H264[] = {"qpy", "qpuv"};
+
+static const char* const QP_NAMES_VP9[] = {"qyac", "qydc", "quvdc", "quvac",
+   "qiyac", "qiydc", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* av_get_qp_type_string(enum AVExtractQPSupportedCodecs codec_id, int 
index)
+{
+switch (codec_id) {
+case AV_EXTRACT_QP_CODEC_ID_H264:
+return index < AV_QP_ARR_SIZE_H264 ? 
av_strdup(QP_NAMES_H264[index]) :NULL;
+case AV_EXTRACT_QP_CODEC_ID_VP9:
+return index < AV_QP_ARR_SIZE_VP9  ? 
av_strdup(QP_NAMES_VP9[index])  :NULL;
+case AV_EXTRACT_QP_CODEC_ID_AV1:
+return index < AV_QP_ARR_SIZE_AV1  ? 
av_strdup(QP_NAMES_AV1[index])  :NULL;
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..d123aade3b
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,114 @@
+/*
+ * 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 Softwar

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
On Mon, Jul 29, 2019 at 12:48 PM Mark Thompson  wrote:

> This doesn't belong in the commit message.
>
> What does belong here would be some commentary on why you want this
> feature.
>
Here is the, somewhat outdated, design document, this should explain it.
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing

In short the purpose is to implement an API to extract QP and calculate min
max and average.

> +int x, y;
>
> How do these values interact with cropping?

I'm not sure I understand, could you elaborate?

> +AVQuantizationParams *qp_arr;
>
> Side-data is reference counted, so how is this pointer managed?  More
> genrally, it would probably help to explain exactly how this is allocated
> and who will be responsible for freeing it.
>
The idea is to allocate the memory, for AVQuantizationParamsArray and the
necessary number of AVQuantizationParams, in a single buffer that can be
freed when the side data is freed.


> > +enum QP_ARR_INDEXES_FOR_H264 {
> > +QP_H264 = 0,// qp value
>
> What value specifically does this refer to?  QP_Y or QP'_Y for the given
> block?
>
It refers to the final QP of the block, not the delta.
Also Added a field for chroma QP, thanks!


> What is the proposed consumer of this?  It might help if you provided that
> as well (a filter?).
>
The filter is incomplete but I can submit what I have so far if needed to
give more context.
The document explains it better.
https://docs.google.com/document/d/1WClt3EqhjwdGXhEw386O0wfn3IBQ1Ib-_5emVM1gbnA/edit?usp=sharing
___
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] fate: add a case for ticket #3229

2019-07-29 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Tuesday, July 30, 2019 4:28 AM
> To: FFmpeg development discussions and patches
> 
> Subject: Re: [FFmpeg-devel] [PATCH V2] fate: add a case for ticket #3229
> 
> On Mon, Jul 29, 2019 at 06:20:39PM +0800, Zhong Li wrote:
> > Signed-off-by: Zhong Li 
> > ---
> > https://patchwork.ffmpeg.org/patch/13725/ introduces a regression but
> not found by fate, so add it.
> > Test clip produced by:
> > ffmpeg -i tickets/3229/bad.avi -vframes 6 -c:v copy
> > /fate-suite/mjpeg/mjpeg_field_order.avi
> >
> >  tests/fate/video.mak|  3 +++
> >  tests/ref/fate/mjpeg-ticket3229 | 11 +++
> >  2 files changed, 14 insertions(+)
> >  create mode 100644 tests/ref/fate/mjpeg-ticket3229
> 
> LGTM & passed on mingw32/64 arm/mips qemu and linux32
> 
> thx

Thanks for review and testing. 
May I search your help to produce/upload the clip to fate server and then apply 
this 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 2/2] convert_from_tensorflow.py: support conv2d with dilation

2019-07-29 Thread Guo, Yejun
conv2d with dilation > 1 generates tens of nodes in graph, it is not
easy to parse each node one by one, so we do special tricks to parse
the conv2d layer.

Signed-off-by: Guo, Yejun 
---
 tools/python/convert_from_tensorflow.py | 80 -
 1 file changed, 59 insertions(+), 21 deletions(-)

diff --git a/tools/python/convert_from_tensorflow.py 
b/tools/python/convert_from_tensorflow.py
index 804c14f..34454b8 100644
--- a/tools/python/convert_from_tensorflow.py
+++ b/tools/python/convert_from_tensorflow.py
@@ -33,9 +33,10 @@ class TFConverter:
 self.output_names = []
 self.name_node_dict = {}
 self.edges = {}
-self.conv_activations = {'Relu':0, 'Tanh':1, 'Sigmoid':2, 
'LeakyRelu':4}
+self.conv_activations = {'Relu':0, 'Tanh':1, 'Sigmoid':2, 'None':3, 
'LeakyRelu':4}
 self.conv_paddings = {'VALID':0, 'SAME':1}
 self.converted_nodes = set()
+self.conv2d_scope_names = set()
 self.op2code = {'Conv2D':1, 'DepthToSpace':2, 'MirrorPad':3}
 self.mirrorpad_mode = {'CONSTANT':0, 'REFLECT':1, 'SYMMETRIC':2}
 
@@ -47,30 +48,45 @@ class TFConverter:
 print('graph saved, run "tensorboard --logdir=/tmp/graph" to see it')
 
 
-def get_conv2d_params(self, node):
-knode = self.name_node_dict[node.input[1]]
-bnode = None
-activation = 'None'
-next = self.edges[node.name][0]
-if next.op == 'BiasAdd':
-self.converted_nodes.add(next.name)
-bnode = self.name_node_dict[next.input[1]]
-next = self.edges[next.name][0]
-if next.op in self.conv_activations:
-self.converted_nodes.add(next.name)
-activation = next.op
-return knode, bnode, activation
+def get_conv2d_params(self, conv2d_scope_name):
+knode = self.name_node_dict[conv2d_scope_name + '/kernel']
+bnode = self.name_node_dict[conv2d_scope_name + '/bias']
+
+if conv2d_scope_name + '/dilation_rate' in self.name_node_dict:
+dnode = self.name_node_dict[conv2d_scope_name + '/dilation_rate']
+else:
+dnode = None
+
+# the BiasAdd name is possible be changed into the output name,
+# if activation is None, and BiasAdd.next is the last op which is 
Identity
+if conv2d_scope_name + '/BiasAdd' in self.edges:
+activation = self.edges[conv2d_scope_name + '/BiasAdd'][0]
+activation = activation.op
+else:
+activation = 'None'
+return knode, bnode, dnode, activation
 
 
 def dump_conv2d_to_file(self, node, f):
 assert(node.op == 'Conv2D')
 self.layer_number = self.layer_number + 1
 self.converted_nodes.add(node.name)
-knode, bnode, activation = self.get_conv2d_params(node)
 
-dilation = node.attr['dilations'].list.i[0]
-padding = node.attr['padding'].s
-padding = self.conv_paddings[padding.decode("utf-8")]
+scope_name = TFConverter.get_scope_name(node.name)
+#knode for kernel, bnode for bias, dnode for dilation
+knode, bnode, dnode, activation = self.get_conv2d_params(scope_name)
+
+if dnode is not None:
+dilation = struct.unpack('i', 
dnode.attr['value'].tensor.tensor_content[0:4])[0]
+else:
+dilation = 1
+
+padding = node.attr['padding'].s.decode("utf-8")
+# conv2d with dilation > 1 generates tens of nodes, not easy to parse 
them, so use tricky.
+if dilation > 1 and scope_name + '/stack' in self.name_node_dict:
+if self.name_node_dict[scope_name + '/stack'].op == "Const":
+padding = 'SAME'
+padding = self.conv_paddings[padding]
 
 ktensor = knode.attr['value'].tensor
 filter_height = ktensor.tensor_shape.dim[0].size
@@ -126,9 +142,15 @@ class TFConverter:
 for node in self.nodes:
 if node.name in self.converted_nodes:
 continue
-if node.op == 'Conv2D':
-self.dump_conv2d_to_file(node, f)
-elif node.op == 'DepthToSpace':
+
+# conv2d with dilation generates very complex nodes, so handle it 
in special
+scope_name = TFConverter.get_scope_name(node.name)
+if scope_name in self.conv2d_scope_names:
+if node.op == 'Conv2D':
+self.dump_conv2d_to_file(node, f)
+continue
+
+if node.op == 'DepthToSpace':
 self.dump_depth2space_to_file(node, f)
 elif node.op == 'MirrorPad':
 self.dump_mirrorpad_to_file(node, f)
@@ -192,11 +214,27 @@ class TFConverter:
 self.edges[input] = [node]
 
 
+@staticmethod
+def get_scope_name(name):
+index = name.rfind('/')
+if index == -1:
+return ""
+return name[0:index]
+
+
+def generate_conv2d_scope_names(self):
+for node in 

[FFmpeg-devel] [PATCH 1/2] convert_from_tensorflow.py: add option to dump graph for visualization in tensorboard

2019-07-29 Thread Guo, Yejun
Signed-off-by: Guo, Yejun 
---
 tools/python/convert.py |  6 +-
 tools/python/convert_from_tensorflow.py | 13 +++--
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/python/convert.py b/tools/python/convert.py
index 662b429..64cf76b 100644
--- a/tools/python/convert.py
+++ b/tools/python/convert.py
@@ -27,6 +27,7 @@ def get_arguments():
 parser.add_argument('--outdir', type=str, default='./', help='where to put 
generated files')
 parser.add_argument('--infmt', type=str, default='tensorflow', 
help='format of the deep learning model')
 parser.add_argument('infile', help='path to the deep learning model with 
weights')
+parser.add_argument('--dump4tb', type=str, default='no', help='dump file 
for visualization in tensorboard')
 
 return parser.parse_args()
 
@@ -44,9 +45,12 @@ def main():
 basefile = os.path.split(args.infile)[1]
 basefile = os.path.splitext(basefile)[0]
 outfile = os.path.join(args.outdir, basefile) + '.model'
+dump4tb = False
+if args.dump4tb.lower() in ('yes', 'true', 't', 'y', '1'):
+dump4tb = True
 
 if args.infmt == 'tensorflow':
-convert_from_tensorflow(args.infile, outfile)
+convert_from_tensorflow(args.infile, outfile, dump4tb)
 
 if __name__ == '__main__':
 main()
diff --git a/tools/python/convert_from_tensorflow.py 
b/tools/python/convert_from_tensorflow.py
index 041c82c..804c14f 100644
--- a/tools/python/convert_from_tensorflow.py
+++ b/tools/python/convert_from_tensorflow.py
@@ -24,10 +24,11 @@ import sys, struct
 __all__ = ['convert_from_tensorflow']
 
 class TFConverter:
-def __init__(self, graph_def, nodes, outfile):
+def __init__(self, graph_def, nodes, outfile, dump4tb):
 self.graph_def = graph_def
 self.nodes = nodes
 self.outfile = outfile
+self.dump4tb = dump4tb
 self.layer_number = 0
 self.output_names = []
 self.name_node_dict = {}
@@ -42,8 +43,8 @@ class TFConverter:
 def dump_for_tensorboard(self):
 graph = tf.get_default_graph()
 tf.import_graph_def(self.graph_def, name="")
-# tensorboard --logdir=/tmp/graph
 tf.summary.FileWriter('/tmp/graph', graph)
+print('graph saved, run "tensorboard --logdir=/tmp/graph" to see it')
 
 
 def get_conv2d_params(self, node):
@@ -197,18 +198,18 @@ class TFConverter:
 self.remove_identity()
 self.generate_edges()
 
-#check the graph with tensorboard with human eyes
-#self.dump_for_tensorboard()
+if self.dump4tb:
+self.dump_for_tensorboard()
 
 self.dump_to_file()
 
 
-def convert_from_tensorflow(infile, outfile):
+def convert_from_tensorflow(infile, outfile, dump4tb):
 with open(infile, 'rb') as f:
 # read the file in .proto format
 graph_def = tf.GraphDef()
 graph_def.ParseFromString(f.read())
 nodes = graph_def.node
 
-converter = TFConverter(graph_def, nodes, outfile)
+converter = TFConverter(graph_def, nodes, outfile, dump4tb)
 converter.run()
-- 
2.7.4

___
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/scpr: Use av_memcpy_backptr() in type 17 and 33

2019-07-29 Thread Michael Niedermayer
This makes the changed code-path faster.

Change not tested except with the fuzzer testcase as I found no other testcase.

Improves: Timeout (136sec -> 74sec)
Improves: 
16040/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SCPR_fuzzer-5705876062601216

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
---
 libavcodec/scpr.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/scpr.c b/libavcodec/scpr.c
index 317950dafb..778b064841 100644
--- a/libavcodec/scpr.c
+++ b/libavcodec/scpr.c
@@ -548,9 +548,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 clr = bytestream2_get_le24(gb);
 }
 for (y = 0; y < avctx->height; y++) {
-for (x = 0; x < avctx->width; x++) {
-dst[x] = clr;
-}
+dst[0] = clr;
+av_memcpy_backptr(dst+1, 4, 4*avctx->width - 4);
 dst += s->current_frame->linesize[0] / 4;
 }
 } else if (type == 0 || type == 1) {
-- 
2.22.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 5/7] cbs_mpeg2: Fix parsing the last unit

2019-07-29 Thread Mark Thompson
On 29/07/2019 20:56, Andreas Rheinhardt wrote:
> There is one way to find out if avpriv_find_start_code has found a start
> code or not: One has to check whether the state variable contains a
> start code, i.e. whether the three most serious bytes are 0x00 00 01.

"most significant bytes"

> Checking for whether the return value is the end of the designated
> buffer is not enough: If the last four bytes constitute a start code,
> the return value is also the end of the buffer. This happens with
> sequence_end_codes which have been ignored for exactly this reason,
> although e.g. all three files used for fate tests of cbs_mpeg2 contain
> sequence_end_codes.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs_mpeg2.c | 28 +---
>  1 file changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index c529038fd9..596e9677b7 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -170,27 +170,41 @@ static int 
> cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
>  CodedBitstreamUnitType unit_type;
>  uint32_t start_code = -1;
>  size_t unit_size;
> -int err, i;
> +int err, i, final = 0;
>  
>  start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
> &start_code);
> +if (start_code >> 8 != 0x01) {
> +// No start code found.
> +return AVERROR_INVALIDDATA;
> +}
> +
>  for (i = 0;; i++) {
>  unit_type = start_code & 0xff;
>  
> +if (start == frag->data + frag->data_size) {
> +// The last four bytes form a start code which constitutes
> +// a unit of its own.  In this situation avpriv_find_start_code
> +// won't modify start_code at all so modify start_code so that
> +// the next unit will be treated as the last unit.
> +start_code = 0;
> +}
> +
>  end = avpriv_find_start_code(start--, frag->data + frag->data_size,
>   &start_code);
>  
>  // start points to the byte containing the start_code_identifier
> -// (or to the last byte of fragment->data); end points to the byte
> +// (may be the last byte of fragment->data); end points to the byte
>  // following the byte containing the start code identifier (or to
>  // the end of fragment->data).
> -if (end == frag->data + frag->data_size) {
> -// We didn't find a start code, so this is the final unit.
> -unit_size = end - start;
> -} else {
> +if (start_code >> 8 == 0x01) {
>  // Unit runs from start to the beginning of the start code
>  // pointed to by end (including any padding zeroes).
>  unit_size = (end - 4) - start;
> +} else {
> +   // We didn't find a start code, so this is the final unit.
> +   unit_size = end - start;
> +   final = 1;
>  }
>  
>  err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, 
> (uint8_t*)start,
> @@ -198,7 +212,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
> *ctx,
>  if (err < 0)
>  return err;
>  
> -if (end == frag->data + frag->data_size)
> +if (final)
>  break;
>  
>  start = end;
> 

1-5 LGTM, applied.

Thanks,

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

Re: [FFmpeg-devel] [PATCH] avcodec/rl2: set dimensions

2019-07-29 Thread Jean-Baptiste Kempf
Yo,

On Tue, Jul 23, 2019, at 04:42, Lynne wrote:
> Jul 23, 2019, 12:00 AM by mich...@niedermayer.cc:
> >> Moreover, if neither the codec, nor container can change the resolution, 
> >> then how does that make anything different?
> >
> >> Please, stop it with those patches. It takes energy and some worry to have 
> >> to open up the ML and scan it for bad patches from people who really 
> >> should know better every time.
> >
> > Please stop with these attacks, this is just making people become
> > mutually more aggressive and filled with hatred.
> 
> Of course I'm frustrated, I've been ignored.

Frustration should not allow this tone on this mailing list.

You may have a point on technical matters, but there are better ways to express 
those, I believe.
Because if everyone gets pissed/frustrated, then we won't get anything done.

If you know how to fix those things in a proper way, please tell us. I am sure 
we could even sponsor you for doing this work.

Best,

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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] fate: add a case for ticket #3229

2019-07-29 Thread Michael Niedermayer
On Mon, Jul 29, 2019 at 06:20:39PM +0800, Zhong Li wrote:
> Signed-off-by: Zhong Li 
> ---
> https://patchwork.ffmpeg.org/patch/13725/ introduces a regression but not 
> found by fate, so add it.
> Test clip produced by:
> ffmpeg -i tickets/3229/bad.avi -vframes 6 -c:v copy 
> /fate-suite/mjpeg/mjpeg_field_order.avi
> 
>  tests/fate/video.mak|  3 +++
>  tests/ref/fate/mjpeg-ticket3229 | 11 +++
>  2 files changed, 14 insertions(+)
>  create mode 100644 tests/ref/fate/mjpeg-ticket3229

LGTM & passed on mingw32/64 arm/mips qemu and linux32

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


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 4/7] cbs_mpeg2: Rearrange start code search

2019-07-29 Thread Andreas Rheinhardt
1. Currently, cbs_mpeg2_split_fragment uses essentially three variables
to hold the start code values found by avpriv_find_start_code. By
rearranging the code, one of them can be omitted.
2. The return value of avpriv_find_start_code points to the byte after
the byte containing the start code identifier (or to the byte after the
last byte of the fragment's data if no start code was found), but
cbs_mpeg2_split_fragment needs to work with the pointer to the byte
containing the start code identifier; it already did this, but in a
clumsy way. This has been changed.
3. Also use the correct type for the variable holding the
CodedBitstreamUnitType.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_mpeg2.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 9a584246c9..c529038fd9 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -167,41 +167,40 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
*ctx,
 int header)
 {
 const uint8_t *start, *end;
-uint8_t *unit_data;
-uint32_t start_code = -1, next_start_code = -1;
+CodedBitstreamUnitType unit_type;
+uint32_t start_code = -1;
 size_t unit_size;
-int err, i, unit_type;
+int err, i;
 
 start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
&start_code);
 for (i = 0;; i++) {
-end = avpriv_find_start_code(start, frag->data + frag->data_size,
- &next_start_code);
-
 unit_type = start_code & 0xff;
 
-// The start and end pointers point at to the byte following the
-// start_code_identifier in the start code that they found.
+end = avpriv_find_start_code(start--, frag->data + frag->data_size,
+ &start_code);
+
+// start points to the byte containing the start_code_identifier
+// (or to the last byte of fragment->data); end points to the byte
+// following the byte containing the start code identifier (or to
+// the end of fragment->data).
 if (end == frag->data + frag->data_size) {
 // We didn't find a start code, so this is the final unit.
-unit_size = end - (start - 1);
+unit_size = end - start;
 } else {
 // Unit runs from start to the beginning of the start code
 // pointed to by end (including any padding zeroes).
-unit_size = (end - 4) - (start - 1);
+unit_size = (end - 4) - start;
 }
 
-unit_data = (uint8_t *)start - 1;
-
-err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type,
-  unit_data, unit_size, frag->data_ref);
+err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, (uint8_t*)start,
+  unit_size, frag->data_ref);
 if (err < 0)
 return err;
 
 if (end == frag->data + frag->data_size)
 break;
 
-start_code = next_start_code;
 start = end;
 }
 
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 5/7] cbs_mpeg2: Fix parsing the last unit

2019-07-29 Thread Andreas Rheinhardt
There is one way to find out if avpriv_find_start_code has found a start
code or not: One has to check whether the state variable contains a
start code, i.e. whether the three most serious bytes are 0x00 00 01.
Checking for whether the return value is the end of the designated
buffer is not enough: If the last four bytes constitute a start code,
the return value is also the end of the buffer. This happens with
sequence_end_codes which have been ignored for exactly this reason,
although e.g. all three files used for fate tests of cbs_mpeg2 contain
sequence_end_codes.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_mpeg2.c | 28 +---
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index c529038fd9..596e9677b7 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -170,27 +170,41 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
*ctx,
 CodedBitstreamUnitType unit_type;
 uint32_t start_code = -1;
 size_t unit_size;
-int err, i;
+int err, i, final = 0;
 
 start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
&start_code);
+if (start_code >> 8 != 0x01) {
+// No start code found.
+return AVERROR_INVALIDDATA;
+}
+
 for (i = 0;; i++) {
 unit_type = start_code & 0xff;
 
+if (start == frag->data + frag->data_size) {
+// The last four bytes form a start code which constitutes
+// a unit of its own.  In this situation avpriv_find_start_code
+// won't modify start_code at all so modify start_code so that
+// the next unit will be treated as the last unit.
+start_code = 0;
+}
+
 end = avpriv_find_start_code(start--, frag->data + frag->data_size,
  &start_code);
 
 // start points to the byte containing the start_code_identifier
-// (or to the last byte of fragment->data); end points to the byte
+// (may be the last byte of fragment->data); end points to the byte
 // following the byte containing the start code identifier (or to
 // the end of fragment->data).
-if (end == frag->data + frag->data_size) {
-// We didn't find a start code, so this is the final unit.
-unit_size = end - start;
-} else {
+if (start_code >> 8 == 0x01) {
 // Unit runs from start to the beginning of the start code
 // pointed to by end (including any padding zeroes).
 unit_size = (end - 4) - start;
+} else {
+   // We didn't find a start code, so this is the final unit.
+   unit_size = end - start;
+   final = 1;
 }
 
 err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, (uint8_t*)start,
@@ -198,7 +212,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-if (end == frag->data + frag->data_size)
+if (final)
 break;
 
 start = end;
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 2/7] cbs_h264: Improve adding SEI messages

2019-07-29 Thread Andreas Rheinhardt
Up until now, if an SEI messages was to be added to a fragment, it was
tried to add said SEI message to the first SEI NAL unit of the fragment
and if this SEI NAL unit already contained H264_NAL_SEI SEI messages (an
arbitrary limit imposed by cbs_h264), adding failed; if there was no SEI
NAL unit, a new one has been added.
With this commit, the fragment is searched for further NAL units to add
the SEI messages to. If all of them are full, a new SEI NAL unit is added.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_h2645.c | 20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 1c35be51e7..69ea6dc6bb 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1588,21 +1588,21 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext 
*ctx,
 CodedBitstreamFragment *au,
 const H264RawSEIPayload *payload)
 {
-H264RawSEI *sei;
-CodedBitstreamUnit *nal = NULL;
+H264RawSEI *sei = NULL;
 int err, i;
 
 // Find an existing SEI NAL unit to add to.
 for (i = 0; i < au->nb_units; i++) {
 if (au->units[i].type == H264_NAL_SEI) {
-nal = &au->units[i];
-break;
+sei = au->units[i].content;
+if (sei->payload_count < H264_MAX_SEI_PAYLOADS)
+break;
+
+sei = NULL;
 }
 }
-if (nal) {
-sei = nal->content;
 
-} else {
+if (!sei) {
 // Need to make a new SEI NAL unit.  Insert it before the first
 // slice data NAL unit; if no slice data, add at the end.
 AVBufferRef *sei_ref;
@@ -1634,12 +1634,6 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext 
*ctx,
 return err;
 }
 
-if (sei->payload_count >= H264_MAX_SEI_PAYLOADS) {
-av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many payloads in "
-   "SEI NAL unit.\n");
-return AVERROR(EINVAL);
-}
-
 memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload));
 ++sei->payload_count;
 
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 3/7] cbs_mpeg2: Decompose Sequence End

2019-07-29 Thread Andreas Rheinhardt
Sequence End units (or actually, sequence_end_codes) have up until now
not been decomposed; in fact due to a bug in cbs_mpeg2_split_fragment they
have mostly been treated as part of the preceding unit. So implement
decomposing them as preparation for fixing said bug.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_mpeg2.c |  3 +++
 libavcodec/cbs_mpeg2.h |  4 
 libavcodec/cbs_mpeg2_syntax_template.c | 12 
 3 files changed, 19 insertions(+)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 3e6797bd42..9a584246c9 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -269,6 +269,8 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
   extension_data,   NULL);
 START(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader,
   group_of_pictures_header, NULL);
+START(MPEG2_START_SEQUENCE_END, MPEG2RawSequenceEnd,
+  sequence_end, NULL);
 #undef START
 default:
 return AVERROR(ENOSYS);
@@ -295,6 +297,7 @@ static int cbs_mpeg2_write_header(CodedBitstreamContext 
*ctx,
 START(MPEG2_START_EXTENSION,   MPEG2RawExtensionData,  
extension_data);
 START(MPEG2_START_GROUP,   MPEG2RawGroupOfPicturesHeader,
  
group_of_pictures_header);
+START(MPEG2_START_SEQUENCE_END,MPEG2RawSequenceEnd,
sequence_end);
 #undef START
 default:
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for start "
diff --git a/libavcodec/cbs_mpeg2.h b/libavcodec/cbs_mpeg2.h
index 2befaab275..118e63d804 100644
--- a/libavcodec/cbs_mpeg2.h
+++ b/libavcodec/cbs_mpeg2.h
@@ -212,6 +212,10 @@ typedef struct MPEG2RawSlice {
 AVBufferRef *data_ref;
 } MPEG2RawSlice;
 
+typedef struct MPEG2RawSequenceEnd {
+uint8_t sequence_end_code;
+} MPEG2RawSequenceEnd;
+
 
 typedef struct CodedBitstreamMPEG2Context {
 // Elements stored in headers which are required for other decoding.
diff --git a/libavcodec/cbs_mpeg2_syntax_template.c 
b/libavcodec/cbs_mpeg2_syntax_template.c
index e7332abe6e..5165a14cd5 100644
--- a/libavcodec/cbs_mpeg2_syntax_template.c
+++ b/libavcodec/cbs_mpeg2_syntax_template.c
@@ -411,3 +411,15 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, 
RWContext *rw,
 
 return 0;
 }
+
+static int FUNC(sequence_end)(CodedBitstreamContext *ctx, RWContext *rw,
+  MPEG2RawSequenceEnd *current)
+{
+int err;
+
+HEADER("Sequence End");
+
+ui(8, sequence_end_code);
+
+return 0;
+}
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 6/7] cbs_mpeg2: Remove zero byte stuffing

2019-07-29 Thread Andreas Rheinhardt
Remove superfluous trailing zeros from slices. Because MPEG-2 slices
can end with zero bits a safe number of trailing zero bits is always
kept.

More explicitly, 6 + max{f_code[i][1] - 1, i = 0,1, f_code[i][1] != 0xf}
is an upper bound for the number of possible trailing zeros that are
part of the slice. Here f_code[i][1] is the relevant value of the
picture coding extension the slice belongs to and the maximum of the
empty set is zero.
It is this number of trailing zero bits that is actually kept.

That this is really an upper bound can be seen as follows:

a) Every slice actually ends with a macroblock.

b) If the last macroblock of a slice ends with a block(i) structure
with pattern_code[i] != 0, then the slice ends with an "End of block"
VLC code (namely the "End of block" code of the last block with
pattern_code[i] != 0).
These codes are 10 and 0110, so that in this case there is exactly one
trailing zero bit.

c) Otherwise, all pattern_code[i] are zero. In this case,
if macroblock_pattern is set for the last macroblock of the slice, then
by the definition of pattern_code[i] in 6.3.17.4 cbp (derived
according to table B.9) must be zero and also the
coded_block_pattern_1/2 (if existing) must consist of zeros alone. The
value zero for cbp is coded by   1 so that the maximum number of
trailing zeros in this case is the length of coded_block_pattern_1/2 which
have a length of two resp. six bits. So six trailing zero bits at most.

d) Otherwise, if the slice actually ends with the marker bit of the
last macroblock, then there are certainly no trailing zero bits at
all.

e) Otherwise, if the slice ends with a motion_vectors(s) structure
(with s = 0 or 1 -- it doesn't matter which one), then it ends with a
motion_vector(r,s) (r, s = 0, 1 -- it doesn't matter) structure. This
structure ends with motion_code[r][s][1] (always existing) potentially
followed by motion_residual[r][s][1] and dmvector[1]. If dmvector[1]
exists, and contains a bit different from 0, there is at most one
trailing zero bit; if dmvector[1] consists of zeros alone, its length
is one according to B.11. motion_residual[r][s][1] (if it exists) has
a length of f_code[s][1] - 1 bits and can consist of zero bits alone.
Given that the value 0xf for f_code indicates that there is no motion
vector of the mentioned type, the length of motion_residual[r][s][1] is
bounded by max{f_code[i][1] - 1, i=1,2, f_code[i][1] != 0xf}. The
motion_code[r][s][1] can end with at most five zero bits (see B.10)
and always contains a bit set to one, so that in this case there are
at most 5 + max{f_code[i][1] - 1, i=1,2, f_code[i][1] != 0xf} + 1
zero trailing bits.

f) Otherwise, if the last macroblock of the slice ends with a
quantiser_scale_code, then there are at most four trailing zero bits,
because quantiser_scale_code has a length of five bits and must not
attain the value zero.

g) Otherwise, the last macroblock ends with the macroblock_modes
syntax structure. The potentially existing dct_type at the end might
be a zero bit; the frame/field_motion_type isn't present here, because
otherwise we would have a motion_vectors(i) (i = 0 or 1 or both) syntax
structure, so that e) (or b)-d)) would have applied.
spatial_temporal_weight_code might entirely consist of two zero bits.
The macroblock_type VLC code always contains a 1 bit and ends with two
zero bits at most (see B.2-B.8 for this), so we have maximally 2+2+1
trailing zero bits.

The fate test cbs-mpeg2-sony-ct3 had to be adapted because the input
file contains trailing zeros that were stripped away; the filesize is
reduced from 135 KB to 117 KB. Of course, decoding the smaller output
still produces the same frames.
Most of these savings happen in between slices rather than after the
last slice: The chomp bitstream filter can only reduce the filesize
by 50 bytes.

Signed-off-by: Andreas Rheinhardt 
---
The fate test result for cbs-mpeg2-sony-ct3 had to be modified compared
to the last patch because the sample ends with a sequence_end_code that
is preceded by several zero bytes. The earlier code thought that the
slice ended at the end of the packet (i.e. at the end of the
sequence_end_code) and therefore did not strip any of these zero bytes
between the last slice and the sequence_start_code away. The now code
does this.

 libavcodec/cbs_mpeg2.c| 30 --
 tests/ref/fate/cbs-mpeg2-sony-ct3 |  2 +-
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 596e9677b7..559793dc98 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -170,7 +170,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
*ctx,
 CodedBitstreamUnitType unit_type;
 uint32_t start_code = -1;
 size_t unit_size;
-int err, i, final = 0;
+int err, i, final = 0, max_trailing_bits = 15;
 
 start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
&

[FFmpeg-devel] [PATCH 7/7] cbs_mpeg2: Drop fragments containing zero-sized units

2019-07-29 Thread Andreas Rheinhardt
They are invalid and can be easily detected, so discard them.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs_mpeg2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 559793dc98..eb0e2c7ba9 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -207,6 +207,12 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
*ctx,
final = 1;
 }
 
+if (unit_size == 0) {
+// This can only happen if frag->data contained data like
+// 0x00 00 01 00 00 01 xy, which is treated as two start codes.
+return AVERROR_INVALIDDATA;
+}
+
 if (unit_type == MPEG2_START_EXTENSION && unit_size >= 4 &&
 start[1] >> 4 == MPEG2_EXTENSION_PICTURE_CODING) {
 // The values f_code[0][1], f_code[1][1] are used to derive
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 1/7] cbs: Don't set AVBuffer's opaque

2019-07-29 Thread Andreas Rheinhardt
cbs is currently inconsistent regarding the opaque field that can be
used as a special argument to av_buffer_create in order to be used
during freeing the buffer: ff_cbs_alloc_unit_content and all the free
functions used name this parameter as if it should contain a pointer to
the unit whose content is about to be created; but both
ff_cbs_alloc_unit_content as well as ff_cbs_h264_add_sei_message
actually use a pointer to the CodedBitstreamContext as opaque. It should
actually be neither, because it is unneeded (as is evidenced by the fact
that none of the free functions use this pointer at all) and because it
ties the unit's content to the lifetime of other objects, although a
refcounted buffer is supposed to have its own lifetime that only ends
when its reference count reaches zero. This problem manifests itself in
the pointer becoming dangling.
The pointer to the unit can become dangling if another unit is added to
the fragment later as happens in the bitstream filters; in this case,
the pointer can point to the wrong unit (if the fragment's unit array
needn't be relocated) or it can point to where the array was earlier.
It can also become dangling if the unit's content is meant to survive
the resetting of the fragment it was originally read with. This applies
to the extradata of H.264 and HEVC.
The pointer to the context can become dangling if the context is closed
before the content is freed. Although this doesn't seem to happen right
now, it could happen, in particular if one uses different
CodedBitstreamContexts for in- and output.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cbs.c   |  2 +-
 libavcodec/cbs.h   |  2 +-
 libavcodec/cbs_av1.c   |  2 +-
 libavcodec/cbs_h2645.c | 18 +-
 libavcodec/cbs_jpeg.c  |  6 +++---
 libavcodec/cbs_mpeg2.c |  6 +++---
 libavcodec/cbs_vp9.c   |  2 +-
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 2350416501..1a43cd2694 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -597,7 +597,7 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
 return AVERROR(ENOMEM);
 
 unit->content_ref = av_buffer_create(unit->content, size,
- free, ctx, 0);
+ free, NULL, 0);
 if (!unit->content_ref) {
 av_freep(&unit->content);
 return AVERROR(ENOMEM);
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index fe57e7b2a5..7c341bffe7 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -341,7 +341,7 @@ void ff_cbs_fragment_free(CodedBitstreamContext *ctx,
 int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
   CodedBitstreamUnit *unit,
   size_t size,
-  void (*free)(void *unit, uint8_t *content));
+  void (*free)(void *opaque, uint8_t *content));
 
 /**
  * Allocate a new internal data buffer of the given size in the unit.
diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 288ef8e14b..98cd37ef74 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -829,7 +829,7 @@ static void cbs_av1_free_metadata(AV1RawMetadata *md)
 }
 }
 
-static void cbs_av1_free_obu(void *unit, uint8_t *content)
+static void cbs_av1_free_obu(void *opaque, uint8_t *content)
 {
 AV1RawOBU *obu = (AV1RawOBU*)content;
 
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 0f697434e5..1c35be51e7 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -443,7 +443,7 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
 #undef allocate
 
 
-static void cbs_h264_free_pps(void *unit, uint8_t *content)
+static void cbs_h264_free_pps(void *opaque, uint8_t *content)
 {
 H264RawPPS *pps = (H264RawPPS*)content;
 av_buffer_unref(&pps->slice_group_id_ref);
@@ -473,7 +473,7 @@ static void cbs_h264_free_sei_payload(H264RawSEIPayload 
*payload)
 }
 }
 
-static void cbs_h264_free_sei(void *unit, uint8_t *content)
+static void cbs_h264_free_sei(void *opaque, uint8_t *content)
 {
 H264RawSEI *sei = (H264RawSEI*)content;
 int i;
@@ -482,35 +482,35 @@ static void cbs_h264_free_sei(void *unit, uint8_t 
*content)
 av_freep(&content);
 }
 
-static void cbs_h264_free_slice(void *unit, uint8_t *content)
+static void cbs_h264_free_slice(void *opaque, uint8_t *content)
 {
 H264RawSlice *slice = (H264RawSlice*)content;
 av_buffer_unref(&slice->data_ref);
 av_freep(&content);
 }
 
-static void cbs_h265_free_vps(void *unit, uint8_t *content)
+static void cbs_h265_free_vps(void *opaque, uint8_t *content)
 {
 H265RawVPS *vps = (H265RawVPS*)content;
 av_buffer_unref(&vps->extension_data.data_ref);
 av_freep(&content);
 }
 
-static void cbs_h265_free_sps(void *unit, uint8_t *content)
+static void cbs_h265_free_sps(void *opaque, uint8_t *content)
 {
 H265RawSPS *sps = (H265RawSPS*)content;
 av_buffer_unref(

Re: [FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-29 Thread Mark Thompson
On 29/07/2019 19:09, Juan De León wrote:
> Changes to libavcodec, hope this addresses all your comments.
> Cheers.

This doesn't belong in the commit message.

What does belong here would be some commentary on why you want this feature.

> Signed-off-by: Juan De León 
> ---
>  libavutil/Makefile  |   2 +
>  libavutil/frame.h   |   6 ++
>  libavutil/quantization_params.c |  41 
>  libavutil/quantization_params.h | 106 
>  4 files changed, 155 insertions(+)
>  create mode 100644 libavutil/quantization_params.c
>  create mode 100644 libavutil/quantization_params.h
> 
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 8a7a44e4b5..be5e5d831f 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -60,6 +60,7 @@ HEADERS = adler32.h 
> \
>pixdesc.h \
>pixelutils.h  \
>pixfmt.h  \
> +  quantization_params.o  
> \

Object file in the list of headers?

Also broken spacing - tabs are not allowed in C files.

>random_seed.h \
>rc4.h \
>rational.h\
> @@ -140,6 +141,7 @@ OBJS = adler32.o  
>   \
> parseutils.o \
> pixdesc.o\
> pixelutils.o \
> +   quantization_params.o\
> random_seed.o\
> rational.o   \
> reverse.o\
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 5d3231e7bb..d48ccf342f 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -179,6 +179,12 @@ enum AVFrameSideDataType {
>   * array element is implied by AVFrameSideData.size / 
> AVRegionOfInterest.self_size.
>   */
>  AV_FRAME_DATA_REGIONS_OF_INTEREST,
> +/**
> + * To extract quantization parameters from supported decoders.
> + * The data stored is AVQuantizationParamsArray type, described in
> + * libavuitls/quantization_params.h
> + */
> +AV_FRAME_DATA_QUANTIZATION_PARAMS,
>  };
>  
>  enum AVActiveFormatDescription {
> diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
> new file mode 100644
> index 00..28b08ebe19
> --- /dev/null
> +++ b/libavutil/quantization_params.c
> @@ -0,0 +1,41 @@
> +/*
> + * 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/quantization_params.h"
> +
> +static const char* const QP_NAMES_H264[] = {"qp"};
> +
> +static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
> +   "qiydc", "qiyac", "qiuvdc", 
> "qiuvac"};
> +
> +static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
> "qvdc", "qvac",
> +  "qiydc", "qiyac", "qiudc", "qiuac", 
> "qivdc", "qivac"};
> +
> +char* get_qp_str(enum AVCodecID codec_id, int index)

The values this function is returning are pointers to const char.

> +{
> +switch (codec_id) {
> +case AV_CODEC_ID_H264:
> +return QP_NAMES_H264[index];
> +case AV_CODEC_ID_VP9:
> +return QP_NAMES_VP9[index];
> +case AV_CODEC_ID_AV1:
> +return QP_NAMES_AV1[index];
> +default:
> +return NULL;
> +}
> +}
> diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
> new file mode 100644
> index 00..7a3daeaae5
> --- /dev/null
> +++ b/libavutil/quantization_params.h
> @@ -0,0 +1,106 @

Re: [FFmpeg-devel] [PATCH 2/4] avc/avcodec: add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag

2019-07-29 Thread Michael Niedermayer
On Mon, Jul 29, 2019 at 10:43:52PM +0800, Linjie Fu wrote:
> Add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag to indicate whether encoder
> supports variable dimension encoding.
> 
> Signed-off-by: Linjie Fu 
> ---
>  fftools/cmdutils.c   | 2 ++
>  libavcodec/avcodec.h | 5 +
>  libavcodec/rawenc.c  | 1 +
>  libavcodec/version.h | 2 +-
>  4 files changed, 9 insertions(+), 1 deletion(-)

Needs a update to APIchanges

thx

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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Thank you for the feedback Andrey, I will fix it ASAP.

On Mon, Jul 29, 2019 at 12:11 PM Andreas Håkon 
wrote:

> Interesting patch. But I have a question:
> Could you implement the same thing when using the hardware decoders?

I believe this might be in the scope of my project.
I'm not too familiar with hardware decoders but when I complete the rest of
the implementation I will take a look at this.


> And also, could you make a similar patch for MPEG-2 as well?

The scope was limited to H264, VP9 and AV1 but I will talk about it with my
team.
Again, thanks for the feedback.
___
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] libavcodec: add timer bitstream filter

2019-07-29 Thread Paul B Mahol
Documentation for bsf does document single option, thus is incomplete.

On Mon, Jul 29, 2019 at 9:14 PM Andreas Håkon 
wrote:

> Ping
>
> ‐‐‐ Original Message ‐‐‐
> On Wednesday, 24 de July de 2019 9:16, Andreas Håkon <
> andreas.ha...@protonmail.com> wrote:
>
> > Hi,
> >
> > ‐‐‐ Original Message ‐‐‐
> > On Friday, 28 de June de 2019 10:44, Andreas Håkon <
> andreas.ha...@protonmail.com> wrote:
> >
> >> Hi,
> >> This is a refined version of the initial version for the new “timer”
> BSF.
> >> Supersedes: https://patchwork.ffmpeg.org/patch/13699/
> >
> > Still waiting to receive comments (or acceptance).
> >
> > Regards.
> > A.H.
> >
> > ---
> ___
> 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] libavcodec: add timer bitstream filter

2019-07-29 Thread Andreas Håkon
Ping

‐‐‐ Original Message ‐‐‐
On Wednesday, 24 de July de 2019 9:16, Andreas Håkon 
 wrote:

> Hi,
>
> ‐‐‐ Original Message ‐‐‐
> On Friday, 28 de June de 2019 10:44, Andreas Håkon 
>  wrote:
>
>> Hi,
>> This is a refined version of the initial version for the new “timer” BSF.
>> Supersedes: https://patchwork.ffmpeg.org/patch/13699/
>
> Still waiting to receive comments (or acceptance).
>
> Regards.
> A.H.
>
> ---
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Andreas Håkon
Hi Juan,


‐‐‐ Original Message ‐‐‐
On Monday, 29 de July de 2019 20:12, Juan De León 
 wrote:

> Here is the second patch, I sent the first one twice accidentaly.
> First patch is libavutil, this patch is libavcodec.
>

Interesting patch. But I have a question:
Could you implement the same thing when using the hardware decoders?

And also, could you make a similar patch for MPEG-2 as well?

Regards.
A.H.

---

___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Andrey Semashev

Just a few random comments. Disclaimer: I'm not a maintainer.

On 7/29/19 9:09 PM, Juan De León wrote:

Changes to libavcodec, hope this addresses all your comments.
Cheers.

Signed-off-by: Juan De León 
---
  libavutil/Makefile  |   2 +
  libavutil/frame.h   |   6 ++
  libavutil/quantization_params.c |  41 
  libavutil/quantization_params.h | 106 
  4 files changed, 155 insertions(+)
  create mode 100644 libavutil/quantization_params.c
  create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be5e5d831f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
pixdesc.h \
pixelutils.h  \
pixfmt.h  \
+  quantization_params.o
\


.h?


random_seed.h \
rc4.h \
rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
 parseutils.o \
 pixdesc.o\
 pixelutils.o \
+   quantization_params.o\
 random_seed.o\
 rational.o   \
 reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..d48ccf342f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
   * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
   */
  AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data stored is AVQuantizationParamsArray type, described in


The data is stored as AVQuantizationParamsArray, described...


+ * libavuitls/quantization_params.h


libavutil


+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
  };
  
  enum AVActiveFormatDescription {

diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..28b08ebe19
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp"};
+
+static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
+   "qiydc", "qiyac", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", "qvdc", 
"qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", "qivdc", 
"qivac"};
+
+char* get_qp_str(enum AVCodecID codec_id, int index)
+{
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+return QP_NAMES_H264[index];
+case AV_CODEC_ID_VP9:
+return QP_NAMES_VP9[index];
+case AV_CODEC_ID_AV1:
+return QP_NAMES_AV1[index];
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..7a3daeaae5
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,106 @@
+/*
+ * 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 distr

Re: [FFmpeg-devel] [PATCH 1/2] cbs_h264: Fix missing inferred colour description fields

2019-07-29 Thread Mark Thompson
On 29/07/2019 00:31, Andreas Rheinhardt wrote:
> Mark Thompson:
>> With video_signal_type_present_flag set but colour_description_present_flag
>> unset the colour fields would not have had their correct values inferred.
>> ---
>>  libavcodec/cbs_h264_syntax_template.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/libavcodec/cbs_h264_syntax_template.c 
>> b/libavcodec/cbs_h264_syntax_template.c
>> index 26be6e590f..1671a15d33 100644
>> --- a/libavcodec/cbs_h264_syntax_template.c
>> +++ b/libavcodec/cbs_h264_syntax_template.c
>> @@ -137,6 +137,10 @@ static int FUNC(vui_parameters)(CodedBitstreamContext 
>> *ctx, RWContext *rw,
>>  ub(8, colour_primaries);
>>  ub(8, transfer_characteristics);
>>  ub(8, matrix_coefficients);
>> +} else {
>> +infer(colour_primaries, 2);
>> +infer(transfer_characteristics, 2);
>> +infer(matrix_coefficients,  2);
>>  }
>>  } else {
>>  infer(video_format, 5);
>>
> LGTM. And sorry for not catching this before 43a18884.

Both patches applied.

Thank you!

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

Re: [FFmpeg-devel] [PATCH] avcodec/arm/sbcenc: save callee preserved vfp registers

2019-07-29 Thread Reimar Döffinger
Seems sensible to me, though extra points if you or someone has numbers on 
performance impact.
To know whether it would be worthwhile to check if it can be optimized...

On 28.07.2019, at 23:46, James Cowgill  wrote:

> When compiling FFmpeg with GCC-9, some very random segfaults were
> observed in code which had previously called down into the SBC encoder
> NEON assembly routines. This was caused by these functions clobbering
> some of the vfp callee saved registers (d8 - d15 aka q4 - q7). GCC was
> using these registers to save local variables, but after these
> functions returned, they would contain garbage.
> 
> Fix by saving the relevant registers on the stack in the affected
> functions.
> 
> Signed-off-by: James Cowgill 
> ---
> libavcodec/arm/sbcdsp_neon.S | 6 ++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/arm/sbcdsp_neon.S b/libavcodec/arm/sbcdsp_neon.S
> index d83d21d202..aa03800096 100644
> --- a/libavcodec/arm/sbcdsp_neon.S
> +++ b/libavcodec/arm/sbcdsp_neon.S
> @@ -38,6 +38,8 @@ function ff_sbc_analyze_4_neon, export=1
> /* TODO: merge even and odd cases (or even merge all four calls to 
> this
>  * function) in order to have only aligned reads from 'in' array
>  * and reduce number of load instructions */
> +vpush   {d8-d11}
> +
> vld1.16 {d4, d5}, [r0, :64]!
> vld1.16 {d8, d9}, [r2, :128]!
> 
> @@ -84,6 +86,7 @@ function ff_sbc_analyze_4_neon, export=1
> 
> vst1.32 {d0, d1}, [r1, :128]
> 
> +vpop{d8-d11}
> bx  lr
> endfunc
> 
> @@ -91,6 +94,8 @@ function ff_sbc_analyze_8_neon, export=1
> /* TODO: merge even and odd cases (or even merge all four calls to 
> this
>  * function) in order to have only aligned reads from 'in' array
>  * and reduce number of load instructions */
> +vpush   {d8-d15}
> +
> vld1.16 {d4, d5}, [r0, :64]!
> vld1.16 {d8, d9}, [r2, :128]!
> 
> @@ -188,6 +193,7 @@ function ff_sbc_analyze_8_neon, export=1
> 
> vst1.32 {d0, d1, d2, d3}, [r1, :128]
> 
> +vpop{d8-d15}
> bx  lr
> endfunc
> 
> -- 
> 2.22.0
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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] avutil/mips: Avoid instruction exception caused by gssqc1/gslqc1.

2019-07-29 Thread Reimar Döffinger


On 29.07.2019, at 11:54, "Shiyou Yin"  wrote:
>> 
> DECLARE_ALIGNED is defined in ' libavutil/mem.h ' and related to compiler. No 
> matter mips or x86,
> it's definition is ' #define DECLARE_ALIGNED(n,t,v)  t __attribute__ 
> ((aligned (n))) v' when build 
> with gcc or clang (Specific implementation within the compiler is not 
> considered here.).
> In libavcodec/x86, DECLARE_ALIGNED is used to define 8/16/32-byte aligned 
> variable too.

The aligned attribute does not work reliably with stack variables in some cases.
Compare with other code, I think you need to use LOCAL_ALIGNED_16 for the stack 
variable.
Yes, it might work in your test even with DECLARE_ALIGNED, but it might not be 
robust.
___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 
 libavutil/quantization_params.h | 106 
 4 files changed, 155 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be5e5d831f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.o
\
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..d48ccf342f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data stored is AVQuantizationParamsArray type, described in
+ * libavuitls/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..28b08ebe19
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp"};
+
+static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
+   "qiydc", "qiyac", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* get_qp_str(enum AVCodecID codec_id, int index)
+{
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+return QP_NAMES_H264[index];
+case AV_CODEC_ID_VP9:
+return QP_NAMES_VP9[index];
+case AV_CODEC_ID_AV1:
+return QP_NAMES_AV1[index];
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..7a3daeaae5
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,106 @@
+/*
+ * 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 

[FFmpeg-devel] [PATCH] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Here is the second patch, I sent the first one twice accidentaly. 
First patch is libavutil, this patch is libavcodec.

Signed-off-by: Juan De León 
---
 libavcodec/avcodec.h   |  1 +
 libavcodec/h264dec.c   | 44 ++
 libavcodec/options_table.h |  1 +
 3 files changed, 46 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271c5b..9e3185720a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2671,6 +2671,7 @@ typedef struct AVCodecContext {
 #endif
 #define FF_DEBUG_BUFFERS 0x8000
 #define FF_DEBUG_THREADS 0x0001
+#define FF_DEBUG_EXTRACTQP   0x0002
 #define FF_DEBUG_GREEN_MD0x0080
 #define FF_DEBUG_NOMC0x0100
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8d1bd16a8e..52ad12e55d 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -33,6 +33,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timer.h"
+#include "libavutil/quantization_params.h"
 #include "internal.h"
 #include "bytestream.h"
 #include "cabac.h"
@@ -922,6 +923,49 @@ static int finalize_frame(H264Context *h, AVFrame *dst, 
H264Picture *out, int *g
 }
 }
 
+if (h->avctx->debug & FF_DEBUG_EXTRACTQP) {
+int mb_height = h->height / 16;
+int mb_width = h->width / 16;
+int mb_xy = mb_width * mb_height;
+
+int buf_size = sizeof(AVQuantizationParamsArray) +
+   mb_xy * sizeof(AVQuantizationParams);
+AVBufferRef *buffer = av_buffer_alloc(buf_size);
+if (!buffer) {
+return AVERROR(ENOMEM);
+}
+
+AVQuantizationParamsArray *params = (AVQuantizationParamsArray 
*)buffer->data;
+params->nb_blocks = mb_xy;
+params->codec_id = h->avctx->codec_id;
+// offset memory for qp_arr in same buffer
+params->qp_arr = (AVQuantizationParams*) (params + 1);
+
+// loop allocate qp
+int qp_index = 0;
+for (int mb_y = 0; mb_y < mb_height; mb_y++) {
+for (int mb_x = 0; mb_x < mb_width; mb_x++) {
+int qs_index = mb_x + mb_y * h->mb_stride;
+AVQuantizationParams *qp_block = &(params->qp_arr[qp_index]);
+
+qp_block->x = mb_x * 16;
+qp_block->y = mb_y * 16;
+qp_block->w = qp_block->h = 16;
+qp_block->type[QP_H264] = out->qscale_table[qs_index];
+
+qp_index++;
+}
+}
+
+AVFrameSideData *sd;
+sd = av_frame_new_side_data_from_buf(dst,
+ AV_FRAME_DATA_QUANTIZATION_PARAMS,
+ buffer);
+if (!sd) {
+return AVERROR(ENOMEM);
+}
+}
+
 return 0;
 }
 
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4a266eca16..e0e78a69c5 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -219,6 +219,7 @@ static const AVOption avcodec_options[] = {
 {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"},
 {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"},
 {"nomc", "skip motion compensation", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_NOMC }, INT_MIN, INT_MAX, V|A|D, "debug"},
+{"extractqp", "enable QP extraction per frame", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_DEBUG_EXTRACTQP }, INT_MIN, INT_MAX, V|D, "debug"},
 {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), 
AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 {"last_pred", "amount of motion predictors from the previous frame", 
OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, 
INT_MAX, V|E},
 #if FF_API_PRIVATE_OPT
-- 
2.22.0.709.g102302147b-goog

___
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] Extract QP from h264 encoded videos

2019-07-29 Thread Juan De León
Changes to libavcodec, hope this addresses all your comments.
Cheers.

Signed-off-by: Juan De León 
---
 libavutil/Makefile  |   2 +
 libavutil/frame.h   |   6 ++
 libavutil/quantization_params.c |  41 
 libavutil/quantization_params.h | 106 
 4 files changed, 155 insertions(+)
 create mode 100644 libavutil/quantization_params.c
 create mode 100644 libavutil/quantization_params.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8a7a44e4b5..be5e5d831f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -60,6 +60,7 @@ HEADERS = adler32.h   
  \
   pixdesc.h \
   pixelutils.h  \
   pixfmt.h  \
+  quantization_params.o
\
   random_seed.h \
   rc4.h \
   rational.h\
@@ -140,6 +141,7 @@ OBJS = adler32.o
\
parseutils.o \
pixdesc.o\
pixelutils.o \
+   quantization_params.o\
random_seed.o\
rational.o   \
reverse.o\
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..d48ccf342f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,12 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+/**
+ * To extract quantization parameters from supported decoders.
+ * The data stored is AVQuantizationParamsArray type, described in
+ * libavuitls/quantization_params.h
+ */
+AV_FRAME_DATA_QUANTIZATION_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/quantization_params.c b/libavutil/quantization_params.c
new file mode 100644
index 00..28b08ebe19
--- /dev/null
+++ b/libavutil/quantization_params.c
@@ -0,0 +1,41 @@
+/*
+ * 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/quantization_params.h"
+
+static const char* const QP_NAMES_H264[] = {"qp"};
+
+static const char* const QP_NAMES_VP9[] = {"qydc", "qyac", "quvdc", "quvac",
+   "qiydc", "qiyac", "qiuvdc", 
"qiuvac"};
+
+static const char* const QP_NAMES_AV1[] = {"qydc", "qyac", "qudc", "quac", 
"qvdc", "qvac",
+  "qiydc", "qiyac", "qiudc", "qiuac", 
"qivdc", "qivac"};
+
+char* get_qp_str(enum AVCodecID codec_id, int index)
+{
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+return QP_NAMES_H264[index];
+case AV_CODEC_ID_VP9:
+return QP_NAMES_VP9[index];
+case AV_CODEC_ID_AV1:
+return QP_NAMES_AV1[index];
+default:
+return NULL;
+}
+}
diff --git a/libavutil/quantization_params.h b/libavutil/quantization_params.h
new file mode 100644
index 00..7a3daeaae5
--- /dev/null
+++ b/libavutil/quantization_params.h
@@ -0,0 +1,106 @@
+/*
+ * 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 m

Re: [FFmpeg-devel] [PATCH 2/3] avcodec/eatqi: Check for minimum frame size

2019-07-29 Thread Michael Niedermayer
On Mon, Jul 29, 2019 at 08:47:07AM +0200, Paul B Mahol wrote:
> LGTM

will apply

thanks

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

Re: [FFmpeg-devel] [PATCH 1/3] avcodec/eatgv: Check remaining size after the keyframe header

2019-07-29 Thread Michael Niedermayer
On Mon, Jul 29, 2019 at 08:49:40AM +0200, Paul B Mahol wrote:
> Actually remove log message completely. 

ok, will apply with that change


> It is invalid because it is warning
> while you return error immediately.

Thats true for most of the error messages in the file.

Thanks

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

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data


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 3/4] fftools/ffmpeg: support variable dimension encode

2019-07-29 Thread James Almer
On 7/29/2019 11:44 AM, Linjie Fu wrote:
> Flush encoders when dimension change happens, reset draining to resume
> encode.
> 
> If encoder doesn't support variable dimension, stop encoding and
> report errors.
> 
> Signed-off-by: Linjie Fu 
> ---
>  fftools/ffmpeg.c| 13 +
>  libavcodec/encode.c |  4 
>  2 files changed, 17 insertions(+)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 5d52430..8ceeaaa 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -130,6 +130,7 @@ static void do_video_stats(OutputStream *ost, int 
> frame_size);
>  static BenchmarkTimeStamps get_benchmark_time_stamps(void);
>  static int64_t getmaxrss(void);
>  static int ifilter_has_all_input_formats(FilterGraph *fg);
> +static void flush_encoders(void);
>  
>  static int run_as_daemon  = 0;
>  static int nb_frames_dup = 0;
> @@ -1067,6 +1068,18 @@ static void do_video_out(OutputFile *of,
>  InputStream *ist = NULL;
>  AVFilterContext *filter = ost->filter->filter;
>  
> +/* flush encoders in dynamic resolution encode */
> +if (next_picture && (enc->width != next_picture->width ||
> + enc->height != next_picture->height)) {
> +flush_encoders();
> +
> +if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
> +av_log(NULL, AV_LOG_ERROR, "Dynamic resolution encode "
> +"is not supported by %s.\n", enc->codec->name);
> +goto error;
> +}
> +}
> +
>  if (ost->source_index >= 0)
>  ist = input_streams[ost->source_index];
>  
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index d12c425..9303bc9 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -389,6 +389,10 @@ int attribute_align_arg 
> avcodec_send_frame(AVCodecContext *avctx, const AVFrame
>  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
>  return AVERROR(EINVAL);
>  
> +/* reset draining when encoder is flushed in variable dimensions 
> encoding */
> +if (frame)
> +avctx->internal->draining = 0;

This is an API change that can break some workflows.

avcodec_flush_buffers() is the public function meant to flush an
AVCodecContext.

> +
>  if (avctx->internal->draining)
>  return AVERROR_EOF;
>  
> 

___
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/cfhd: add bayer support

2019-07-29 Thread Paul B Mahol
On Mon, Jul 29, 2019 at 6:22 PM Carl Eugen Hoyos  wrote:

> Am Mo., 29. Juli 2019 um 18:07 Uhr schrieb Paul B Mahol  >:
> >
> > On Mon, Jul 29, 2019 at 6:05 PM Carl Eugen Hoyos 
> wrote:
> >
> > > Am Mo., 29. Juli 2019 um 16:35 Uhr schrieb Paul B Mahol <
> g...@videolan.org
> > > >:
> > >
> > > > +static inline void process_bayer(AVFrame *frame)
> > > > +{
> > > > +const int linesize = frame->linesize[0];
> > > > +uint16_t *r = (uint16_t *)frame->data[0];
> > > > +uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
> > > > +uint16_t *g2 = (uint16_t *)(frame->data[0] +
> frame->linesize[0]);
> > > > +uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0]
> + 2);
> > > > +const int mid = 2048;
> > > > +
> > > > +for (int y = 0; y < frame->height >> 1; y++) {
> > > > +for (int x = 0; x < frame->width; x += 2) {
> > > > +int R, G1, G2, B;
> > > > +int g, rg, bg, gd;
> > > > +
> > > > +g  = r[x];
> > > > +rg = g1[x];
> > > > +bg = g2[x];
> > > > +gd = b[x];
> > > > +gd -= mid;
> > > > +
> > > > +R  = (rg - mid) * 2 + g;
> > > > +G1 = g + gd;
> > > > +G2 = g - gd;
> > > > +B  = (bg - mid) * 2 + g;
> > > > +
> > > > +R  = av_clip_uintp2(R  * 16, 16);
> > > > +G1 = av_clip_uintp2(G1 * 16, 16);
> > > > +G2 = av_clip_uintp2(G2 * 16, 16);
> > > > +B  = av_clip_uintp2(B  * 16, 16);
> > > > +
> > > > +r[x]  = R;
> > > > +g1[x] = G1;
> > > > +g2[x] = G2;
> > > > +b[x]  = B;
> > >
> > > Doesn't this mean you have to disable direct rendering?
> > >
> >
> > Nope. Do you even know what is DR for?
>
> The way I remembered was that there are access limitations for
> direct rendering.


There are bunch of decoders accessing frame->data[] multiple times.
So I think you picked meaning of DR from old mplayer days.
___
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/cfhd: add bayer support

2019-07-29 Thread Carl Eugen Hoyos
Am Mo., 29. Juli 2019 um 18:07 Uhr schrieb Paul B Mahol :
>
> On Mon, Jul 29, 2019 at 6:05 PM Carl Eugen Hoyos  wrote:
>
> > Am Mo., 29. Juli 2019 um 16:35 Uhr schrieb Paul B Mahol  > >:
> >
> > > +static inline void process_bayer(AVFrame *frame)
> > > +{
> > > +const int linesize = frame->linesize[0];
> > > +uint16_t *r = (uint16_t *)frame->data[0];
> > > +uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
> > > +uint16_t *g2 = (uint16_t *)(frame->data[0] + frame->linesize[0]);
> > > +uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0] + 2);
> > > +const int mid = 2048;
> > > +
> > > +for (int y = 0; y < frame->height >> 1; y++) {
> > > +for (int x = 0; x < frame->width; x += 2) {
> > > +int R, G1, G2, B;
> > > +int g, rg, bg, gd;
> > > +
> > > +g  = r[x];
> > > +rg = g1[x];
> > > +bg = g2[x];
> > > +gd = b[x];
> > > +gd -= mid;
> > > +
> > > +R  = (rg - mid) * 2 + g;
> > > +G1 = g + gd;
> > > +G2 = g - gd;
> > > +B  = (bg - mid) * 2 + g;
> > > +
> > > +R  = av_clip_uintp2(R  * 16, 16);
> > > +G1 = av_clip_uintp2(G1 * 16, 16);
> > > +G2 = av_clip_uintp2(G2 * 16, 16);
> > > +B  = av_clip_uintp2(B  * 16, 16);
> > > +
> > > +r[x]  = R;
> > > +g1[x] = G1;
> > > +g2[x] = G2;
> > > +b[x]  = B;
> >
> > Doesn't this mean you have to disable direct rendering?
> >
>
> Nope. Do you even know what is DR for?

The way I remembered was that there are access limitations for
direct rendering.

Carl Eugen
___
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/cfhd: add bayer support

2019-07-29 Thread Paul B Mahol
On Mon, Jul 29, 2019 at 6:05 PM Carl Eugen Hoyos  wrote:

> Am Mo., 29. Juli 2019 um 16:35 Uhr schrieb Paul B Mahol  >:
>
> > +static inline void process_bayer(AVFrame *frame)
> > +{
> > +const int linesize = frame->linesize[0];
> > +uint16_t *r = (uint16_t *)frame->data[0];
> > +uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
> > +uint16_t *g2 = (uint16_t *)(frame->data[0] + frame->linesize[0]);
> > +uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0] + 2);
> > +const int mid = 2048;
> > +
> > +for (int y = 0; y < frame->height >> 1; y++) {
> > +for (int x = 0; x < frame->width; x += 2) {
> > +int R, G1, G2, B;
> > +int g, rg, bg, gd;
> > +
> > +g  = r[x];
> > +rg = g1[x];
> > +bg = g2[x];
> > +gd = b[x];
> > +gd -= mid;
> > +
> > +R  = (rg - mid) * 2 + g;
> > +G1 = g + gd;
> > +G2 = g - gd;
> > +B  = (bg - mid) * 2 + g;
> > +
> > +R  = av_clip_uintp2(R  * 16, 16);
> > +G1 = av_clip_uintp2(G1 * 16, 16);
> > +G2 = av_clip_uintp2(G2 * 16, 16);
> > +B  = av_clip_uintp2(B  * 16, 16);
> > +
> > +r[x]  = R;
> > +g1[x] = G1;
> > +g2[x] = G2;
> > +b[x]  = B;
>
> Doesn't this mean you have to disable direct rendering?
>

Nope. Do you even know what is DR for?
___
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/cfhd: add bayer support

2019-07-29 Thread Carl Eugen Hoyos
Am Mo., 29. Juli 2019 um 16:35 Uhr schrieb Paul B Mahol :

> +static inline void process_bayer(AVFrame *frame)
> +{
> +const int linesize = frame->linesize[0];
> +uint16_t *r = (uint16_t *)frame->data[0];
> +uint16_t *g1 = (uint16_t *)(frame->data[0] + 2);
> +uint16_t *g2 = (uint16_t *)(frame->data[0] + frame->linesize[0]);
> +uint16_t *b = (uint16_t *)(frame->data[0] + frame->linesize[0] + 2);
> +const int mid = 2048;
> +
> +for (int y = 0; y < frame->height >> 1; y++) {
> +for (int x = 0; x < frame->width; x += 2) {
> +int R, G1, G2, B;
> +int g, rg, bg, gd;
> +
> +g  = r[x];
> +rg = g1[x];
> +bg = g2[x];
> +gd = b[x];
> +gd -= mid;
> +
> +R  = (rg - mid) * 2 + g;
> +G1 = g + gd;
> +G2 = g - gd;
> +B  = (bg - mid) * 2 + g;
> +
> +R  = av_clip_uintp2(R  * 16, 16);
> +G1 = av_clip_uintp2(G1 * 16, 16);
> +G2 = av_clip_uintp2(G2 * 16, 16);
> +B  = av_clip_uintp2(B  * 16, 16);
> +
> +r[x]  = R;
> +g1[x] = G1;
> +g2[x] = G2;
> +b[x]  = B;

Doesn't this mean you have to disable direct rendering?

Carl Eugen
___
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 1/3] dnn: add layer pad which is equivalent to tf.pad

2019-07-29 Thread Pedro Arthur
LGTM.
Pushed, thanks!

Em dom, 28 de jul de 2019 às 22:59, Guo, Yejun  escreveu:
>
> the reason to add this layer first is that vf_sr uses it in its
> tensorflow model, and the next plan is to update the python script
> to convert tf.pad into native model.
>
> Signed-off-by: Guo, Yejun 
> ---
>  libavfilter/dnn/Makefile   |   1 +
>  libavfilter/dnn/dnn_backend_native_layer_pad.c | 211 
> +
>  libavfilter/dnn/dnn_backend_native_layer_pad.h |  40 +
>  3 files changed, 252 insertions(+)
>  create mode 100644 libavfilter/dnn/dnn_backend_native_layer_pad.c
>  create mode 100644 libavfilter/dnn/dnn_backend_native_layer_pad.h
>
> diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
> index 1d12ade..83938e5 100644
> --- a/libavfilter/dnn/Makefile
> +++ b/libavfilter/dnn/Makefile
> @@ -1,5 +1,6 @@
>  OBJS-$(CONFIG_DNN)   += dnn/dnn_interface.o
>  OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
> +OBJS-$(CONFIG_DNN)   += 
> dnn/dnn_backend_native_layer_pad.o
>
>  DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn/dnn_backend_tf.o
>
> diff --git a/libavfilter/dnn/dnn_backend_native_layer_pad.c 
> b/libavfilter/dnn/dnn_backend_native_layer_pad.c
> new file mode 100644
> index 000..5417d73
> --- /dev/null
> +++ b/libavfilter/dnn/dnn_backend_native_layer_pad.c
> @@ -0,0 +1,211 @@
> +/*
> + * Copyright (c) 2019 Guo Yejun
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include 
> +#include "libavutil/avassert.h"
> +#include "dnn_backend_native_layer_pad.h"
> +
> +static int before_get_buddy(int given, int paddings, LayerPadModeParam mode)
> +{
> +if (mode == LPMP_SYMMETRIC) {
> +return (2 * paddings - 1 - given);
> +} else if (mode == LPMP_REFLECT) {
> +return (2 * paddings - given);
> +} else {
> +av_assert0(!"should not reach here");
> +return 0;
> +}
> +}
> +
> +static int after_get_buddy(int given, int border, LayerPadModeParam mode)
> +{
> +if (mode == LPMP_SYMMETRIC) {
> +int offset = given - border;
> +return (border - 1 - offset);
> +} else if (mode == LPMP_REFLECT) {
> +int offset = given - border;
> +return (border - 2 - offset);
> +} else {
> +av_assert0(!"should not reach here");
> +return 0;
> +}
> +}
> +
> +void dnn_execute_layer_pad(const float *input, float *output, const 
> LayerPadParams *params, int number, int height, int width, int channel)
> +{
> +int32_t before_paddings;
> +int32_t after_paddings;
> +
> +// suppose format is 
> +int new_number = number + params->paddings[0][0] + 
> params->paddings[0][1];
> +int new_height = height + params->paddings[1][0] + 
> params->paddings[1][1];
> +int new_width = width + params->paddings[2][0] + params->paddings[2][1];
> +int new_channel = channel + params->paddings[3][0] + 
> params->paddings[3][1];
> +
> +int c_stride = channel;
> +int wc_stride = c_stride * width;
> +int hwc_stride = wc_stride * height;
> +
> +int new_c_stride = new_channel;
> +int new_wc_stride = new_c_stride * new_width;
> +int new_hwc_stride = new_wc_stride * new_height;
> +
> +// copy the original data
> +for (int n = 0; n < number; n++) {
> +for (int h = 0; h < height; h++) {
> +for (int w = 0; w < width; w++) {
> +const float *src = input + n * hwc_stride + h * wc_stride + 
> w * c_stride;
> +float *dst = output + (n + params->paddings[0][0]) * 
> new_hwc_stride
> ++ (h + params->paddings[1][0]) * 
> new_wc_stride
> ++ (w + params->paddings[2][0]) * 
> new_c_stride
> ++ params->paddings[3][0];
> +memcpy(dst, src, channel * sizeof(float));
> +}
> +}
> +}
> +
> +// handle the first dimension
> +before_paddings = params->paddings[0][0];
> +after_paddings = params->paddings[0][1];
> +for (int n = 0; n < before_paddings; n++) {
> +float *dst = output + n * new_hwc_stride;
> +if (params->mode == 

Re: [FFmpeg-devel] [PATCH V2 3/3] dnn: convert tf.pad to native model in python script, and load/execute it in the c code.

2019-07-29 Thread Pedro Arthur
LGTM.
Pushed, thanks!

Em dom, 28 de jul de 2019 às 23:00, Guo, Yejun  escreveu:
>
> since tf.pad is enabled, the conv2d(valid) changes back to its original 
> behavior.
>
> Signed-off-by: Guo, Yejun 
> ---
>  libavfilter/dnn/dnn_backend_native.c| 35 
> +
>  libavfilter/dnn/dnn_backend_native.h|  2 +-
>  tools/python/convert_from_tensorflow.py | 23 +-
>  3 files changed, 54 insertions(+), 6 deletions(-)
>
> diff --git a/libavfilter/dnn/dnn_backend_native.c 
> b/libavfilter/dnn/dnn_backend_native.c
> index 82e900b..09c583b 100644
> --- a/libavfilter/dnn/dnn_backend_native.c
> +++ b/libavfilter/dnn/dnn_backend_native.c
> @@ -25,6 +25,7 @@
>
>  #include "dnn_backend_native.h"
>  #include "libavutil/avassert.h"
> +#include "dnn_backend_native_layer_pad.h"
>
>  static DNNReturnType set_input_output_native(void *model, DNNInputData 
> *input, const char *input_name, const char **output_names, uint32_t nb_output)
>  {
> @@ -32,6 +33,7 @@ static DNNReturnType set_input_output_native(void *model, 
> DNNInputData *input, c
>  InputParams *input_params;
>  ConvolutionalParams *conv_params;
>  DepthToSpaceParams *depth_to_space_params;
> +LayerPadParams *pad_params;
>  int cur_width, cur_height, cur_channels;
>  int32_t layer;
>
> @@ -77,6 +79,12 @@ static DNNReturnType set_input_output_native(void *model, 
> DNNInputData *input, c
>  cur_height *= depth_to_space_params->block_size;
>  cur_width *= depth_to_space_params->block_size;
>  break;
> +case MIRROR_PAD:
> +pad_params = (LayerPadParams *)network->layers[layer].params;
> +cur_height = cur_height + pad_params->paddings[1][0] + 
> pad_params->paddings[1][1];
> +cur_width = cur_width + pad_params->paddings[2][0] + 
> pad_params->paddings[2][1];
> +cur_channels = cur_channels + pad_params->paddings[3][0] + 
> pad_params->paddings[3][1];
> +break;
>  default:
>  return DNN_ERROR;
>  }
> @@ -110,6 +118,7 @@ DNNModel *ff_dnn_load_model_native(const char 
> *model_filename)
>  DNNLayerType layer_type;
>  ConvolutionalParams *conv_params;
>  DepthToSpaceParams *depth_to_space_params;
> +LayerPadParams *pad_params;
>
>  model = av_malloc(sizeof(DNNModel));
>  if (!model){
> @@ -207,6 +216,23 @@ DNNModel *ff_dnn_load_model_native(const char 
> *model_filename)
>  network->layers[layer].type = DEPTH_TO_SPACE;
>  network->layers[layer].params = depth_to_space_params;
>  break;
> +case MIRROR_PAD:
> +pad_params = av_malloc(sizeof(LayerPadParams));
> +if (!pad_params){
> +avio_closep(&model_file_context);
> +ff_dnn_free_model_native(&model);
> +return NULL;
> +}
> +pad_params->mode = (int32_t)avio_rl32(model_file_context);
> +dnn_size += 4;
> +for (i = 0; i < 4; ++i) {
> +pad_params->paddings[i][0] = avio_rl32(model_file_context);
> +pad_params->paddings[i][1] = avio_rl32(model_file_context);
> +dnn_size += 8;
> +}
> +network->layers[layer].type = MIRROR_PAD;
> +network->layers[layer].params = pad_params;
> +break;
>  default:
>  avio_closep(&model_file_context);
>  ff_dnn_free_model_native(&model);
> @@ -314,6 +340,7 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel 
> *model, DNNData *output
>  InputParams *input_params;
>  ConvolutionalParams *conv_params;
>  DepthToSpaceParams *depth_to_space_params;
> +LayerPadParams *pad_params;
>
>  if (network->layers_num <= 0 || network->layers[0].type != INPUT || 
> !network->layers[0].output){
>  return DNN_ERROR;
> @@ -348,6 +375,14 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel 
> *model, DNNData *output
>  cur_width *= depth_to_space_params->block_size;
>  cur_channels /= depth_to_space_params->block_size * 
> depth_to_space_params->block_size;
>  break;
> +case MIRROR_PAD:
> +pad_params = (LayerPadParams *)network->layers[layer].params;
> +dnn_execute_layer_pad(network->layers[layer - 1].output, 
> network->layers[layer].output,
> +  pad_params, 1, cur_height, cur_width, 
> cur_channels);
> +cur_height = cur_height + pad_params->paddings[1][0] + 
> pad_params->paddings[1][1];
> +cur_width = cur_width + pad_params->paddings[2][0] + 
> pad_params->paddings[2][1];
> +cur_channels = cur_channels + pad_params->paddings[3][0] + 
> pad_params->paddings[3][1];
> +break;
>  case INPUT:
>  return DNN_ERROR;
>  }
> diff --git a/libavfilter/dnn/dnn_backend_native.h 
> b/libavfilter/dnn/dnn_backe

Re: [FFmpeg-devel] [PATCH V2 2/3] fate: add unit test for dnn-layer-pad

2019-07-29 Thread Pedro Arthur
LGTM.
Pushed, thanks!

Em dom, 28 de jul de 2019 às 22:59, Guo, Yejun  escreveu:
>
> 'make fate-dnn-layer-pad' to run the test
>
> Signed-off-by: Guo, Yejun 
> ---
>  tests/Makefile |   5 +-
>  tests/dnn/Makefile |  11 +++
>  tests/dnn/dnn-layer-pad-test.c | 203 
> +
>  tests/fate/dnn.mak |   8 ++
>  4 files changed, 226 insertions(+), 1 deletion(-)
>  create mode 100644 tests/dnn/Makefile
>  create mode 100644 tests/dnn/dnn-layer-pad-test.c
>  create mode 100644 tests/fate/dnn.mak
>
> diff --git a/tests/Makefile b/tests/Makefile
> index 624292d..0ef571b 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -10,7 +10,8 @@ FFMPEG=ffmpeg$(PROGSSUF)$(EXESUF)
>  $(AREF): CMP=
>
>  APITESTSDIR := tests/api
> -FATE_OUTDIRS = tests/data tests/data/fate tests/data/filtergraphs 
> tests/data/lavf tests/data/lavf-fate tests/data/pixfmt tests/vsynth1 
> $(APITESTSDIR)
> +DNNTESTSDIR := tests/dnn
> +FATE_OUTDIRS = tests/data tests/data/fate tests/data/filtergraphs 
> tests/data/lavf tests/data/lavf-fate tests/data/pixfmt tests/vsynth1 
> $(APITESTSDIR) $(DNNTESTSDIR)
>  OUTDIRS += $(FATE_OUTDIRS)
>
>  $(VREF): tests/videogen$(HOSTEXESUF) | tests/vsynth1
> @@ -85,6 +86,7 @@ FILTERDEMDECENCMUX = $(call ALLYES, $(1:%=%_FILTER) 
> $(2)_DEMUXER $(3)_DECODER $(
>  PARSERDEMDEC   = $(call ALLYES, $(1)_PARSER $(2)_DEMUXER $(3)_DECODER)
>
>  include $(SRC_PATH)/$(APITESTSDIR)/Makefile
> +include $(SRC_PATH)/$(DNNTESTSDIR)/Makefile
>
>  include $(SRC_PATH)/tests/fate/acodec.mak
>  include $(SRC_PATH)/tests/fate/vcodec.mak
> @@ -118,6 +120,7 @@ include $(SRC_PATH)/tests/fate/cover-art.mak
>  include $(SRC_PATH)/tests/fate/dca.mak
>  include $(SRC_PATH)/tests/fate/demux.mak
>  include $(SRC_PATH)/tests/fate/dfa.mak
> +include $(SRC_PATH)/tests/fate/dnn.mak
>  include $(SRC_PATH)/tests/fate/dnxhd.mak
>  include $(SRC_PATH)/tests/fate/dpcm.mak
>  include $(SRC_PATH)/tests/fate/ea.mak
> diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
> new file mode 100644
> index 000..b2e6680
> --- /dev/null
> +++ b/tests/dnn/Makefile
> @@ -0,0 +1,11 @@
> +DNNTESTPROGS += dnn-layer-pad
> +
> +DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
> $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
> +DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
> +-include $(wildcard $(DNNTESTOBJS:.o=.d))
> +
> +$(DNNTESTPROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
> +   $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) 
> $(FF_EXTRALIBS) $(ELIBS)
> +
> +testclean::
> +   $(RM) $(addprefix $(DNNTESTSDIR)/,$(CLEANSUFFIXES) *-test$(EXESUF))
> diff --git a/tests/dnn/dnn-layer-pad-test.c b/tests/dnn/dnn-layer-pad-test.c
> new file mode 100644
> index 000..28a49eb
> --- /dev/null
> +++ b/tests/dnn/dnn-layer-pad-test.c
> @@ -0,0 +1,203 @@
> +/*
> + * Copyright (c) 2019 Guo Yejun
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include "libavfilter/dnn/dnn_backend_native_layer_pad.h"
> +
> +#define EPSON 0.1
> +
> +static int test_with_mode_symmetric(void)
> +{
> +// the input data and expected data are generated with below python code.
> +/*
> +x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
> +y = tf.pad(x, [[0, 0], [2, 3], [3, 2], [0, 0]], 'SYMMETRIC')
> +data = np.arange(48).reshape(1, 4, 4, 3);
> +
> +sess=tf.Session()
> +sess.run(tf.global_variables_initializer())
> +output = sess.run(y, feed_dict={x: data})
> +
> +print(list(data.flatten()))
> +print(list(output.flatten()))
> +print(data.shape)
> +print(output.shape)
> +*/
> +
> +LayerPadParams params;
> +float input[1*4*4*3] = {
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
> 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 
> 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
> +};
> +float expected_output[1*9*9*3] = {
> +18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 
> 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 
> 18.0, 19.0, 20.0, 6.0, 7.0, 8.0, 3.0,
> +4.0, 5.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 

Re: [FFmpeg-devel] [PATCH, v4 1/2] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale

2019-07-29 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Monday, July 29, 2019 00:48
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH, v4 1/2] fftools/ffmpeg_filter: add -
> autoscale to disable/enable the default scale
> 
> On Sun, Jul 28, 2019 at 05:54:24PM +0800, Linjie Fu wrote:
> > Currently, ffmpeg inserts scale filter by default in the filter graph
> > to force the whole decoded stream to scale into the same size with the
> > first frame. It's not quite make sense in resolution changing cases if
> > user wants the rawvideo without any scale.
> >
> > Using autoscale/noautoscale to indicate whether auto inserting the scale
> > filter in the filter graph:
> > -noautoscale or -autoscale 0:
> > disable the default auto scale filter inserting.
> >
> > Update docs.
> >
> > Signed-off-by: U. Artie Eoff 
> > Signed-off-by: Linjie Fu 
> > ---
> >  doc/ffmpeg.texi | 16 
> >  fftools/ffmpeg.c|  1 +
> >  fftools/ffmpeg.h|  4 
> >  fftools/ffmpeg_filter.c |  2 +-
> >  fftools/ffmpeg_opt.c|  8 
> >  5 files changed, 26 insertions(+), 5 deletions(-)
> 
> I think this is ok-ish but it would be more robust if encoders would
> have a CODEC_CAP listing if they actually support changing resolution
> 

AV_CODEC_CAP_VARIABLE_DIMENSIONS is added,  and currently set for rawvideo and 
libvpx.
New patch set has been sent.

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

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

[FFmpeg-devel] [PATCH 4/4] lavc/libvpxenc: add dynamic resolution encode support for libvpx

2019-07-29 Thread Linjie Fu
According to spec, libvpx should support dynamic resolution changes.

Add dynamic resolution encoding support in libvpx.

Format change should also be supported, but I didn't test it so just
leave it open.

cmdline:
ffmpeg -noautoscale -y -i ./reinit-large_420_8-to-small_420_8.h264
 -pix_fmt yuv420p -c:v libvpx-vp9 lena.ivf

Signed-off-by: Linjie Fu 
---
 libavcodec/libvpxenc.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index feb52ea..6af6c50 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1067,6 +1067,15 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 int res, coded_size;
 vpx_enc_frame_flags_t flags = 0;
 
+if (frame && (avctx->width != frame->width ||
+  avctx->height != frame->height)) {
+avctx->width  = frame->width;
+avctx->height = frame->height;
+
+avctx->codec->close(avctx);
+avctx->codec->init(avctx);
+}
+
 if (frame) {
 rawimg  = &ctx->rawimg;
 rawimg->planes[VPX_PLANE_Y] = frame->data[0];
@@ -1295,7 +1304,7 @@ AVCodec ff_libvpx_vp8_encoder = {
 .init   = vp8_init,
 .encode2= vpx_encode,
 .close  = vpx_free,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS | 
AV_CODEC_CAP_VARIABLE_DIMENSIONS,
 .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE },
 .priv_class = &class_vp8,
 .defaults   = defaults,
@@ -1325,7 +1334,7 @@ AVCodec ff_libvpx_vp9_encoder = {
 .init   = vp9_init,
 .encode2= vpx_encode,
 .close  = vpx_free,
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS | 
AV_CODEC_CAP_VARIABLE_DIMENSIONS,
 .profiles   = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
 .priv_class = &class_vp9,
 .defaults   = defaults,
-- 
2.7.4

___
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/4] fftools/ffmpeg: support variable dimension encode

2019-07-29 Thread Linjie Fu
Flush encoders when dimension change happens, reset draining to resume
encode.

If encoder doesn't support variable dimension, stop encoding and
report errors.

Signed-off-by: Linjie Fu 
---
 fftools/ffmpeg.c| 13 +
 libavcodec/encode.c |  4 
 2 files changed, 17 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d52430..8ceeaaa 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -130,6 +130,7 @@ static void do_video_stats(OutputStream *ost, int 
frame_size);
 static BenchmarkTimeStamps get_benchmark_time_stamps(void);
 static int64_t getmaxrss(void);
 static int ifilter_has_all_input_formats(FilterGraph *fg);
+static void flush_encoders(void);
 
 static int run_as_daemon  = 0;
 static int nb_frames_dup = 0;
@@ -1067,6 +1068,18 @@ static void do_video_out(OutputFile *of,
 InputStream *ist = NULL;
 AVFilterContext *filter = ost->filter->filter;
 
+/* flush encoders in dynamic resolution encode */
+if (next_picture && (enc->width != next_picture->width ||
+ enc->height != next_picture->height)) {
+flush_encoders();
+
+if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) {
+av_log(NULL, AV_LOG_ERROR, "Dynamic resolution encode "
+"is not supported by %s.\n", enc->codec->name);
+goto error;
+}
+}
+
 if (ost->source_index >= 0)
 ist = input_streams[ost->source_index];
 
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index d12c425..9303bc9 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -389,6 +389,10 @@ int attribute_align_arg avcodec_send_frame(AVCodecContext 
*avctx, const AVFrame
 if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
 return AVERROR(EINVAL);
 
+/* reset draining when encoder is flushed in variable dimensions encoding 
*/
+if (frame)
+avctx->internal->draining = 0;
+
 if (avctx->internal->draining)
 return AVERROR_EOF;
 
-- 
2.7.4

___
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/4] avc/avcodec: add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag

2019-07-29 Thread Linjie Fu
Add AV_CODEC_CAP_VARIABLE_DIMENSIONS flag to indicate whether encoder
supports variable dimension encoding.

Signed-off-by: Linjie Fu 
---
 fftools/cmdutils.c   | 2 ++
 libavcodec/avcodec.h | 5 +
 libavcodec/rawenc.c  | 1 +
 libavcodec/version.h | 2 +-
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 9cfbc45..25ea1c6 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1424,6 +1424,8 @@ static void print_codec(const AVCodec *c)
 printf("hardware ");
 if (c->capabilities & AV_CODEC_CAP_HYBRID)
 printf("hybrid ");
+if (c->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)
+printf("multidimension ");
 if (!c->capabilities)
 printf("none");
 printf("\n");
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d234271..a7704ea 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1092,6 +1092,11 @@ typedef struct RcOverride{
 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
 
 /**
+ * Codec supports variable dimensions in encoding.
+ */
+#define AV_CODEC_CAP_VARIABLE_DIMENSIONS (1 << 21)
+
+/**
  * Pan Scan area.
  * This specifies the area which should be displayed.
  * Note there may be multiple such areas for one frame.
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index d181b74..486c0d7 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -92,4 +92,5 @@ AVCodec ff_rawvideo_encoder = {
 .id = AV_CODEC_ID_RAWVIDEO,
 .init   = raw_encode_init,
 .encode2= raw_encode,
+.capabilities   = AV_CODEC_CAP_VARIABLE_DIMENSIONS,
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 43c8cdb..e70ebc0 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  55
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.7.4

___
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, v4 1/4] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale

2019-07-29 Thread Linjie Fu
Currently, ffmpeg inserts scale filter by default in the filter graph
to force the whole decoded stream to scale into the same size with the
first frame. It's not quite make sense in resolution changing cases if
user wants the rawvideo without any scale.

Using autoscale/noautoscale to indicate whether auto inserting the scale
filter in the filter graph:
-noautoscale or -autoscale 0:
disable the default auto scale filter inserting.

Update docs.

Signed-off-by: U. Artie Eoff 
Signed-off-by: Linjie Fu 
---
[no update]
 doc/ffmpeg.texi | 16 
 fftools/ffmpeg.c|  1 +
 fftools/ffmpeg.h|  4 
 fftools/ffmpeg_filter.c |  2 +-
 fftools/ffmpeg_opt.c|  8 
 5 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index cd35eb4..29da951 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -734,10 +734,6 @@ ffmpeg -dump_attachment:t "" -i INPUT
 Technical note -- attachments are implemented as codec extradata, so this
 option can actually be used to extract extradata from any stream, not just
 attachments.
-
-@item -noautorotate
-Disable automatically rotating video based on file metadata.
-
 @end table
 
 @section Video Options
@@ -819,6 +815,18 @@ Create the filtergraph specified by @var{filtergraph} and 
use it to
 filter the stream.
 
 This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter 
option}.
+
+@item -autorotate
+Automatically rotate the video according to file metadata. Enabled by
+default, use @option{-noautorotate} to disable it.
+
+@item -autoscale
+Automatically scale the video according to the resolution of first frame.
+Enabled by default, use @option{-noautoscale} to disable it. When autoscale is
+disabled, all output frames of filter graph might not be in the same resolution
+and may be inadequate for some encoder/muxer. Therefore, it is not recommended
+to disable it unless you really know what you are doing.
+Disable autoscale at your own risk.
 @end table
 
 @section Advanced Video options
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f0410..5d52430 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2133,6 +2133,7 @@ static int ifilter_send_frame(InputFilter *ifilter, 
AVFrame *frame)
 
 /* determine if the parameters for this input changed */
 need_reinit = ifilter->format != frame->format;
+fg->autoscale = ifilter->ist->autoscale;
 
 switch (ifilter->ist->st->codecpar->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7b6f802..1602406 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -133,6 +133,8 @@ typedef struct OptionsContext {
 intnb_hwaccel_output_formats;
 SpecifierOpt *autorotate;
 intnb_autorotate;
+SpecifierOpt *autoscale;
+intnb_autoscale;
 
 /* output options */
 StreamMap *stream_maps;
@@ -285,6 +287,7 @@ typedef struct FilterGraph {
 
 AVFilterGraph *graph;
 int reconfiguration;
+int autoscale;
 
 InputFilter   **inputs;
 int  nb_inputs;
@@ -335,6 +338,7 @@ typedef struct InputStream {
 int guess_layout_max;
 
 int autorotate;
+int autoscale;
 
 int fix_sub_duration;
 struct { /* previous decoded subtitle and related variables */
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 72838de..2a2eb08 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -469,7 +469,7 @@ static int configure_output_video_filter(FilterGraph *fg, 
OutputFilter *ofilter,
 if (ret < 0)
 return ret;
 
-if (ofilter->width || ofilter->height) {
+if ((ofilter->width || ofilter->height) && fg->autoscale) {
 char args[255];
 AVFilterContext *filter;
 AVDictionaryEntry *e = NULL;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f5ca18a..41cb676 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -742,7 +742,9 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
 
 ist->autorotate = 1;
+ist->autoscale  = 1;
 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
+MATCH_PER_STREAM_OPT(autoscale, i, ist->autoscale, ic, st);
 
 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
 if (codec_tag) {
@@ -3640,6 +3642,12 @@ const OptionDef options[] = {
 { "autorotate",   HAS_ARG | OPT_BOOL | OPT_SPEC |
   OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(autorotate) },
 "automatically insert correct rotate filters" },
+{ "autoscale",HAS_ARG | OPT_BOOL | OPT_SPEC |
+  OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(autoscale) },
+"automatically insert a scale filter at the end of the filter graph if 
a resolution"
+"change is de

Re: [FFmpeg-devel] [PATCH] avcodec/cfhd: add bayer support

2019-07-29 Thread Paul B Mahol
Hi,

Fixed possible issue with invalid files.

New patch attached.

>


0001-avcodec-cfhd-add-bayer-support.patch
Description: Binary data
___
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] fate: add a case for ticket #3229

2019-07-29 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Monday, July 15, 2019 2:56 AM
> To: FFmpeg development discussions and patches
> 
> Subject: Re: [FFmpeg-devel] [PATCH] fate: add a case for ticket #3229
> 
> On Sun, Jul 14, 2019 at 06:16:19PM +0800, Zhong Li wrote:
> > Signed-off-by: Zhong Li 
> > ---
> > https://patchwork.ffmpeg.org/patch/13725/ introduces a regression but
> not found by fate, so add it.
> > Test clip produced by:
> > ffmpeg -i tickets/3229/bad.avi -vframes 20 -c:v copy
> > /fate-suite/mjpeg/mjpeg_field_order.avi
> 
> do we need 20 frames for this ?
> the file is over 4mb large, which is why i ask
> 
> thx

Good point, Michael.
A new version cut to 6 frames has been sent.
___
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] libavformat/mpegtsenc: fix incorrect PCR with multiple programs [v3]

2019-07-29 Thread Andreas Håkon
Hi Andriy,

A new updated version here: https://patchwork.ffmpeg.org/patch/14121/

‐‐‐ Original Message ‐‐‐
On Monday, 29 de July de 2019 8:46, Andriy Gelman  
wrote:

> > The MPEG-TS muxer has a serious bug related to the PCR pid selection.
> > This bug appears when more than one program is used. The root cause is 
> > because
> > the current code targets only one program when selecting the stream for the 
> > PCR.
>
> I'd suggest to update the commit message because pid selection is not the main
> issue.

Done!


> > +if (!service->pcr_st) {
> > +av_log(s, AV_LOG_ERROR, "no PCR selected for the service %i", 
> > service->sid);
> > +ret = AVERROR(EINVAL);
> > +goto fail;
> > +}
>
> Do you have to consider an edge case where the streams are not unique to each
> program?
> For example the following will return an error, whereas it works before the
> patch:
>
> ./ffmpeg -loglevel verbose -y -f mpegts -i day_flight.mpg \
> -map i:0x1e1 -c:v:0 copy \
> -program st=0 -program st=0 -f mpegts out-error.ts
>

Wow! A real edge case... Just solving it has involved a great rewriting.
However, it is worth considering as this patch is the prelude to another
(the one for real MPTS interleave muxing).


> Also, you are missing \n at the end of your error message.

Done!

Thank you Andriy for pointing this edge case.
Regards.
A.H.

---

___
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] libavformat/mpegtsenc: fix incorrect PCR with multiple programs [v4]

2019-07-29 Thread Andreas Håkon
Hi,

An updated version that fixes all previous bugs:
https://patchwork.ffmpeg.org/patch/14109/
https://patchwork.ffmpeg.org/patch/14099/
https://patchwork.ffmpeg.org/patch/14036/

It passes the tests pointed by Michael Niedermayer (Sample_cut.ts) and
Andriy Gelman (day_flight.mpg).

I hope this time the patch will be accepted.
Regards.
A.H.

---From 8381febd0e881cfcd53583b0ccdd7eb2c580e422 Mon Sep 17 00:00:00 2001
From: Andreas Hakon 
Date: Mon, 29 Jul 2019 12:02:06 +0100
Subject: [PATCH] libavformat/mpegtsenc: fix incorrect PCR with multiple
 programs [v4]

The MPEG-TS muxer has a serious bug related to the use of multiple programs:
in that case, the PCR pid selection is incomplete for all services except one.
This patch solves this problem and select correct streams for each program.
Furthermore, it passes all the checks and doesn't generate any regression.
Also fully compatible with shared pids over services.

You can check it with this example command:

$ ./ffmpeg -loglevel verbose -y -f data -i /dev/zero \
 -filter_complex "nullsrc=s=60x60,split=2[v0][v1],anullsrc[a]" \
 -map [v0] -c:v:0 rawvideo \
 -map [v1] -c:v:1 rawvideo \
 -map [a]  -c:a:0 pcm_s8 \
 -program st=0,2 -program st=1,2 -program st=2 -program st=0 -f mpegts out.ts

And you will see something like:

[mpegts @ 0x55f8452797c0] service 1 using PCR in pid=256
[mpegts @ 0x55f8452797c0] service 2 using PCR in pid=257
[mpegts @ 0x55f8452797c0] service 3 using PCR in pid=258
[mpegts @ 0x55f8452797c0] service 4 using PCR in pid=256


Signed-off-by: Andreas Hakon 
---
 libavformat/mpegtsenc.c |  167 +--
 1 file changed, 105 insertions(+), 62 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fc0ea22..6a0dd55 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -60,6 +60,7 @@ typedef struct MpegTSService {
 int pcr_packet_count;
 int pcr_packet_period;
 AVProgram *program;
+AVStream *pcr_st;
 } MpegTSService;
 
 // service_type values as defined in ETSI 300 468
@@ -774,7 +775,7 @@ static int mpegts_init(AVFormatContext *s)
 MpegTSWrite *ts = s->priv_data;
 MpegTSWriteStream *ts_st;
 MpegTSService *service;
-AVStream *st, *pcr_st = NULL;
+AVStream *st;
 AVDictionaryEntry *title, *provider;
 int i, j;
 const char *service_name;
@@ -831,6 +832,11 @@ static int mpegts_init(AVFormatContext *s)
 }
 }
 
+for (i = 0; i < ts->nb_services; i++) {
+service = ts->services[i];
+service->pcr_st = NULL;
+}
+
 ts->pat.pid  = PAT_PID;
 /* Initialize at 15 so that it wraps and is equal to 0 for the
  * first packet we write. */
@@ -872,17 +878,6 @@ static int mpegts_init(AVFormatContext *s)
 goto fail;
 }
 
-program = av_find_program_from_stream(s, NULL, i);
-if (program) {
-for (j = 0; j < ts->nb_services; j++) {
-if (ts->services[j]->program == program) {
-service = ts->services[j];
-break;
-}
-}
-}
-
-ts_st->service = service;
 /* MPEG pid values < 16 are reserved. Applications which set st->id in
  * this range are assigned a calculated pid. */
 if (st->id < 16) {
@@ -895,11 +890,6 @@ static int mpegts_init(AVFormatContext *s)
 ret = AVERROR(EINVAL);
 goto fail;
 }
-if (ts_st->pid == service->pmt.pid) {
-av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid);
-ret = AVERROR(EINVAL);
-goto fail;
-}
 for (j = 0; j < i; j++) {
 if (pids[j] == ts_st->pid) {
 av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", 
ts_st->pid);
@@ -913,12 +903,7 @@ static int mpegts_init(AVFormatContext *s)
 ts_st->first_pts_check = 1;
 ts_st->cc  = 15;
 ts_st->discontinuity   = ts->flags & MPEGTS_FLAG_DISCONT;
-/* update PCR pid by using the first video stream */
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-service->pcr_pid == 0x1fff) {
-service->pcr_pid = ts_st->pid;
-pcr_st   = st;
-}
+
 if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
 st->codecpar->extradata_size > 0) {
 AVStream *ast;
@@ -949,50 +934,109 @@ static int mpegts_init(AVFormatContext *s)
 if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
 ts_st->opus_pending_trim_start = st->codecpar->initial_padding * 
48000 / st->codecpar->sample_rate;
 }
+
+/* program service checks */
+program = av_find_program_from_stream(s, NULL, i);
+do {
+for (j = 0; j < ts->nb_services; j++) {
+if (program) {
+/* search for the services corresponding to this program */
+if (ts->services[j]->p

[FFmpeg-devel] [PATCH V2] fate: add a case for ticket #3229

2019-07-29 Thread Zhong Li
Signed-off-by: Zhong Li 
---
https://patchwork.ffmpeg.org/patch/13725/ introduces a regression but not found 
by fate, so add it.
Test clip produced by:
ffmpeg -i tickets/3229/bad.avi -vframes 6 -c:v copy 
/fate-suite/mjpeg/mjpeg_field_order.avi

 tests/fate/video.mak|  3 +++
 tests/ref/fate/mjpeg-ticket3229 | 11 +++
 2 files changed, 14 insertions(+)
 create mode 100644 tests/ref/fate/mjpeg-ticket3229

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index be1458c..d2d43e5 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -232,6 +232,9 @@ fate-mimic: CMD = framecrc -idct simple -i 
$(TARGET_SAMPLES)/mimic/mimic2-womanl
 FATE_VIDEO-$(call DEMDEC, MOV, MJPEGB) += fate-mjpegb
 fate-mjpegb: CMD = framecrc -idct simple -fflags +bitexact -i 
$(TARGET_SAMPLES)/mjpegb/mjpegb_part.mov -an
 
+FATE_VIDEO-$(call DEMDEC, AVI, MJPEG) += fate-mjpeg-ticket3229
+fate-mjpeg-ticket3229: CMD = framecrc -idct simple -fflags +bitexact -i 
$(TARGET_SAMPLES)/mjpeg/mjpeg_field_order.avi -an
+
 FATE_VIDEO-$(call DEMDEC, MVI, MOTIONPIXELS) += fate-motionpixels
 fate-motionpixels: CMD = framecrc -i 
$(TARGET_SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24 -frames:v 
111
 
diff --git a/tests/ref/fate/mjpeg-ticket3229 b/tests/ref/fate/mjpeg-ticket3229
new file mode 100644
index 000..d3068b2
--- /dev/null
+++ b/tests/ref/fate/mjpeg-ticket3229
@@ -0,0 +1,11 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 468x312
+#sar 0: 0/1
+0,  0,  0,1,   292032, 0x3af3a5f7
+0,  6,  6,1,   292032, 0xe97fb504
+0,  8,  8,1,   292032, 0xd448db04
+0,  9,  9,1,   292032, 0xd448db04
+0, 10, 10,1,   292032, 0xd448db04
+0, 11, 11,1,   292032, 0xd448db04
-- 
2.7.4

___
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/dsddec: add slice threading support

2019-07-29 Thread Peter Ross
On Sun, Jul 28, 2019 at 11:35:45PM +0200, Paul B Mahol wrote:
> Hi,
> 
> patch attached.

> From ddfb95d32213406bc68a2803c13c7cfb2d99ee6a Mon Sep 17 00:00:00 2001
> From: Paul B Mahol 
> Date: Sun, 28 Jul 2019 22:27:34 +0200
> Subject: [PATCH 2/2] avcodec/dsddec: add slice threading support
> 
> ---
>  libavcodec/dsddec.c | 47 ++---
>  1 file changed, 32 insertions(+), 15 deletions(-)

also approve.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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] avcodec/dstdec: add slice threading support

2019-07-29 Thread Peter Ross
On Sun, Jul 28, 2019 at 11:34:51PM +0200, Paul B Mahol wrote:
> Hi,
> 
> patch attached.

> From b0d0e0e025fc696270ef59a451d9ee93e2ba27b5 Mon Sep 17 00:00:00 2001
> From: Paul B Mahol 
> Date: Sun, 28 Jul 2019 22:27:10 +0200
> Subject: [PATCH 1/2] avcodec/dstdec: add slice threading support
> 
> ---
>  libavcodec/dstdec.c | 23 +++
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 

approve.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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 v3] avutil/mips: Avoid instruction exception caused by gssqc1/gslqc1.

2019-07-29 Thread Shiyou Yin
>-Original Message-
>From: ffmpeg-devel-boun...@ffmpeg.org [mailto:ffmpeg-devel-boun...@ffmpeg.org] 
>On Behalf Of
>Reimar D?ffinger
>Sent: Sunday, July 28, 2019 6:37 AM
>To: FFmpeg development discussions and patches
>Subject: Re: [FFmpeg-devel] [PATCH v3] avutil/mips: Avoid instruction 
>exception caused by gssqc1/gslqc1.
>
>On 26.07.2019, at 07:18, Shiyou Yin  wrote:
>
>> Ensure the address accesed by gssqc1/gslqc1 are 16-bits memory-aligned.
>
>Looks good to me if standard DECLARE_ALIGNED should work for stack on MIPS.
>(on x86 it used to be possible for the stack pointer to only be 8-byte 
>aligned, in which case
>DECLARE_ALIGNED could not actually provide 16-byte aligned stack variables, so 
>there were special
>macros - I have not checked how it works nowadays or if MIPS has that issue).
>Well, I guess regardless of that, this is better than before, so should be 
>fine to apply either way.
>
DECLARE_ALIGNED is defined in ' libavutil/mem.h ' and related to compiler. No 
matter mips or x86,
it's definition is ' #define DECLARE_ALIGNED(n,t,v)  t __attribute__ 
((aligned (n))) v' when build 
with gcc or clang (Specific implementation within the compiler is not 
considered here.).
In libavcodec/x86, DECLARE_ALIGNED is used to define 8/16/32-byte aligned 
variable too.

Here is a test on mips.
1) Defined variable with 'double temp[8];', and compiled with 'gcc 
-fstack-protector-all'.
In this case, address of temp is not 16-byte aligned and gssqc1/gslqc1 caused 
instruction exception. 
2) Replacing ' double temp[8];' with ' double __attribute__((aligned(16))) 
__back_temp[8];'.
Address of temp is 16-byte aligned and gssqc1/gslqc1 works properly.

There is a typo in the commit message and have revised in v4. Please help to 
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".

[FFmpeg-devel] [PATCH v4] avutil/mips: Avoid instruction exception caused by gssqc1/gslqc1.

2019-07-29 Thread Shiyou Yin
Ensure the address accesed by gssqc1/gslqc1 are 16-byte aligned.
---
 libavcodec/mips/simple_idct_mmi.c | 2 +-
 libavutil/mips/mmiutils.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mips/simple_idct_mmi.c 
b/libavcodec/mips/simple_idct_mmi.c
index 7f4bb74..73d797f 100644
--- a/libavcodec/mips/simple_idct_mmi.c
+++ b/libavcodec/mips/simple_idct_mmi.c
@@ -39,7 +39,7 @@
 #define COL_SHIFT 20
 #define DC_SHIFT 3
 
-DECLARE_ALIGNED(8, const int16_t, W_arr)[46] = {
+DECLARE_ALIGNED(16, const int16_t, W_arr)[46] = {
 W4,  W2,  W4,  W6,
 W1,  W3,  W5,  W7,
 W4,  W6, -W4, -W2,
diff --git a/libavutil/mips/mmiutils.h b/libavutil/mips/mmiutils.h
index 05f6b31..14b6d20 100644
--- a/libavutil/mips/mmiutils.h
+++ b/libavutil/mips/mmiutils.h
@@ -205,7 +205,7 @@
  * backup register
  */
 #define BACKUP_REG \
-  double temp_backup_reg[8];\
+  DECLARE_ALIGNED(16, double, temp_backup_reg)[8];  \
   if (_MIPS_SIM == _ABI64)  \
 __asm__ volatile (  \
   "gssqc1   $f25,  $f24,   0x00(%[temp])  \n\t" \
-- 
2.1.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 2/2] h264_metadata: Support overscan_appropriate_flag

2019-07-29 Thread Andreas Rheinhardt
Mark Thompson:
> On 29/07/2019 00:40, Andreas Rheinhardt wrote:
>> Mark Thompson:
>>> Fixes #8041.
>>> ---
>>> Requested in .
>>>
>>>
>>>  doc/bitstream_filters.texi |  4 
>>>  libavcodec/h264_metadata_bsf.c | 11 +++
>>>  2 files changed, 15 insertions(+)
>>>
>>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
>>> index 023945e9be..50a1679fc7 100644
>>> --- a/doc/bitstream_filters.texi
>>> +++ b/doc/bitstream_filters.texi
>>> @@ -224,6 +224,10 @@ Insert or remove AUD NAL units in all access units of 
>>> the stream.
>>>  @item sample_aspect_ratio
>>>  Set the sample aspect ratio of the stream in the VUI parameters.
>>>  
>>> +@item overscan_appropriate_flag
>>> +Set whether the stream is suitable for display using overscan
>>> +or not (see H.264 section E.2.1).
>>> +
>>>  @item video_format
>>>  @item video_full_range_flag
>>>  Set the video format in the stream (see H.264 section E.2.1 and
>>> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
>>> index 3684e6bf7f..5de74be9d6 100644
>>> --- a/libavcodec/h264_metadata_bsf.c
>>> +++ b/libavcodec/h264_metadata_bsf.c
>>> @@ -57,6 +57,8 @@ typedef struct H264MetadataContext {
>>>  
>>>  AVRational sample_aspect_ratio;
>>>  
>>> +int overscan_appropriate_flag;
>>> +
>>>  int video_format;
>>>  int video_full_range_flag;
>>>  int colour_primaries;
>>> @@ -129,6 +131,11 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>>>  } \
>>>  } while (0)
>>>  
>>> +if (ctx->overscan_appropriate_flag >= 0) {
>>> +SET_VUI_FIELD(overscan_appropriate_flag);
>>
>> LGTM. But just to make sure: You are aware that the check contained in
>> SET_VUI_FIELD is redundant here?
> 
> It seemed marginally more consistent to use the same logic as other places.  
> I'll change it if you have any stronger feelings on it than "I already wrote 
> it this way"?

I don't care. The compiler will optimize it away anyway.

- 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 2/2] h264_metadata: Support overscan_appropriate_flag

2019-07-29 Thread Mark Thompson
On 29/07/2019 00:40, Andreas Rheinhardt wrote:
> Mark Thompson:
>> Fixes #8041.
>> ---
>> Requested in .
>>
>>
>>  doc/bitstream_filters.texi |  4 
>>  libavcodec/h264_metadata_bsf.c | 11 +++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
>> index 023945e9be..50a1679fc7 100644
>> --- a/doc/bitstream_filters.texi
>> +++ b/doc/bitstream_filters.texi
>> @@ -224,6 +224,10 @@ Insert or remove AUD NAL units in all access units of 
>> the stream.
>>  @item sample_aspect_ratio
>>  Set the sample aspect ratio of the stream in the VUI parameters.
>>  
>> +@item overscan_appropriate_flag
>> +Set whether the stream is suitable for display using overscan
>> +or not (see H.264 section E.2.1).
>> +
>>  @item video_format
>>  @item video_full_range_flag
>>  Set the video format in the stream (see H.264 section E.2.1 and
>> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
>> index 3684e6bf7f..5de74be9d6 100644
>> --- a/libavcodec/h264_metadata_bsf.c
>> +++ b/libavcodec/h264_metadata_bsf.c
>> @@ -57,6 +57,8 @@ typedef struct H264MetadataContext {
>>  
>>  AVRational sample_aspect_ratio;
>>  
>> +int overscan_appropriate_flag;
>> +
>>  int video_format;
>>  int video_full_range_flag;
>>  int colour_primaries;
>> @@ -129,6 +131,11 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>>  } \
>>  } while (0)
>>  
>> +if (ctx->overscan_appropriate_flag >= 0) {
>> +SET_VUI_FIELD(overscan_appropriate_flag);
> 
> LGTM. But just to make sure: You are aware that the check contained in
> SET_VUI_FIELD is redundant here?

It seemed marginally more consistent to use the same logic as other places.  
I'll change it if you have any stronger feelings on it than "I already wrote it 
this way"?

>> +sps->vui.overscan_info_present_flag = 1;
>> +}
>> +
>>  if (ctx->video_format >= 0 ||
>>  ctx->video_full_range_flag>= 0 ||
>>  ctx->colour_primaries >= 0 ||
>> @@ -630,6 +637,10 @@ static const AVOption h264_metadata_options[] = {
>>  OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL,
>>  { .dbl = 0.0 }, 0, 65535, FLAGS },
>>  
>> +{ "overscan_appropriate_flag", "Set VUI overscan appropriate flag",
>> +OFFSET(overscan_appropriate_flag), AV_OPT_TYPE_INT,
>> +{ .i64 = -1 }, -1, 1, FLAGS },
>> +
>>  { "video_format", "Set video format (table E-2)",
>>  OFFSET(video_format), AV_OPT_TYPE_INT,
>>  { .i64 = -1 }, -1, 7, FLAGS},
>>

Thanks,

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

Re: [FFmpeg-devel] [PATCH 25/31] cbs: Add function to update video codec parameters

2019-07-29 Thread Mark Thompson
On 29/07/2019 02:33, Andreas Rheinhardt wrote:
> Mark Thompson:
>> On 20/06/2019 00:45, Andreas Rheinhardt wrote:
>>> If any of the *_metadata filter based upon cbs currently updates a video
>>> codec parameter like color information, the AVCodecParameters are not
>>> updated accordingly, so that e.g. muxers write header values based upon
>>> outdated information that may precede and thereby nullify the new values
>>> on the bitstream level.
>>> This commit adds a function to also update the video codec parameters
>>> so that the above situation can be fixed in a unified manner.
>>>
>>> Signed-off-by: Andreas Rheinhardt 
>>> ---
>>>  libavcodec/cbs.c | 35 +++
>>>  libavcodec/cbs.h | 15 +++
>>>  2 files changed, 50 insertions(+)
>>>
>>> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
>>> index 47679eca1b..37b080b5ba 100644
>>> --- a/libavcodec/cbs.c
>>> +++ b/libavcodec/cbs.c
>>> @@ -342,6 +342,41 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
>>>  return 0;
>>>  }
>>>  
>>> +void ff_cbs_update_video_parameters(CodedBitstreamContext *ctx,
>>
>> The context argument isn't used at all.
>>
> I know. I thought that's how you wanted the API to look like. After
> all, ff_cbs_fragment_uninit always used a context argument without
> needing it (cbs_unit_uninit doesn't use its context argument at all
> and it is the only place where ff_cbs_fragment_uninit used it; I of
> course kept this behaviour when replacing ff_cbs_fragment_uninit). Now
> that it seems that this was unintentional, I will send a patch to
> remove the argument.

Hmm.  I think the real reason that seemed wrong to me was that it isn't really 
a CBS function, rather a BSF function - it can be used by things with no other 
CBS interaction, such as prores_metadata.  So, maybe it should go in bsf.h 
rather than cbs.h?

ff_cbs_fragment_uninit(), on the other hand, really is a CBS function, so even 
though it doesn't currently use the context/logging argument it still feels 
right to pass it.

>>> +AVCodecParameters *par, int profile,
>>> +int level, int width, int height,
>>> +int field_order, int color_range,
>>> +int color_primaries, int color_trc,
>>> +int color_space, int chroma_location,
>>> +int video_delay)
>>> +{
>>> +#define SET_IF_NONNEGATIVE(elem) \
>>> +if (elem >= 0) \
>>> +par->elem = elem;
>>> +SET_IF_NONNEGATIVE(profile)
>>> +SET_IF_NONNEGATIVE(level)
>>> +SET_IF_NONNEGATIVE(width)
>>> +SET_IF_NONNEGATIVE(height)
>>> +SET_IF_NONNEGATIVE(field_order)
>>> +SET_IF_NONNEGATIVE(video_delay)
>>> +#undef SET_IF_NONNEGATIVE
>>> +
>>> +#define SET_IF_VALID(elem, upper_bound) \
>>> +if (0 <= elem && elem < upper_bound) \
>>> +par->elem = elem;
>>> +SET_IF_VALID(color_range, AVCOL_RANGE_NB)
>>> +SET_IF_VALID(color_trc,   AVCOL_TRC_NB)
>>> +SET_IF_VALID(color_space, AVCOL_SPC_NB)
>>
>> I think we generally want to admit future values for the 23001-8 / H.273 
>> fields (see range ..255 on all the metadata filters).
>>
> Do you want to omit checking entirely? Or should I still check against
> the sentinel? I prefer the latter. I dislike setting an enum to
> something else than an enum constant and moreover, if a future
> standard would allow (say) color_range > 255 (or a bsf would simply
> forget to check the value), but libavcodec does not, then it might be
> that the compiler uses char as underlying type for the enum which of
> course could not hold such a value.

No future standard will backward-compatibly allow color_range > 255 because 
it's an 8-bit field in all current use.

I'm purely considering the behaviour for a new N + 1 value, since other 
components do allow that (for example, in 
).

>>> +SET_IF_VALID(chroma_location, AVCHROMA_LOC_NB)
>>> +#undef SET_IF_VALID
>>> +
>>> +if (0 <= color_primaries && color_primaries <= AVCOL_PRI_SMPTE432
>>> + || color_primaries == AVCOL_PRI_JEDEC_P22)
>>> +par->color_primaries = color_primaries;
>>> +
> And how about the gap in the color_primaries values?

Same argument applies, I think?

>>> +return;
>>> +}
>>> +
>>>  int ff_cbs_write_packet(CodedBitstreamContext *ctx,
>>>  AVPacket *pkt,
>>>  CodedBitstreamFragment *frag)
>>> diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
>>> index e1e6055ceb..1655f790cd 100644
>>> --- a/libavcodec/cbs.h
>>> +++ b/libavcodec/cbs.h
>>> @@ -304,6 +304,21 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
>>> AVCodecParameters *par,
>>> CodedBit

Re: [FFmpeg-devel] [PATCH] avfilter/fade: don't allow nb_frames == 0

2019-07-29 Thread Gyan



On 29-07-2019 12:16 PM, Paul B Mahol wrote:

LGTM

Pushed as 43891ea8ab286a08e731ebac78123c4f1b1d35ca

Thanks,
Gyan
___
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".