Re: [FFmpeg-devel] [PATCH v2 16/36] vaapi_encode: Clean up rate control configuration

2018-06-07 Thread myp...@gmail.com
On Fri, Jun 8, 2018 at 7:45 AM Mark Thompson  wrote:
>
> Query which modes are supported and select between VBR and CBR based
> on that - this removes all of the codec-specific rate control mode
> selection code.
> ---
>  doc/encoders.texi   |   2 -
>  libavcodec/vaapi_encode.c   | 173 
> 
>  libavcodec/vaapi_encode.h   |   6 +-
>  libavcodec/vaapi_encode_h264.c  |  18 +
>  libavcodec/vaapi_encode_h265.c  |  14 +---
>  libavcodec/vaapi_encode_mjpeg.c |   3 +-
>  libavcodec/vaapi_encode_mpeg2.c |   9 +--
>  libavcodec/vaapi_encode_vp8.c   |  13 +--
>  libavcodec/vaapi_encode_vp9.c   |  13 +--
>  9 files changed, 137 insertions(+), 114 deletions(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 62a1509a96..0c0a307987 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2643,8 +2643,6 @@ Always encodes using the standard quantisation and 
> huffman tables -
>  @item mpeg2_vaapi
>  @option{profile} and @option{level} set the value of 
> @emph{profile_and_level_indication}.
>
> -No rate control is supported.
> -
>  @item vp8_vaapi
>  B-frames are not supported.
>
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index f4c063734c..5de5483454 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1217,7 +1217,6 @@ static av_cold int 
> vaapi_encode_config_attributes(AVCodecContext *avctx)
>  int i;
>
>  VAConfigAttrib attr[] = {
> -{ VAConfigAttribRateControl  },
>  { VAConfigAttribEncMaxRefFrames  },
>  { VAConfigAttribEncPackedHeaders },
>  };
> @@ -1241,32 +1240,6 @@ static av_cold int 
> vaapi_encode_config_attributes(AVCodecContext *avctx)
>  continue;
>  }
>  switch (attr[i].type) {
> -case VAConfigAttribRateControl:
> -// Hack for backward compatibility: CBR was the only
> -// usable RC mode for a long time, so old drivers will
> -// only have it.  Normal default options may now choose
> -// VBR and then fail, however, so override it here with
> -// CBR if that is the only supported mode.
> -if (ctx->va_rc_mode == VA_RC_VBR &&
> -!(attr[i].value & VA_RC_VBR) &&
> -(attr[i].value & VA_RC_CBR)) {
> -av_log(avctx, AV_LOG_WARNING, "VBR rate control is "
> -   "not supported with this driver version; "
> -   "using CBR instead.\n");
> -ctx->va_rc_mode = VA_RC_CBR;
> -}
> -if (!(ctx->va_rc_mode & attr[i].value)) {
> -av_log(avctx, AV_LOG_ERROR, "Rate control mode %#x "
> -   "is not supported (mask: %#x).\n",
> -   ctx->va_rc_mode, attr[i].value);
> -return AVERROR(EINVAL);
> -}
> -ctx->config_attributes[ctx->nb_config_attributes++] =
> -(VAConfigAttrib) {
> -.type  = VAConfigAttribRateControl,
> -.value = ctx->va_rc_mode,
> -};
> -break;
>  case VAConfigAttribEncMaxRefFrames:
>  {
>  unsigned int ref_l0 = attr[i].value & 0x;
> @@ -1313,44 +1286,144 @@ static av_cold int 
> vaapi_encode_config_attributes(AVCodecContext *avctx)
>  static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
>  {
>  VAAPIEncodeContext *ctx = avctx->priv_data;
> -int rc_bits_per_second;
> -int rc_target_percentage;
> -int rc_window_size;
> -int hrd_buffer_size;
> -int hrd_initial_buffer_fullness;
> +int64_t rc_bits_per_second;
> +int rc_target_percentage;
> +int rc_window_size;
> +int64_t hrd_buffer_size;
> +int64_t hrd_initial_buffer_fullness;
>  int fr_num, fr_den;
> +VAConfigAttrib rc_attr = { VAConfigAttribRateControl };
> +VAStatus vas;
> +
> +vas = vaGetConfigAttributes(ctx->hwctx->display,
> +ctx->va_profile, ctx->va_entrypoint,
> +&rc_attr, 1);
> +if (vas != VA_STATUS_SUCCESS) {
> +av_log(avctx, AV_LOG_ERROR, "Failed to query rate control "
> +   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
> +return AVERROR_EXTERNAL;
> +}
>
> -if (avctx->bit_rate > INT32_MAX) {
> -av_log(avctx, AV_LOG_ERROR, "Target bitrate of 2^31 bps or "
> -   "higher is not supported.\n");
> +if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> +av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any "
> +   "supported rate control modes: assuming constant-quality.\n");
> +ctx->va_rc_mode = VA_RC_CQP;
> +return 0;
> +}
> +if (avctx->flags & AV_CODEC_FLAG_QSCALE ||
> +avctx->bit_rate <= 0) {
> +if (rc_attr.value & VA_RC_CQP) {
> +av_log(avctx, AV_LOG_VERBOSE, "Using 

Re: [FFmpeg-devel] [PATCH v2 24/36] lavc/cbs: Add JPEG support

2018-06-07 Thread James Almer
On 6/7/2018 8:43 PM, Mark Thompson wrote:
> +static int cbs_jpeg_write_unit(CodedBitstreamContext *ctx,
> +CodedBitstreamUnit *unit)
> +{
> +CodedBitstreamJPEGContext *priv = ctx->priv_data;
> +PutBitContext pbc;
> +int err;
> +
> +if (!priv->write_buffer) {
> +// Initial write buffer size is 1MB.
> +priv->write_buffer_size = 1024 * 1024;
> +
> +reallocate_and_try_again:
> +err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);

You could use av_fast_malloc() instead, since you don't care about the
previous contents of the buffer. But it will make no real difference
admittedly since at most it will be reallocated twice or thrice for
really big files and that's it.

I sent a patch implementing this change for the other modules some
weeks, which i guess you didn't see and i forgot about :p

> +if (err < 0) {
> +av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
> +   "sufficiently large write buffer (last attempt "
> +   "%"SIZE_SPECIFIER" bytes).\n", priv->write_buffer_size);
> +return err;
> +}
> +}

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


[FFmpeg-devel] [PATCH] lavfi/atempo: raise max tempo limit (v2)

2018-06-07 Thread Pavel Koshevoy
---
 doc/filters.texi| 17 ++---
 libavfilter/af_atempo.c |  6 +++---
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 256ab42b00..6b98b04774 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1986,7 +1986,12 @@ Adjust audio tempo.
 
 The filter accepts exactly one parameter, the audio tempo. If not
 specified then the filter will assume nominal 1.0 tempo. Tempo must
-be in the [0.5, 2.0] range.
+be in the [0.5, 100.0] range.
+
+Note that tempo greater than 2 will skip some samples rather than
+blend them in.  If for any reason this is a concern it is always
+possible to daisy-chain several instances of atempo to achieve the
+desired product tempo.
 
 @subsection Examples
 
@@ -1998,9 +2003,15 @@ atempo=0.8
 @end example
 
 @item
-To speed up audio to 125% tempo:
+To speed up audio to 300% tempo:
+@example
+atempo=3
+@end example
+
+@item
+To speed up audio to 300% tempo by daisy-chaining two atempo instances:
 @example
-atempo=1.25
+atempo=sqrt(3),atempo=sqrt(3)
 @end example
 @end itemize
 
diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index 8b214bccd7..52f15f2769 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -153,7 +153,7 @@ typedef struct ATempoContext {
 
 static const AVOption atempo_options[] = {
 { "tempo", "set tempo scale factor",
-  OFFSET(tempo), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 0.5, 2.0,
+  OFFSET(tempo), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 0.5, 100.0,
   AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
 { NULL }
 };
@@ -439,8 +439,8 @@ static int yae_load_data(ATempoContext *atempo,
 return 0;
 }
 
-// samples are not expected to be skipped:
-av_assert0(read_size <= atempo->ring);
+// samples are not expected to be skipped, unless tempo is greater than 2:
+av_assert0(read_size <= atempo->ring || atempo->tempo > 2.0);
 
 while (atempo->position[0] < stop_here && src < src_end) {
 int src_samples = (src_end - src) / atempo->stride;
-- 
2.16.4

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


Re: [FFmpeg-devel] [PATCH v2 24/36] lavc/cbs: Add JPEG support

2018-06-07 Thread myp...@gmail.com
On Fri, Jun 8, 2018 at 7:46 AM Mark Thompson  wrote:
>
> ---
>  configure |   2 +
>  libavcodec/Makefile   |   1 +
>  libavcodec/cbs.c  |   6 +
>  libavcodec/cbs_internal.h |   1 +
>  libavcodec/cbs_jpeg.c | 513 
> ++
>  libavcodec/cbs_jpeg.h | 128 +
>  libavcodec/cbs_jpeg_syntax_template.c | 191 +
>  7 files changed, 842 insertions(+)
>  create mode 100644 libavcodec/cbs_jpeg.c
>  create mode 100644 libavcodec/cbs_jpeg.h
>  create mode 100644 libavcodec/cbs_jpeg_syntax_template.c
>
> diff --git a/configure b/configure
> index 790f55be14..d908283954 100755
> --- a/configure
> +++ b/configure
> @@ -2244,6 +2244,7 @@ CONFIG_EXTRA="
>  cbs
>  cbs_h264
>  cbs_h265
> +cbs_jpeg
>  cbs_mpeg2
>  cbs_vp9
>  dirac_parse
> @@ -2507,6 +2508,7 @@ threads_if_any="$THREADS_LIST"
>  # subsystems
>  cbs_h264_select="cbs golomb"
>  cbs_h265_select="cbs golomb"
> +cbs_jpeg_select="cbs"
>  cbs_mpeg2_select="cbs"
>  cbs_vp9_select="cbs"
>  dct_select="rdft"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3ab071a039..2a1e0de110 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -64,6 +64,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
>  OBJS-$(CONFIG_CBS) += cbs.o
>  OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
>  OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
> +OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
>  OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
>  OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
>  OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index be6c043b58..bb3ce95971 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -35,6 +35,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
>  #if CONFIG_CBS_H265
>  &ff_cbs_type_h265,
>  #endif
> +#if CONFIG_CBS_JPEG
> +&ff_cbs_type_jpeg,
> +#endif
>  #if CONFIG_CBS_MPEG2
>  &ff_cbs_type_mpeg2,
>  #endif
> @@ -50,6 +53,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
>  #if CONFIG_CBS_H265
>  AV_CODEC_ID_H265,
>  #endif
> +#if CONFIG_CBS_JPEG
> +AV_CODEC_ID_MJPEG,
> +#endif
>  #if CONFIG_CBS_MPEG2
>  AV_CODEC_ID_MPEG2VIDEO,
>  #endif
> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> index 172b8a2515..e0e912e28e 100644
> --- a/libavcodec/cbs_internal.h
> +++ b/libavcodec/cbs_internal.h
> @@ -88,6 +88,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
> PutBitContext *pbc,
>
>  extern const CodedBitstreamType ff_cbs_type_h264;
>  extern const CodedBitstreamType ff_cbs_type_h265;
> +extern const CodedBitstreamType ff_cbs_type_jpeg;
>  extern const CodedBitstreamType ff_cbs_type_mpeg2;
>  extern const CodedBitstreamType ff_cbs_type_vp9;
>
> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> new file mode 100644
> index 00..365db73394
> --- /dev/null
> +++ b/libavcodec/cbs_jpeg.c
> @@ -0,0 +1,513 @@
> +/*
> + * 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 "cbs.h"
> +#include "cbs_internal.h"
> +#include "cbs_jpeg.h"
> +
> +
> +#define HEADER(name) do { \
> +ff_cbs_trace_header(ctx, name); \
> +} while (0)
> +
> +#define CHECK(call) do { \
> +err = (call); \
> +if (err < 0) \
> +return err; \
> +} while (0)
> +
> +#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, 
> __VA_ARGS__ }) : NULL)
> +
> +#define u(width, name, range_min, range_max) \
> +xu(width, name, range_min, range_max, 0)
> +#define us(width, name, sub, range_min, range_max) \
> +xu(width, name, range_min, range_max, 1, sub)
> +
> +
> +#define READ
> +#define READWRITE read
> +#define RWContext GetBitContext
> +#define FUNC(name) cbs_jpeg_read_ ## name
> +
> +#define xu(width, name, range_min, range_max, subs, ...) do { \
> +uint32_t value = range_min; \
> +CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
> +   SUBSCRIPTS(subs, __VA_ARGS__), \
> +   

[FFmpeg-devel] [PATCH v2 36/36] doc/encoders: Document -sei option to hevc_vaapi

2018-06-07 Thread Mark Thompson
---
 doc/encoders.texi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index d61a1cc4bc..3894774bef 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2663,6 +2663,16 @@ Include access unit delimiters in the stream (not 
included by default).
 Set @emph{general_tier_flag}.  This may affect the level chosen for the stream
 if it is not explicitly specified.
 
+@item sei
+Set SEI message types to include.
+Some combination of the following values:
+@table @samp
+@item hdr
+Include HDR metadata if the input frames have it
+(@emph{mastering_display_colour_volume} and @emph{content_light_level}
+messages).
+@end table
+
 @end table
 
 @item mjpeg_vaapi
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 33/36] vaapi_encode_h265: Improve profile support

2018-06-07 Thread Mark Thompson
Set profile compatibility/constraint flags properly (including the
constraint flags used for RExt profiles, as all streams we can currently
generate are RExt-compatible), and use that to add support for the "Main
Intra" and "Main 10 Intra" RExt subprofiles (for which we can re-use the
existing Main and Main10 VAAPI profiles).
---
 libavcodec/Makefile|  2 +-
 libavcodec/vaapi_encode_h265.c | 71 +-
 2 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 079f546918..71b800c09d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -371,7 +371,7 @@ OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o   \
   hevc_data.o
 OBJS-$(CONFIG_HEVC_RKMPP_DECODER)  += rkmppdec.o
-OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o
+OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += h265_profile_level.o 
vaapi_encode_h265.o
 OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
 OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
 OBJS-$(CONFIG_HNM4_VIDEO_DECODER)  += hnm4video.o
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 97bb9cef6c..2cee19be68 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
+#include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
 #include "libavutil/mastering_display_metadata.h"
 
@@ -260,9 +261,12 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 H265RawVPS*vps = &priv->raw_vps;
 H265RawSPS*sps = &priv->raw_sps;
 H265RawPPS*pps = &priv->raw_pps;
+H265RawProfileTierLevel   *ptl = &vps->profile_tier_level;
 H265RawVUI*vui = &sps->vui;
 VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
 VAEncPictureParameterBufferHEVC  *vpic = ctx->codec_picture_params;
+const AVPixFmtDescriptor *desc;
+int chroma_format, bit_depth;
 int i;
 
 memset(&priv->current_access_unit, 0,
@@ -273,6 +277,25 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 memset(pps, 0, sizeof(*pps));
 
 
+desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format);
+av_assert0(desc);
+if (desc->nb_components == 1) {
+chroma_format = 0;
+} else {
+if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) {
+chroma_format = 1;
+} else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) {
+chroma_format = 2;
+} else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
+chroma_format = 3;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
+   "%s is not supported.\n", desc->name);
+}
+}
+bit_depth = desc->comp[0].depth;
+
+
 // VPS
 
 vps->nal_unit_header = (H265RawNALUnitHeader) {
@@ -289,19 +312,35 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 vps->vps_max_sub_layers_minus1 = 0;
 vps->vps_temporal_id_nesting_flag  = 1;
 
-vps->profile_tier_level = (H265RawProfileTierLevel) {
-.general_profile_space = 0,
-.general_profile_idc   = avctx->profile,
-.general_tier_flag = 0,
+ptl->general_profile_space = 0;
+ptl->general_profile_space = 0;
+ptl->general_profile_idc   = avctx->profile;
+ptl->general_tier_flag = 0;
 
-.general_progressive_source_flag= 1,
-.general_interlaced_source_flag = 0,
-.general_non_packed_constraint_flag = 1,
-.general_frame_only_constraint_flag = 1,
+if (chroma_format == 1) {
+ptl->general_profile_compatibility_flag[1] = bit_depth ==  8;
+ptl->general_profile_compatibility_flag[2] = bit_depth <= 10;
+}
+ptl->general_profile_compatibility_flag[4] = 1;
 
-.general_level_idc = avctx->level,
-};
-vps->profile_tier_level.general_profile_compatibility_flag[avctx->profile 
& 31] = 1;
+ptl->general_progressive_source_flag= 1;
+ptl->general_interlaced_source_flag = 0;
+ptl->general_non_packed_constraint_flag = 1;
+ptl->general_frame_only_constraint_flag = 1;
+
+ptl->general_max_12bit_constraint_flag = bit_depth <= 12;
+ptl->general_max_10bit_constraint_flag = bit_depth <= 10;
+ptl->general_max_8bit_constraint_flag  = bit_depth ==  8;
+
+ptl->general_max_422chroma_constraint_flag  = chroma_format <= 2;
+ptl->general_max_420chroma_constraint_flag  = chroma_format <= 1;
+ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
+
+ptl->general_intra_constraint_flag = ctx->gop_size == 1;
+
+

[FFmpeg-devel] [PATCH v2 35/36] vaapi_encode_h265: Set level based on stream if not set by user

2018-06-07 Thread Mark Thompson
Sets the level based on the stream properties if it is not explicitly
set by the user.  Also add a tier option to set general_tier_flag, since
that affects the level choice.
---
 doc/encoders.texi  |  4 
 libavcodec/vaapi_encode_h265.c | 34 +++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ceddfdda64..d61a1cc4bc 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2659,6 +2659,10 @@ Include recovery points where appropriate 
(@emph{recovery_point} messages).
 @item aud
 Include access unit delimiters in the stream (not included by default).
 
+@item tier
+Set @emph{general_tier_flag}.  This may affect the level chosen for the stream
+if it is not explicitly specified.
+
 @end table
 
 @item mjpeg_vaapi
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 2cee19be68..100f8338d7 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -30,6 +30,7 @@
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h265.h"
+#include "h265_profile_level.h"
 #include "hevc.h"
 #include "hevc_sei.h"
 #include "internal.h"
@@ -48,6 +49,7 @@ typedef struct VAAPIEncodeH265Context {
 int qp;
 int aud;
 int profile;
+int tier;
 int level;
 int sei;
 
@@ -315,7 +317,7 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 ptl->general_profile_space = 0;
 ptl->general_profile_space = 0;
 ptl->general_profile_idc   = avctx->profile;
-ptl->general_tier_flag = 0;
+ptl->general_tier_flag = priv->tier;
 
 if (chroma_format == 1) {
 ptl->general_profile_compatibility_flag[1] = bit_depth ==  8;
@@ -340,7 +342,25 @@ static int 
vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
 
 ptl->general_lower_bit_rate_constraint_flag = 1;
 
-ptl->general_level_idc = avctx->level;
+if (avctx->level != FF_LEVEL_UNKNOWN) {
+ptl->general_level_idc = avctx->level;
+} else {
+const H265LevelDescriptor *level;
+
+level = ff_h265_guess_level(ptl, avctx->bit_rate,
+ctx->surface_width, ctx->surface_height,
+1, 1, 1, (ctx->b_per_p > 0) + 1);
+if (level) {
+av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
+ptl->general_level_idc = level->level_idc;
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
+   "any normal level; using level 8.5.\n");
+ptl->general_level_idc = 255;
+// The tier flag must be set in level 8.5.
+ptl->general_tier_flag = 1;
+}
+}
 
 vps->vps_sub_layer_ordering_info_present_flag = 0;
 vps->vps_max_dec_pic_buffering_minus1[0]  = (ctx->b_per_p > 0) + 1;
@@ -1146,9 +1166,17 @@ static const AVOption vaapi_encode_h265_options[] = {
 { PROFILE("rext",   FF_PROFILE_HEVC_REXT) },
 #undef PROFILE
 
+{ "tier", "Set tier (general_tier_flag)",
+  OFFSET(tier), AV_OPT_TYPE_INT,
+  { .i64 = 0 }, 0, 1, FLAGS, "tier" },
+{ "main", NULL, 0, AV_OPT_TYPE_CONST,
+  { .i64 = 0 }, 0, 0, FLAGS, "tier" },
+{ "high", NULL, 0, AV_OPT_TYPE_CONST,
+  { .i64 = 1 }, 0, 0, FLAGS, "tier" },
+
 { "level", "Set level (general_level_idc)",
   OFFSET(level), AV_OPT_TYPE_INT,
-  { .i64 = 153 }, 0x00, 0xff, FLAGS, "level" },
+  { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
 
 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
   { .i64 = value }, 0, 0, FLAGS, "level"
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 34/36] lavc/h265: Add some common code for profile/tier/level handling

2018-06-07 Thread Mark Thompson
Adds support for determining for level limits, including mapping PTL
blocks to profiles to check profile-dependent level limits.
---
 libavcodec/h265_profile_level.c | 245 
 libavcodec/h265_profile_level.h |  89 +++
 2 files changed, 334 insertions(+)
 create mode 100644 libavcodec/h265_profile_level.c
 create mode 100644 libavcodec/h265_profile_level.h

diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c
new file mode 100644
index 00..aac1529c9b
--- /dev/null
+++ b/libavcodec/h265_profile_level.c
@@ -0,0 +1,245 @@
+/*
+ * 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 "h265_profile_level.h"
+
+
+static const H265LevelDescriptor h265_levels[] = {
+// Name CpbFactor-MainMaxSliceSegmentsPerPicture
+// |  level_idc| CpbFactor-High   MaxLumaSr  
BrFactor-High
+// |  |   MaxLumaPs|   |  | MaxTileRows   |   
BrFactor-Main | MinCr-Main
+// |  |  | |   |  |   | MaxTileCols |  
 ||  MinCr-High
+{ "1",30,36864,350,  0,  16,  1,  1, 552960,128,   
   0, 2, 2 },
+{ "2",60,   122880,   1500,  0,  16,  1,  1,3686400,   1500,   
   0, 2, 2 },
+{ "2.1",  63,   245760,   3000,  0,  20,  1,  1,7372800,   3000,   
   0, 2, 2 },
+{ "3",90,   552960,   6000,  0,  30,  2,  2,   16588800,   6000,   
   0, 2, 2 },
+{ "3.1",  93,   983040,  1,  0,  40,  3,  3,   33177600,  1,   
   0, 2, 2 },
+{ "4",   120,  2228224,  12000,  3,  75,  5,  5,   66846720,  12000,  
3, 4, 4 },
+{ "4.1", 123,  2228224,  2,  5,  75,  5,  5,  133693440,  2,  
5, 4, 4 },
+{ "5",   150,  8912896,  25000, 10, 200, 11, 10,  267386880,  25000, 
10, 6, 4 },
+{ "5.1", 153,  8912896,  4, 16, 200, 11, 10,  534773760,  4, 
16, 8, 4 },
+{ "5.2", 156,  8912896,  6, 24, 200, 11, 10, 1069547520,  6, 
24, 8, 4 },
+{ "6",   180, 35651584,  6, 24, 600, 22, 20, 1069547520,  6, 
24, 8, 4 },
+{ "6.1", 183, 35651584, 12, 48, 600, 22, 20, 2139095040, 12, 
48, 8, 4 },
+{ "6.2", 186, 35651584, 24, 80, 600, 22, 20, 4278190080, 24, 
80, 6, 4 },
+};
+
+static const H265ProfileDescriptor h265_profiles[] = {
+// profile_idc   8bit   one-picture
+//   HT-profile  | 422chroma| lower-bit-rate
+//   |  14bit|  | 420chroma |  | CpbVclFactor MinCrScaleFactor
+//   |  |  12bit |  |  | monochrome|| CpbNalFactor|
+//   |  |  |  10bit |  |  | intra  || | FormatCapabilityFactor
+{ "Monochrome", //  |  |  |  |  |  || | | |
+  4, 0, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1,  667,  733, 1.000, 1.0 },
+{ "Monochrome 12",
+  4, 0, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1000, 1100, 1.500, 1.0 },
+{ "Monochrome 16",
+  4, 0, 2, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1333, 1467, 2.000, 1.0 },
+{ "Main",
+  1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0 },
+{ "Screen-Extended Main",
+  9, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.500, 1.0 },
+{ "Main 10",
+  2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.875, 1.0 },
+{ "Screen-Extended Main 10",
+  9, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1000, 1100, 1.875, 1.0 },
+{ "Main 12",
+  4, 0, 2, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1500, 1650, 2.250, 1.0 },
+{ "Main Still Picture",
+  3, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1000, 1100, 1.500, 1.0 },
+{ "Main 4:2:2 10",
+  4, 0, 2, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1667, 1833, 2.500, 0.5 },
+{ "Main 4:2:2 12",
+  4, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 },
+{ "Main 4:4:4",
+  4, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 },
+{ "High Throughput 4:4:4",
+  5, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 },
+{ "Screen-Extended Main 4:4:4",
+  9, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 },
+{ "Screen-Extended High Throughput 4:4:4",
+  9, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 2000, 2200, 3.000, 0.5 },
+{ "Main 4:4:4 10",
+  4, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2500, 

[FFmpeg-devel] [PATCH v2 32/36] cbs_h264: Infer default VUI values if VUI parameters are not present

2018-06-07 Thread Mark Thompson
---
 libavcodec/cbs_h264_syntax_template.c | 42 +++
 1 file changed, 42 insertions(+)

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index f53c02467e..03f2a15b0b 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -211,6 +211,46 @@ static int FUNC(vui_parameters)(CodedBitstreamContext 
*ctx, RWContext *rw,
 return 0;
 }
 
+static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx,
+RWContext *rw, H264RawVUI *current,
+H264RawSPS *sps)
+{
+infer(aspect_ratio_idc, 0);
+
+infer(video_format, 5);
+infer(video_full_range_flag,0);
+infer(colour_primaries, 2);
+infer(transfer_characteristics, 2);
+infer(matrix_coefficients,  2);
+
+infer(chroma_sample_loc_type_top_field,0);
+infer(chroma_sample_loc_type_bottom_field, 0);
+
+infer(fixed_frame_rate_flag, 0);
+infer(low_delay_hrd_flag,1);
+
+infer(pic_struct_present_flag, 0);
+
+infer(motion_vectors_over_pic_boundaries_flag, 1);
+infer(max_bytes_per_pic_denom, 2);
+infer(max_bits_per_mb_denom,   1);
+infer(log2_max_mv_length_horizontal, 15);
+infer(log2_max_mv_length_vertical,   15);
+
+if ((sps->profile_idc ==  44 || sps->profile_idc ==  86 ||
+ sps->profile_idc == 100 || sps->profile_idc == 110 ||
+ sps->profile_idc == 122 || sps->profile_idc == 244) &&
+sps->constraint_set3_flag) {
+infer(max_num_reorder_frames,  0);
+infer(max_dec_frame_buffering, 0);
+} else {
+infer(max_num_reorder_frames,  H264_MAX_DPB_FRAMES);
+infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
+}
+
+return 0;
+}
+
 static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
  H264RawSPS *current)
 {
@@ -315,6 +355,8 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext 
*rw,
 flag(vui_parameters_present_flag);
 if (current->vui_parameters_present_flag)
 CHECK(FUNC(vui_parameters)(ctx, rw, ¤t->vui, current));
+else
+CHECK(FUNC(vui_parameters_default)(ctx, rw, ¤t->vui, current));
 
 CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 28/36] vaapi_encode_h264: Set level based on stream if not set by user

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h264.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 82166d4457..4034053dc0 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -30,6 +30,7 @@
 #include "cbs.h"
 #include "cbs_h264.h"
 #include "h264.h"
+#include "h264_levels.h"
 #include "h264_sei.h"
 #include "internal.h"
 #include "vaapi_encode.h"
@@ -294,6 +295,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 H264RawPPS*pps = &priv->raw_pps;
 VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
 VAEncPictureParameterBufferH264  *vpic = ctx->codec_picture_params;
+int dpb_frames;
 
 memset(&priv->current_access_unit, 0,
sizeof(priv->current_access_unit));
@@ -319,7 +321,32 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->constraint_set5_flag = ctx->b_per_p == 0;
 }
 
-sps->level_idc = avctx->level;
+if (ctx->gop_size == 1)
+dpb_frames = 0;
+else
+dpb_frames = 1 + (ctx->b_per_p > 0);
+
+if (avctx->level != FF_LEVEL_UNKNOWN) {
+sps->level_idc = avctx->level;
+} else {
+const H264LevelDescriptor *level;
+
+level = ff_h264_guess_level(sps->profile_idc,
+avctx->bit_rate,
+priv->mb_width  * 16,
+priv->mb_height * 16,
+dpb_frames);
+if (level) {
+av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
+if (level->constraint_set3_flag)
+sps->constraint_set3_flag = 1;
+sps->level_idc = level->level_idc;
+} else {
+av_log(avctx, AV_LOG_WARNING, "Stream will not conform "
+   "to any level: using level 6.2.\n");
+sps->level_idc = 62;
+}
+}
 
 sps->seq_parameter_set_id = 0;
 sps->chroma_format_idc= 1;
@@ -329,8 +356,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->log2_max_pic_order_cnt_lsb_minus4 =
 av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12);
 
-sps->max_num_ref_frames =
-ctx->gop_size == 1 ? 0 : 1 + (ctx->b_per_p > 0);
+sps->max_num_ref_frames = dpb_frames;
 
 sps->pic_width_in_mbs_minus1= priv->mb_width  - 1;
 sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
@@ -1005,7 +1031,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "level", "Set level (level_idc)",
   OFFSET(level), AV_OPT_TYPE_INT,
-  { .i64 = 51 }, 0x00, 0xff, FLAGS, "level" },
+  { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
 
 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
   { .i64 = value }, 0, 0, FLAGS, "level"
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 30/36] cbs_h264: Fix range and default value of max mv lengths

2018-06-07 Thread Mark Thompson
The max and default values are 15, not 16.
---
 libavcodec/cbs_h264_syntax_template.c | 8 
 libavcodec/vaapi_encode_h264.c| 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index 027b555db6..21edcb799e 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -185,16 +185,16 @@ static int FUNC(vui_parameters)(CodedBitstreamContext 
*ctx, RWContext *rw,
 flag(motion_vectors_over_pic_boundaries_flag);
 ue(max_bytes_per_pic_denom, 0, 16);
 ue(max_bits_per_mb_denom,   0, 16);
-ue(log2_max_mv_length_horizontal, 0, 16);
-ue(log2_max_mv_length_vertical,   0, 16);
+ue(log2_max_mv_length_horizontal, 0, 15);
+ue(log2_max_mv_length_vertical,   0, 15);
 ue(max_num_reorder_frames,  0, H264_MAX_DPB_FRAMES);
 ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES);
 } else {
 infer(motion_vectors_over_pic_boundaries_flag, 1);
 infer(max_bytes_per_pic_denom, 2);
 infer(max_bits_per_mb_denom,   1);
-infer(log2_max_mv_length_horizontal, 16);
-infer(log2_max_mv_length_vertical,   16);
+infer(log2_max_mv_length_horizontal, 15);
+infer(log2_max_mv_length_vertical,   15);
 
 if ((sps->profile_idc ==  44 || sps->profile_idc ==  86 ||
  sps->profile_idc == 110 || sps->profile_idc == 110 ||
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 4034053dc0..0d7780110c 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -491,8 +491,8 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 
 sps->vui.bitstream_restriction_flag= 1;
 sps->vui.motion_vectors_over_pic_boundaries_flag = 1;
-sps->vui.log2_max_mv_length_horizontal = 16;
-sps->vui.log2_max_mv_length_vertical   = 16;
+sps->vui.log2_max_mv_length_horizontal = 15;
+sps->vui.log2_max_mv_length_vertical   = 15;
 sps->vui.max_num_reorder_frames= (ctx->b_per_p > 0);
 sps->vui.max_dec_frame_buffering   = sps->max_num_ref_frames;
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 29/36] h264_metadata: Add option to set the level of the stream

2018-06-07 Thread Mark Thompson
---
 doc/bitstream_filters.texi |  9 +
 libavcodec/h264_metadata_bsf.c | 90 ++
 2 files changed, 99 insertions(+)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 7d7e97503a..d948c6d658 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -215,6 +215,15 @@ insert the string ``hello'' associated with the given UUID.
 @item delete_filler
 Deletes both filler NAL units and filler SEI messages.
 
+@item level
+Set the level in the SPS.  Refer to H.264 section A.3 and tables A-1
+to A-5.
+
+The argument must be the name of a level (for example, @samp{4.2}), a
+level_idc value (for example, @samp{42}), or the special name @samp{auto}
+indicating that the filter should attempt to guess the level from the
+input stream properties.
+
 @end table
 
 @section h264_mp4toannexb
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 90ad4aad98..cb1a835fb8 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -25,6 +25,7 @@
 #include "cbs.h"
 #include "cbs_h264.h"
 #include "h264.h"
+#include "h264_levels.h"
 #include "h264_sei.h"
 
 enum {
@@ -39,6 +40,11 @@ enum {
 FLIP_VERTICAL   = 2,
 };
 
+enum {
+LEVEL_UNSET = -2,
+LEVEL_AUTO  = -1,
+};
+
 typedef struct H264MetadataContext {
 const AVClass *class;
 
@@ -74,6 +80,8 @@ typedef struct H264MetadataContext {
 int display_orientation;
 double rotate;
 int flip;
+
+int level;
 } H264MetadataContext;
 
 
@@ -208,6 +216,58 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
 CROP(bottom, crop_unit_y);
 #undef CROP
 
+if (ctx->level != LEVEL_UNSET) {
+int level_idc;
+
+if (ctx->level == LEVEL_AUTO) {
+const H264LevelDescriptor *desc;
+int64_t bit_rate;
+int width, height;
+
+if (sps->vui.nal_hrd_parameters_present_flag) {
+bit_rate = 
(sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
+ (1 << (sps->vui.nal_hrd_parameters.bit_rate_scale + 6));
+} else if (sps->vui.vcl_hrd_parameters_present_flag) {
+bit_rate = 
(sps->vui.vcl_hrd_parameters.bit_rate_value_minus1[0] + 1) *
+ (1 << (sps->vui.vcl_hrd_parameters.bit_rate_scale + 6));
+// Adjust for VCL vs. NAL limits.
+bit_rate = bit_rate * 6 / 5;
+} else {
+bit_rate = 0;
+}
+
+width  = 16 * (sps->pic_width_in_mbs_minus1 + 1);
+height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
+(2 - sps->frame_mbs_only_flag);
+
+desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
+   width, height,
+   sps->vui.max_dec_frame_buffering);
+if (desc) {
+level_idc = desc->level_idc;
+} else {
+av_log(bsf, AV_LOG_WARNING, "Stream does not appear to "
+   "conform to any level: using level 6.2.\n");
+level_idc = 62;
+}
+} else {
+level_idc = ctx->level;
+}
+
+if (level_idc == 9) {
+if (sps->profile_idc == 66 ||
+sps->profile_idc == 77 ||
+sps->profile_idc == 88) {
+sps->level_idc = 10;
+sps->constraint_set3_flag = 1;
+} else {
+sps->level_idc = 9;
+}
+} else {
+sps->level_idc = level_idc;
+}
+}
+
 if (need_vui)
 sps->vui_parameters_present_flag = 1;
 
@@ -683,6 +743,36 @@ static const AVOption h264_metadata_options[] = {
 0, AV_OPT_TYPE_CONST,
 { .i64 = FLIP_VERTICAL },   .flags = FLAGS, .unit = "flip" },
 
+{ "level", "Set level (table A-1)",
+OFFSET(level), AV_OPT_TYPE_INT,
+{ .i64 = LEVEL_UNSET }, LEVEL_UNSET, 0xff, FLAGS, "level" },
+{ "auto", "Attempt to guess level from stream properties",
+0, AV_OPT_TYPE_CONST,
+{ .i64 = LEVEL_AUTO }, 0, 0, FLAGS, "level" },
+#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+{ .i64 = value }, 0, 0, FLAGS, "level"
+{ LEVEL("1",   10) },
+{ LEVEL("1b",   9) },
+{ LEVEL("1.1", 11) },
+{ LEVEL("1.2", 12) },
+{ LEVEL("1.3", 13) },
+{ LEVEL("2",   20) },
+{ LEVEL("2.1", 21) },
+{ LEVEL("2.2", 22) },
+{ LEVEL("3",   30) },
+{ LEVEL("3.1", 31) },
+{ LEVEL("3.2", 32) },
+{ LEVEL("4",   40) },
+{ LEVEL("4.1", 41) },
+{ LEVEL("4.2", 42) },
+{ LEVEL("5",   50) },
+{ LEVEL("5.1", 51) },
+{ LEVEL("5.2", 52) },
+{ LEVEL("6",   60) },
+{ LEVEL("6.1", 61) },
+{ LEVEL("6.2", 62) },
+#undef LEVEL
+
 { NULL }
 };
 
-- 
2.16.3

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org

[FFmpeg-devel] [PATCH v2 31/36] cbs_h264: Fix profile typo

2018-06-07 Thread Mark Thompson
---
 libavcodec/cbs_h264_syntax_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index 21edcb799e..f53c02467e 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -197,7 +197,7 @@ static int FUNC(vui_parameters)(CodedBitstreamContext *ctx, 
RWContext *rw,
 infer(log2_max_mv_length_vertical,   15);
 
 if ((sps->profile_idc ==  44 || sps->profile_idc ==  86 ||
- sps->profile_idc == 110 || sps->profile_idc == 110 ||
+ sps->profile_idc == 100 || sps->profile_idc == 110 ||
  sps->profile_idc == 122 || sps->profile_idc == 244) &&
 sps->constraint_set3_flag) {
 infer(max_num_reorder_frames,  0);
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 26/36] hwcontext_vaapi: Improve format mapping

2018-06-07 Thread Mark Thompson
Give the entries in the VAAPI format map table an explicit type and add
functions to do the necessary lookups.  Add another field to this table
indicating whether the chroma planes are swapped (as in YV12), and use
that rather than explicit comparisons where swapping is needed.
---
 libavutil/hwcontext_vaapi.c | 133 +---
 1 file changed, 76 insertions(+), 57 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 4088a96be4..8624369bb9 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -87,57 +87,82 @@ typedef struct VAAPIMapping {
 int flags;
 } VAAPIMapping;
 
-#define MAP(va, rt, av) { \
+typedef struct VAAPIFormat {
+unsigned int fourcc;
+unsigned int rt_format;
+enum AVPixelFormat pix_fmt;
+int chroma_planes_swapped;
+} VAAPIFormatDescriptor;
+
+#define MAP(va, rt, av, swap_uv) { \
 VA_FOURCC_ ## va, \
 VA_RT_FORMAT_ ## rt, \
-AV_PIX_FMT_ ## av \
+AV_PIX_FMT_ ## av, \
+swap_uv, \
 }
 // The map fourcc <-> pix_fmt isn't bijective because of the annoying U/V
 // plane swap cases.  The frame handling below tries to hide these.
-static const struct {
-unsigned int fourcc;
-unsigned int rt_format;
-enum AVPixelFormat pix_fmt;
-} vaapi_format_map[] = {
-MAP(NV12, YUV420,  NV12),
-MAP(YV12, YUV420,  YUV420P), // With U/V planes swapped.
-MAP(IYUV, YUV420,  YUV420P),
+static const VAAPIFormatDescriptor vaapi_format_map[] = {
+MAP(NV12, YUV420,  NV12,0),
 #ifdef VA_FOURCC_I420
-MAP(I420, YUV420,  YUV420P),
+MAP(I420, YUV420,  YUV420P, 0),
 #endif
+MAP(YV12, YUV420,  YUV420P, 1),
+MAP(IYUV, YUV420,  YUV420P, 0),
+MAP(422H, YUV422,  YUV422P, 0),
 #ifdef VA_FOURCC_YV16
-MAP(YV16, YUV422,  YUV422P), // With U/V planes swapped.
+MAP(YV16, YUV422,  YUV422P, 1),
 #endif
-MAP(422H, YUV422,  YUV422P),
-MAP(UYVY, YUV422,  UYVY422),
-MAP(YUY2, YUV422,  YUYV422),
-MAP(411P, YUV411,  YUV411P),
-MAP(422V, YUV422,  YUV440P),
-MAP(444P, YUV444,  YUV444P),
-MAP(Y800, YUV400,  GRAY8),
+MAP(UYVY, YUV422,  UYVY422, 0),
+MAP(YUY2, YUV422,  YUYV422, 0),
+MAP(411P, YUV411,  YUV411P, 0),
+MAP(422V, YUV422,  YUV440P, 0),
+MAP(444P, YUV444,  YUV444P, 0),
+MAP(Y800, YUV400,  GRAY8,   0),
 #ifdef VA_FOURCC_P010
-MAP(P010, YUV420_10BPP, P010),
+MAP(P010, YUV420_10BPP, P010, 0),
 #endif
-MAP(BGRA, RGB32,   BGRA),
-MAP(BGRX, RGB32,   BGR0),
-MAP(RGBA, RGB32,   RGBA),
-MAP(RGBX, RGB32,   RGB0),
+MAP(BGRA, RGB32,   BGRA, 0),
+MAP(BGRX, RGB32,   BGR0, 0),
+MAP(RGBA, RGB32,   RGBA, 0),
+MAP(RGBX, RGB32,   RGB0, 0),
 #ifdef VA_FOURCC_ABGR
-MAP(ABGR, RGB32,   ABGR),
-MAP(XBGR, RGB32,   0BGR),
+MAP(ABGR, RGB32,   ABGR, 0),
+MAP(XBGR, RGB32,   0BGR, 0),
 #endif
-MAP(ARGB, RGB32,   ARGB),
-MAP(XRGB, RGB32,   0RGB),
+MAP(ARGB, RGB32,   ARGB, 0),
+MAP(XRGB, RGB32,   0RGB, 0),
 };
 #undef MAP
 
-static enum AVPixelFormat vaapi_pix_fmt_from_fourcc(unsigned int fourcc)
+static const VAAPIFormatDescriptor *
+vaapi_format_from_fourcc(unsigned int fourcc)
 {
 int i;
 for (i = 0; i < FF_ARRAY_ELEMS(vaapi_format_map); i++)
 if (vaapi_format_map[i].fourcc == fourcc)
-return vaapi_format_map[i].pix_fmt;
-return AV_PIX_FMT_NONE;
+return &vaapi_format_map[i];
+return NULL;
+}
+
+static const VAAPIFormatDescriptor *
+vaapi_format_from_pix_fmt(enum AVPixelFormat pix_fmt)
+{
+int i;
+for (i = 0; i < FF_ARRAY_ELEMS(vaapi_format_map); i++)
+if (vaapi_format_map[i].pix_fmt == pix_fmt)
+return &vaapi_format_map[i];
+return NULL;
+}
+
+static enum AVPixelFormat vaapi_pix_fmt_from_fourcc(unsigned int fourcc)
+{
+const VAAPIFormatDescriptor *desc;
+desc = vaapi_format_from_fourcc(fourcc);
+if (desc)
+return desc->pix_fmt;
+else
+return AV_PIX_FMT_NONE;
 }
 
 static int vaapi_get_image_format(AVHWDeviceContext *hwdev,
@@ -461,22 +486,16 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
 AVVAAPIFramesContext  *avfc = hwfc->hwctx;
 VAAPIFramesContext *ctx = hwfc->internal->priv;
 AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx;
+const VAAPIFormatDescriptor *desc;
 VAImageFormat *expected_format;
 AVBufferRef *test_surface = NULL;
 VASurfaceID test_surface_id;
 VAImage test_image;
 VAStatus vas;
 int err, i;
-unsigned int fourcc, rt_format;
 
-for (i = 0; i < FF_ARRAY_ELEMS(vaapi_format_map); i++) {
-if (vaapi_format_map[i].pix_fmt == hwfc->sw_format) {
-fourcc= vaapi_format_map[i].fourcc;
-rt_format = vaapi_format_map[i].rt_format;
-break;
-}
-}
-if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
+desc = vaapi_format_from_pix_fmt(hwfc->sw_format);
+if (!desc) {
 av_log(hwfc, AV_

[FFmpeg-devel] [PATCH v2 27/36] lavc/h264: Add common code for level handling

2018-06-07 Thread Mark Thompson
Including a unit test.
---
 libavcodec/Makefile|   3 +-
 libavcodec/h264_levels.c   | 130 +
 libavcodec/h264_levels.h   |  53 
 libavcodec/tests/.gitignore|   1 +
 libavcodec/tests/h264_levels.c | 183 +
 tests/fate/libavcodec.mak  |   5 ++
 6 files changed, 374 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/h264_levels.c
 create mode 100644 libavcodec/h264_levels.h
 create mode 100644 libavcodec/tests/h264_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2a1e0de110..079f546918 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -353,7 +353,7 @@ OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
 OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
-OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o
+OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += h264_levels.o vaapi_encode_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_H264_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
 OBJS-$(CONFIG_H264_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
@@ -1129,6 +1129,7 @@ TESTPROGS-$(CONFIG_IDCTDSP)   += dct
 TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
 TESTPROGS-$(HAVE_MMX) += motion
 TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
+TESTPROGS-$(CONFIG_H264_VAAPI_ENCODER)+= h264_levels
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
new file mode 100644
index 00..6b4e18a914
--- /dev/null
+++ b/libavcodec/h264_levels.c
@@ -0,0 +1,130 @@
+/*
+ * 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 "avcodec.h"
+#include "h264_levels.h"
+
+// H.264 table A-1.
+static const H264LevelDescriptor h264_levels[] = {
+// Name  MaxMBPS   MaxBR  MinCR
+//  | level_idc |   MaxFS|MaxCPB| 
MaxMvsPer2Mb
+//  | | cs3f| |  MaxDpbMbs   |   |  MaxVmvR |   |
+{ "1",   10, 0, 1485, 99,396, 64,175,   64, 2,  0 },
+{ "1b",  10, 1, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1b",   9, 0, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1.1", 11, 0, 3000,396,900,192,500,  128, 2,  0 },
+{ "1.2", 12, 0, 6000,396,   2376,384,   1000,  128, 2,  0 },
+{ "1.3", 13, 0,11880,396,   2376,768,   2000,  128, 2,  0 },
+{ "2",   20, 0,11880,396,   2376,   2000,   2000,  128, 2,  0 },
+{ "2.1", 21, 0,19800,792,   4752,   4000,   4000,  256, 2,  0 },
+{ "2.2", 22, 0,20250,   1620,   8100,   4000,   4000,  256, 2,  0 },
+{ "3",   30, 0,40500,   1620,   8100,  1,  1,  256, 2, 32 },
+{ "3.1", 31, 0,   108000,   3600,  18000,  14000,  14000,  512, 4, 16 },
+{ "3.2", 32, 0,   216000,   5120,  20480,  2,  2,  512, 4, 16 },
+{ "4",   40, 0,   245760,   8192,  32768,  2,  25000,  512, 4, 16 },
+{ "4.1", 41, 0,   245760,   8192,  32768,  5,  62500,  512, 2, 16 },
+{ "4.2", 42, 0,   522240,   8704,  34816,  5,  62500,  512, 2, 16 },
+{ "5",   50, 0,   589824,  22080, 110400, 135000, 135000,  512, 2, 16 },
+{ "5.1", 51, 0,   983040,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "5.2", 52, 0,  2073600,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "6",   60, 0,  4177920, 139264, 696320, 24, 24, 8192, 2, 16 },
+{ "6.1", 61, 0,  8355840, 139264, 696320, 48, 48, 8192, 2, 16 },
+{ "6.2", 62, 0, 16711680, 139264, 696320, 80, 80, 8192, 2, 16 },
+};
+
+// H.264 table A-2 plus values from A-1.
+static const struct {
+int profile_idc;
+int cpb_br_vcl_factor;
+int cpb_br_nal_factor;
+} h264_br_factors[] = {
+{  66, 1000, 1200 },
+{  77, 1000, 1200 },
+{  88, 1000, 1200 },
+{ 100, 1250, 1500 },
+{ 110, 3000, 3600 },
+{ 122, 4000, 4800 },
+{ 244, 4000, 4800 },
+{  44, 4000, 4800 },
+};
+
+// 

[FFmpeg-devel] [PATCH v2 25/36] vaapi_encode_mjpeg: Use CBS to store parameters and write headers

2018-06-07 Thread Mark Thompson
Also adds greyscale, 4:2:2, 4:4:4 and RGB support.
---
 configure   |   2 +-
 doc/encoders.texi   |  17 +-
 libavcodec/vaapi_encode_mjpeg.c | 529 +---
 3 files changed, 347 insertions(+), 201 deletions(-)

diff --git a/configure b/configure
index d908283954..cde32a8fad 100755
--- a/configure
+++ b/configure
@@ -2939,7 +2939,7 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
-mjpeg_vaapi_encoder_select="vaapi_encode jpegtables"
+mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mpeg1_cuvid_decoder_deps="cuvid"
 mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
 mpeg2_crystalhd_decoder_select="crystalhd"
diff --git a/doc/encoders.texi b/doc/encoders.texi
index b451142cfb..ceddfdda64 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2662,8 +2662,21 @@ Include access unit delimiters in the stream (not 
included by default).
 @end table
 
 @item mjpeg_vaapi
-Always encodes using the standard quantisation and huffman tables -
-@option{global_quality} scales the standard quantisation table (range 1-100).
+Only baseline DCT encoding is supported.  The encoder always uses the standard
+quantisation and huffman tables - @option{global_quality} scales the standard
+quantisation table (range 1-100).
+
+For YUV, 4:2:0, 4:2:2 and 4:4:4 subsampling modes are supported.  RGB is also
+supported, and will create an RGB JPEG.
+
+@table @option
+@item jfif
+Include JFIF header in each frame (not included by default).
+@item huffman
+Include standard huffman tables (on by default).  Turning this off will save
+a few hundred bytes in each output frame, but may lose compatibility with some
+JPEG decoders which don't fully handle MJPEG.
+@end table
 
 @item mpeg2_vaapi
 @option{profile} and @option{level} set the value of 
@emph{profile_and_level_indication}.
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index f76645425a..2f79070e58 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -23,9 +23,12 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
+#include "libavutil/pixdesc.h"
 
 #include "avcodec.h"
+#include "bytestream.h"
+#include "cbs.h"
+#include "cbs_jpeg.h"
 #include "internal.h"
 #include "jpegtables.h"
 #include "mjpeg.h"
@@ -58,253 +61,346 @@ static const unsigned char 
vaapi_encode_mjpeg_quant_chrominance[64] = {
 typedef struct VAAPIEncodeMJPEGContext {
 VAAPIEncodeContext common;
 
+// User options.
+int jfif;
+int huffman;
+
+// Derived settings.
 int quality;
-int component_subsample_h[3];
-int component_subsample_v[3];
+uint8_t jfif_data[14];
+
+// Writer structures.
+JPEGRawFrameHeader frame_header;
+JPEGRawScanscan;
+JPEGRawApplicationData jfif_header;
+JPEGRawQuantisationTableSpecification quant_tables;
+JPEGRawHuffmanTableSpecification  huffman_tables;
 
-VAQMatrixBufferJPEG quant_tables;
-VAHuffmanTableBufferJPEGBaseline huffman_tables;
+CodedBitstreamContext *cbc;
+CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMJPEGContext;
 
-static av_cold void vaapi_encode_mjpeg_copy_huffman(unsigned char *dst_lengths,
-unsigned char *dst_values,
-const unsigned char 
*src_lengths,
-const unsigned char 
*src_values)
+static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx,
+ VAAPIEncodePicture *pic,
+ VAAPIEncodeSlice *slice,
+ char *data, size_t *data_len)
 {
-int i, mt;
-
-++src_lengths;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
+CodedBitstreamFragment  *frag = &priv->current_fragment;
+int err;
+
+if (priv->jfif) {
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_APPN + 0,
+ &priv->jfif_header, NULL);
+if (err < 0)
+goto fail;
+}
 
-mt = 0;
-for (i = 0; i < 16; i++)
-mt += (dst_lengths[i] = src_lengths[i]);
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_DQT,
+ &priv->quant_tables, NULL);
+if (err < 0)
+goto fail;
+
+err = ff_cbs_insert_unit_content(priv->cbc, frag, -1,
+ JPEG_MARKER_SOF0,
+ &priv->frame_header, NULL);
+if (err < 0)
+goto fail;
+
+if (priv->huffman) {
+err = ff_c

[FFmpeg-devel] [PATCH v2 22/36] doc/encoders: Add missing options to VAAPI encoders

2018-06-07 Thread Mark Thompson
---
 doc/encoders.texi | 24 
 1 file changed, 24 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 861f9f4f1f..b451142cfb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2631,12 +2631,36 @@ Use CABAC.
 @item cavlc
 Use CAVLC.
 @end table
+
+@item aud
+Include access unit delimiters in the stream (not included by default).
+
+@item sei
+Set SEI message types to include.
+Some combination of the following values:
+@table @samp
+@item identifier
+Include a @emph{user_data_unregistered} message containing information about
+the encoder.
+@item timing
+Include picture timing parameters (@emph{buffering_period} and
+@emph{pic_timing} messages).
+@item recovery_point
+Include recovery points where appropriate (@emph{recovery_point} messages).
+@end table
+
 @end table
 
 @item hevc_vaapi
 @option{profile} and @option{level} set the values of
 @emph{general_profile_idc} and @emph{general_level_idc} respectively.
 
+@table @option
+@item aud
+Include access unit delimiters in the stream (not included by default).
+
+@end table
+
 @item mjpeg_vaapi
 Always encodes using the standard quantisation and huffman tables -
 @option{global_quality} scales the standard quantisation table (range 1-100).
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 24/36] lavc/cbs: Add JPEG support

2018-06-07 Thread Mark Thompson
---
 configure |   2 +
 libavcodec/Makefile   |   1 +
 libavcodec/cbs.c  |   6 +
 libavcodec/cbs_internal.h |   1 +
 libavcodec/cbs_jpeg.c | 513 ++
 libavcodec/cbs_jpeg.h | 128 +
 libavcodec/cbs_jpeg_syntax_template.c | 191 +
 7 files changed, 842 insertions(+)
 create mode 100644 libavcodec/cbs_jpeg.c
 create mode 100644 libavcodec/cbs_jpeg.h
 create mode 100644 libavcodec/cbs_jpeg_syntax_template.c

diff --git a/configure b/configure
index 790f55be14..d908283954 100755
--- a/configure
+++ b/configure
@@ -2244,6 +2244,7 @@ CONFIG_EXTRA="
 cbs
 cbs_h264
 cbs_h265
+cbs_jpeg
 cbs_mpeg2
 cbs_vp9
 dirac_parse
@@ -2507,6 +2508,7 @@ threads_if_any="$THREADS_LIST"
 # subsystems
 cbs_h264_select="cbs golomb"
 cbs_h265_select="cbs golomb"
+cbs_jpeg_select="cbs"
 cbs_mpeg2_select="cbs"
 cbs_vp9_select="cbs"
 dct_select="rdft"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3ab071a039..2a1e0de110 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -64,6 +64,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index be6c043b58..bb3ce95971 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -35,6 +35,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H265
 &ff_cbs_type_h265,
 #endif
+#if CONFIG_CBS_JPEG
+&ff_cbs_type_jpeg,
+#endif
 #if CONFIG_CBS_MPEG2
 &ff_cbs_type_mpeg2,
 #endif
@@ -50,6 +53,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
 #if CONFIG_CBS_H265
 AV_CODEC_ID_H265,
 #endif
+#if CONFIG_CBS_JPEG
+AV_CODEC_ID_MJPEG,
+#endif
 #if CONFIG_CBS_MPEG2
 AV_CODEC_ID_MPEG2VIDEO,
 #endif
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 172b8a2515..e0e912e28e 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -88,6 +88,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
+extern const CodedBitstreamType ff_cbs_type_jpeg;
 extern const CodedBitstreamType ff_cbs_type_mpeg2;
 extern const CodedBitstreamType ff_cbs_type_vp9;
 
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
new file mode 100644
index 00..365db73394
--- /dev/null
+++ b/libavcodec/cbs_jpeg.c
@@ -0,0 +1,513 @@
+/*
+ * 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 "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_jpeg.h"
+
+
+#define HEADER(name) do { \
+ff_cbs_trace_header(ctx, name); \
+} while (0)
+
+#define CHECK(call) do { \
+err = (call); \
+if (err < 0) \
+return err; \
+} while (0)
+
+#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ 
}) : NULL)
+
+#define u(width, name, range_min, range_max) \
+xu(width, name, range_min, range_max, 0)
+#define us(width, name, sub, range_min, range_max) \
+xu(width, name, range_min, range_max, 1, sub)
+
+
+#define READ
+#define READWRITE read
+#define RWContext GetBitContext
+#define FUNC(name) cbs_jpeg_read_ ## name
+
+#define xu(width, name, range_min, range_max, subs, ...) do { \
+uint32_t value = range_min; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+   SUBSCRIPTS(subs, __VA_ARGS__), \
+   &value, range_min, range_max)); \
+current->name = value; \
+} while (0)
+
+#include "cbs_jpeg_syntax_template.c"
+
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef FUNC
+#undef xu
+
+#define WRITE
+#define READWRITE write
+#define RWContext PutBitContext
+#define FUNC(name) cbs_jpeg_write_ ## name
+
+#define xu(wi

[FFmpeg-devel] [PATCH v2 20/36] vaapi_encode_h264: Properly set constraint flags

2018-06-07 Thread Mark Thompson
constraint_set1_flag should be set for constrained baseline and main
profiles, because the stream conforms to main profile.

constraint_set3_flag should be set for high profile when the stream
is intra-only.

constraint_set4_flag should always be set for main and high profiles
because interlaced encoding is not supported.

constraint_set5_flag should be set for main and high profiles when
B-frames are not used.

Also fix the setting of max_num_ref_frames - use the gop_size value
to check for intra-only rather than the constraint flag (which is not
necessarily set).
---
 libavcodec/vaapi_encode_h264.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index e2f4f4f2f5..a4594ef9f2 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -305,10 +305,19 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
 
 sps->profile_idc = avctx->profile & 0xff;
-sps->constraint_set1_flag =
-!!(avctx->profile & FF_PROFILE_H264_CONSTRAINED);
-sps->constraint_set3_flag =
-!!(avctx->profile & FF_PROFILE_H264_INTRA);
+
+if (avctx->profile == FF_PROFILE_H264_CONSTRAINED_BASELINE ||
+avctx->profile == FF_PROFILE_H264_MAIN)
+sps->constraint_set1_flag = 1;
+
+if (avctx->profile == FF_PROFILE_H264_HIGH)
+sps->constraint_set3_flag = ctx->gop_size == 1;
+
+if (avctx->profile == FF_PROFILE_H264_MAIN ||
+avctx->profile == FF_PROFILE_H264_HIGH) {
+sps->constraint_set4_flag = 1;
+sps->constraint_set5_flag = ctx->b_per_p == 0;
+}
 
 sps->level_idc = avctx->level;
 
@@ -321,8 +330,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12);
 
 sps->max_num_ref_frames =
-(avctx->profile & FF_PROFILE_H264_INTRA) ? 0 :
-1 + (ctx->b_per_p > 0);
+ctx->gop_size == 1 ? 0 : 1 + (ctx->b_per_p > 0);
 
 sps->pic_width_in_mbs_minus1= priv->mb_width  - 1;
 sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 21/36] vaapi_encode_h26[45]: Make the AUD option a boolean

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h264.c | 2 +-
 libavcodec/vaapi_encode_h265.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index a4594ef9f2..82166d4457 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -976,7 +976,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "ac",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
 
 { "aud", "Include AUD",
-  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 04dfef27c8..97bb9cef6c 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1093,7 +1093,7 @@ static const AVOption vaapi_encode_h265_options[] = {
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
 
 { "aud", "Include AUD",
-  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
 
 { "profile", "Set profile (general_profile_idc)",
   OFFSET(profile), AV_OPT_TYPE_INT,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 23/36] hwcontext_vaapi: Improve logging around quirk detection

2018-06-07 Thread Mark Thompson
Clarify that the list is the naughty list, and therefore being on it is
not desirable.  The i965 driver does not need to be on the list after
version 2.0 (when the standard parameter buffer rendering behaviour was
changed).
---
 libavutil/hwcontext_vaapi.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index a2387d4fc4..4088a96be4 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -279,11 +279,14 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
+#if !VA_CHECK_VERSION(1, 0, 0)
+// The i965 driver did not conform before version 2.0.
 {
 "Intel i965 (Quick Sync)",
 "i965",
 AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
 },
+#endif
 {
 "Intel iHD",
 "ubit",
@@ -344,29 +347,37 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
 }
 }
 
+vendor_string = vaQueryVendorString(hwctx->display);
+if (vendor_string)
+av_log(hwdev, AV_LOG_VERBOSE, "VAAPI driver: %s.\n", vendor_string);
+
 if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_USER_SET) {
-av_log(hwdev, AV_LOG_VERBOSE, "Not detecting driver: "
-   "quirks set by user.\n");
+av_log(hwdev, AV_LOG_VERBOSE, "Using quirks set by user (%#x).\n",
+   hwctx->driver_quirks);
 } else {
 // Detect the driver in use and set quirk flags if necessary.
-vendor_string = vaQueryVendorString(hwctx->display);
 hwctx->driver_quirks = 0;
 if (vendor_string) {
 for (i = 0; i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table); i++) {
 if (strstr(vendor_string,
vaapi_driver_quirks_table[i].match_string)) {
-av_log(hwdev, AV_LOG_VERBOSE, "Matched \"%s\" as known "
-   "driver \"%s\".\n", vendor_string,
-   vaapi_driver_quirks_table[i].friendly_name);
+av_log(hwdev, AV_LOG_VERBOSE, "Matched driver string "
+   "as known nonstandard driver \"%s\", setting "
+   "quirks (%#x).\n",
+   vaapi_driver_quirks_table[i].friendly_name,
+   vaapi_driver_quirks_table[i].quirks);
 hwctx->driver_quirks |=
 vaapi_driver_quirks_table[i].quirks;
 break;
 }
 }
 if (!(i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table))) {
-av_log(hwdev, AV_LOG_VERBOSE, "Unknown driver \"%s\", "
-   "assuming standard behaviour.\n", vendor_string);
+av_log(hwdev, AV_LOG_VERBOSE, "Driver not found in known "
+   "nonstandard list, using standard behaviour.\n");
 }
+} else {
+av_log(hwdev, AV_LOG_VERBOSE, "Driver has no vendor string, "
+   "assuming standard behaviour.\n");
 }
 }
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 16/36] vaapi_encode: Clean up rate control configuration

2018-06-07 Thread Mark Thompson
Query which modes are supported and select between VBR and CBR based
on that - this removes all of the codec-specific rate control mode
selection code.
---
 doc/encoders.texi   |   2 -
 libavcodec/vaapi_encode.c   | 173 
 libavcodec/vaapi_encode.h   |   6 +-
 libavcodec/vaapi_encode_h264.c  |  18 +
 libavcodec/vaapi_encode_h265.c  |  14 +---
 libavcodec/vaapi_encode_mjpeg.c |   3 +-
 libavcodec/vaapi_encode_mpeg2.c |   9 +--
 libavcodec/vaapi_encode_vp8.c   |  13 +--
 libavcodec/vaapi_encode_vp9.c   |  13 +--
 9 files changed, 137 insertions(+), 114 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 62a1509a96..0c0a307987 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2643,8 +2643,6 @@ Always encodes using the standard quantisation and 
huffman tables -
 @item mpeg2_vaapi
 @option{profile} and @option{level} set the value of 
@emph{profile_and_level_indication}.
 
-No rate control is supported.
-
 @item vp8_vaapi
 B-frames are not supported.
 
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f4c063734c..5de5483454 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1217,7 +1217,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 int i;
 
 VAConfigAttrib attr[] = {
-{ VAConfigAttribRateControl  },
 { VAConfigAttribEncMaxRefFrames  },
 { VAConfigAttribEncPackedHeaders },
 };
@@ -1241,32 +1240,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 continue;
 }
 switch (attr[i].type) {
-case VAConfigAttribRateControl:
-// Hack for backward compatibility: CBR was the only
-// usable RC mode for a long time, so old drivers will
-// only have it.  Normal default options may now choose
-// VBR and then fail, however, so override it here with
-// CBR if that is the only supported mode.
-if (ctx->va_rc_mode == VA_RC_VBR &&
-!(attr[i].value & VA_RC_VBR) &&
-(attr[i].value & VA_RC_CBR)) {
-av_log(avctx, AV_LOG_WARNING, "VBR rate control is "
-   "not supported with this driver version; "
-   "using CBR instead.\n");
-ctx->va_rc_mode = VA_RC_CBR;
-}
-if (!(ctx->va_rc_mode & attr[i].value)) {
-av_log(avctx, AV_LOG_ERROR, "Rate control mode %#x "
-   "is not supported (mask: %#x).\n",
-   ctx->va_rc_mode, attr[i].value);
-return AVERROR(EINVAL);
-}
-ctx->config_attributes[ctx->nb_config_attributes++] =
-(VAConfigAttrib) {
-.type  = VAConfigAttribRateControl,
-.value = ctx->va_rc_mode,
-};
-break;
 case VAConfigAttribEncMaxRefFrames:
 {
 unsigned int ref_l0 = attr[i].value & 0x;
@@ -1313,44 +1286,144 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-int rc_bits_per_second;
-int rc_target_percentage;
-int rc_window_size;
-int hrd_buffer_size;
-int hrd_initial_buffer_fullness;
+int64_t rc_bits_per_second;
+int rc_target_percentage;
+int rc_window_size;
+int64_t hrd_buffer_size;
+int64_t hrd_initial_buffer_fullness;
 int fr_num, fr_den;
+VAConfigAttrib rc_attr = { VAConfigAttribRateControl };
+VAStatus vas;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile, ctx->va_entrypoint,
+&rc_attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query rate control "
+   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
 
-if (avctx->bit_rate > INT32_MAX) {
-av_log(avctx, AV_LOG_ERROR, "Target bitrate of 2^31 bps or "
-   "higher is not supported.\n");
+if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any "
+   "supported rate control modes: assuming constant-quality.\n");
+ctx->va_rc_mode = VA_RC_CQP;
+return 0;
+}
+if (avctx->flags & AV_CODEC_FLAG_QSCALE ||
+avctx->bit_rate <= 0) {
+if (rc_attr.value & VA_RC_CQP) {
+av_log(avctx, AV_LOG_VERBOSE, "Using constant-quality mode.\n");
+ctx->va_rc_mode = VA_RC_CQP;
+return 0;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Driver does not support "
+   "constant-quality mode (%#x).\n", rc_attr.value);
+return AVERROR(EINVAL);

[FFmpeg-devel] [PATCH v2 14/36] vaapi_encode: Clean up the encode quality configuration

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode.c  | 84 +-
 libavcodec/vaapi_encode_h264.c |  7 ++--
 2 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6104470b31..4da8a7083c 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1391,6 +1391,51 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
+{
+#if VA_CHECK_VERSION(0, 36, 0)
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
+int quality = avctx->compression_level;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+&attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query quality "
+   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+if (quality != 0) {
+av_log(avctx, AV_LOG_WARNING, "Quality attribute is not "
+   "supported: will use default quality level.\n");
+}
+} else {
+if (quality > attr.value) {
+av_log(avctx, AV_LOG_WARNING, "Invalid quality level: "
+   "valid range is 0-%d, using %d.\n",
+   attr.value, attr.value);
+quality = attr.value;
+}
+
+ctx->quality_params.misc.type = VAEncMiscParameterTypeQualityLevel;
+ctx->quality_params.quality.quality_level = quality;
+
+vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc,
+  sizeof(ctx->quality_params));
+}
+#else
+av_log(avctx, AV_LOG_WARNING, "The encode quality option is "
+   "not supported with this VAAPI version.\n");
+#endif
+
+return 0;
+}
+
 static void vaapi_encode_free_output_buffer(void *opaque,
 uint8_t *data)
 {
@@ -1572,6 +1617,12 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 if (err < 0)
 goto fail;
 
+if (avctx->compression_level >= 0) {
+err = vaapi_encode_init_quality(avctx);
+if (err < 0)
+goto fail;
+}
+
 vas = vaCreateConfig(ctx->hwctx->display,
  ctx->va_profile, ctx->va_entrypoint,
  ctx->config_attributes, ctx->nb_config_attributes,
@@ -1621,39 +1672,6 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 goto fail;
 }
 
-if (avctx->compression_level >= 0) {
-#if VA_CHECK_VERSION(0, 36, 0)
-VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
-
-vas = vaGetConfigAttributes(ctx->hwctx->display,
-ctx->va_profile,
-ctx->va_entrypoint,
-&attr, 1);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_WARNING, "Failed to query quality "
-   "attribute: will use default compression level.\n");
-} else {
-if (avctx->compression_level > attr.value) {
-av_log(avctx, AV_LOG_WARNING, "Invalid compression "
-   "level: valid range is 0-%d, using %d.\n",
-   attr.value, attr.value);
-avctx->compression_level = attr.value;
-}
-
-ctx->quality_params.misc.type =
-VAEncMiscParameterTypeQualityLevel;
-ctx->quality_params.quality.quality_level =
-avctx->compression_level;
-
-vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc,
-  sizeof(ctx->quality_params));
-}
-#else
-av_log(avctx, AV_LOG_WARNING, "The encode compression level "
-   "option is not supported with this VAAPI version.\n");
-#endif
-}
-
 ctx->input_order  = 0;
 ctx->output_delay = avctx->max_b_frames;
 ctx->decode_delay = 1;
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index c72fb9f00a..df6f39a946 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -831,9 +831,6 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
 av_assert0(0 && "Invalid RC mode.");
 }
 
-if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
-avctx->compression_level = priv->quality;
-
 if (priv->sei & SEI_IDENTIFIER) {
 const char *lavc  = LIBAVCODEC_IDENT;
 const char *vaapi = VA_VERSION_S;
@@ -907,6 +904,8 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 avctx->profile = priv->pr

[FFmpeg-devel] [PATCH v2 18/36] vaapi_encode: Clean up the GOP structure configuration

2018-06-07 Thread Mark Thompson
Choose what types of reference frames will be used based on what types
are available, and make the intra-only mode explicit (GOP size one,
which must be used for MJPEG).
---
 libavcodec/vaapi_encode.c   | 83 +++--
 libavcodec/vaapi_encode.h   |  1 +
 libavcodec/vaapi_encode_h264.c  |  4 +-
 libavcodec/vaapi_encode_h265.c  |  4 +-
 libavcodec/vaapi_encode_mjpeg.c |  1 +
 libavcodec/vaapi_encode_mpeg2.c |  2 +-
 libavcodec/vaapi_encode_vp8.c   |  7 +---
 libavcodec/vaapi_encode_vp9.c   |  7 ++--
 8 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 0e806a29e3..af9224c98f 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -680,7 +680,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 return AVERROR(ENOMEM);
 
 if (ctx->input_order == 0 || ctx->force_idr ||
-ctx->gop_counter >= avctx->gop_size) {
+ctx->gop_counter >= ctx->gop_size) {
 pic->type = PICTURE_TYPE_IDR;
 ctx->force_idr = 0;
 ctx->gop_counter = 1;
@@ -703,7 +703,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 // encode-after it, but not exceeding the GOP size.
 
 for (i = 0; i < ctx->b_per_p &&
- ctx->gop_counter < avctx->gop_size; i++) {
+ ctx->gop_counter < ctx->gop_size; i++) {
 pic = vaapi_encode_alloc(avctx);
 if (!pic)
 goto fail;
@@ -1217,7 +1217,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 int i;
 
 VAConfigAttrib attr[] = {
-{ VAConfigAttribEncMaxRefFrames  },
 { VAConfigAttribEncPackedHeaders },
 };
 
@@ -1240,24 +1239,6 @@ static av_cold int 
vaapi_encode_config_attributes(AVCodecContext *avctx)
 continue;
 }
 switch (attr[i].type) {
-case VAConfigAttribEncMaxRefFrames:
-{
-unsigned int ref_l0 = attr[i].value & 0x;
-unsigned int ref_l1 = (attr[i].value >> 16) & 0x;
-
-if (avctx->gop_size > 1 && ref_l0 < 1) {
-av_log(avctx, AV_LOG_ERROR, "P frames are not "
-   "supported (%#x).\n", attr[i].value);
-return AVERROR(EINVAL);
-}
-if (avctx->max_b_frames > 0 && ref_l1 < 1) {
-av_log(avctx, AV_LOG_WARNING, "B frames are not "
-   "supported (%#x) by the underlying driver.\n",
-   attr[i].value);
-avctx->max_b_frames = 0;
-}
-}
-break;
 case VAConfigAttribEncPackedHeaders:
 if (ctx->va_packed_headers & ~attr[i].value) {
 // This isn't fatal, but packed headers are always
@@ -1465,6 +1446,54 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
+uint32_t ref_l0, ref_l1;
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+&attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query reference frames "
+   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+ref_l0 = ref_l1 = 0;
+} else {
+ref_l0 = attr.value   & 0x;
+ref_l1 = attr.value >> 16 & 0x;
+}
+
+if (avctx->gop_size <= 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
+ctx->gop_size = 1;
+} else if (ref_l0 < 1) {
+av_log(avctx, AV_LOG_ERROR, "Driver does not support any "
+   "reference frames.\n");
+return AVERROR(EINVAL);
+} else if (ref_l1 < 1 || avctx->max_b_frames < 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
+   "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = 0;
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
+   "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = avctx->max_b_frames;
+}
+
+return 0;
+}
+
 static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
 {
 #if VA_CHECK_VERSION(0, 36, 0)
@@ -1636,7 +1665,7 @@ static av_cold int 
vaapi_encode_create_recon_frames(AVCodecContext *avctx)
 ctx->recon_frames->height= ctx->surface_height;
 // At most three IDR/I/P frames

[FFmpeg-devel] [PATCH v2 15/36] vaapi_encode: Always reapply global parameters after the sequence header

2018-06-07 Thread Mark Thompson
The codec sequence headers may contain fields which can overwrite the
fine parameters given in the specific settings (e.g. a crude bitrate
value vs. the max-rate / target-percentage / etc. values in
VAEncMiscParameterRateControl).  Always reapply all global parameters
after a sequence header to avoid this causing problems.
---
 libavcodec/vaapi_encode.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 4da8a7083c..f4c063734c 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -207,9 +207,16 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 pic->nb_param_buffers = 0;
 
-if (pic->encode_order == 0) {
-// Global parameter buffers are set on the first picture only.
+if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) {
+err = vaapi_encode_make_param_buffer(avctx, pic,
+ VAEncSequenceParameterBufferType,
+ ctx->codec_sequence_params,
+ ctx->codec->sequence_params_size);
+if (err < 0)
+goto fail;
+}
 
+if (pic->type == PICTURE_TYPE_IDR) {
 for (i = 0; i < ctx->nb_global_params; i++) {
 err = vaapi_encode_make_param_buffer(avctx, pic,
  VAEncMiscParameterBufferType,
@@ -220,15 +227,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }
 
-if (pic->type == PICTURE_TYPE_IDR && ctx->codec->init_sequence_params) {
-err = vaapi_encode_make_param_buffer(avctx, pic,
- VAEncSequenceParameterBufferType,
- ctx->codec_sequence_params,
- ctx->codec->sequence_params_size);
-if (err < 0)
-goto fail;
-}
-
 if (ctx->codec->init_picture_params) {
 err = ctx->codec->init_picture_params(avctx, pic);
 if (err < 0) {
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 19/36] vaapi_encode: Clean up the packed header configuration

2018-06-07 Thread Mark Thompson
Add a larger warning more clearly explaining the consequences of missing
packed header support in the driver.  Also only write the extradata if the
user actually requests it via the GLOBAL_HEADER flag.
---
 libavcodec/vaapi_encode.c   | 118 +---
 libavcodec/vaapi_encode.h   |   7 ++-
 libavcodec/vaapi_encode_h264.c  |   2 +-
 libavcodec/vaapi_encode_h265.c  |   2 +-
 libavcodec/vaapi_encode_mjpeg.c |   2 +-
 libavcodec/vaapi_encode_mpeg2.c |   4 +-
 libavcodec/vaapi_encode_vp8.c   |   6 +-
 libavcodec/vaapi_encode_vp9.c   |   6 +-
 8 files changed, 79 insertions(+), 68 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index af9224c98f..14d1846ea3 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1210,60 +1210,6 @@ fail:
 return err;
 }
 
-static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
-{
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAStatus vas;
-int i;
-
-VAConfigAttrib attr[] = {
-{ VAConfigAttribEncPackedHeaders },
-};
-
-vas = vaGetConfigAttributes(ctx->hwctx->display,
-ctx->va_profile, ctx->va_entrypoint,
-attr, FF_ARRAY_ELEMS(attr));
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to fetch config "
-   "attributes: %d (%s).\n", vas, vaErrorStr(vas));
-return AVERROR(EINVAL);
-}
-
-for (i = 0; i < FF_ARRAY_ELEMS(attr); i++) {
-if (attr[i].value == VA_ATTRIB_NOT_SUPPORTED) {
-// Unfortunately we have to treat this as "don't know" and hope
-// for the best, because the Intel MJPEG encoder returns this
-// for all the interesting attributes.
-av_log(avctx, AV_LOG_DEBUG, "Attribute (%d) is not supported.\n",
-   attr[i].type);
-continue;
-}
-switch (attr[i].type) {
-case VAConfigAttribEncPackedHeaders:
-if (ctx->va_packed_headers & ~attr[i].value) {
-// This isn't fatal, but packed headers are always
-// preferable because they are under our control.
-// When absent, the driver is generating them and some
-// features may not work (e.g. VUI or SEI in H.264).
-av_log(avctx, AV_LOG_WARNING, "Warning: some packed "
-   "headers are not supported (want %#x, got %#x).\n",
-   ctx->va_packed_headers, attr[i].value);
-ctx->va_packed_headers &= attr[i].value;
-}
-ctx->config_attributes[ctx->nb_config_attributes++] =
-(VAConfigAttrib) {
-.type  = VAConfigAttribEncPackedHeaders,
-.value = ctx->va_packed_headers,
-};
-break;
-default:
-av_assert0(0 && "Unexpected config attribute.");
-}
-}
-
-return 0;
-}
-
 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -1494,6 +1440,65 @@ static av_cold int 
vaapi_encode_init_gop_structure(AVCodecContext *avctx)
 return 0;
 }
 
+static av_cold int vaapi_encode_init_packed_headers(AVCodecContext *avctx)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+VAStatus vas;
+VAConfigAttrib attr = { VAConfigAttribEncPackedHeaders };
+
+vas = vaGetConfigAttributes(ctx->hwctx->display,
+ctx->va_profile,
+ctx->va_entrypoint,
+&attr, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to query packed headers "
+   "attribute: %d (%s).\n", vas, vaErrorStr(vas));
+return AVERROR_EXTERNAL;
+}
+
+if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+if (ctx->packed_headers) {
+av_log(avctx, AV_LOG_WARNING, "Driver does not support any "
+   "packed headers (wanted %#x).\n", ctx->packed_headers);
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "Driver does not support any "
+   "packed headers (none wanted).\n");
+}
+ctx->va_packed_headers = 0;
+} else {
+if (ctx->packed_headers & ~attr.value) {
+av_log(avctx, AV_LOG_WARNING, "Driver does not support some "
+   "wanted packed headers (wanted %#x, found %#x).\n",
+   ctx->packed_headers, attr.value);
+} else {
+av_log(avctx, AV_LOG_VERBOSE, "All wanted packed headers "
+   "available (wanted %#x, found %#x).\n",
+   ctx->packed_headers, attr.value);
+}
+ctx->va_packed_headers = ctx->packed_headers & attr.value;
+}
+
+if (ctx->va_packed_headers) {
+ctx->config_attributes[ctx->nb_config_attributes++] =
+(VAConfigAt

[FFmpeg-devel] [PATCH v2 17/36] vaapi_encode: Add support for max QP in rate control

2018-06-07 Thread Mark Thompson
This was added in libva 2.1.0 (VAAPI 1.1.0).  Use AVCodecContext.qmax,
matching the existing behaviour for qmin, and clean up the defaults so
that we only pass min/max when explicitly set.
---
 doc/encoders.texi   | 3 ++-
 libavcodec/vaapi_encode.c   | 3 +++
 libavcodec/vaapi_encode_h264.c  | 3 ++-
 libavcodec/vaapi_encode_h265.c  | 2 ++
 libavcodec/vaapi_encode_mpeg2.c | 2 ++
 libavcodec/vaapi_encode_vp8.c   | 2 ++
 libavcodec/vaapi_encode_vp9.c   | 2 ++
 7 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 0c0a307987..861f9f4f1f 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2588,7 +2588,8 @@ Speed / quality tradeoff: higher values are faster / 
worse quality.
 Size / quality tradeoff: higher values are smaller / worse quality.
 @item
 @option{qmin}
-(only: @option{qmax} is not supported)
+@item
+@option{qmax}
 @item
 @option{i_qfactor} / @option{i_quant_factor}
 @item
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 5de5483454..0e806a29e3 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1432,6 +1432,9 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 .initial_qp= 0,
 .min_qp= (avctx->qmin > 0 ? avctx->qmin : 0),
 .basic_unit_size   = 0,
+#if VA_CHECK_VERSION(1, 1, 0)
+.max_qp= (avctx->qmax > 0 ? avctx->qmax : 0),
+#endif
 };
 vaapi_encode_add_global_param(avctx, &ctx->rc_params.misc,
   sizeof(ctx->rc_params));
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 1e6eb2e39b..87c0d9acf3 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -1033,7 +1033,8 @@ static const AVCodecDefault vaapi_encode_h264_defaults[] 
= {
 { "i_qoffset",  "0"   },
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
-{ "qmin",   "0"   },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index b296919b37..13ddad79ae 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1148,6 +1148,8 @@ static const AVCodecDefault vaapi_encode_h265_defaults[] 
= {
 { "i_qoffset",  "0"   },
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index ff86b8817e..db72516187 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -672,6 +672,8 @@ static const AVCodecDefault vaapi_encode_mpeg2_defaults[] = 
{
 { "b_qfactor",  "6/5" },
 { "b_qoffset",  "0"   },
 { "global_quality", "10"  },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index 40871a6bbf..db67136556 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -230,6 +230,8 @@ static const AVCodecDefault vaapi_encode_vp8_defaults[] = {
 { "bf", "0"   },
 { "g",  "120" },
 { "global_quality", "40"  },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index e400bc8b79..2b0658ec1f 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -253,6 +253,8 @@ static const AVCodecDefault vaapi_encode_vp9_defaults[] = {
 { "bf", "0"   },
 { "g",  "250" },
 { "global_quality", "100" },
+{ "qmin",   "-1"  },
+{ "qmax",   "-1"  },
 { NULL },
 };
 
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 11/36] vaapi_encode: Choose profiles dynamically

2018-06-07 Thread Mark Thompson
Previously there was one fixed choice for each codec (e.g. H.265 -> Main
profile), and using anything else then required an explicit option from
the user.  This changes to selecting the profile based on the input format
and the set of profiles actually supported by the driver (e.g. P010 input
will choose Main 10 profile for H.265 if the driver supports it).

The entrypoint and render target format are also chosen dynamically in the
same way, removing those explicit selections from the per-codec code.
---
 doc/encoders.texi   |   3 +
 libavcodec/vaapi_encode.c   | 271 
 libavcodec/vaapi_encode.h   |  43 +--
 libavcodec/vaapi_encode_h264.c  |  45 ++-
 libavcodec/vaapi_encode_h265.c  |  35 ++
 libavcodec/vaapi_encode_mjpeg.c |  13 +-
 libavcodec/vaapi_encode_mpeg2.c |  36 ++
 libavcodec/vaapi_encode_vp8.c   |  11 +-
 libavcodec/vaapi_encode_vp9.c   |  34 ++---
 9 files changed, 310 insertions(+), 181 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7b095754d1..16be6359b3 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2565,6 +2565,9 @@ The following standard libavcodec options are used:
 @option{bf} / @option{max_b_frames}
 @item
 @option{profile}
+
+If not set, this will be determined automatically from the format of the input
+frames and the profiles supported by the driver.
 @item
 @option{level}
 @item
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 27ce792fbe..6104470b31 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -983,70 +983,247 @@ static av_cold void 
vaapi_encode_add_global_param(AVCodecContext *avctx,
 ++ctx->nb_global_params;
 }
 
-static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
+typedef struct VAAPIEncodeRTFormat {
+const char *name;
+unsigned int value;
+int depth;
+int components;
+int log2_chroma_w;
+int log2_chroma_h;
+} VAAPIEncodeRTFormat;
+
+static const VAAPIEncodeRTFormat vaapi_encode_rt_formats[] = {
+{ "YUV400",VA_RT_FORMAT_YUV400,8, 1,  },
+{ "YUV420",VA_RT_FORMAT_YUV420,8, 3, 1, 1 },
+{ "YUV422",VA_RT_FORMAT_YUV422,8, 3, 1, 0 },
+{ "YUV444",VA_RT_FORMAT_YUV444,8, 3, 0, 0 },
+{ "YUV411",VA_RT_FORMAT_YUV411,8, 3, 2, 0 },
+#if VA_CHECK_VERSION(0, 38, 1)
+{ "YUV420_10", VA_RT_FORMAT_YUV420_10BPP, 10, 3, 1, 1 },
+#endif
+};
+
+static const VAEntrypoint vaapi_encode_entrypoints_normal[] = {
+VAEntrypointEncSlice,
+VAEntrypointEncPicture,
+#if VA_CHECK_VERSION(0, 39, 2)
+VAEntrypointEncSliceLP,
+#endif
+0
+};
+#if VA_CHECK_VERSION(0, 39, 2)
+static const VAEntrypoint vaapi_encode_entrypoints_low_power[] = {
+VAEntrypointEncSliceLP,
+0
+};
+#endif
+
+static av_cold int vaapi_encode_profile_entrypoint(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAProfile*va_profiles= NULL;
+VAEntrypoint *va_entrypoints = NULL;
 VAStatus vas;
-int i, n, err;
-VAProfile*profiles= NULL;
-VAEntrypoint *entrypoints = NULL;
-VAConfigAttrib attr[] = {
-{ VAConfigAttribRTFormat },
-{ VAConfigAttribRateControl  },
-{ VAConfigAttribEncMaxRefFrames  },
-{ VAConfigAttribEncPackedHeaders },
-};
+const VAEntrypoint *usable_entrypoints;
+const VAAPIEncodeProfile *profile;
+const AVPixFmtDescriptor *desc;
+VAConfigAttrib rt_format_attr;
+const VAAPIEncodeRTFormat *rt_format;
+int i, j, n, depth, err;
+
+
+if (ctx->low_power) {
+#if VA_CHECK_VERSION(0, 39, 2)
+usable_entrypoints = vaapi_encode_entrypoints_low_power;
+#else
+av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
+   "supported with this VAAPI version.\n");
+return AVERROR(EINVAL);
+#endif
+} else {
+usable_entrypoints = vaapi_encode_entrypoints_normal;
+}
+
+desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
+if (!desc) {
+av_log(avctx, AV_LOG_ERROR, "Invalid input pixfmt (%d).\n",
+   ctx->input_frames->sw_format);
+return AVERROR(EINVAL);
+}
+depth = desc->comp[0].depth;
+for (i = 1; i < desc->nb_components; i++) {
+if (desc->comp[i].depth != depth) {
+av_log(avctx, AV_LOG_ERROR, "Invalid input pixfmt (%s).\n",
+   desc->name);
+return AVERROR(EINVAL);
+}
+}
+av_log(avctx, AV_LOG_VERBOSE, "Input surface format is %s.\n",
+   desc->name);
 
 n = vaMaxNumProfiles(ctx->hwctx->display);
-profiles = av_malloc_array(n, sizeof(VAProfile));
-if (!profiles) {
+va_profiles = av_malloc_array(n, sizeof(VAProfile));
+if (!va_profiles) {
 err = AVERROR(ENOMEM);
 goto fail;
 }
-vas = vaQueryConfigProfiles(ctx->hwctx->display, pr

[FFmpeg-devel] [PATCH v2 12/36] vaapi_encode: Add common options between all encoders

2018-06-07 Thread Mark Thompson
The only common option here is low_power - it was previously supported
for H.264 only, that specific option is removed.
---
 doc/encoders.texi  | 14 --
 libavcodec/vaapi_encode.h  |  9 +
 libavcodec/vaapi_encode_h264.c |  8 ++--
 libavcodec/vaapi_encode_h265.c |  2 ++
 libavcodec/vaapi_encode_vp8.c  |  1 +
 libavcodec/vaapi_encode_vp9.c  |  1 +
 6 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 16be6359b3..62a1509a96 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2599,6 +2599,18 @@ Size / quality tradeoff: higher values are smaller / 
worse quality.
 @option{b_qoffset} / @option{b_quant_offset}
 @end itemize
 
+All encoders support the following options:
+@itemize
+@item
+@option{low_power}
+
+Some drivers/platforms offer a second encoder for some codecs intended to use
+less power than the default encoder; setting this option will attempt to use
+that encoder.  Note that it may support a reduced feature set, so some other
+options may not be available in this mode.
+@end itemize
+
+Each encoder also has its own specific options:
 @table @option
 
 @item h264_vaapi
@@ -2606,8 +2618,6 @@ Size / quality tradeoff: higher values are smaller / 
worse quality.
 @option{level} sets the value of @emph{level_idc}.
 
 @table @option
-@item low_power
-Use low-power encoding mode.
 @item coder
 Set entropy encoder (default is @emph{cabac}).  Possible values:
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 212ab6726d..b8f2ed6d21 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -302,4 +302,13 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
 int ff_vaapi_encode_init(AVCodecContext *avctx);
 int ff_vaapi_encode_close(AVCodecContext *avctx);
 
+
+#define VAAPI_ENCODE_COMMON_OPTIONS \
+{ "low_power", \
+  "Use low-power encoding mode (only available on some platforms; " \
+  "may not support all encoding features)", \
+  OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
+  { .i64 = 0 }, 0, 1, FLAGS }
+
+
 #endif /* AVCODEC_VAAPI_ENCODE_H */
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index ab8bf13ef3..c72fb9f00a 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -52,7 +52,6 @@ typedef struct VAAPIEncodeH264Context {
 // User options.
 int qp;
 int quality;
-int low_power;
 int coder;
 int aud;
 int sei;
@@ -936,8 +935,6 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext 
*avctx)
 return AVERROR_PATCHWELCOME;
 }
 
-ctx->low_power = priv->low_power;
-
 if (avctx->bit_rate > 0) {
 if (avctx->rc_max_rate == avctx->bit_rate)
 ctx->va_rc_mode = VA_RC_CBR;
@@ -970,13 +967,12 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h264_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
+
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
 { "quality", "Set encode quality (trades off against speed, higher is 
faster)",
   OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, FLAGS },
-{ "low_power", "Use low-power encoding mode (experimental: only supported "
-  "on some platforms, does not support all features)",
-  OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
 { "coder", "Entropy coder type",
   OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
 { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 9fa16593d0..b8b66b87cb 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1099,6 +1099,8 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_h265_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
+
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
 
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index a502df7885..9588826bfb 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -228,6 +228,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext 
*avctx)
 #define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp8_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
 { "loop_filter_level", "Loop fi

[FFmpeg-devel] [PATCH v2 13/36] vaapi_encode_mpeg2: Add options

2018-06-07 Thread Mark Thompson
Include the common options, and also named options for setting the profile
and level.
---
 libavcodec/vaapi_encode_mpeg2.c | 53 +++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 7f6c7833da..db79d72115 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -30,6 +30,10 @@
 typedef struct VAAPIEncodeMPEG2Context {
 VAAPIEncodeContext common;
 
+// User options.
+int profile;
+int level;
+
 // Derived settings.
 int mb_width;
 int mb_height;
@@ -581,10 +585,18 @@ static const VAAPIEncodeType vaapi_encode_type_mpeg2 = {
 
 static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 
 ctx->codec = &vaapi_encode_type_mpeg2;
 
+if (avctx->profile == FF_PROFILE_UNKNOWN)
+avctx->profile = priv->profile;
+if (avctx->level == FF_LEVEL_UNKNOWN)
+avctx->level = priv->level;
+
+// Reject unknown levels (these are required to set f_code for
+// motion vector encoding).
 switch (avctx->level) {
 case 4: // High
 case 6: // High 1440
@@ -623,8 +635,37 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext 
*avctx)
 return ff_vaapi_encode_close(avctx);
 }
 
+#define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
+#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
+static const AVOption vaapi_encode_mpeg2_options[] = {
+VAAPI_ENCODE_COMMON_OPTIONS,
+
+{ "profile", "Set profile (in profile_and_level_indication)",
+  OFFSET(profile), AV_OPT_TYPE_INT,
+  { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 7, FLAGS, "profile" },
+
+#define PROFILE(name, value)  name, NULL, 0, AV_OPT_TYPE_CONST, \
+  { .i64 = value }, 0, 0, FLAGS, "profile"
+{ PROFILE("simple", FF_PROFILE_MPEG2_SIMPLE) },
+{ PROFILE("main",   FF_PROFILE_MPEG2_MAIN)   },
+#undef PROFILE
+
+{ "level", "Set level (in profile_and_level_indication)",
+  OFFSET(level), AV_OPT_TYPE_INT,
+  { .i64 = 4 }, 0, 15, FLAGS, "level" },
+
+#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+  { .i64 = value }, 0, 0, FLAGS, "level"
+{ LEVEL("low",   10) },
+{ LEVEL("main",   8) },
+{ LEVEL("high_1440",  6) },
+{ LEVEL("high",   4) },
+#undef LEVEL
+
+{ NULL },
+};
+
 static const AVCodecDefault vaapi_encode_mpeg2_defaults[] = {
-{ "level",  "4"   },
 { "bf", "1"   },
 { "g",  "120" },
 { "i_qfactor",  "1"   },
@@ -635,6 +676,13 @@ static const AVCodecDefault vaapi_encode_mpeg2_defaults[] 
= {
 { NULL },
 };
 
+static const AVClass vaapi_encode_mpeg2_class = {
+.class_name = "mpeg2_vaapi",
+.item_name  = av_default_item_name,
+.option = vaapi_encode_mpeg2_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_mpeg2_vaapi_encoder = {
 .name   = "mpeg2_vaapi",
 .long_name  = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"),
@@ -644,6 +692,7 @@ AVCodec ff_mpeg2_vaapi_encoder = {
 .init   = &vaapi_encode_mpeg2_init,
 .encode2= &ff_vaapi_encode2,
 .close  = &vaapi_encode_mpeg2_close,
+.priv_class = &vaapi_encode_mpeg2_class,
 .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
 .defaults   = vaapi_encode_mpeg2_defaults,
 .pix_fmts = (const enum AVPixelFormat[]) {
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 07/36] vaapi_encode_vp9: Move options and common structures into context

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_vp9.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 9108699ac3..6e62213bc9 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -33,21 +33,25 @@
 
 
 typedef struct VAAPIEncodeVP9Context {
+VAAPIEncodeContext common;
+
+// User options.
+int loop_filter_level;
+int loop_filter_sharpness;
+
+// Derived settings.
 int q_idx_idr;
 int q_idx_p;
 int q_idx_b;
 
+// Stream state.
+
 // Reference direction for B-like frames:
 // 0 - most recent P/IDR frame is last.
 // 1 - most recent P frame is golden.
 int last_ref_dir;
 } VAAPIEncodeVP9Context;
 
-typedef struct VAAPIEncodeVP9Options {
-int loop_filter_level;
-int loop_filter_sharpness;
-} VAAPIEncodeVP9Options;
-
 
 #define vseq_var(name) vseq->name, name
 #define vseq_field(name)   vseq->seq_fields.bits.name, name
@@ -82,10 +86,8 @@ static int 
vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeVP9Context  *priv = avctx->priv_data;
 VAEncPictureParameterBufferVP9 *vpic = pic->codec_picture_params;
-VAAPIEncodeVP9Context  *priv = ctx->priv_data;
-VAAPIEncodeVP9Options   *opt = ctx->codec_options;
 int i;
 
 vpic->reconstructed_frame = pic->recon_surface;
@@ -169,8 +171,8 @@ static int 
vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 vpic->chroma_ac_qindex_delta = 0;
 vpic->chroma_dc_qindex_delta = 0;
 
-vpic->filter_level= opt->loop_filter_level;
-vpic->sharpness_level = opt->loop_filter_sharpness;
+vpic->filter_level= priv->loop_filter_level;
+vpic->sharpness_level = priv->loop_filter_sharpness;
 
 if (avctx->max_b_frames > 0 && pic->type == PICTURE_TYPE_P)
 priv->last_ref_dir = !priv->last_ref_dir;
@@ -180,8 +182,7 @@ static int 
vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP9Context *priv = ctx->priv_data;
+VAAPIEncodeVP9Context *priv = avctx->priv_data;
 
 priv->q_idx_p = av_clip(avctx->global_quality, 0, VP9_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
@@ -266,8 +267,7 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext 
*avctx)
 return ff_vaapi_encode_init(avctx);
 }
 
-#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
-   offsetof(VAAPIEncodeVP9Options, x))
+#define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp9_options[] = {
 { "loop_filter_level", "Loop filter level",
@@ -298,8 +298,7 @@ AVCodec ff_vp9_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("VP9 (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_VP9,
-.priv_data_size = (sizeof(VAAPIEncodeContext) +
-   sizeof(VAAPIEncodeVP9Options)),
+.priv_data_size = sizeof(VAAPIEncodeVP9Context),
 .init   = &vaapi_encode_vp9_init,
 .encode2= &ff_vaapi_encode2,
 .close  = &ff_vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 06/36] vaapi_encode_vp8: Move options and common structures into context

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_vp8.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index a2e861a8d1..ab5e0b2dda 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -32,14 +32,16 @@
 
 
 typedef struct VAAPIEncodeVP8Context {
-int q_index_i;
-int q_index_p;
-} VAAPIEncodeVP8Context;
+VAAPIEncodeContext common;
 
-typedef struct VAAPIEncodeVP8Options {
+// User options.
 int loop_filter_level;
 int loop_filter_sharpness;
-} VAAPIEncodeVP8Options;
+
+// Derived settings.
+int q_index_i;
+int q_index_p;
+} VAAPIEncodeVP8Context;
 
 
 #define vseq_var(name) vseq->name, name
@@ -73,9 +75,8 @@ static int 
vaapi_encode_vp8_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
 VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeVP8Context  *priv = avctx->priv_data;
 VAEncPictureParameterBufferVP8 *vpic = pic->codec_picture_params;
-VAAPIEncodeVP8Options   *opt = ctx->codec_options;
 int i;
 
 vpic->reconstructed_frame = pic->recon_surface;
@@ -116,8 +117,8 @@ static int 
vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx,
 vpic->pic_flags.bits.version = 0;
 vpic->pic_flags.bits.loop_filter_type = 0;
 for (i = 0; i < 4; i++)
-vpic->loop_filter_level[i] = opt->loop_filter_level;
-vpic->sharpness_level = opt->loop_filter_sharpness;
+vpic->loop_filter_level[i] = priv->loop_filter_level;
+vpic->sharpness_level = priv->loop_filter_sharpness;
 
 vpic->clamp_qindex_low  = 0;
 vpic->clamp_qindex_high = 127;
@@ -130,8 +131,7 @@ static int 
vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
   int index, int *type,
   char *data, size_t *data_len)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP8Context *priv = ctx->priv_data;
+VAAPIEncodeVP8Context *priv = avctx->priv_data;
 VAQMatrixBufferVP8 quant;
 int i, q;
 
@@ -161,8 +161,7 @@ static int 
vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_vp8_configure(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeVP8Context *priv = ctx->priv_data;
+VAAPIEncodeVP8Context *priv = avctx->priv_data;
 
 priv->q_index_p = av_clip(avctx->global_quality, 0, VP8_MAX_QUANT);
 if (avctx->i_quant_factor > 0.0)
@@ -225,8 +224,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext 
*avctx)
 return ff_vaapi_encode_init(avctx);
 }
 
-#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
-   offsetof(VAAPIEncodeVP8Options, x))
+#define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption vaapi_encode_vp8_options[] = {
 { "loop_filter_level", "Loop filter level",
@@ -256,8 +254,7 @@ AVCodec ff_vp8_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("VP8 (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_VP8,
-.priv_data_size = (sizeof(VAAPIEncodeContext) +
-   sizeof(VAAPIEncodeVP8Options)),
+.priv_data_size = sizeof(VAAPIEncodeVP8Context),
 .init   = &vaapi_encode_vp8_init,
 .encode2= &ff_vaapi_encode2,
 .close  = &ff_vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 08/36] vaapi_encode: Remove common priv_data and options fields

2018-06-07 Thread Mark Thompson
The codec-specific context now contains both the common context and the
codec-specific options directly.
---
 libavcodec/vaapi_encode.c   | 10 --
 libavcodec/vaapi_encode.h   | 11 ---
 libavcodec/vaapi_encode_h264.c  |  2 --
 libavcodec/vaapi_encode_h265.c  |  2 --
 libavcodec/vaapi_encode_mjpeg.c |  2 --
 libavcodec/vaapi_encode_mpeg2.c |  2 --
 libavcodec/vaapi_encode_vp8.c   |  2 --
 libavcodec/vaapi_encode_vp9.c   |  2 --
 8 files changed, 33 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 910fd1b365..cedf3d3549 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1372,17 +1372,9 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-ctx->codec_options = ctx->codec_options_data;
-
 ctx->va_config  = VA_INVALID_ID;
 ctx->va_context = VA_INVALID_ID;
 
-ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
-if (!ctx->priv_data) {
-err = AVERROR(ENOMEM);
-goto fail;
-}
-
 ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
 if (!ctx->input_frames_ref) {
 err = AVERROR(ENOMEM);
@@ -1583,7 +1575,5 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
 av_buffer_unref(&ctx->input_frames_ref);
 av_buffer_unref(&ctx->device_ref);
 
-av_freep(&ctx->priv_data);
-
 return 0;
 }
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index bcb9d57371..c7370a17e2 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -113,9 +113,6 @@ typedef struct VAAPIEncodeContext {
 // Everything above this point must be set before calling
 // ff_vaapi_encode_init().
 
-// Codec-specific state.
-void *priv_data;
-
 // Configuration attributes to use when creating va_config.
 VAConfigAttrib  config_attributes[MAX_CONFIG_ATTRIBUTES];
 int  nb_config_attributes;
@@ -205,18 +202,10 @@ typedef struct VAAPIEncodeContext {
 int gop_counter;
 int p_counter;
 int end_of_stream;
-
-// Codec-local options are allocated to follow this structure in
-// memory (in the AVCodec definition, set priv_data_size to
-// sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
-void *codec_options;
-char codec_options_data[0];
 } VAAPIEncodeContext;
 
 
 typedef struct VAAPIEncodeType {
-size_t priv_data_size;
-
 // Perform any extra codec-specific configuration after the
 // codec context is initialised (set up the private data and
 // add any necessary global parameters).
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 26061974a4..8f999b2311 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -867,8 +867,6 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_h264 = {
-.priv_data_size= sizeof(VAAPIEncodeH264Context),
-
 .configure = &vaapi_encode_h264_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferH264),
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 757fd74c30..8f191efc4b 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1026,8 +1026,6 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_h265 = {
-.priv_data_size= sizeof(VAAPIEncodeH265Context),
-
 .configure = &vaapi_encode_h265_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferHEVC),
diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index 983c77d194..481981a71c 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -360,8 +360,6 @@ static av_cold int 
vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_mjpeg = {
-.priv_data_size= sizeof(VAAPIEncodeMJPEGContext),
-
 .configure = &vaapi_encode_mjpeg_configure,
 
 .picture_params_size   = sizeof(VAEncPictureParameterBufferJPEG),
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index ae77a9ce76..5577fa9e04 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -553,8 +553,6 @@ static av_cold int 
vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
 }
 
 static const VAAPIEncodeType vaapi_encode_type_mpeg2 = {
-.priv_data_size= sizeof(VAAPIEncodeMPEG2Context),
-
 .configure = &vaapi_encode_mpeg2_configure,
 
 .sequence_params_size  = sizeof(VAEncSequenceParameterBufferMPEG2),
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c
index ab5e0b2dda..6cdd30abda 100644
--- a/libavcodec/vaapi_encode_vp8.c
+++ b/libavcodec/vaapi_encode_vp8.c
@@ -178,8 +178,6 @@ static av_cold i

[FFmpeg-devel] [PATCH v2 10/36] vaapi_encode: Factorise out adding global parameters

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode.c | 38 ++
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index ed6d289c6b..27ce792fbe 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -969,6 +969,20 @@ fail:
 return err;
 }
 
+static av_cold void vaapi_encode_add_global_param(AVCodecContext *avctx,
+  VAEncMiscParameterBuffer 
*buffer,
+  size_t size)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+
+av_assert0(ctx->nb_global_params < MAX_GLOBAL_PARAMS);
+
+ctx->global_params [ctx->nb_global_params] = buffer;
+ctx->global_params_size[ctx->nb_global_params] = size;
+
+++ctx->nb_global_params;
+}
+
 static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -1191,20 +1205,16 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 .min_qp= (avctx->qmin > 0 ? avctx->qmin : 0),
 .basic_unit_size   = 0,
 };
-ctx->global_params[ctx->nb_global_params] =
-&ctx->rc_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->rc_params);
+vaapi_encode_add_global_param(avctx, &ctx->rc_params.misc,
+  sizeof(ctx->rc_params));
 
 ctx->hrd_params.misc.type = VAEncMiscParameterTypeHRD;
 ctx->hrd_params.hrd = (VAEncMiscParameterHRD) {
 .initial_buffer_fullness = hrd_initial_buffer_fullness,
 .buffer_size = hrd_buffer_size,
 };
-ctx->global_params[ctx->nb_global_params] =
-&ctx->hrd_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->hrd_params);
+vaapi_encode_add_global_param(avctx, &ctx->hrd_params.misc,
+  sizeof(ctx->hrd_params));
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
 av_reduce(&fr_num, &fr_den,
@@ -1217,10 +1227,8 @@ static av_cold int 
vaapi_encode_init_rate_control(AVCodecContext *avctx)
 ctx->fr_params.fr.framerate = (unsigned int)fr_den << 16 | fr_num;
 
 #if VA_CHECK_VERSION(0, 40, 0)
-ctx->global_params[ctx->nb_global_params] =
-&ctx->fr_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->fr_params);
+vaapi_encode_add_global_param(avctx, &ctx->fr_params.misc,
+  sizeof(ctx->fr_params));
 #endif
 
 return 0;
@@ -1476,10 +1484,8 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 ctx->quality_params.quality.quality_level =
 avctx->compression_level;
 
-ctx->global_params[ctx->nb_global_params] =
-&ctx->quality_params.misc;
-ctx->global_params_size[ctx->nb_global_params++] =
-sizeof(ctx->quality_params);
+vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc,
+  sizeof(ctx->quality_params));
 }
 #else
 av_log(avctx, AV_LOG_WARNING, "The encode compression level "
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 04/36] vaapi_encode_mjpeg: Move common structure into context

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_mjpeg.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
index c949e89646..983c77d194 100644
--- a/libavcodec/vaapi_encode_mjpeg.c
+++ b/libavcodec/vaapi_encode_mjpeg.c
@@ -56,6 +56,8 @@ static const unsigned char 
vaapi_encode_mjpeg_quant_chrominance[64] = {
 };
 
 typedef struct VAAPIEncodeMJPEGContext {
+VAAPIEncodeContext common;
+
 int quality;
 int component_subsample_h[3];
 int component_subsample_v[3];
@@ -83,8 +85,7 @@ static av_cold void vaapi_encode_mjpeg_copy_huffman(unsigned 
char *dst_lengths,
 
 static av_cold void vaapi_encode_mjpeg_init_tables(AVCodecContext *avctx)
 {
-VAAPIEncodeContext*ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext  *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext  *priv = avctx->priv_data;
 VAQMatrixBufferJPEG *quant = &priv->quant_tables;
 VAHuffmanTableBufferJPEGBaseline *huff = &priv->huffman_tables;
 int i;
@@ -133,10 +134,9 @@ static int 
vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx,
  VAAPIEncodeSlice *slice,
  char *data, size_t *data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params;
 VAEncSliceParameterBufferJPEG *vslice = slice->codec_slice_params;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
 PutBitContext pbc;
 int t, i, quant_scale;
 
@@ -242,8 +242,7 @@ static int 
vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
  int index, int *type,
  char *data, size_t *data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 
 if (index == 0) {
 // Write quantisation tables.
@@ -270,9 +269,8 @@ static int 
vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx,
 static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx,
   VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
 
 vpic->reconstructed_picture = pic->recon_surface;
 vpic->coded_buf = pic->output_buffer;
@@ -336,7 +334,7 @@ static int 
vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx,
 static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
 {
 VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMJPEGContext *priv = ctx->priv_data;
+VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
 
 priv->quality = avctx->global_quality;
 if (priv->quality < 1 || priv->quality > 100) {
@@ -417,7 +415,7 @@ AVCodec ff_mjpeg_vaapi_encoder = {
 .long_name  = NULL_IF_CONFIG_SMALL("MJPEG (VAAPI)"),
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_MJPEG,
-.priv_data_size = sizeof(VAAPIEncodeContext),
+.priv_data_size = sizeof(VAAPIEncodeMJPEGContext),
 .init   = &vaapi_encode_mjpeg_init,
 .encode2= &ff_vaapi_encode2,
 .close  = &ff_vaapi_encode_close,
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 09/36] vaapi_encode: Allocate picture-private data in generic code

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode.c | 15 ---
 libavcodec/vaapi_encode.h |  4 
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index cedf3d3549..ed6d289c6b 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -528,14 +528,23 @@ static int vaapi_encode_discard(AVCodecContext *avctx,
 return 0;
 }
 
-static VAAPIEncodePicture *vaapi_encode_alloc(void)
+static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
 {
+VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodePicture *pic;
 
 pic = av_mallocz(sizeof(*pic));
 if (!pic)
 return NULL;
 
+if (ctx->codec->picture_priv_data_size > 0) {
+pic->priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
+if (!pic->priv_data) {
+av_freep(&pic);
+return NULL;
+}
+}
+
 pic->input_surface = VA_INVALID_ID;
 pic->recon_surface = VA_INVALID_ID;
 pic->output_buffer = VA_INVALID_ID;
@@ -668,7 +677,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 }
 }
 
-pic = vaapi_encode_alloc();
+pic = vaapi_encode_alloc(avctx);
 if (!pic)
 return AVERROR(ENOMEM);
 
@@ -697,7 +706,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 
 for (i = 0; i < ctx->b_per_p &&
  ctx->gop_counter < avctx->gop_size; i++) {
-pic = vaapi_encode_alloc();
+pic = vaapi_encode_alloc(avctx);
 if (!pic)
 goto fail;
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index c7370a17e2..54dc4a475e 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -211,6 +211,10 @@ typedef struct VAAPIEncodeType {
 // add any necessary global parameters).
 int (*configure)(AVCodecContext *avctx);
 
+// The size of any private data structure associated with each
+// picture (can be zero if not required).
+size_t picture_priv_data_size;
+
 // The size of the parameter structures:
 // sizeof(VAEnc{type}ParameterBuffer{codec}).
 size_t sequence_params_size;
-- 
2.16.3

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


[FFmpeg-devel] [PATCH v2 05/36] vaapi_encode_mpeg2: Move common structure into context

2018-06-07 Thread Mark Thompson
---
 libavcodec/vaapi_encode_mpeg2.c | 53 +++--
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 42df77ea49..ae77a9ce76 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -28,6 +28,9 @@
 #include "vaapi_encode.h"
 
 typedef struct VAAPIEncodeMPEG2Context {
+VAAPIEncodeContext common;
+
+// Derived settings.
 int mb_width;
 int mb_height;
 
@@ -35,15 +38,6 @@ typedef struct VAAPIEncodeMPEG2Context {
 int quant_p;
 int quant_b;
 
-MPEG2RawSequenceHeader sequence_header;
-MPEG2RawExtensionData  sequence_extension;
-MPEG2RawExtensionData  sequence_display_extension;
-MPEG2RawGroupOfPicturesHeader gop_header;
-MPEG2RawPictureHeader  picture_header;
-MPEG2RawExtensionData  picture_coding_extension;
-
-int64_t last_i_frame;
-
 unsigned int bit_rate;
 unsigned int vbv_buffer_size;
 
@@ -52,6 +46,17 @@ typedef struct VAAPIEncodeMPEG2Context {
 unsigned int f_code_horizontal;
 unsigned int f_code_vertical;
 
+// Stream state.
+int64_t last_i_frame;
+
+// Writer structures.
+MPEG2RawSequenceHeader sequence_header;
+MPEG2RawExtensionData  sequence_extension;
+MPEG2RawExtensionData  sequence_display_extension;
+MPEG2RawGroupOfPicturesHeader gop_header;
+MPEG2RawPictureHeader  picture_header;
+MPEG2RawExtensionData  picture_coding_extension;
+
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMPEG2Context;
@@ -61,8 +66,7 @@ static int vaapi_encode_mpeg2_write_fragment(AVCodecContext 
*avctx,
  char *data, size_t *data_len,
  CodedBitstreamFragment *frag)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, frag);
@@ -88,8 +92,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext 
*avctx,
  CodedBitstreamFragment *frag,
  int type, void *header)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL);
@@ -105,8 +108,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext 
*avctx,
 static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
 char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 CodedBitstreamFragment  *frag = &priv->current_fragment;
 int err;
 
@@ -140,8 +142,7 @@ static int 
vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
 CodedBitstreamFragment  *frag = &priv->current_fragment;
 int err;
 
@@ -164,7 +165,7 @@ fail:
 static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context   *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context   *priv = avctx->priv_data;
 MPEG2RawSequenceHeader  *sh = &priv->sequence_header;
 MPEG2RawSequenceExtension   *se = 
&priv->sequence_extension.data.sequence;
 MPEG2RawSequenceDisplayExtension   *sde = 
&priv->sequence_display_extension.data.sequence_display;
@@ -416,8 +417,7 @@ static int 
vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
 static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
  VAAPIEncodePicture *pic)
 {
-VAAPIEncodeContext*ctx = avctx->priv_data;
-VAAPIEncodeMPEG2Context  *priv = ctx->priv_data;
+VAAPIEncodeMPEG2Context  *priv = avctx->priv_data;
 MPEG2RawPictureHeader  *ph = &priv->picture_header;
 MPEG2RawPictureCodingExtension*pce = 
&priv->picture_coding_extension.data.picture_coding;
 VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params;
@@ -482,9 +482,8 @@ static int 
vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
 

[FFmpeg-devel] [PATCH v2 02/36] vaapi_encode_h264: Move options and common structures into context

2018-06-07 Thread Mark Thompson
This will make it easier to support options in common between different
encoders.  It also cleans up some of the field naming.
---
 libavcodec/vaapi_encode_h264.c | 228 +
 1 file changed, 115 insertions(+), 113 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 905c50760e..26061974a4 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -47,6 +47,19 @@ static const uint8_t 
vaapi_encode_h264_sei_identifier_uuid[16] = {
 };
 
 typedef struct VAAPIEncodeH264Context {
+VAAPIEncodeContext common;
+
+// User options.
+int qp;
+int quality;
+int low_power;
+int coder;
+int aud;
+int sei;
+int profile;
+int level;
+
+// Derived settings.
 int mb_width;
 int mb_height;
 
@@ -54,18 +67,7 @@ typedef struct VAAPIEncodeH264Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
-H264RawAUD aud;
-H264RawSPS sps;
-H264RawPPS pps;
-H264RawSEI sei;
-H264RawSlice slice;
-
-H264RawSEIBufferingPeriod buffering_period;
-H264RawSEIPicTiming pic_timing;
-H264RawSEIRecoveryPoint recovery_point;
-H264RawSEIUserDataUnregistered identifier;
-char *identifier_string;
-
+// Stream state.
 int frame_num;
 int pic_order_cnt;
 int next_frame_num;
@@ -78,32 +80,33 @@ typedef struct VAAPIEncodeH264Context {
 int cpb_delay;
 int dpb_delay;
 
+// Writer structures.
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
+
+H264RawAUD   raw_aud;
+H264RawSPS   raw_sps;
+H264RawPPS   raw_pps;
+H264RawSEI   raw_sei;
+H264RawSlice raw_slice;
+
+H264RawSEIBufferingPeriod  sei_buffering_period;
+H264RawSEIPicTimingsei_pic_timing;
+H264RawSEIRecoveryPointsei_recovery_point;
+H264RawSEIUserDataUnregistered sei_identifier;
+char  *sei_identifier_string;
+
 int aud_needed;
 int sei_needed;
 int sei_cbr_workaround_needed;
 } VAAPIEncodeH264Context;
 
-typedef struct VAAPIEncodeH264Options {
-int qp;
-int quality;
-int low_power;
-// Entropy encoder type.
-int coder;
-int aud;
-int sei;
-int profile;
-int level;
-} VAAPIEncodeH264Options;
-
 
 static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx,
char *data, size_t *data_len,
CodedBitstreamFragment *au)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, au);
@@ -129,8 +132,7 @@ static int vaapi_encode_h264_add_nal(AVCodecContext *avctx,
  CodedBitstreamFragment *au,
  void *nal_unit)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 H264RawNALUnitHeader *header = nal_unit;
 int err;
 
@@ -148,23 +150,22 @@ static int vaapi_encode_h264_add_nal(AVCodecContext 
*avctx,
 static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h264_add_nal(avctx, au, &priv->sps);
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_sps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h264_add_nal(avctx, au, &priv->pps);
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_pps);
 if (err < 0)
 goto fail;
 
@@ -179,19 +180,18 @@ static int 
vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
 VAAPIEncodeSlice *slice,
 char *data, size_t *data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH264Context *priv = ctx->priv_data;
+VAAPIEncodeH264Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
+err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed =

[FFmpeg-devel] [PATCH v2 03/36] vaapi_encode_h265: Move options and common structures into context

2018-06-07 Thread Mark Thompson
Matching previous commit for H.264.
---
 libavcodec/vaapi_encode_h265.c | 182 -
 1 file changed, 90 insertions(+), 92 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index bbba2b8cd9..757fd74c30 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -41,6 +41,16 @@ enum {
 };
 
 typedef struct VAAPIEncodeH265Context {
+VAAPIEncodeContext common;
+
+// User options.
+int qp;
+int aud;
+int profile;
+int level;
+int sei;
+
+// Derived settings.
 unsigned int ctu_width;
 unsigned int ctu_height;
 
@@ -48,16 +58,7 @@ typedef struct VAAPIEncodeH265Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
-H265RawAUD aud;
-H265RawVPS vps;
-H265RawSPS sps;
-H265RawPPS pps;
-H265RawSlice slice;
-H265RawSEI sei;
-
-H265RawSEIMasteringDisplayColourVolume mastering_display;
-H265RawSEIContentLightLevelInfo content_light_level;
-
+// Stream state.
 int64_t last_idr_frame;
 int pic_order_cnt;
 
@@ -65,27 +66,29 @@ typedef struct VAAPIEncodeH265Context {
 int slice_type;
 int pic_type;
 
+// Writer structures.
+H265RawAUD   raw_aud;
+H265RawVPS   raw_vps;
+H265RawSPS   raw_sps;
+H265RawPPS   raw_pps;
+H265RawSEI   raw_sei;
+H265RawSlice raw_slice;
+
+H265RawSEIMasteringDisplayColourVolume sei_mastering_display;
+H265RawSEIContentLightLevelInfosei_content_light_level;
+
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_access_unit;
 int aud_needed;
 int sei_needed;
 } VAAPIEncodeH265Context;
 
-typedef struct VAAPIEncodeH265Options {
-int qp;
-int aud;
-int profile;
-int level;
-int sei;
-} VAAPIEncodeH265Options;
-
 
 static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx,
char *data, size_t *data_len,
CodedBitstreamFragment *au)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 int err;
 
 err = ff_cbs_write_fragment_data(priv->cbc, au);
@@ -111,8 +114,7 @@ static int vaapi_encode_h265_add_nal(AVCodecContext *avctx,
  CodedBitstreamFragment *au,
  void *nal_unit)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 H265RawNALUnitHeader *header = nal_unit;
 int err;
 
@@ -130,27 +132,26 @@ static int vaapi_encode_h265_add_nal(AVCodecContext 
*avctx,
 static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->vps);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_vps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->sps);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_sps);
 if (err < 0)
 goto fail;
 
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->pps);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_pps);
 if (err < 0)
 goto fail;
 
@@ -165,19 +166,18 @@ static int 
vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
 VAAPIEncodeSlice *slice,
 char *data, size_t *data_len)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAAPIEncodeH265Context *priv = ctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
 CodedBitstreamFragment   *au = &priv->current_access_unit;
 int err;
 
 if (priv->aud_needed) {
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
 if (err < 0)
 goto fail;
 priv->aud_needed = 0;
 }
 
-err = vaapi_encode_h265_add_nal(avctx, au, &priv->slice);
+err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
 if (err < 0)
 goto fail;
 
@@ -192,12 +192,13 @@ static int 
vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
 int index, in

[FFmpeg-devel] [PATCH v2 00/36] VAAPI encode and related stuff

2018-06-07 Thread Mark Thompson

On 07/06/18 05:13, Xiang, Haihao wrote:
> On Sat, 2018-05-26 at 17:26 +0100, Mark Thompson wrote:
>> On 25/05/18 07:01, Xiang, Haihao wrote:
>>>
>>> Hi Mark
>>>
>>> Do you plan to merge this commit any time soon?
>>
>> There are quite a few changes throughout the set, I'll resend it soon.
>>
> 
> Thanks for your reply, I'd like to give a try with your new patchset.
> 
> Thanks
> Haihao

Here you go.

Not necessarily final yet, I still have some testing to do.  Should be pretty 
close, though.

Thanks,

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


[FFmpeg-devel] [PATCH v2 01/36] configure: Use pkgconfig for VAAPI

2018-06-07 Thread Mark Thompson
Set the minimum version to 0.35.0 (libva 1.3.0) and remove redundant
configure tests.
---
This is the version in Ubuntu 14.04 LTS - I don't think it's worth keeping 
support for anything older now.


 configure | 25 -
 libavcodec/vaapi_decode.c |  2 --
 2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index 53224f0ed5..790f55be14 100755
--- a/configure
+++ b/configure
@@ -2862,7 +2862,7 @@ vc1_vdpau_hwaccel_deps="vdpau"
 vc1_vdpau_hwaccel_select="vc1_decoder"
 vp8_nvdec_hwaccel_deps="nvdec"
 vp8_nvdec_hwaccel_select="vp8_decoder"
-vp8_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferVP8"
+vp8_vaapi_hwaccel_deps="vaapi"
 vp8_vaapi_hwaccel_select="vp8_decoder"
 vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
@@ -2916,7 +2916,6 @@ h264_qsv_decoder_select="h264_mp4toannexb_bsf h264_parser 
qsvdec"
 h264_qsv_encoder_select="qsvenc"
 h264_rkmpp_decoder_deps="rkmpp"
 h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
-h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
 h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
 h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
 h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
@@ -2947,7 +2946,6 @@ mpeg2_mmal_decoder_deps="mmal"
 mpeg2_mediacodec_decoder_deps="mediacodec"
 mpeg2_qsv_decoder_select="qsvdec mpegvideo_parser"
 mpeg2_qsv_encoder_select="qsvenc"
-mpeg2_vaapi_encoder_deps="VAEncPictureParameterBufferMPEG2"
 mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
 mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m"
 mpeg4_crystalhd_decoder_select="crystalhd"
@@ -3326,7 +3324,7 @@ deconvolve_filter_select="fft"
 deinterlace_qsv_filter_deps="libmfx"
 deinterlace_vaapi_filter_deps="vaapi"
 delogo_filter_deps="gpl"
-denoise_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
+denoise_vaapi_filter_deps="vaapi"
 deshake_filter_select="pixelutils"
 drawtext_filter_deps="libfreetype"
 drawtext_filter_suggest="libfontconfig libfribidi"
@@ -3370,7 +3368,7 @@ perspective_filter_deps="gpl"
 phase_filter_deps="gpl"
 pp7_filter_deps="gpl"
 pp_filter_deps="gpl postproc"
-procamp_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
+procamp_vaapi_filter_deps="vaapi"
 program_opencl_filter_deps="opencl"
 pullup_filter_deps="gpl"
 removelogo_filter_deps="avcodec avformat swscale"
@@ -3382,7 +3380,7 @@ scale2ref_filter_deps="swscale"
 scale_filter_deps="swscale"
 scale_qsv_filter_deps="libmfx"
 select_filter_select="pixelutils"
-sharpness_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
+sharpness_vaapi_filter_deps="vaapi"
 showcqt_filter_deps="avcodec avformat swscale"
 showcqt_filter_suggest="libfontconfig libfreetype"
 showcqt_filter_select="fft"
@@ -3419,7 +3417,7 @@ libvmaf_filter_deps="libvmaf pthreads"
 zmq_filter_deps="libzmq"
 zoompan_filter_deps="swscale"
 zscale_filter_deps="libzimg const_nan"
-scale_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
+scale_vaapi_filter_deps="vaapi"
 vpp_qsv_filter_deps="libmfx"
 vpp_qsv_filter_select="qsvvpp"
 
@@ -5891,13 +5889,9 @@ check_type "windows.h d3d11.h" "ID3D11VideoContext"
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 
 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_type "va/va.h va/va_dec_vp8.h" "VAPictureParameterBufferVP8"
 check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
-check_type "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer"
-check_type "va/va.h va/va_enc_h264.h" "VAEncPictureParameterBufferH264"
 check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
-check_type "va/va.h va/va_enc_mpeg2.h" "VAEncPictureParameterBufferMPEG2"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
 check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 
@@ -6310,14 +6304,11 @@ test_cpp <= 0.35.0" "va/va.h" vaInitialize
 
 if enabled vaapi; then
-check_lib vaapi_drm "va/va.h va/va_drm.h" vaGetDisplayDRM -lva -lva-drm
-check_lib vaapi_x11 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 -lX11
+check_pkg_config vaapi_drm "libva-drm" "va/va_drm.h" vaGetDisplayDRM
+check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi
 
 enabled vaapi &&
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index d0a6b5817d..ece75c0815 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -389,9 +389,7 @@ static const struct {
 MAP(VC1, VC1_MAIN,VC1Main ),
 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
 MAP(VC1, VC1_ADVANCED,VC1Advanced ),
-#if VA_CHECK_VERSION(0, 35, 0)
 MAP(VP8, UNKNOWN,   VP8Version0_3 ),
-#endif
 #if VA_CHECK_VERSION(0, 38, 0)
 MAP(VP9, VP9_0,   VP9Profile0 ),
 #endif
-- 
2.16.3

___
ffmpeg-de

Re: [FFmpeg-devel] [PATCH] libavfilter/boxblur_opencl filter.

2018-06-07 Thread Mark Thompson
On 06/06/18 00:45, Danil Iashchenko wrote:
> Behaves like existing boxblur filter. 
> 
> ---
> 
> Thanks! Fixed.
> 
>  libavfilter/Makefile|   2 +
>  libavfilter/allfilters.c|   1 +
>  libavfilter/vf_avgblur_opencl.c | 419 
> ++--
>  3 files changed, 324 insertions(+), 98 deletions(-)
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index c68ef05..6f00059 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -153,6 +153,8 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER)+= 
> vf_blackdetect.o
>  OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
>  OBJS-$(CONFIG_BLEND_FILTER)  += vf_blend.o framesync.o
>  OBJS-$(CONFIG_BOXBLUR_FILTER)+= vf_boxblur.o
> +OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o 
> \
> + opencl/avgblur.o
 ^
There's a tab here.

>  OBJS-$(CONFIG_BWDIF_FILTER)  += vf_bwdif.o
>  OBJS-$(CONFIG_CHROMAKEY_FILTER)  += vf_chromakey.o
>  OBJS-$(CONFIG_CIESCOPE_FILTER)   += vf_ciescope.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index b44093d..97d92a0 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -146,6 +146,7 @@ extern AVFilter ff_vf_blackdetect;
>  extern AVFilter ff_vf_blackframe;
>  extern AVFilter ff_vf_blend;
>  extern AVFilter ff_vf_boxblur;
> +extern AVFilter ff_vf_boxblur_opencl;
>  extern AVFilter ff_vf_bwdif;
>  extern AVFilter ff_vf_chromakey;
>  extern AVFilter ff_vf_ciescope;
> diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c
> index 48cebb5..d4759de 100644
> --- a/libavfilter/vf_avgblur_opencl.c
> +++ b/libavfilter/vf_avgblur_opencl.c
> ...
> +
> +static int boxblur_opencl_make_filter_params(AVFilterLink *inlink)
> +{
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
> +AVFilterContext*ctx = inlink->dst;
> +AverageBlurOpenCLContext *s = ctx->priv;
> +int w = inlink->w, h = inlink->h;
> +int cw, ch;
> +double var_values[VARS_NB], res;
> +char *expr;
> +int ret, i;
> +
> +if (!s->luma_param.radius_expr) {
> +av_log(s, AV_LOG_ERROR, "Luma radius expression is not set.\n");
> +return AVERROR(EINVAL);
> +}
> +
> +/* fill missing params */
> +if (!s->chroma_param.radius_expr) {
> +s->chroma_param.radius_expr = av_strdup(s->luma_param.radius_expr);
> +if (!s->chroma_param.radius_expr)
> +return AVERROR(ENOMEM);
> +}
> +if (s->chroma_param.power < 0)
> +s->chroma_param.power = s->luma_param.power;
> +
> +if (!s->alpha_param.radius_expr) {
> +s->alpha_param.radius_expr = av_strdup(s->luma_param.radius_expr);
> +if (!s->alpha_param.radius_expr)
> +return AVERROR(ENOMEM);
> +}
> +if (s->alpha_param.power < 0)
> +s->alpha_param.power = s->luma_param.power;
> +
> +s->hsub = desc->log2_chroma_w;
> +s->vsub = desc->log2_chroma_h;
> +
> +var_values[VAR_W]   = inlink->w;
> +var_values[VAR_H]   = inlink->h;
> +var_values[VAR_CW] = cw = w>>s->hsub;
> +var_values[VAR_CH] = ch = h>>s->vsub;
> +var_values[VAR_HSUB]= 1 +var_values[VAR_VSUB]= 1 +
> +#define EVAL_RADIUS_EXPR(comp)  \
> +expr = s->comp##_param.radius_expr; \
> +ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
> + NULL, NULL, NULL, NULL, NULL, 0, ctx); \
> +s->comp##_param.radius = res;   \
> +if (ret < 0) {  \
> +av_log(NULL, AV_LOG_ERROR,  \
> +   "Error when evaluating " #comp " radius expression '%s'\n", 
> expr); \
> +return ret; \
> +}
> +EVAL_RADIUS_EXPR(luma);
> +EVAL_RADIUS_EXPR(chroma);
> +EVAL_RADIUS_EXPR(alpha);
> +
> +av_log(ctx, AV_LOG_VERBOSE,
> +   "luma_radius:%d luma_power:%d "
> +   "chroma_radius:%d chroma_power:%d "
> +   "alpha_radius:%d alpha_power:%d "
> +   "w:%d chroma_w:%d h:%d chroma_h:%d\n",
> +   s->luma_param  .radius, s->luma_param  .power,
> +   s->chroma_param.radius, s->chroma_param.power,
> +   s->alpha_param .radius, s->alpha_param .power,
> +   w, cw, h, ch);
> +
> +#define CHECK_RADIUS_VAL(w_, h_, comp)  \
> +if (s->comp##_param.radius < 0 ||   \
> +2*s->comp##_param.radius > FFMIN(w_, h_)) { \
> +av_log(ctx, AV_LOG_ERROR,   \
> +   "Invalid " #comp " radius v

Re: [FFmpeg-devel] [PATCH] lavfi/atempo: raise max tempo limit

2018-06-07 Thread Moritz Barsnick
On Tue, Jun 05, 2018 at 20:59:16 -0600, Pavel Koshevoy wrote:
> ---
>  libavfilter/af_atempo.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)

Please have a look at doc/filters.texi and adapt the atempo section in
the same commit.

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


Re: [FFmpeg-devel] [PATCH v4 1/4] lavu/hwcontext_opecl: fix the build warning

2018-06-07 Thread Moritz Barsnick
On Tue, Jun 05, 2018 at 22:21:23 +0800, Jun Zhao wrote:
> Subject: [FFmpeg-devel] [PATCH v4 1/4] lavu/hwcontext_opecl: fix the build 
> warning   
>
   ^ typo

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


Re: [FFmpeg-devel] [PATCH v7 1/4] avcodec: add side data type for ancillary

2018-06-07 Thread Patrick Keroulas
Would someone be nice to review this patchset?
Thank you.

- Original Message -
> From: "Patrick Keroulas" 
> To: ffmpeg-devel@ffmpeg.org
> Cc: "Patrick Keroulas" 
> Sent: Friday, May 25, 2018 10:16:28 AM
> Subject: [PATCH v7 1/4] avcodec: add side data type for ancillary

> avcodec: add side data type for ancillary
> 
> Create a new type of side data to be attached to AVPacket in order
> to transmit out of band parameters for typical codecs.
> 
> Signed-off-by: Patrick Keroulas 
> ---
> doc/APIchanges | 3 +++
> libavcodec/avcodec.h | 7 ++-
> libavcodec/avpacket.c | 1 +
> libavcodec/version.h | 4 ++--
> 4 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index efe15ba..ff2baff 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
> 
> API changes, most recent first:
> 
> +2018-05-xx - xx - lavc 58.20.100 - avcodec.h
> + Add AV_PKT_DATA_ANCILLARY to hold various side data.
> +
> 2018-05-xx - xx - lavf 58.15.100 - avformat.h
> Add pmt_version field to AVProgram
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index fb0c6fa..fc2c5dc 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -1358,6 +1358,12 @@ enum AVPacketSideDataType {
> AV_PKT_DATA_ENCRYPTION_INFO,
> 
> /**
> + * Generic side data for any parameter that can't fit in a AVPacket,
> + * e.g. interlaced field flags.
> + */
> + AV_PKT_DATA_ANCILLARY,
> +
> + /**
> * The number of side data types.
> * This is not part of the public API/ABI in the sense that it may
> * change when new side data types are added.
> @@ -1480,7 +1486,6 @@ typedef struct AVPacket {
> */
> #define AV_PKT_FLAG_DISPOSABLE 0x0010
> 
> -
> enum AVSideDataParamChangeFlags {
> AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
> AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 99a0c13..27355e1 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -388,6 +388,7 @@ const char *av_packet_side_data_name(enum
> AVPacketSideDataType type)
> case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
> case AV_PKT_DATA_SPHERICAL: return "Spherical Mapping";
> case AV_PKT_DATA_A53_CC: return "A53 Closed Captions";
> + case AV_PKT_DATA_ANCILLARY: return "Ancillary data";
> }
> return NULL;
> }
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index da893da..b9752ce 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -28,8 +28,8 @@
> #include "libavutil/version.h"
> 
> #define LIBAVCODEC_VERSION_MAJOR 58
> -#define LIBAVCODEC_VERSION_MINOR 19
> -#define LIBAVCODEC_VERSION_MICRO 102
> +#define LIBAVCODEC_VERSION_MINOR 20
> +#define LIBAVCODEC_VERSION_MICRO 100
> 
> #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> LIBAVCODEC_VERSION_MINOR, \
> --
> 2.7.4
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]ffmpeg: Fail if the user requested impossible subtitle encoding

2018-06-07 Thread Michael Niedermayer
On Wed, Jun 06, 2018 at 10:34:42PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch is meant to fix ticket #7239.
> 
> Please comment, Carl Eugen

>  ffmpeg.c |   17 +
>  1 file changed, 17 insertions(+)
> 95832712dd42b9c4e99f2345e93a9853f1758871  
> 0001-ffmpeg-Fail-if-the-user-requested-impossible-subtitl.patch
> From 309b7855f663053a5d11c5403a811bd723e472b9 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos 
> Date: Wed, 6 Jun 2018 21:09:38 +0200
> Subject: [PATCH] ffmpeg: Fail if the user requested impossible subtitle
>  encoding.

probably ok

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire


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


Re: [FFmpeg-devel] [PATCH] Limited timecode support for lavd/decklink

2018-06-07 Thread Marton Balint


On Thu, 7 Jun 2018, Dave Rice wrote:


[...]



Before I only tested with vitc but now have a serial cable connected as 
well and found a source tape that has distinct values for LTC and VITC 
timecodes. The LTC values are from 1:00:00 to 2:00:00 and the VITC 
values are from 07:00:00 - 08:00:00.


With the deckcontrol utility at https://github.com/bavc/deckcontrol 
, I can use the command gettimecode 
to grab the LTC value:


deckcontrol gettimecode
Issued command 'gettimecode'
TC=07:37:56:21
Command sucessfully issued
Error sending command (No error)

With these patches, I can only grab the vitc values:

for i in rp188vitc rp188vitc2 rp188ltc rp188any vitc vitc2 serial ; do echo -n "${i}: " ; ./ffprobe 
-v quiet -timecode_format "$i" -f decklink -draw_bars 0 -audio_input embedded -video_input sdi 
-format_code ntsc -channels 8 -raw_format yuv422p10 -i "UltraStudio Express" -select_streams v 
-show_entries stream_tags=timecode -of default=nw=1:nk=1 ; echo ; done
rp188vitc: 
rp188vitc2: 
rp188ltc: 
rp188any: 
vitc: 01:41:44;06

vitc2: 01:41:44;21
serial:

Also it may be interesting in cases like this to support accepting 
multiple timecode inputs at once, such as "-timecode_format 
vitc+rp188ltc” though it would need to be contextualized more in 
metadata.


With a serial cable connected, I can access LTC via the deckcontrol 
utility but not with this patch.


Well, the way I understand it, deckcontrol is using a totally different 
timecode source: the RS422 deck control interface. In contrast, the

timecode capture in the patch is using the SDI (video) source.

If the deck does not put the LTC timecode into SDI line 10, then the 
driver won't be able to capture it if you specify 'rp188ltc'. I am not 
sure however why 'serial' does not work, but from a quick look at the 
SDK maybe that only works if you use the deck control capture functions...


Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Evolution of lavfi's design and API

2018-06-07 Thread Michael Niedermayer
On Thu, Jun 07, 2018 at 11:23:40AM +0200, Paul B Mahol wrote:
> On 6/6/18, Nicolas George  wrote:
> > Michael Niedermayer (2018-06-04):
> >> If noone, who has time to reply knows the awnser then you probably have
> >> to
> >> find it out from the code and any unfinished patchsets
> >>
> >> sending nicolas a private mail may also be more vissible to him than the
> >> ML
> >> in case he is busy
> >
> > In terms of design, the big thing missing from lavfi is a clean API to
> > run a filter graph. Right now, it relies on requests on outputs, with a
> > fragile heuristic to find the "oldest" one. A clean API would allow to
> > run it as a whole and react to frames on output or requests on inputs,
> > possibly with callbacks.
> >
> > This must come before threading, because it is what allows to control
> > threading: threading is efficient when the system can start several
> > threads and let them run, doing their work. If it is constantly stopping
> > and re-starting because the calling API makes too small steps, much time
> > is wasted.
> >

> > But more than that, it requires somebody working on it. Speaking for
> > myself, the toxic ambiance in the project since a few months has
> > destroyed my motivation for doing anything ambitious on it. And to be
> > completely forthright, I feel that Paul is partly responsible for that
> > toxic ambiance; see his interventions on the thread about enforcing the
> > code of conduct for example.
> 
> Your contributions will be missed.
> 
> Good bye.

Id like to see both you and nicolas work together on libavfilter. Thats a
"WIN" for the community and FFmpeg. You two are the top 2 libavfilter
develoepers currently. Its really _REALLY_ stupid if you two fight like this.
Because no matter who "wins" this, everyone looses.

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

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras


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


Re: [FFmpeg-devel] [PATCH] avformat/mov: Fix reading saio/saiz for clear content.

2018-06-07 Thread Jacob Trimble
On Thu, Jun 7, 2018 at 10:38 AM Jacob Trimble  wrote:
>
> Found by Chrome's ClusterFuzz: http://crbug.com/850389
>
> Signed-off-by: Jacob Trimble 
> ---
>  libavformat/mov.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 4ad19122b3..d07171b3f4 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -6041,6 +6041,11 @@ static int mov_read_saiz(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  if (ret != 1)
>  return ret;
>
> +if (!sc->cenc.default_encrypted_sample) {
> +// Didn't see a 'schm' or 'tenc' atom, so it isn't encrypted.
> +return 0;
> +}
> +
>  if (encryption_index->nb_encrypted_samples) {
>  // This can happen if we have both saio/saiz and senc atoms.
>  av_log(c->fc, AV_LOG_DEBUG, "Ignoring duplicate encryption info in 
> saiz\n");
> @@ -6095,6 +6100,11 @@ static int mov_read_saio(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  if (ret != 1)
>  return ret;
>
> +if (!sc->cenc.default_encrypted_sample) {
> +// Didn't see a 'schm' or 'tenc' atom, so it isn't encrypted.
> +return 0;
> +}
> +
>  if (encryption_index->nb_encrypted_samples) {
>  // This can happen if we have both saio/saiz and senc atoms.
>  av_log(c->fc, AV_LOG_DEBUG, "Ignoring duplicate encryption info in 
> saio\n");
> --
> 2.17.1.1185.g55be947832-goog
>

Based on comments downstream, I've added error checks for the
encrypted type of saio/saiz atoms.
From e4185c0fd08a1baedcf81935ff0f5ac9a97eba4e Mon Sep 17 00:00:00 2001
From: Jacob Trimble 
Date: Thu, 7 Jun 2018 10:29:33 -0700
Subject: [PATCH] avformat/mov: Fix reading saio/saiz for clear content.

This validates that the common encryption saio/saiz atoms only appear
when the data is actually encrypted.  This also ignores those atoms
in clear content.

Found by Chrome's ClusterFuzz: http://crbug.com/850389

Signed-off-by: Jacob Trimble 
---
 libavformat/mov.c | 71 ---
 1 file changed, 55 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 4ad19122b3..2fca025889 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6035,7 +6035,7 @@ static int mov_read_saiz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 MOVEncryptionIndex *encryption_index;
 MOVStreamContext *sc;
 int ret;
-unsigned int sample_count;
+unsigned int sample_count, aux_info_type, aux_info_param;
 
 ret = get_current_encryption_info(c, &encryption_index, &sc);
 if (ret != 1)
@@ -6054,14 +6054,33 @@ static int mov_read_saiz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 
 avio_r8(pb); /* version */
 if (avio_rb24(pb) & 0x01) {  /* flags */
-if (avio_rb32(pb) != sc->cenc.default_encrypted_sample->scheme) {
-av_log(c->fc, AV_LOG_DEBUG, "Ignoring saiz box with non-zero aux_info_type\n");
-return 0;
-}
-if (avio_rb32(pb) != 0) {
-av_log(c->fc, AV_LOG_DEBUG, "Ignoring saiz box with non-zero aux_info_type_parameter\n");
-return 0;
+aux_info_type = avio_rb32(pb);
+aux_info_param = avio_rb32(pb);
+if (sc->cenc.default_encrypted_sample) {
+if (aux_info_type != sc->cenc.default_encrypted_sample->scheme) {
+av_log(c->fc, AV_LOG_DEBUG, "Ignoring saiz box with non-zero aux_info_type\n");
+return 0;
+}
+if (aux_info_param != 0) {
+av_log(c->fc, AV_LOG_DEBUG, "Ignoring saiz box with non-zero aux_info_type_parameter\n");
+return 0;
+}
+} else {
+// Didn't see 'schm' or 'tenc', so this isn't encrypted.
+if ((aux_info_type == MKBETAG('c','e','n','c') ||
+ aux_info_type == MKBETAG('c','e','n','s') ||
+ aux_info_type == MKBETAG('c','b','c','1') ||
+ aux_info_type == MKBETAG('c','b','c','s')) &&
+aux_info_param == 0) {
+av_log(c->fc, AV_LOG_ERROR, "Saw encrypted saiz without schm/tenc\n");
+return AVERROR_INVALIDDATA;
+} else {
+return 0;
+}
 }
+} else if (!sc->cenc.default_encrypted_sample) {
+// Didn't see 'schm' or 'tenc', so this isn't encrypted.
+return 0;
 }
 
 encryption_index->auxiliary_info_default_size = avio_r8(pb);
@@ -6089,7 +6108,8 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 MOVEncryptionIndex *encryption_index;
 MOVStreamContext *sc;
 int i, ret;
-unsigned int version, entry_count, alloc_size = 0;
+unsigned int version, entry_count, aux_info_type, aux_info_param;
+unsigned int alloc_size = 0;
 
 ret = get_current_encryption_info(c, &encryption_index, &sc);
 if (ret != 1)
@@ -6108,14 +6128,33 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, M

Re: [FFmpeg-devel] libavutil/encryption_info: Allow multiple init info.

2018-06-07 Thread Jacob Trimble
On Thu, May 31, 2018 at 5:50 PM Jacob Trimble  wrote:
>
> On Thu, May 31, 2018 at 9:40 AM Jacob Trimble  wrote:
> >
> > On Fri, May 25, 2018 at 6:13 PM Michael Niedermayer
> >  wrote:
> > >
> > > [...]
> > >
> > > > Added fix for issue found by Chrome's ClusterFuzz 
> > > > (http://crbug.com/846662).
> > >
> > > this belongs in a seperate patch unless its a bug specific to the code 
> > > added
> > > with this patch
> > >
> >
> > Ok.  Now this patch depends on
> > http://ffmpeg.org/pipermail/ffmpeg-devel/2018-May/230782.html.
> >
>
> Noticed some bugs when integrating it.
>
> > > [...]
> > >
> > > --
> > > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> > >
> > > I have often repented speaking, but never of holding my tongue.
> > > -- Xenocrates
> > > ___
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Removed controversial NULL checks.  This patch no longer depends on anything.
From 0c4c33f26ba4204a775709cdd6367dd1ea4bd024 Mon Sep 17 00:00:00 2001
From: Jacob Trimble 
Date: Mon, 23 Apr 2018 10:33:58 -0700
Subject: [PATCH] libavutil/encryption_info: Allow multiple init info.

It is possible for there to be multiple encryption init info structure.
For example, to support multiple key systems or in key rotation.  This
changes the AVEncryptionInitInfo struct to be a linked list so there
can be multiple structs without breaking ABI.

Signed-off-by: Jacob Trimble 
---
 libavutil/encryption_info.c | 140 
 libavutil/encryption_info.h |   5 ++
 2 files changed, 100 insertions(+), 45 deletions(-)

diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c
index 20a752d6b4..1072d2795b 100644
--- a/libavutil/encryption_info.c
+++ b/libavutil/encryption_info.c
@@ -160,13 +160,16 @@ uint8_t *av_encryption_info_add_side_data(const AVEncryptionInfo *info, size_t *
 }
 
 // The format of the AVEncryptionInitInfo side data:
-// u32be system_id_size
-// u32be num_key_ids
-// u32be key_id_size
-// u32be data_size
-// u8[system_id_size] system_id
-// u8[key_id_size][num_key_id] key_ids
-// u8[data_size] data
+// u32be init_info_count
+// {
+//   u32be system_id_size
+//   u32be num_key_ids
+//   u32be key_id_size
+//   u32be data_size
+//   u8[system_id_size] system_id
+//   u8[key_id_size][num_key_id] key_ids
+//   u8[data_size] data
+// }[init_info_count]
 
 #define FF_ENCRYPTION_INIT_INFO_EXTRA 16
 
@@ -215,6 +218,7 @@ void av_encryption_init_info_free(AVEncryptionInitInfo *info)
 for (i = 0; i < info->num_key_ids; i++) {
 av_free(info->key_ids[i]);
 }
+av_encryption_init_info_free(info->next);
 av_free(info->system_id);
 av_free(info->key_ids);
 av_free(info->data);
@@ -225,71 +229,117 @@ void av_encryption_init_info_free(AVEncryptionInitInfo *info)
 AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
 const uint8_t *side_data, size_t side_data_size)
 {
-AVEncryptionInitInfo *info;
-uint64_t system_id_size, num_key_ids, key_id_size, data_size, i;
+// |ret| tracks the front of the list, |info| tracks the back.
+AVEncryptionInitInfo *ret = NULL, *info, *temp_info;
+uint64_t system_id_size, num_key_ids, key_id_size, data_size, i, j;
+uint64_t init_info_count;
 
-if (!side_data || side_data_size < FF_ENCRYPTION_INIT_INFO_EXTRA)
+if (!side_data || side_data_size < 4)
 return NULL;
 
-system_id_size = AV_RB32(side_data);
-num_key_ids = AV_RB32(side_data + 4);
-key_id_size = AV_RB32(side_data + 8);
-data_size = AV_RB32(side_data + 12);
+init_info_count = AV_RB32(side_data);
+side_data += 4;
+side_data_size -= 4;
+for (i = 0; i < init_info_count; i++) {
+if (side_data_size < FF_ENCRYPTION_INIT_INFO_EXTRA) {
+av_encryption_init_info_free(ret);
+return NULL;
+}
 
-// UINT32_MAX + UINT32_MAX + UINT32_MAX * UINT32_MAX == UINT64_MAX
-if (side_data_size - FF_ENCRYPTION_INIT_INFO_EXTRA < system_id_size + data_size + num_key_ids * key_id_size)
-return NULL;
+system_id_size = AV_RB32(side_data);
+num_key_ids = AV_RB32(side_data + 4);
+key_id_size = AV_RB32(side_data + 8);
+data_size = AV_RB32(side_data + 12);
 
-info = av_encryption_init_info_alloc(system_id_size, num_key_ids, key_id_size, data_size);
-if (!info)
-return NULL;
+// UINT32_MAX + UINT32_MAX + UINT32_MAX * UINT32_MAX == UINT64_MAX
+if (side_data_size - FF_ENCRYPTION_INIT_INFO_EXTRA < system_id_size + data_size + num_key_ids * key_id_size) {
+av_encryption_init_info_free(ret);
+return NULL;
+}
+side_data += FF_ENCRYPTION_INIT_INFO_EXTRA;
+side_data_size -= FF_ENCRYPTION_INIT_INFO_EXTRA;
 
-memcpy(info->system_id, side_data + 16, system_id_size);
-side_data += system_id_size + 16

[FFmpeg-devel] [PATCH] ffmpeg: sseof is marked as an input-only option

2018-06-07 Thread Gyan Doshi
From 91d98675cc85bd78e46971f9e5d3708245345654 Mon Sep 17 00:00:00 2001
From: Gyan Doshi 
Date: Thu, 7 Jun 2018 23:15:35 +0530
Subject: [PATCH] ffmpeg: sseof is marked as an input-only option

---
 doc/ffmpeg.texi  | 2 +-
 fftools/ffmpeg_opt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 79da1ae14d..3717f22d42 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -508,7 +508,7 @@ input until the timestamps reach @var{position}.
 @var{position} must be a time duration specification,
 see @ref{time duration syntax,,the Time duration section in the 
ffmpeg-utils(1) manual,ffmpeg-utils}.
 
-@item -sseof @var{position} (@emph{input/output})
+@item -sseof @var{position} (@emph{input})
 
 Like the @code{-ss} option but relative to the "end of file". That is negative
 values are earlier in the file, 0 is at EOF.
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 36bce4465a..a2ecddae71 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3340,7 +3340,7 @@ const OptionDef options[] = {
 OPT_INPUT | OPT_OUTPUT,  { .off = 
OFFSET(start_time) },
 "set the start time offset", "time_off" },
 { "sseof",  HAS_ARG | OPT_TIME | OPT_OFFSET |
-OPT_INPUT | OPT_OUTPUT,  { .off = 
OFFSET(start_time_eof) },
+OPT_INPUT,   { .off = 
OFFSET(start_time_eof) },
 "set the start time offset relative to EOF", "time_off" },
 { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
 OPT_INPUT,   { .off = 
OFFSET(seek_timestamp) },
-- 
2.17.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/mov: Fix reading saio/saiz for clear content.

2018-06-07 Thread Jacob Trimble
Found by Chrome's ClusterFuzz: http://crbug.com/850389

Signed-off-by: Jacob Trimble 
---
 libavformat/mov.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 4ad19122b3..d07171b3f4 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6041,6 +6041,11 @@ static int mov_read_saiz(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (ret != 1)
 return ret;
 
+if (!sc->cenc.default_encrypted_sample) {
+// Didn't see a 'schm' or 'tenc' atom, so it isn't encrypted.
+return 0;
+}
+
 if (encryption_index->nb_encrypted_samples) {
 // This can happen if we have both saio/saiz and senc atoms.
 av_log(c->fc, AV_LOG_DEBUG, "Ignoring duplicate encryption info in 
saiz\n");
@@ -6095,6 +6100,11 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (ret != 1)
 return ret;
 
+if (!sc->cenc.default_encrypted_sample) {
+// Didn't see a 'schm' or 'tenc' atom, so it isn't encrypted.
+return 0;
+}
+
 if (encryption_index->nb_encrypted_samples) {
 // This can happen if we have both saio/saiz and senc atoms.
 av_log(c->fc, AV_LOG_DEBUG, "Ignoring duplicate encryption info in 
saio\n");
-- 
2.17.1.1185.g55be947832-goog

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


Re: [FFmpeg-devel] [PATCH 1/4] avcodec/shorten: Sanity check nmeans

2018-06-07 Thread Michael Niedermayer
On Tue, Jun 05, 2018 at 03:45:14PM +0200, Michael Niedermayer wrote:
> Fixes: OOM
> Fixes: 
> 8195/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SHORTEN_fuzzer-5179785826271232
> 
> The reference software appears to use longs for 32bits and it uses int for 
> nmeans
> hinting that the intended maximum size was not 32bit.
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/shorten.c | 4 
>  1 file changed, 4 insertions(+)

will apply patchset

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

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



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


Re: [FFmpeg-devel] [PATCH] libavutil/encryption_info: Add NULL checks.

2018-06-07 Thread Jacob Trimble
On Tue, Jun 5, 2018 at 1:06 PM Mark Thompson  wrote:
>
> On 05/06/18 17:30, Jacob Trimble wrote:
> > Just because I can't check whether my food has salmonella doesn't mean
> > I shouldn't check the temperature when I cook it.  Adding a NULL check
> > is trivial and will catch the most common error case.  We also can't
> > check whether malloc() allocates enough memory, so should we then not
> > check for NULL?  NULL is used as an error signal, so if the caller
> > didn't include a NULL check, they will pass it here.  Rather than
> > crashing the program (hopefully it will crash, it is undefined
> > behavior, so anything could happen), we should be nice and validate
> > the input and error out.  Just because it is impossible to check other
> > error cases doesn't mean we should ignore all error checks.
>
> (My opinion, others may disagree.)
>
> Please consider what is actually useful to an API user here.
>
> The check you are suggesting will cause the function to, when passed entirely 
> invalid arguments, silently return having done nothing.  Is this better than 
> the almost-guaranteed segfault you will get instead?  Well, no.  There is 
> much more scope for the error to go unnoticed and cause other hard-to-debug 
> issues later, where it could have been caught immediately.

It returns an error, which should be checked by the caller.  We can't
do anything to change the caller's code, but we can make our code not
crash their program.

>
> If there is a concern that a function like this could be misused then (since 
> this is certainly undefined behaviour in any case) turning it into an abort() 
> is the best case so that the program will definitely fail and any errors can 
> be diagnosed immediately.  As such, I think argument checks for nonsensical 
> invalid input like this should be done either with av_assert or not at all.

What about invalid MP4 files?  Should we convert those to abort() too?
 When parsing MP4 files, we check that it is valid and return an error
code if it is not.  There is no difference between a method to parse
an MP4 file and these, so these should validate the inputs as best it
can and return errors if we find them.

>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

When I design an API, I try to make it hard to misuse, being as
helpful to the caller as possible.  Having the function intentionally
crash on certain input when a simple if could solve it is not a good
idea.  I think the memcpy API is an example of a bad api, it assumes
valid input.  Are we going to stop checking that MP4 files are valid
too?  If we only accept valid MP4 files it seems pointless to check it
and return errors.  These functions return NULL on errors, it is an
error to pass NULL, therefore we should check and return NULL.  It is
impossible to check some things, but if it were possible, I would
suggest checking that too.

One other problem is that NULL is sometimes a valid value to pass to a
function and sometimes not.  NULL is used as a signal value whereas an
invalid pointer is never valid.  From the compiler's point of view,
there is no difference between a function that accepts NULL as valid
and one that does not.  So the only thing we can do is write a comment
saying "Does not accept NULL", but this is fragile as the compiler
can't check this (without static analysis).  By having us return an
error for invalid input, it makes the API more stable and easier to
use.  We can't stop the caller from ignoring the return value, but we
can at least do our best to validate the input and avoid crashing the
program.

But if you aren't going to accept a patch to increase code heath,
there is nothing I can do.  I'll remove the NULL checks from my other
patch so it can be submitted.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Limited timecode support for lavd/decklink

2018-06-07 Thread Dave Rice

> On Jun 7, 2018, at 12:12 PM, Dave Rice  wrote:
> 
> 
>> On Jun 6, 2018, at 5:32 PM, Marton Balint  wrote:
>> 
>> On Wed, 6 Jun 2018, Dave Rice wrote:
>> 
 On Jun 6, 2018, at 4:50 PM, Marton Balint  wrote:
 On Mon, 4 Jun 2018, Dave Rice wrote:
>>> In my testing the timecode value set here has corrected been associated 
>>> with the first video frame (maintaining the timecode-to-first-frame 
>>> relationship as found on the source video stream). Although only having 
>>> first timecode value known is limiting, I think this is still quite 
>>> useful. This function also mirrors how BlackMagic Media Express and 
>>> Adobe Premiere handle capturing video+timecode where only the first 
>>> value is documented and all subsequent values are presumed.
>> Could you give me an example? (e.g. ffmpeg command line?)
> ./ffmpeg -timecode_format vitc2 -f decklink -draw_bars 0 -audio_input 
> embedded -video_input sdi -format_code ntsc -channels 8 -raw_format 
> yuv422p10 -i "UltraStudio 3D" -c:v v210 -c:a aac output.mov
> This worked for me to embed a QuickTime timecode track based upon the 
> timecode value of the first frame. If the input contained non-sequential 
> timecode values then the timecode track would not be accurate from that 
> point onward, but creating a timecode track based only upon the initial 
> value is what BlackMagic Media Express and Adobe Premiere are doing 
> anyhow.
 Hmm, either the decklink drivers became better in hinding the first few 
 NoSignal frames, or maybe that issue only affected to old models? (e.g. 
 DeckLink SDI or DeckLink Duo 1). I did some test with a Mini Recorder, and 
 even the first frame was useful, in this case the timecode was indeed 
 correct.
 I'd rather see a new AVPacketSideData type which will contain the 
 timecode as a string, so you can set it frame-by-frame.
>>> Using side data for timecode would be preferable, but the possibility 
>>> that a patch for that may someday arrive shouldn’t completely block 
>>> this more limited patch.
>> I would like to make sure the code works reliably even for the limited 
>> use case and no race conditions are affectig the way it works.
> Feel welcome to suggest any testing. I’ll have access for testing again 
> tomorrow.
 I reworked the patch a bit (see attached), and added per-frame timcode 
 support into the PKT_STRINGS_METADATA packet side data, this way the 
 drawtext filter can also be used to blend the timecode into the frames, 
 which seems like a useful feature.
>>> 
>>> 
>>> That sounds helpful.
>>> 
>>> libavdevice/decklink_dec.cpp:734:21: error: unknown type name 'DECKLINK_STR'
>>>  DECKLINK_STR decklink_tc;
>> 
>> The patch I sent only replaces the second patch, the first one:
>> 
>> http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180526/185eb219/attachment.obj
>>  
>> 
> 
> Thanks for the update. I continued testing and found this very useful, 
> particularly with the side data.
> 
> Before I only tested with vitc but now have a serial cable connected as well 
> and found a source tape that has distinct values for LTC and VITC timecodes. 
> The LTC values are from 1:00:00 to 2:00:00 and the VITC values are from 
> 07:00:00 - 08:00:00.

Realized a mix up here, in the samples below VITC values are in 1:00:00 to 
2:00:00 and the LTC values are from 07:00:00 - 08:00:00

> With the deckcontrol utility at https://github.com/bavc/deckcontrol 
> , I can use the command gettimecode to 
> grab the LTC value:
> 
> deckcontrol gettimecode
> Issued command 'gettimecode'
> TC=07:37:56:21
> Command sucessfully issued
> Error sending command (No error)
> 
> With these patches, I can only grab the vitc values:
> 
> for i in rp188vitc rp188vitc2 rp188ltc rp188any vitc vitc2 serial ; do echo 
> -n "${i}: " ; ./ffprobe -v quiet -timecode_format "$i" -f decklink -draw_bars 
> 0 -audio_input embedded -video_input sdi -format_code ntsc -channels 8 
> -raw_format yuv422p10 -i "UltraStudio Express" -select_streams v 
> -show_entries stream_tags=timecode -of default=nw=1:nk=1 ; echo ; done
> rp188vitc: 
> rp188vitc2: 
> rp188ltc: 
> rp188any: 
> vitc: 01:41:44;06
> vitc2: 01:41:44;21
> serial: 
> 
> Also it may be interesting in cases like this to support accepting multiple 
> timecode inputs at once, such as "-timecode_format vitc+rp188ltc” though it 
> would need to be contextualized more in metadata.
> 
> With a serial cable connected, I can access LTC via the deckcontrol utility 
> but not with this patch.
> 
> ./ffprobe -timecode_format rp188ltc -v debug -f decklink -draw_bars 0 
> -audio_input embedded -video_input sdi -format_code ntsc -channels 8 
> -raw_format yuv422p10 -i "UltraStudio Express"
> ffprobe version N-91240-g3769aafb7c C

Re: [FFmpeg-devel] [PATCH] Limited timecode support for lavd/decklink

2018-06-07 Thread Dave Rice

> On Jun 6, 2018, at 5:32 PM, Marton Balint  wrote:
> 
> On Wed, 6 Jun 2018, Dave Rice wrote:
> 
>>> On Jun 6, 2018, at 4:50 PM, Marton Balint  wrote:
>>> On Mon, 4 Jun 2018, Dave Rice wrote:
>> In my testing the timecode value set here has corrected been associated 
>> with the first video frame (maintaining the timecode-to-first-frame 
>> relationship as found on the source video stream). Although only having 
>> first timecode value known is limiting, I think this is still quite 
>> useful. This function also mirrors how BlackMagic Media Express and 
>> Adobe Premiere handle capturing video+timecode where only the first 
>> value is documented and all subsequent values are presumed.
> Could you give me an example? (e.g. ffmpeg command line?)
 ./ffmpeg -timecode_format vitc2 -f decklink -draw_bars 0 -audio_input 
 embedded -video_input sdi -format_code ntsc -channels 8 -raw_format 
 yuv422p10 -i "UltraStudio 3D" -c:v v210 -c:a aac output.mov
 This worked for me to embed a QuickTime timecode track based upon the 
 timecode value of the first frame. If the input contained non-sequential 
 timecode values then the timecode track would not be accurate from that 
 point onward, but creating a timecode track based only upon the initial 
 value is what BlackMagic Media Express and Adobe Premiere are doing anyhow.
>>> Hmm, either the decklink drivers became better in hinding the first few 
>>> NoSignal frames, or maybe that issue only affected to old models? (e.g. 
>>> DeckLink SDI or DeckLink Duo 1). I did some test with a Mini Recorder, and 
>>> even the first frame was useful, in this case the timecode was indeed 
>>> correct.
>>> I'd rather see a new AVPacketSideData type which will contain the 
>>> timecode as a string, so you can set it frame-by-frame.
>> Using side data for timecode would be preferable, but the possibility 
>> that a patch for that may someday arrive shouldn’t completely block this 
>> more limited patch.
> I would like to make sure the code works reliably even for the limited 
> use case and no race conditions are affectig the way it works.
 Feel welcome to suggest any testing. I’ll have access for testing again 
 tomorrow.
>>> I reworked the patch a bit (see attached), and added per-frame timcode 
>>> support into the PKT_STRINGS_METADATA packet side data, this way the 
>>> drawtext filter can also be used to blend the timecode into the frames, 
>>> which seems like a useful feature.
>> 
>> 
>> That sounds helpful.
>> 
>> libavdevice/decklink_dec.cpp:734:21: error: unknown type name 'DECKLINK_STR'
>>   DECKLINK_STR decklink_tc;
> 
> The patch I sent only replaces the second patch, the first one:
> 
> http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180526/185eb219/attachment.obj
>  
> 

Thanks for the update. I continued testing and found this very useful, 
particularly with the side data.

Before I only tested with vitc but now have a serial cable connected as well 
and found a source tape that has distinct values for LTC and VITC timecodes. 
The LTC values are from 1:00:00 to 2:00:00 and the VITC values are from 
07:00:00 - 08:00:00.

With the deckcontrol utility at https://github.com/bavc/deckcontrol 
, I can use the command gettimecode to 
grab the LTC value:

deckcontrol gettimecode
Issued command 'gettimecode'
TC=07:37:56:21
Command sucessfully issued
Error sending command (No error)

With these patches, I can only grab the vitc values:

for i in rp188vitc rp188vitc2 rp188ltc rp188any vitc vitc2 serial ; do echo -n 
"${i}: " ; ./ffprobe -v quiet -timecode_format "$i" -f decklink -draw_bars 0 
-audio_input embedded -video_input sdi -format_code ntsc -channels 8 
-raw_format yuv422p10 -i "UltraStudio Express" -select_streams v -show_entries 
stream_tags=timecode -of default=nw=1:nk=1 ; echo ; done
rp188vitc: 
rp188vitc2: 
rp188ltc: 
rp188any: 
vitc: 01:41:44;06
vitc2: 01:41:44;21
serial: 

Also it may be interesting in cases like this to support accepting multiple 
timecode inputs at once, such as "-timecode_format vitc+rp188ltc” though it 
would need to be contextualized more in metadata.

With a serial cable connected, I can access LTC via the deckcontrol utility but 
not with this patch.

./ffprobe -timecode_format rp188ltc -v debug -f decklink -draw_bars 0 
-audio_input embedded -video_input sdi -format_code ntsc -channels 8 
-raw_format yuv422p10 -i "UltraStudio Express"
ffprobe version N-91240-g3769aafb7c Copyright (c) 2007-2018 the FFmpeg 
developers
  built with Apple LLVM version 9.0.0 (clang-900.0.38)
  configuration: --enable-libfreetype --enable-nonfree --enable-decklink 
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/include 
--disable-muxer=mxf --disable-demuxer=mxf
  libavutil  56. 18.102 / 56. 18.102
  

Re: [FFmpeg-devel] [PATCH] lavu: add calling convention for OpenCL callback.

2018-06-07 Thread Song, Ruiling


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Mark Thompson
> Sent: Thursday, June 7, 2018 6:21 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavu: add calling convention for OpenCL
> callback.
> 
> On 06/06/18 16:31, Ruiling Song wrote:
> > This fix a build error on Windows:
> > C2440: connot convert from 'void (__cdecl *) (...)' to 'void (__stdcall 
> > *)(...)'.
> >
> > Signed-off-by: Ruiling Song 
> > ---
> >  libavutil/hwcontext_opencl.c | 7 ---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> > index 43b5c5a..e08d7bc 100644
> > --- a/libavutil/hwcontext_opencl.c
> > +++ b/libavutil/hwcontext_opencl.c
> > @@ -141,9 +141,10 @@ typedef struct OpenCLFramesContext {
> >  } OpenCLFramesContext;
> >
> >
> > -static void opencl_error_callback(const char *errinfo,
> > -  const void *private_info, size_t cb,
> > -  void *user_data)
> > +static void CL_CALLBACK opencl_error_callback(const char *errinfo,
> > +  const void *private_info,
> > +  size_t cb,
> > +  void *user_data)
> >  {
> >  AVHWDeviceContext *ctx = user_data;
> >  av_log(ctx, AV_LOG_ERROR, "OpenCL error: %s\n", errinfo);
> >
> 
> Yep, applied.
> 
> Is this visible in any MSVC build, or does it have to be 32-bit?  (All my 
> testing on
> Windows has been done with MinGW-w64, where __stdcall/__cdecl have no
> effect and this goes unnoticed.)
Yes, I think this should only occur on 32bit. In fact, I am not intentionally 
trying to build 32bit.
I am basically follow the steps in: 
https://pracucci.com/compile-ffmpeg-on-windows-with-visual-studio-compiler.html
I installed VS 2017 and msys2-x86_64 (http://www.msys2.org)
Then I launch mingw64 in vs2017 command prompt through 'msys2_shell.cmd 
-mingw64 -use-full-path'.
I installed Intel OpenCL SDK, and modify INCLUDE and LIB to point to it.
The Intel OpenCL SDK provides both x86 and x64 OpenCL.lib.
I first use x64 version OpenCL.lib. then I configure FFmpeg like:
./configure --toolchain=msvc --enable-yasm --arch=x86_x64 --enable-asm 
--enable-opencl.
But the configure failed with below error log. Seems it still tries to build 
WIN32. I am not sure what's wrong.
I just didn't have enough time to look into this. so I switched to x86 version 
OpenCL.lib, then I met the bug.

cl -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS 
-D_WIN32_WINNT=0x0600 -nologo -c -Fo./ffconf.EeohdeiF/test.o 
./ffconf.EeohdeiF/test.c
test.c
./compat/windows/mslink -nologo -LARGEADDRESSAWARE 
-out:./ffconf.EeohdeiF/test.exe ./ffconf.EeohdeiF/test.o OpenCL.lib
test.o : error LNK2019: unresolved external symbol _clEnqueueNDRangeKernel@36 
referenced in function _check_clEnqueueNDRangeKernel
C:\Program Files (x86)\Intel\OpenCL SDK\6.3\lib\x64\OpenCL.lib : warning 
LNK4272: library machine type 'x64' conflicts with target machine type 'x86'

Thanks!
Ruiling
> 
> Thanks,
> 
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [GSOC] [PATCH] TensorFlow backend introduction for DNN module

2018-06-07 Thread Sergey Lavrushkin
2018-06-06 17:22 GMT+03:00 Pedro Arthur :

> Hi,
>
> 2018-06-05 20:23 GMT-03:00 Sergey Lavrushkin :
> > Here is the patch, that fixes described issues.
> When I try to run (video input), when tf is not enabled in configure it
> crashes.
>
>
> $ffmpeg -i in.mp4 -vf srcnn=dnn_backend=tensorflow out.mp4
>
> ffmpeg version N-91232-g256386fd3e Copyright (c) 2000-2018 the FFmpeg
> developers
>   built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
>   configuration:
>   libavutil  56. 18.102 / 56. 18.102
>   libavcodec 58. 19.105 / 58. 19.105
>   libavformat58. 17.100 / 58. 17.100
>   libavdevice58.  4.100 / 58.  4.100
>   libavfilter 7. 25.100 /  7. 25.100
>   libswscale  5.  2.100 /  5.  2.100
>   libswresample   3.  2.100 /  3.  2.100
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mp4':
>   Metadata:
> major_brand : isom
> minor_version   : 512
> compatible_brands: isomiso2mp41
> encoder : Lavf58.17.100
>   Duration: 00:06:13.70, start: 0.00, bitrate: 5912 kb/s
> Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v /
> 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 5777 kb/s, 29.97
> fps, 29.97 tbr, 30k tbn, 30k tbc (default)
> Metadata:
>   handler_name: VideoHandler
> Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
> stereo, fltp, 128 kb/s (default)
> Metadata:
>   handler_name: SoundHandler
> Stream mapping:
>   Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
>   Stream #0:1 -> #0:1 (aac (native) -> aac (native))
> Press [q] to stop, [?] for help
> free(): invalid pointer
> Aborted (core dumped)
>
>
>
> When the output is an image, t does not crashes but neither fallback to
> native
>
>
> $ffmpeg -i in.jpg -vf srcnn=dnn_backend=tensorflow out.png
>
> ffmpeg version N-91232-g256386fd3e Copyright (c) 2000-2018 the FFmpeg
> developers
>   built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
>   configuration:
>   libavutil  56. 18.102 / 56. 18.102
>   libavcodec 58. 19.105 / 58. 19.105
>   libavformat58. 17.100 / 58. 17.100
>   libavdevice58.  4.100 / 58.  4.100
>   libavfilter 7. 25.100 /  7. 25.100
>   libswscale  5.  2.100 /  5.  2.100
>   libswresample   3.  2.100 /  3.  2.100
> Input #0, image2, from 'in.jpg':
>   Duration: 00:00:00.04, start: 0.00, bitrate: 43469 kb/s
> Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown),
> 1192x670 [SAR 1:1 DAR 596:335], 25 tbr, 25 tbn, 25 tbc
> Stream mapping:
>   Stream #0:0 -> #0:0 (mjpeg (native) -> png (native))
> Press [q] to stop, [?] for help
> [Parsed_srcnn_0 @ 0x557d3ea55980] could not create DNN module for
> requested backend
> [AVFilterGraph @ 0x557d3ea102c0] Error initializing filter 'srcnn'
> with args 'dnn_backend=tensorflow'
> Error reinitializing filters!
> Failed to inject frame into filter network: Cannot allocate memory
> Error while processing the decoded data for stream #0:0
> Conversion failed!
>
>
> I think you could disable the tensorflow option if it is not enable in
> configure or fallback to native, either solution is ok for me.


I disabled tensorflow option when it is not configured with it. Here is the
updated patch.
I think, crash occurred due to improper call to av_freep for dnn_module.
Here is also the patch, that fixes this bug.
From 33c1e08b650f3724c1317f024d716c8234e283b6 Mon Sep 17 00:00:00 2001
From: Sergey Lavrushkin 
Date: Wed, 6 Jun 2018 01:44:40 +0300
Subject: [PATCH 1/2] libavfilter/vf_srcnn.c: adds DNN module backend AVOption,
 changes AV_LOG_INFO message to AV_LOG_VERBOSE.

---
 libavfilter/vf_srcnn.c | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
index 5c5e26b33a..bba54f6780 100644
--- a/libavfilter/vf_srcnn.c
+++ b/libavfilter/vf_srcnn.c
@@ -36,6 +36,7 @@ typedef struct SRCNNContext {
 
 char* model_filename;
 float* input_output_buf;
+DNNBackendType backend_type;
 DNNModule* dnn_module;
 DNNModel* model;
 DNNData input_output;
@@ -44,6 +45,11 @@ typedef struct SRCNNContext {
 #define OFFSET(x) offsetof(SRCNNContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption srcnn_options[] = {
+{ "dnn_backend", "DNN backend used for model execution", OFFSET(backend_type), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, 1, FLAGS, "backend" },
+{ "native", "native backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, "backend" },
+#if (CONFIG_LIBTENSORFLOW == 1)
+{ "tensorflow", "tensorflow backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "backend" },
+#endif
 { "model_filename", "path to model file specifying network architecture and its parameters", OFFSET(model_filename), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
 { NULL }
 };
@@ -54,29 +60,20 @@ static av_cold int init(AVFilterContext* context)
 {
 SRCNNContext* srcnn_context = context->priv;
 
-srcnn_context->dnn_module = ff_get_dn

Re: [FFmpeg-devel] [PATCH v3 1/2] lavfi: add opencl tonemap filter.

2018-06-07 Thread Song, Ruiling


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Michael Niedermayer
> Sent: Thursday, June 7, 2018 4:40 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v3 1/2] lavfi: add opencl tonemap filter.
> 
> On Wed, Jun 06, 2018 at 03:23:53PM +0800, Ruiling Song wrote:
> > This filter does HDR(HDR10/HLG) to SDR conversion with tone-mapping.
> >
> > An example command to use this filter with vaapi codecs:
> > FFMPEG -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device \
> > opencl=ocl@va -hwaccel vaapi -hwaccel_device va -hwaccel_output_format \
> > vaapi -i INPUT -filter_hw_device ocl -filter_complex \
> > '[0:v]hwmap,tonemap_opencl=t=bt2020:tonemap=linear:format=p010[x1]; \
> > [x1]hwmap=derive_device=vaapi:reverse=1' -c:v hevc_vaapi -profile 2
> OUTPUT
> >
> > Signed-off-by: Ruiling Song 
> > ---
> > this version mainly address Mark's comments on v2.
> >
> > Thanks!
> > Ruiling
> >
> >  configure   |   1 +
> >  libavfilter/Makefile|   2 +
> >  libavfilter/allfilters.c|   1 +
> >  libavfilter/colorspace.c|  90 +
> >  libavfilter/colorspace.h|  41 ++
> >  libavfilter/opencl/colorspace_common.cl | 220 +++
> >  libavfilter/opencl/tonemap.cl   | 272 +
> >  libavfilter/opencl_source.h |   2 +
> >  libavfilter/vf_tonemap_opencl.c | 657
> 
> >  9 files changed, 1286 insertions(+)
> >  create mode 100644 libavfilter/colorspace.c
> >  create mode 100644 libavfilter/colorspace.h
> >  create mode 100644 libavfilter/opencl/colorspace_common.cl
> >  create mode 100644 libavfilter/opencl/tonemap.cl
> >  create mode 100644 libavfilter/vf_tonemap_opencl.c
> >
> > --- /dev/null
> > +++ b/libavfilter/opencl/colorspace_common.cl
> > @@ -0,0 +1,220 @@
> > +/*
> > + * 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
> > + */
> > +
> > +#define ST2084_MAX_LUMINANCE 1.0f
> > +#define REFERENCE_WHITE 100.0f
> > +
> 
> > +#if chroma_loc == 1
> > +#define chroma_sample(a,b,c,d) ((a + c) * 0.5f)
> > +#elif chroma_loc == 3
> > +#define chroma_sample(a,b,c,d) (a)
> > +#elif chroma_loc == 4
> > +#define chroma_sample(a,b,c,d) ((a + b) * 0.5f)
> > +#elif chroma_loc == 5
> > +#define chroma_sample(a,b,c,d) (c)
> > +#elif chroma_loc == 6
> > +#define chroma_sample(a,b,c,d) ((c + d) * 0.5f)
> > +#else
> > +#define chroma_sample(a,b,c,d) ((a + b + c + d) * 0.25f)
> > +#endif
> 
> the arguments should be protected by () otherwise unexpected results can
> occur with some expressions
Yes, that's true, will fix it.

Ruiling
> 
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Old school: Use the lowest level language in which you can solve the problem
> conveniently.
> New school: Use the highest level language in which the latest supercomputer
> can solve the problem without the user falling asleep waiting.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/nvenc: enable nvenc encoder instance reuse (v2)

2018-06-07 Thread Pavel Koshevoy
---
 libavcodec/nvenc.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index b4186c0bec..cfa7268a5e 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2051,8 +2051,16 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 if ((!ctx->cu_context && !ctx->d3d11_device) || !ctx->nvencoder)
 return AVERROR(EINVAL);
 
-if (ctx->encoder_flushing)
-return AVERROR_EOF;
+if (ctx->encoder_flushing) {
+if (avctx->internal->draining)
+return AVERROR_EOF;
+
+ctx->encoder_flushing = 0;
+ctx->first_packet_output = 0;
+ctx->initial_pts[0] = AV_NOPTS_VALUE;
+ctx->initial_pts[1] = AV_NOPTS_VALUE;
+av_fifo_reset(ctx->timestamp_list);
+}
 
 if (frame) {
 in_surf = get_free_frame(ctx);
-- 
2.16.4

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


Re: [FFmpeg-devel] [PATCH] lavc/nvenc: enable nvenc encoder instance reuse after draining

2018-06-07 Thread Pavel Koshevoy
On Thu, Jun 7, 2018, 03:08 Timo Rothenpieler  wrote:

> On 07.06.2018 06:38, Pavel Koshevoy wrote:
> > ---
> >  libavcodec/nvenc.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> > index b4186c0bec..8928eacc70 100644
> > --- a/libavcodec/nvenc.c
> > +++ b/libavcodec/nvenc.c
> > @@ -2181,6 +2181,12 @@ int ff_nvenc_receive_packet(AVCodecContext
> *avctx, AVPacket *pkt)
> >
> >  av_fifo_generic_write(ctx->unused_surface_queue, &tmp_out_surf,
> sizeof(tmp_out_surf), NULL);
> >  } else if (ctx->encoder_flushing) {
> > +/* reset to initial state so the encoder can be re-used */
> > +ctx->encoder_flushing = 0;
> > +ctx->first_packet_output = 0;
> > +ctx->initial_pts[0] = AV_NOPTS_VALUE;
> > +ctx->initial_pts[1] = AV_NOPTS_VALUE;
> > +av_fifo_reset(ctx->timestamp_list);
> >  return AVERROR_EOF;
> >  } else {
> >  return AVERROR(EAGAIN);
> >
>
> I'm not sure if the send/receive API intends for an encoder to be
> re-used after is has entered EOF state.
>
> If an API user were to rely on getting EOF here repeatedly, and suddenly
> getting EAGAIN after a single EOF, it might mess things up.
>
> The only way I'd see to make this work is to introduce another flag, so
> it stays in EOF state until more input is given. And I'm not even sure
> if that is true to the API.
>


I'll post another patch that resets to initial state on 1st non-NULL frame
if ctx->encoder_flushing != 0.  That would preserve the behavior of
returning EOF repeatedly when called with NULL frame repeatedly.

The motivation for this patch is to avoid nvenc spinup cost on hardware
that supports more than 2 nvenc instances. This cost becomes a bottleneck
when repeatedly encoding short video fragments (4 seconds in my case). In
my testing with a P4 card I've observed that avcodec_open becomes slower as
number of nvenc instances increases.  In the worst case I've observed it
took ~6 seconds for avcodec_open to complete.

Pavel

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


Re: [FFmpeg-devel] [RFC] libfdk_aac license

2018-06-07 Thread Gyan Doshi



On 31-05-2018 11:03 AM, Gyan Doshi wrote:



"The Fraunhofer AAC library is licensed under a license incompatible to
  the GPL. Therefore, for GPL builds, you have to pass
  @code{--enable-nonfree} to configure to use it. To the best of our
  knowledge, it is compatible with the LGPL" ?


Will push in a day with above changes.


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


[FFmpeg-devel] [PATCH] configure: fix inline neon regression

2018-06-07 Thread John Cox
Hi

This patch fixes the regression whereby inline neon is not enabled

Actually I'm a bit unsure about this patch (despite the fact I'm
submitting it).  It does do its job in that if you specify an armv7a cpu
then it will try to enable neon, but it is a bit mucky due to
uncertainties about exactly what capabilities each cpu actually has.

Really configure probably wants a --fpu= option, but my understanding of
how it is meant to work isn't up to that, so for the moment if the fpu
type is specified by the user then I expect it to turn up in
cextra_flags.

I'll also note that probe_arm_arch ends up setting subarch to armv7-a
when the other bits of the script expect armv7a (although gcc wants
armv7-a in -march).  Again I am confused by this but I'm not sure what
the right answer is let alone the correct fix.  Maybe whoever wrote this
bit of configure could revisit it?

Regards

John Cox


neon_inline.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] qsvenc: use the compression_level to replace private option

2018-06-07 Thread Zhong Li
Use a common way to control target_usage, keeping consistent with vaapi
encoders. The private option preset is kept only for compatibility.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index ce003ad..c7eb1f4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -453,8 +453,19 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->level > 0)
 q->param.mfx.CodecLevel = avctx->level;
 
+if (avctx->compression_level == FF_COMPRESSION_DEFAULT) {
+avctx->compression_level = q->preset;
+} else if (avctx->compression_level >= 0) {
+if (avctx->compression_level > MFX_TARGETUSAGE_BEST_SPEED) {
+av_log(avctx, AV_LOG_WARNING, "Invalid compression level: "
+"valid range is 0-%d, using %d instead\n",
+MFX_TARGETUSAGE_BEST_SPEED, MFX_TARGETUSAGE_BEST_SPEED);
+avctx->compression_level = MFX_TARGETUSAGE_BEST_SPEED;
+}
+}
+
 q->param.mfx.CodecProfile   = q->profile;
-q->param.mfx.TargetUsage= q->preset;
+q->param.mfx.TargetUsage= avctx->compression_level;
 q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size);
 q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1;
 q->param.mfx.GopOptFlag = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ?
-- 
2.7.4

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


Re: [FFmpeg-devel] Evolution of lavfi's design and API

2018-06-07 Thread Paul B Mahol
On 6/6/18, Nicolas George  wrote:
> Michael Niedermayer (2018-06-04):
>> If noone, who has time to reply knows the awnser then you probably have
>> to
>> find it out from the code and any unfinished patchsets
>>
>> sending nicolas a private mail may also be more vissible to him than the
>> ML
>> in case he is busy
>
> In terms of design, the big thing missing from lavfi is a clean API to
> run a filter graph. Right now, it relies on requests on outputs, with a
> fragile heuristic to find the "oldest" one. A clean API would allow to
> run it as a whole and react to frames on output or requests on inputs,
> possibly with callbacks.
>
> This must come before threading, because it is what allows to control
> threading: threading is efficient when the system can start several
> threads and let them run, doing their work. If it is constantly stopping
> and re-starting because the calling API makes too small steps, much time
> is wasted.
>
> But more than that, it requires somebody working on it. Speaking for
> myself, the toxic ambiance in the project since a few months has
> destroyed my motivation for doing anything ambitious on it. And to be
> completely forthright, I feel that Paul is partly responsible for that
> toxic ambiance; see his interventions on the thread about enforcing the
> code of conduct for example.

Your contributions will be missed.

Good bye.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/nvenc: enable nvenc encoder instance reuse after draining

2018-06-07 Thread Timo Rothenpieler
On 07.06.2018 06:38, Pavel Koshevoy wrote:
> ---
>  libavcodec/nvenc.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index b4186c0bec..8928eacc70 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -2181,6 +2181,12 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, 
> AVPacket *pkt)
>  
>  av_fifo_generic_write(ctx->unused_surface_queue, &tmp_out_surf, 
> sizeof(tmp_out_surf), NULL);
>  } else if (ctx->encoder_flushing) {
> +/* reset to initial state so the encoder can be re-used */
> +ctx->encoder_flushing = 0;
> +ctx->first_packet_output = 0;
> +ctx->initial_pts[0] = AV_NOPTS_VALUE;
> +ctx->initial_pts[1] = AV_NOPTS_VALUE;
> +av_fifo_reset(ctx->timestamp_list);
>  return AVERROR_EOF;
>  } else {
>  return AVERROR(EAGAIN);
> 

I'm not sure if the send/receive API intends for an encoder to be
re-used after is has entered EOF state.

If an API user were to rely on getting EOF here repeatedly, and suddenly
getting EAGAIN after a single EOF, it might mess things up.

The only way I'd see to make this work is to introduce another flag, so
it stays in EOF state until more input is given. And I'm not even sure
if that is true to the API.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] qsvenc: remove vcm option on Linux

2018-06-07 Thread Zhong Li
1. vcm mode is only available for H264.
2. vcm is not supported on Linux, but it is shown when run "./ffmpeg -h
encoder=h264_qsv |grep vcm". This shouldn't happen.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.h  | 1 -
 libavcodec/qsvenc_h264.c | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index d482722..b32b7f6 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -78,7 +78,6 @@
 { "slow",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_3  },
INT_MIN, INT_MAX, VE, "preset" },   
 \
 { "slower",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_2  },
INT_MIN, INT_MAX, VE, "preset" },   
 \
 { "veryslow",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BEST_QUALITY  }, INT_MIN, INT_MAX, VE, "preset" },  
  \
-{ "vcm",  "Use the video conferencing mode ratecontrol",  OFFSET(qsv.vcm), 
 AV_OPT_TYPE_INT, { .i64 = 0  },  0, 1, VE },   
 \
 { "rdo","Enable rate distortion optimization",OFFSET(qsv.rdo), 
   AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE },
 \
 { "max_frame_size", "Maximum encoded frame size in bytes",
OFFSET(qsv.max_frame_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX, VE 
}, \
 { "max_slice_size", "Maximum encoded slice size in bytes",
OFFSET(qsv.max_slice_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, UINT16_MAX, VE 
}, \
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 7aa65e9..d5e8df7 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -103,6 +103,9 @@ static const AVOption options[] = {
 QSV_COMMON_OPTS
 
 { "cavlc",  "Enable CAVLC",   
OFFSET(qsv.cavlc),  AV_OPT_TYPE_INT, { .i64 = 0 },   0,  1, VE 
},
+#if QSV_HAVE_VCM
+{ "vcm",  "Use the video conferencing mode ratecontrol",  
OFFSET(qsv.vcm),  AV_OPT_TYPE_INT, { .i64 = 0  },  0, 1, VE },
+#endif
 { "idr_interval", "Distance (in I-frames) between IDR frames", 
OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 { "pic_timing_sei","Insert picture timing SEI with pic_struct_syntax 
element", OFFSET(qsv.pic_timing_sei), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
 { "single_sei_nal_unit","Put all the SEI messages into one NALU",  
  OFFSET(qsv.single_sei_nal_unit), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  
1, VE },
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 4/6] avformat/mxfdec: remove check for NULL MXFTrack in mxf_set_pts

2018-06-07 Thread Tomas Härdin
tis 2018-06-05 klockan 20:38 +0200 skrev Marton Balint:
> 
> On Tue, 5 Jun 2018, Tomas Härdin wrote:
> 
> > tor 2018-05-31 klockan 02:05 +0200 skrev Marton Balint:
> > > It cannot happen for video streams.
> > > 
> > > > Signed-off-by: Marton Balint 
> > > 
> > > ---
> > >  libavformat/mxfdec.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> > > index e80ef62d57..cf1cd71987 100644
> > > --- a/libavformat/mxfdec.c
> > > +++ b/libavformat/mxfdec.c
> > > @@ -3221,7 +3221,7 @@ static int mxf_set_pts(MXFContext *mxf, AVStream 
> > > *st, AVPacket *pkt, int64_t nex
> > >  if (mxf->nb_index_tables >= 1 && mxf->current_edit_unit < 
> > > t->nb_ptses) {
> > >  pkt->dts = mxf->current_edit_unit + t->first_dts;
> > >  pkt->pts = t->ptses[mxf->current_edit_unit];
> > > -} else if (track && track->intra_only) {
> > > +} else if (track->intra_only) {
> > 
> > I wonder what actually caused this check to be inserted. That is, what
> > could lead to track being NULL that is no longer the case?
> 
> I don't know, I cc'd the original patch author about it. IMHO this was 
> never needed because only streams which are added in 
> mxf_add_metadata_stream have their priv_data (track) set to NULL, 
> and those streams are always DATA.

I can forsee someone in the future missing this. But I also don't like
cargo culting things that shouldn't be necessary. Grrr...

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


Re: [FFmpeg-devel] [PATCH v3 1/2] lavfi: add opencl tonemap filter.

2018-06-07 Thread Michael Niedermayer
On Wed, Jun 06, 2018 at 03:23:53PM +0800, Ruiling Song wrote:
> This filter does HDR(HDR10/HLG) to SDR conversion with tone-mapping.
> 
> An example command to use this filter with vaapi codecs:
> FFMPEG -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device \
> opencl=ocl@va -hwaccel vaapi -hwaccel_device va -hwaccel_output_format \
> vaapi -i INPUT -filter_hw_device ocl -filter_complex \
> '[0:v]hwmap,tonemap_opencl=t=bt2020:tonemap=linear:format=p010[x1]; \
> [x1]hwmap=derive_device=vaapi:reverse=1' -c:v hevc_vaapi -profile 2 OUTPUT
> 
> Signed-off-by: Ruiling Song 
> ---
> this version mainly address Mark's comments on v2.
> 
> Thanks!
> Ruiling
> 
>  configure   |   1 +
>  libavfilter/Makefile|   2 +
>  libavfilter/allfilters.c|   1 +
>  libavfilter/colorspace.c|  90 +
>  libavfilter/colorspace.h|  41 ++
>  libavfilter/opencl/colorspace_common.cl | 220 +++
>  libavfilter/opencl/tonemap.cl   | 272 +
>  libavfilter/opencl_source.h |   2 +
>  libavfilter/vf_tonemap_opencl.c | 657 
> 
>  9 files changed, 1286 insertions(+)
>  create mode 100644 libavfilter/colorspace.c
>  create mode 100644 libavfilter/colorspace.h
>  create mode 100644 libavfilter/opencl/colorspace_common.cl
>  create mode 100644 libavfilter/opencl/tonemap.cl
>  create mode 100644 libavfilter/vf_tonemap_opencl.c
> 
> diff --git a/configure b/configure
> index 53224f0..4ff651f 100755
> --- a/configure
> +++ b/configure
> @@ -3410,6 +3410,7 @@ tinterlace_filter_deps="gpl"
>  tinterlace_merge_test_deps="tinterlace_filter"
>  tinterlace_pad_test_deps="tinterlace_filter"
>  tonemap_filter_deps="const_nan"
> +tonemap_opencl_filter_deps="opencl const_nan"
>  unsharp_opencl_filter_deps="opencl"
>  uspp_filter_deps="gpl avcodec"
>  vaguedenoiser_filter_deps="gpl"
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 5b4be49..d2c85cf 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -356,6 +356,8 @@ OBJS-$(CONFIG_TINTERLACE_FILTER) += 
> vf_tinterlace.o
>  OBJS-$(CONFIG_TLUT2_FILTER)  += vf_lut2.o framesync.o
>  OBJS-$(CONFIG_TMIX_FILTER)   += vf_mix.o framesync.o
>  OBJS-$(CONFIG_TONEMAP_FILTER)+= vf_tonemap.o
> +OBJS-$(CONFIG_TONEMAP_OPENCL_FILTER) += vf_tonemap_opencl.o 
> colorspace.o opencl.o \
> +opencl/tonemap.o 
> opencl/colorspace_common.o
>  OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
>  OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
>  OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o framesync.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index f2d27d2..fa85c29 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -345,6 +345,7 @@ extern AVFilter ff_vf_tinterlace;
>  extern AVFilter ff_vf_tlut2;
>  extern AVFilter ff_vf_tmix;
>  extern AVFilter ff_vf_tonemap;
> +extern AVFilter ff_vf_tonemap_opencl;
>  extern AVFilter ff_vf_transpose;
>  extern AVFilter ff_vf_trim;
>  extern AVFilter ff_vf_unpremultiply;
> diff --git a/libavfilter/colorspace.c b/libavfilter/colorspace.c
> new file mode 100644
> index 000..7fd7bdf
> --- /dev/null
> +++ b/libavfilter/colorspace.c
> @@ -0,0 +1,90 @@
> +/*
> + * Copyright (c) 2016 Ronald S. Bultje 
> + * 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 "colorspace.h"
> +
> +
> +void invert_matrix3x3(const double in[3][3], double out[3][3])
> +{
> +double m00 = in[0][0], m01 = in[0][1], m02 = in[0][2],
> +   m10 = in[1][0], m11 = in[1][1], m12 = in[1][2],
> +   m20 = in[2][0], m21 = in[2][1], m22 = in[2][2];
> +int i, j;
> +double det;
> +
> +out[0][0] =  (m11 * m22 - m21 * m12);
> +out[0][1] = -(m01 * m22 - m21 * m02);
> +out[0][2] =  (m01 * m12 - m11 * m02);
> +out[1][0] = -(m10 * m22 - m20 * m12);
> +out[1][1] =  (m00 * m22 - m20 * m02);
> +out[1][2] = -(m00 * m12 - m10 * m02);
> +out[2][0] =  (m10 * m21 - m20 * m11);
> +out[2][1] = -(m00 * m21 - m20 * m01);
> +o