[FFmpeg-devel] [PATCH v5] avformat/mpegts: reduce buffering during initialization

2019-03-08 Thread Andriy Gelman
From: Andriy Gelman 

Reduces buffering latency with low bitrate streams, where
8192 bytes can mean several seconds.
---
 libavformat/mpegts.c | 59 +++-
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b04fd7b4f4..7047ba6522 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -53,6 +53,9 @@
 (prev_dividend) = (dividend);  
\
 } while (0)
 
+#define PROBE_PACKET_MAX_BUF 8192
+#define PROBE_PACKET_MARGIN 5
+
 enum MpegTSFilterType {
 MPEGTS_PES,
 MPEGTS_SECTION,
@@ -591,28 +594,42 @@ static int analyze(const uint8_t *buf, int size, int 
packet_size,
 return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
 }
 
-/* autodetect fec presence. Must have at least 1024 bytes  */
-static int get_packet_size(const uint8_t *buf, int size)
+/* autodetect fec presence */
+static int get_packet_size(AVFormatContext* s)
 {
 int score, fec_score, dvhs_score;
+int margin;
+int ret;
 
-if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
-return AVERROR_INVALIDDATA;
+/*init buffer to store stream for probing */
+uint8_t buf[PROBE_PACKET_MAX_BUF] = {0};
+int buf_size = 0;
 
-score  = analyze(buf, size, TS_PACKET_SIZE,  0);
-dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, 0);
-fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE,  0);
-av_log(NULL, AV_LOG_TRACE, "score: %d, dvhs_score: %d, fec_score: %d \n",
-score, dvhs_score, fec_score);
-
-if (score > fec_score && score > dvhs_score)
-return TS_PACKET_SIZE;
-else if (dvhs_score > score && dvhs_score > fec_score)
-return TS_DVHS_PACKET_SIZE;
-else if (score < fec_score && dvhs_score < fec_score)
-return TS_FEC_PACKET_SIZE;
-else
-return AVERROR_INVALIDDATA;
+while (buf_size < PROBE_PACKET_MAX_BUF) {
+ret = avio_read_partial(s->pb, buf + buf_size, PROBE_PACKET_MAX_BUF - 
buf_size);
+if (ret < 0)
+return AVERROR_INVALIDDATA;
+buf_size += ret;
+
+score  = analyze(buf, buf_size, TS_PACKET_SIZE,  0);
+dvhs_score = analyze(buf, buf_size, TS_DVHS_PACKET_SIZE, 0);
+fec_score  = analyze(buf, buf_size, TS_FEC_PACKET_SIZE,  0);
+av_log(s, AV_LOG_TRACE, "Probe: %d, score: %d, dvhs_score: %d, 
fec_score: %d \n",
+buf_size, score, dvhs_score, fec_score);
+
+if (buf_size < PROBE_PACKET_MAX_BUF)
+margin = PROBE_PACKET_MARGIN; /*if buffer not filled */
+else
+margin = 0;
+
+if (score > FFMAX(fec_score, dvhs_score) + margin)
+return TS_PACKET_SIZE;
+else if (dvhs_score > FFMAX(score, fec_score) + margin)
+return TS_DVHS_PACKET_SIZE;
+else if (fec_score > FFMAX(score, dvhs_score) + margin)
+return TS_FEC_PACKET_SIZE;
+}
+return AVERROR_INVALIDDATA;
 }
 
 typedef struct SectionHeader {
@@ -2841,8 +2858,6 @@ static int mpegts_read_header(AVFormatContext *s)
 {
 MpegTSContext *ts = s->priv_data;
 AVIOContext *pb   = s->pb;
-uint8_t buf[8 * 1024] = {0};
-int len;
 int64_t pos, probesize = s->probesize;
 
 s->internal->prefer_codec_framerate = 1;
@@ -2850,10 +2865,8 @@ static int mpegts_read_header(AVFormatContext *s)
 if (ffio_ensure_seekback(pb, probesize) < 0)
 av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n");
 
-/* read the first 8192 bytes to get packet size */
 pos = avio_tell(pb);
-len = avio_read(pb, buf, sizeof(buf));
-ts->raw_packet_size = get_packet_size(buf, len);
+ts->raw_packet_size = get_packet_size(s);
 if (ts->raw_packet_size <= 0) {
 av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting 
to non-FEC/DVHS\n");
 ts->raw_packet_size = TS_PACKET_SIZE;
-- 
2.20.1

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


[FFmpeg-devel] [PATCH] Added more commandline options for libaom encoder.

2019-03-08 Thread Sam John
The following are the newly added options:
arnr_max_frames, arnr_strength, aq_mode, denoise_noise_level, 
denoise_block_size,
rc_undershoot_pct, rc_overshoot_pct, minsection_pct, maxsection_pct, 
frame_parallel,
enable_cdef, and enable_global_motion.

Also added macros for compiling for aom 1.0.0.
---
 libavcodec/libaomenc.c | 86 --
 1 file changed, 83 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index faec61cacd..8e0ba7241e 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -66,36 +66,65 @@ typedef struct AOMEncoderContext {
 struct FrameListData *coded_frame_list;
 int cpu_used;
 int auto_alt_ref;
+int arnr_max_frames;
+int arnr_strength;
+int aq_mode;
 int lag_in_frames;
 int error_resilient;
 int crf;
 int static_thresh;
 int drop_threshold;
+int denoise_noise_level;
+int denoise_block_size;
 uint64_t sse[4];
 int have_sse; /**< true if we have pending sse[] */
 uint64_t frame_number;
+int rc_undershoot_pct;
+int rc_overshoot_pct;
+int minsection_pct;
+int maxsection_pct;
+int frame_parallel;
 int tile_cols, tile_rows;
 int tile_cols_log2, tile_rows_log2;
 aom_superblock_size_t superblock_size;
 int uniform_tiles;
 int row_mt;
+int enable_cdef;
+int enable_global_motion;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
 [AOME_SET_CPUUSED]  = "AOME_SET_CPUUSED",
 [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
 [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
+[AOME_SET_ARNR_MAXFRAMES]   = "AOME_SET_ARNR_MAXFRAMES",
+[AOME_SET_ARNR_STRENGTH]= "AOME_SET_ARNR_STRENGTH",
 [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
 [AV1E_SET_COLOR_RANGE]  = "AV1E_SET_COLOR_RANGE",
 [AV1E_SET_COLOR_PRIMARIES]  = "AV1E_SET_COLOR_PRIMARIES",
 [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
 [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
+[AV1E_SET_AQ_MODE]  = "AV1E_SET_AQ_MODE",
+[AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING",
 [AV1E_SET_SUPERBLOCK_SIZE]  = "AV1E_SET_SUPERBLOCK_SIZE",
 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
 [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
 [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
 #endif
+#ifdef AV1E_SET_DENOISE_NOISE_LEVEL
+[AV1E_SET_DENOISE_NOISE_LEVEL] =  "AV1E_SET_DENOISE_NOISE_LEVEL",
+#endif
+#ifdef AV1E_SET_DENOISE_BLOCK_SIZE
+[AV1E_SET_DENOISE_BLOCK_SIZE] =   "AV1E_SET_DENOISE_BLOCK_SIZE",
+#endif
+#ifdef AV1E_SET_MAX_REFERENCE_FRAMES
+[AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
+#endif
+#ifdef AV1E_SET_ENABLE_GLOBAL_MOTION
+[AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
+#endif
+[AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -567,10 +596,14 @@ static av_cold int aom_init(AVCodecContext *avctx,
 
 // 0-100 (0 => CBR, 100 => VBR)
 enccfg.rc_2pass_vbr_bias_pct   = round(avctx->qcompress * 100);
-if (avctx->bit_rate)
+if (ctx->minsection_pct >= 0)
+enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct;
+else if (avctx->bit_rate)
 enccfg.rc_2pass_vbr_minsection_pct =
 avctx->rc_min_rate * 100LL / avctx->bit_rate;
-if (avctx->rc_max_rate)
+if (ctx->maxsection_pct >= 0)
+enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct;
+else if (avctx->rc_max_rate)
 enccfg.rc_2pass_vbr_maxsection_pct =
 avctx->rc_max_rate * 100LL / avctx->bit_rate;
 
@@ -582,6 +615,11 @@ static av_cold int aom_init(AVCodecContext *avctx,
 avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
 
+if (ctx->rc_undershoot_pct >= 0)
+enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
+if (ctx->rc_overshoot_pct >= 0)
+enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
+
 // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
 if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
 enccfg.kf_min_dist = avctx->keyint_min;
@@ -643,7 +681,12 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
-
+if (ctx->arnr_max_frames >= 0)
+codecctl_int(avctx, AOME_SET_ARNR_MAXFRAMES,   ctx->arnr_max_frames);
+if (ctx->arnr_strength >= 0)
+codecctl_int(avctx, AOME_SET_ARNR_STRENGTH,ctx->arnr_strength);
+if (ctx->enable_cdef >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, 

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-08 Thread Rogozhkin, Dmitry V
On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> Using MSDK parser can improve qsv decoder pass rate in some cases
> (E.g:
> sps declares a wrong level_idc, smaller than it should be).
> And it is necessary for adding new qsv decoders such as MJPEG and VP9
> since current parser can't provide enough information.
> Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and
> merged as commit 1acb19d,
> but was overwritten when merged libav patches (commit: 1f26a23)
> without any explain.
> 
> v2: split decode header from decode_init, and call it for everyframe
> to
> detect format/resoultion change. It can fix some regression issues
> such
> as hevc 10bits decoding.
> 
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvdec.c   | 172 --
> 
>  libavcodec/qsvdec.h   |   2 +
>  libavcodec/qsvdec_h2645.c |   1 +
>  libavcodec/qsvdec_other.c |   1 +
>  4 files changed, 93 insertions(+), 83 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 4a0be811fb..b78026e14d 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const
> AVFifoBuffer* fifo)
>  return av_fifo_size(fifo) / qsv_fifo_item_size();
>  }
>  
> -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q,
> enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
>  {
> -const AVPixFmtDescriptor *desc;
>  mfxSession session = NULL;
>  int iopattern = 0;
> -mfxVideoParam param = { 0 };
> -int frame_width  = avctx->coded_width;
> -int frame_height = avctx->coded_height;
>  int ret;
>  
> -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> -if (!desc)
> -return AVERROR_BUG;
> +ret = ff_get_format(avctx, pix_fmts);
> +if (ret < 0) {
> +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> +return ret;
> +}
>  
>  if (!q->async_fifo) {
>  q->async_fifo = av_fifo_alloc(q->async_depth *
> qsv_fifo_item_size());
> @@ -170,48 +168,72 @@ static int qsv_decode_init(AVCodecContext
> *avctx, QSVContext *q)
>  return ret;
>  }
>  
> -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> -if (ret < 0)
> -return ret;
> +param->IOPattern   = q->iopattern;
> +param->AsyncDepth  = q->async_depth;
> +param->ExtParam= q->ext_buffers;
> +param->NumExtParam = q->nb_ext_buffers;
>  
> -param.mfx.CodecId  = ret;
> -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id,
> avctx->profile);
> -param.mfx.CodecLevel   = avctx->level == FF_LEVEL_UNKNOWN ?
> MFX_LEVEL_UNKNOWN : avctx->level;
> -
> -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> -param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
> -param.mfx.FrameInfo.FourCC = q->fourcc;
> -param.mfx.FrameInfo.Width  = frame_width;
> -param.mfx.FrameInfo.Height = frame_height;
> -param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
> -
> -switch (avctx->field_order) {
> -case AV_FIELD_PROGRESSIVE:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
> -break;
> -case AV_FIELD_TT:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
> -break;
> -case AV_FIELD_BB:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
> -break;
> -default:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
> -break;
> -}
> +return 0;
> + }
>  
> -param.IOPattern   = q->iopattern;
> -param.AsyncDepth  = q->async_depth;
> -param.ExtParam= q->ext_buffers;
> -param.NumExtParam = q->nb_ext_buffers;
> +static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q,
> mfxVideoParam *param)
> +{
> +int ret;
>  
> -ret = MFXVideoDECODE_Init(q->session, );
> +avctx->width= param->mfx.FrameInfo.CropW;
> +avctx->height   = param->mfx.FrameInfo.CropH;
> +avctx->coded_width  = param->mfx.FrameInfo.Width;
> +avctx->coded_height = param->mfx.FrameInfo.Height;
> +avctx->level= param->mfx.CodecLevel;
> +avctx->profile  = param->mfx.CodecProfile;
> +avctx->field_order  = ff_qsv_map_picstruct(param-
> >mfx.FrameInfo.PicStruct);
> +avctx->pix_fmt  = ff_qsv_map_fourcc(param-
> >mfx.FrameInfo.FourCC);
> +
> +ret = MFXVideoDECODE_Init(q->session, param);
>  if (ret < 0)
>  return ff_qsv_print_error(avctx, ret,
>    "Error initializing the MFX video
> decoder");
>  
> -q->frame_info = param.mfx.FrameInfo;
> +q->frame_info = param->mfx.FrameInfo;
> +
> +return 0;
> +}
> +
> +static int qsv_decode_header(AVCodecContext *avctx, 

Re: [FFmpeg-devel] [PATCH v4] avformat/mpegts: reduce buffering during initialization

2019-03-08 Thread Michael Niedermayer
On Thu, Mar 07, 2019 at 09:31:19PM -0500, Andriy Gelman wrote:
> From: Andriy Gelman 
> 
> Reduces buffering latency with low bitrate streams, where
> 8192 bytes can mean several seconds.
> ---
>  libavformat/mpegts.c | 59 +++-
>  1 file changed, 36 insertions(+), 23 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index b04fd7b4f4..88e2150d55 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -53,6 +53,9 @@
>  (prev_dividend) = (dividend);
>   \
>  } while (0)
>  
> +#define PROBE_PACKET_MAX_BUF 8192
> +#define PROBE_PACKET_MARGIN 5
> +
>  enum MpegTSFilterType {
>  MPEGTS_PES,
>  MPEGTS_SECTION,
> @@ -591,28 +594,42 @@ static int analyze(const uint8_t *buf, int size, int 
> packet_size,
>  return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
>  }
>  
> -/* autodetect fec presence. Must have at least 1024 bytes  */
> -static int get_packet_size(const uint8_t *buf, int size)
> +/* autodetect fec presence */
> +static int get_packet_size(AVIOContext* pb)
>  {
>  int score, fec_score, dvhs_score;
> +int margin;
> +int ret;
>  
> -if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
> -return AVERROR_INVALIDDATA;
> +/*init buffer to store stream for probing */
> +uint8_t buf[PROBE_PACKET_MAX_BUF] = {0};
> +int buf_size = 0;
>  
> -score  = analyze(buf, size, TS_PACKET_SIZE,  0);
> -dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, 0);
> -fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE,  0);
> -av_log(NULL, AV_LOG_TRACE, "score: %d, dvhs_score: %d, fec_score: %d \n",
> -score, dvhs_score, fec_score);
> -
> -if (score > fec_score && score > dvhs_score)
> -return TS_PACKET_SIZE;
> -else if (dvhs_score > score && dvhs_score > fec_score)
> -return TS_DVHS_PACKET_SIZE;
> -else if (score < fec_score && dvhs_score < fec_score)
> -return TS_FEC_PACKET_SIZE;
> -else
> -return AVERROR_INVALIDDATA;
> +while (buf_size < PROBE_PACKET_MAX_BUF) {
> +ret = avio_read_partial(pb, buf + buf_size, PROBE_PACKET_MAX_BUF - 
> buf_size);
> +if (ret < 0)
> +return AVERROR_INVALIDDATA;
> +buf_size += ret;
> +
> +score  = analyze(buf, buf_size, TS_PACKET_SIZE,  0);
> +dvhs_score = analyze(buf, buf_size, TS_DVHS_PACKET_SIZE, 0);
> +fec_score  = analyze(buf, buf_size, TS_FEC_PACKET_SIZE,  0);
> +av_log(NULL, AV_LOG_TRACE, "Probe: %d, score: %d, dvhs_score: %d, 
> fec_score: %d \n",
> +buf_size, score, dvhs_score, fec_score);

av_log() should have a context not NULL otherwise it cannot be associated with
the source if there are multiple demuxers

patch probably ok otherwise

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


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


Re: [FFmpeg-devel] [PATCH 09/10] avformat/matroskadec: Improve length check

2019-03-08 Thread Michael Niedermayer
On Fri, Mar 08, 2019 at 10:26:03AM +0100, Andreas Rheinhardt wrote:
> The earlier code had three flaws:
> 
> 1. The case of an unknown-sized element inside a finite-sized element
> (which is against the specifications) was not caught.
> 
> 2. The error message wasn't helpful: It compared the length of the child
> with the offset of the end of the parent and claimed that the first
> exceeds the latter, although that is not necessarily true.
> 
> 3. Unknown-sized elements that are not parsed can't be skipped. Given
> that according to the Matroska specifications only the segment and the
> clusters can be of unknown-size, this is handled by not allowing any
> other units to have infinite size whereas the earlier code would seek
> back by 1 byte upon encountering an infinite-size element that ought
> to be skipped.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 17 ++---
>  1 file changed, 14 insertions(+), 3 deletions(-)

i think this patch is ok but there are people around who know matroska better
than i do ...

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

I have often repented speaking, but never of holding my tongue.
-- Xenocrates


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


Re: [FFmpeg-devel] [PATCH 02/10] avformat/matroskadec: Don't zero unnecessarily

2019-03-08 Thread James Almer
On 3/8/2019 6:25 AM, Andreas Rheinhardt wrote:
> It is only necessary to zero the initial allocated memory used to store
> the size of laced frames if the block used Xiph lacing. Otherwise no
> unintialized data was ever used, so use av_malloc instead of av_mallocz.
> 
> Also use the correct type for the allocations.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index de27d63b17..8a14764d1a 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2796,7 +2796,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
> *matroska, uint8_t **buf,
>  
>  if (!type) {
>  *laces= 1;
> -*lace_buf = av_mallocz(sizeof(int));
> +*lace_buf = av_malloc(sizeof(**lace_buf));
>  if (!*lace_buf)
>  return AVERROR(ENOMEM);
>  
> @@ -2808,7 +2808,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
> *matroska, uint8_t **buf,
>  *laces= *data + 1;
>  data += 1;
>  size -= 1;
> -lace_size = av_mallocz(*laces * sizeof(int));
> +lace_size = av_malloc(*laces * sizeof(*lace_size));
>  if (!lace_size)
>  return AVERROR(ENOMEM);
>  
> @@ -2818,6 +2818,8 @@ static int matroska_parse_laces(MatroskaDemuxContext 
> *matroska, uint8_t **buf,
>  uint8_t temp;
>  uint32_t total = 0;
>  for (n = 0; res == 0 && n < *laces - 1; n++) {
> +lace_size[n] = 0;
> +
>  while (1) {
>  if (size <= total) {
>  res = AVERROR_INVALIDDATA;
> 

Should be ok if tested under Valgrind to make sure there's really no
uninitialized data read.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/10] avformat/matroskadec: Remove an unused variable

2019-03-08 Thread James Almer
On 3/8/2019 6:25 AM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 0e3a6890c1..de27d63b17 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -322,7 +322,6 @@ typedef struct MatroskaDemuxContext {
>  /* EBML stuff */
>  int num_levels;
>  MatroskaLevel levels[EBML_MAX_DEPTH];
> -int level_up;
>  uint32_t current_id;
>  
>  uint64_t time_scale;
> @@ -1593,7 +1592,6 @@ static void matroska_convert_tags(AVFormatContext *s)
>  static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
>   uint64_t pos)
>  {
> -uint32_t level_up   = matroska->level_up;
>  uint32_t saved_id   = matroska->current_id;
>  int64_t before_pos = avio_tell(matroska->ctx->pb);
>  MatroskaLevel level;
> @@ -1629,7 +1627,6 @@ static int 
> matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
>  }
>  /* seek back */
>  avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
> -matroska->level_up   = level_up;
>  matroska->current_id = saved_id;
>  
>  return ret;

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


Re: [FFmpeg-devel] [PATCH 04/10] avformat/matroskadec: Use generic size check for signed integers

2019-03-08 Thread James Almer
On 3/8/2019 6:25 AM, Andreas Rheinhardt wrote:
> and drop the redundant checks contained in ebml_read_uint and
> ebml_read_sint.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 7 +--
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 88e80b2fda..55a153d982 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -882,9 +882,6 @@ static int ebml_read_uint(AVIOContext *pb, int size, 
> uint64_t *num)
>  {
>  int n = 0;
>  
> -if (size > 8)
> -return AVERROR_INVALIDDATA;
> -
>  /* big-endian ordering; build up number */
>  *num = 0;
>  while (n++ < size)
> @@ -901,9 +898,6 @@ static int ebml_read_sint(AVIOContext *pb, int size, 
> int64_t *num)
>  {
>  int n = 1;
>  
> -if (size > 8)
> -return AVERROR_INVALIDDATA;
> -
>  if (size == 0) {
>  *num = 0;
>  } else {
> @@ -1161,6 +1155,7 @@ static int ebml_parse_elem(MatroskaDemuxContext 
> *matroska,
>  {
>  static const uint64_t max_lengths[EBML_TYPE_COUNT] = {
>  [EBML_UINT]  = 8,
> +[EBML_SINT]  = 8,
>  [EBML_FLOAT] = 8,
>  // max. 16 MB for strings
>  [EBML_STR]   = 0x100,

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


Re: [FFmpeg-devel] [PATCH 05/10] avformat/matroskadec: Remove non-incremental parsing of clusters

2019-03-08 Thread Michael Niedermayer
On Fri, Mar 08, 2019 at 10:25:59AM +0100, Andreas Rheinhardt wrote:
> When the new incremental parser was introduced, the old parser was
> kept, because the new parser was unable to handle the way SSA packets
> are put into Matroska. But since 2014 (since
> c7d8dbad14ed5fa3c217a4fc1790021d6c0b6416) this is no longer needed, so
> that the old parser can be completely removed.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskadec.c | 72 ++-
>  1 file changed, 10 insertions(+), 62 deletions(-)

This affects seeking:

libavformat/tests/seek 
issues/388/Matrix.Reloaded.Trailer-640x346-XviD-1.0beta2-HE_AAC_subtitled.mkv 
-duration 400 >oldseek

The file appears to be available here:
https://samples.ffmpeg.org/Matroska/matrix/Matrix.Reloaded.Trailer-640x346-XviD-1.0beta2-HE_AAC_subtitled.mkv

--- oldseek 2019-03-08 23:08:21.380042329 +0100
+++ newseek 2019-03-08 23:08:02.048041745 +0100
@@ -8,7 +8,7 @@
 ret: 0 st:13 flags:1 dts: 86.75 pts: 86.75 pos: -1 size: 
50436
 ret:-1 st: 1 flags:0  ts: 250.577000
 ret: 0 st: 1 flags:1  ts: 13.471000
-ret: 0 st:13 flags:1 dts: 1.776000 pts: 1.776000 pos: -1 size: 
50436
+ret: 0 st:13 flags:1 dts: 0.00 pts: 0.00 pos: -1 size: 
50436
 ret:-1 st: 2 flags:0  ts: 176.365000
 ret: 0 st: 2 flags:1  ts: 339.259000
 ret: 0 st:13 flags:1 dts: 145.08 pts: 145.08 pos: -1 size: 
50436

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

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire


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


Re: [FFmpeg-devel] [PATCH] libavcodec/zmbvenc: Add support for RGB formats

2019-03-08 Thread Matthew Fearnley
On Fri, 8 Mar 2019 at 18:07, Carl Eugen Hoyos  wrote:

> 2019-03-08 15:04 GMT+01:00, Tomas Härdin :
> > tor 2019-03-07 klockan 14:42 + skrev Matthew Fearnley:
> >> This consists mostly of the following changes:
> >> - add newly supported pixel formats (RGB555LE, RGB565LE, BGR0)
> >> - select the ZMBV format (c->fmt) and bytes per pixel (c->bypp) based on
> >>   avctx->pix_fmt
> >> - multiply widths/x-values by c->bypp, in places where bytes, not
> pixels,
> >> are
> >>   expected
> >> - disable palette-writing code for non-palette pix_fmts
> >> - make a note about histogram[]'s datatype (it could need increasing if
> >>   ZMBV_BLOCK is increased)
> >> - adjust the c->score_tab length to take up to (and including) 4 times
> the
> >>   number of pixels in a block
> >> - initialise c->score_tab up to c->bypp * the number of pixels
> >>
> >> Note: the ZmbvFormat enum allows for additional bit depths:
> >> - 1,2,4-bit (palette)
> >> - 24-bit (RGB)
> >>
> >> At time of writing the specifics of these (e.g. channel order, bit
> >> alignment)
> >> are not currently defined, and DOSBox only implements support for
> >> 8/15/16/32
> >> bpp.
> >> One might expect the 24-bit format - if implemented - to be BGR24, to
> have
> >> the
> >> same channel order as BGR0.
> >> However, the decoder in zmbv.c has been guessed to use RGB24, so I have
> >> chosen
> >> to not contradict this, and omitted specific support for this format.
> >
> > Sounds good.
>
> Yes.
>
> > Maybe we could coordinate 1/2/4/24-bit support with the
>
> I believe FFmpeg cannot support 1/2/4 bit for encoding.
>
As far as I can see, FFmpeg has very limited support for bit depths less
than 8.  I think there are basically two formats (plus variants), with
fixed "palettes":
1bpp: MONO_BLACK / MONO_WHITE (black/white only)
4bpp: RGB4[_BYTE], BGR4[_BYTE] (RGB 1:2:1, 16 colours - I presume red/blue
would be 0,255; green would be 0,85,170,255)

If the ZMBV formats were defined, these might be worth encoder adding
support for.
(Practically speaking though, it would be a slight pain, because the
encoder would do the work in 8bpp and pack/unpack as needed.)
But with PAL8 being the only format allowing a free palette, all sub-8bpp
formats would have to decode to that, so they wouldn't round-trip.

(It should be possible to implement decoding to pal8 if
> that doesn't work yet and if samples exist.)
>
No samples or specifications exist that I know of, so I don't plan to
submit any patches to the decoder unless/until there is something to work
with there.

> dosbox devs? And maybe we should do something about
> > the RGB24 thing in the decoder..
>
Yeah, I think talking with the DOSBox devs sounds like a potentially good
idea.

>
> Do I understand correctly that no existing implementation
> supports 24bit rgb? If that is correct, I believe FFmpeg
> shouldn't add it (but this may only be me).
>
I agree that FFmpeg shouldn't add support for any formats that haven't been
defined.
As far as I know, the specifics of the 24-bit RGB format havn't been
discussed anywhere, and there are no samples I know of.

A likely specification of 24-bit is trivial enough to add support for, that
I was originally planning to add it with an #ifdef (like in the decoder).
But it wouldn't do to have contradictory channel orders proposed in the
decoder and encoder, so I will leave that for now unless DOSBox will commit
to one.

I presume that FFmpeg generally doesn't like to set standards in media
formats, only to implement existing ones.
My personal feelings in this case would be to provide support that's
disabled at compile-time if an official specification can be agreed, and to
have support included by default if an independent implementation - or at
least independent samples - are available that agree with the specification.
,
Matthew
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2019-03-08 Thread Carl Eugen Hoyos
2019-03-08 11:36 GMT+01:00, Jing SUN :

> +static void free_buffer(SvtContext *svt_enc)
> +{
> +EB_H265_ENC_INPUT *in_data =
> (EB_H265_ENC_INPUT *)svt_enc->in_buf.pBuffer;

Is the cast necessary?
Or actually: Can't in_data be whatever doesn't produce
a warning?

> +
> +if (in_data)
> +av_freep(_data);

The condition is unnecessary.

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


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

2019-03-08 Thread Vittorio Giovara
On Fri, Mar 8, 2019 at 4:39 AM Jing SUN  wrote:

> From: Jing Sun 
>
> base on patch by Huang, Zhengxu from https://github.com/intel/SVT-HEVC
>
> V4: - Fix the build error with new API in PR#52
> - Fix the encoding hang issue by API change in PR#52
> - Fix the last frame dropping issue
> - Fix the invalid parameter causing segmentation fault issue
> - Add the support to svt hevc and av1 plugins coexistance
> - Add the VMAF optimized mode to "-tune"
> - Add the "-hdr" parameter
>

Apologies if i missed your reply but i think my question was not answered

Is there any way to preserve the color matrix/primary/transfer properties
during encoding?

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


Re: [FFmpeg-devel] How to filter private folders from GIT patch

2019-03-08 Thread Moritz Barsnick
On Fri, Mar 08, 2019 at 14:11:30 +0100, Ulf Zibis wrote:
> >> Can some other developer please give me a practical hint how to deal
> >> with private folders not to appear in GIT patches?
[...]
> Are there other possibilities which are directly project-bounded?

Hoe about not committing them in the first place? (Don't use "git
commit -A", but instead carefully inspect everything "git status"
offers you.) Or, if you must, for your development desire, then commit
them in a separate commit which you then don't include in your exported
patch(es).

I don't know about Netbeans, but e.g. Qt Creator offers me to add its
projects files to a detected revision control, but I can click "no
thanks" (or un-add them later, before committing).

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


Re: [FFmpeg-devel] [PATCH] fate: Add Canon XF705 demux tests

2019-03-08 Thread Tomas Härdin
fre 2019-03-08 klockan 20:28 +0100 skrev Carl Eugen Hoyos:
> > 2019-03-08 20:10 GMT+01:00, Matthew McKenna :
> > On 3/8/2019 1:36 PM, Tomas Härdin wrote:
> > > fre 2019-03-08 klockan 19:04 +0100 skrev Carl Eugen Hoyos:
> > > > > > > > 2019-03-08 14:20 GMT+01:00, Tomas Härdin :
> > > > 
> > > > > This adds some HEVC demux tests for mxfdec.c for the
> > > > > Canon XF705 samples provided by Matthew McKenna.
> > > > > I suspect the thing that's most valuable here is that the
> > > > > codec probing works correctly, which it seems to do.
> > > > 
> > > > This email is missing the additional size in the fate repo.
> > > > 
> > > > I would prefer not to be the one arguing against an additional
> > > > test but afaict this is testing one line in a static array: Is that
> > > > really useful and does it justify a large additional file?
> > > 
> > > That's a fair point. Maybe if they were a single frame each.. Matthew?
> > 
> > The "verysmall" clips are as small as I can make them -- 1.3 megabytes
> > -- 1 second of video + audio w/ bars+tone.  As this is coming off the
> > camera there is not much editing capability, and the camera has a
> > minimum record duration.
> > 
> > Would it suffice to test only a subset or sample of the clips?
> 
> Allow me to repeat my question:
> Is this test meant to check a single entry in a static table?
> If this test is necessary, we should patch the mxf muxer to
> create a very low-res hevc mxf file that uses this uid.

Well, it'd be a functional test. But more than likely the email chain
that goes with the original patch would provide enough justification
for the UL being there. And there already tests for HEVC itself. So no,
it's probably not necessary. The files are very well behaved

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


Re: [FFmpeg-devel] [PATCH] fate: Add Canon XF705 demux tests

2019-03-08 Thread Carl Eugen Hoyos
2019-03-08 20:10 GMT+01:00, Matthew McKenna :
> On 3/8/2019 1:36 PM, Tomas Härdin wrote:
>> fre 2019-03-08 klockan 19:04 +0100 skrev Carl Eugen Hoyos:
>>> 2019-03-08 14:20 GMT+01:00, Tomas Härdin :
>>>
 This adds some HEVC demux tests for mxfdec.c for the
 Canon XF705 samples provided by Matthew McKenna.
 I suspect the thing that's most valuable here is that the
 codec probing works correctly, which it seems to do.
>>> This email is missing the additional size in the fate repo.
>>>
>>> I would prefer not to be the one arguing against an additional
>>> test but afaict this is testing one line in a static array: Is that
>>> really useful and does it justify a large additional file?
>>
>> That's a fair point. Maybe if they were a single frame each.. Matthew?

>
> The "verysmall" clips are as small as I can make them -- 1.3 megabytes
> -- 1 second of video + audio w/ bars+tone.  As this is coming off the
> camera there is not much editing capability, and the camera has a
> minimum record duration.
>
> Would it suffice to test only a subset or sample of the clips?

Allow me to repeat my question:
Is this test meant to check a single entry in a static table?
If this test is necessary, we should patch the mxf muxer to
create a very low-res hevc mxf file that uses this uid.

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


Re: [FFmpeg-devel] [PATCH] fate: Add Canon XF705 demux tests

2019-03-08 Thread Matthew McKenna

On 3/8/2019 1:36 PM, Tomas Härdin wrote:

fre 2019-03-08 klockan 19:04 +0100 skrev Carl Eugen Hoyos:

2019-03-08 14:20 GMT+01:00, Tomas Härdin :


This adds some HEVC demux tests for mxfdec.c for the
Canon XF705 samples provided by Matthew McKenna.
I suspect the thing that's most valuable here is that the
codec probing works correctly, which it seems to do.

This email is missing the additional size in the fate repo.

I would prefer not to be the one arguing against an additional
test but afaict this is testing one line in a static array: Is that
really useful and does it justify a large additional file?

That's a fair point. Maybe if they were a single frame each.. Matthew?

/Tomas



Hi-


The "verysmall" clips are as small as I can make them -- 1.3 megabytes 
-- 1 second of video + audio w/ bars+tone.  As this is coming off the 
camera there is not much editing capability, and the camera has a 
minimum record duration.



Would it suffice to test only a subset or sample of the clips?


-Matt





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


Re: [FFmpeg-devel] [PATCH] fate: Add Canon XF705 demux tests

2019-03-08 Thread Tomas Härdin
fre 2019-03-08 klockan 19:04 +0100 skrev Carl Eugen Hoyos:
> 2019-03-08 14:20 GMT+01:00, Tomas Härdin :
> 
> > This adds some HEVC demux tests for mxfdec.c for the
> > Canon XF705 samples provided by Matthew McKenna.
> > I suspect the thing that's most valuable here is that the
> > codec probing works correctly, which it seems to do.
> 
> This email is missing the additional size in the fate repo.
> 
> I would prefer not to be the one arguing against an additional
> test but afaict this is testing one line in a static array: Is that
> really useful and does it justify a large additional file?

That's a fair point. Maybe if they were a single frame each.. Matthew?

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


Re: [FFmpeg-devel] [PATCH] libavcodec/zmbvenc: Add support for RGB formats

2019-03-08 Thread Carl Eugen Hoyos
2019-03-08 15:04 GMT+01:00, Tomas Härdin :
> tor 2019-03-07 klockan 14:42 + skrev Matthew Fearnley:
>> This consists mostly of the following changes:
>> - add newly supported pixel formats (RGB555LE, RGB565LE, BGR0)
>> - select the ZMBV format (c->fmt) and bytes per pixel (c->bypp) based on
>>   avctx->pix_fmt
>> - multiply widths/x-values by c->bypp, in places where bytes, not pixels,
>> are
>>   expected
>> - disable palette-writing code for non-palette pix_fmts
>> - make a note about histogram[]'s datatype (it could need increasing if
>>   ZMBV_BLOCK is increased)
>> - adjust the c->score_tab length to take up to (and including) 4 times the
>>   number of pixels in a block
>> - initialise c->score_tab up to c->bypp * the number of pixels
>>
>> Note: the ZmbvFormat enum allows for additional bit depths:
>> - 1,2,4-bit (palette)
>> - 24-bit (RGB)
>>
>> At time of writing the specifics of these (e.g. channel order, bit
>> alignment)
>> are not currently defined, and DOSBox only implements support for
>> 8/15/16/32
>> bpp.
>> One might expect the 24-bit format - if implemented - to be BGR24, to have
>> the
>> same channel order as BGR0.
>> However, the decoder in zmbv.c has been guessed to use RGB24, so I have
>> chosen
>> to not contradict this, and omitted specific support for this format.
>
> Sounds good.

Yes.

> Maybe we could coordinate 1/2/4/24-bit support with the

I believe FFmpeg cannot support 1/2/4 bit for encoding.
(It should be possible to implement decoding to pal8 if
that doesn't work yet and if samples exist.)

> dosbox devs? And maybe we should do something about
> the RGB24 thing in the decoder..

Do I understand correctly that no existing implementation
supports 24bit rgb? If that is correct, I believe FFmpeg
shouldn't add it (but this may only be me).

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


Re: [FFmpeg-devel] [PATCH] fate: Add Canon XF705 demux tests

2019-03-08 Thread Carl Eugen Hoyos
2019-03-08 14:20 GMT+01:00, Tomas Härdin :

> This adds some HEVC demux tests for mxfdec.c for the
> Canon XF705 samples provided by Matthew McKenna.
> I suspect the thing that's most valuable here is that the
> codec probing works correctly, which it seems to do.

This email is missing the additional size in the fate repo.

I would prefer not to be the one arguing against an additional
test but afaict this is testing one line in a static array: Is that
really useful and does it justify a large additional file?

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/ffv1dec_template: Optimize golomb run mode

2019-03-08 Thread Carl Eugen Hoyos
2019-03-08 18:45 GMT+01:00, Michael Niedermayer :
> On Fri, Mar 08, 2019 at 06:33:30PM +0100, Carl Eugen Hoyos wrote:
>> 2019-03-08 17:38 GMT+01:00, Michael Niedermayer :
>> > Fixes: Timeout (34sec -> 12sec)
>>
>> Am I correct that this is the speedup for an invalid input file?
>> Is there a measurable effect on valid files?
>
> This should speed up valid files

Thank you!

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


Re: [FFmpeg-devel] [PATCH] mpegaudiodec_template: add ability to check CRC

2019-03-08 Thread Lynne



7 Mar 2019, 21:18 by mich...@niedermayer.cc:

> On Wed, Mar 06, 2019 at 07:09:52PM +0100, Lynne wrote:
>
>> A lot of files have CRC included.
>> The CRC only covers 34 bytes at most from the frame but it should still be
>> enough for some amount of error detection.
>>
>> mpegaudiodec_template.c |   20 +---
>>  1 file changed, 17 insertions(+), 3 deletions(-)
>> e8276f62fa92aa3f78e53b182b4ca7a2a460754c  
>> 0001-mpegaudiodec_template-add-ability-to-check-CRC.patch
>> From e1f4410f35d3d7f774a0de59ab72764033d14900 Mon Sep 17 00:00:00 2001
>> From: Lynne <>> d...@lynne.ee >> >
>> Date: Wed, 6 Mar 2019 17:04:04 +
>> Subject: [PATCH] mpegaudiodec_template: add ability to check CRC
>>
>> A lot of files have CRC included.
>> The CRC only covers 34 bytes at most from the frame but it should still be
>> enough for some amount of error detection.
>> ---
>>  libavcodec/mpegaudiodec_template.c | 20 +---
>>  1 file changed, 17 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/mpegaudiodec_template.c 
>> b/libavcodec/mpegaudiodec_template.c
>> index 9cce88e263..0881b60bf5 100644
>> --- a/libavcodec/mpegaudiodec_template.c
>> +++ b/libavcodec/mpegaudiodec_template.c
>> @@ -27,6 +27,7 @@
>>  #include "libavutil/attributes.h"
>>  #include "libavutil/avassert.h"
>>  #include "libavutil/channel_layout.h"
>> +#include "libavutil/crc.h"
>>  #include "libavutil/float_dsp.h"
>>  #include "libavutil/libm.h"
>>  #include "avcodec.h"
>> @@ -1565,9 +1566,22 @@ static int mp_decode_frame(MPADecodeContext *s, 
>> OUT_INT **samples,
>>  
>>  init_get_bits(>gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
>>  
>> -/* skip error protection field */
>> -if (s->error_protection)
>> -skip_bits(>gb, 16);
>> +if (s->error_protection) {
>> +uint16_t crc = get_bits(>gb, 16);
>> +if (s->err_recognition & AV_EF_CRCCHECK) {
>> +const int sec_len = s->lsf ? ((s->nb_channels == 1) ? 9  : 17) :
>> + ((s->nb_channels == 1) ? 17 : 32);
>> +const AVCRC *crc_tab = av_crc_get_table(AV_CRC_16_ANSI);
>> +uint32_t crc_cal = av_crc(crc_tab, UINT16_MAX, [2], 2);
>> +crc_cal = av_crc(crc_tab, crc_cal, [6], sec_len);
>> +
>> +if (av_bswap16(crc) ^ crc_cal) {
>> +av_log(s->avctx, AV_LOG_ERROR, "CRC mismatch!\n");
>> +if (s->err_recognition & AV_EF_EXPLODE)
>> +return AVERROR_INVALIDDATA;
>> +}
>> +}
>> +}
>>
>
> For files with crcs and with damage, do they sound better with the
> check and error out or without ?
>
> The behavior which provides the best user experience should be the
> default
>
> It also may make sense to add one of AV_EF_CAREFUL / AV_EF_COMPLIANT / 
> AV_EF_AGGRESSIVE
> depending on how the check affects actual real world files
>

This is just a quick check to verify the files are uncorrupted, it shouldn't
make broken files sound better unless the decoder somehow outputs white noise
when it tries to decode them.
I corrupted some files with -bsf:a noise=0.5 and couldn't notice an improvement
with or without -err_detect crccheck+explode even though the outputs looked 
different. crccheck+explode makes much less errors about incorrect timestamps.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] avcodec/ffv1dec_template: Optimize golomb run mode

2019-03-08 Thread Michael Niedermayer
Fixes: Timeout (34sec -> 12sec)
Fixes: 
13398/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5664106709778432

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ffv1dec_template.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 25032feda0..1b7f6c4bf5 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -86,6 +86,11 @@ static av_always_inline int RENAME(decode_line)(FFV1Context 
*s, int w,
 run_mode = 2;
 }
 }
+while (run_count > 1 && w-x > 1) {
+sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + 
x);
+x++;
+run_count--;
+}
 run_count--;
 if (run_count < 0) {
 run_mode  = 0;
-- 
2.21.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/diracdec: Count truncated parts as errors in decode_component()

2019-03-08 Thread Michael Niedermayer
Fixes: Timeout (29sec -> 4sec)
Fixes: 
13150/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DIRAC_fuzzer-5690185671507968

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/diracdec.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 30b4bfad79..a1e759f656 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -685,7 +685,10 @@ static int decode_component(DiracContext *s, int comp)
 }
 align_get_bits(>gb);
 b->coeff_data = s->gb.buffer + get_bits_count(>gb)/8;
-b->length = FFMIN(b->length, FFMAX(get_bits_left(>gb)/8, 
0));
+if (b->length > FFMAX(get_bits_left(>gb)/8, 0)) {
+b->length = FFMAX(get_bits_left(>gb)/8, 0);
+damaged_count ++;
+}
 skip_bits_long(>gb, b->length*8);
 }
 }
-- 
2.21.0

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


Re: [FFmpeg-devel] [PATCH v2 6/6] lavc/qsvdec: Add VP9 decoder support

2019-03-08 Thread Li, Zhong
> > +AVCodec ff_vp9_qsv_decoder = {
> > +.name   = "vp9_qsv",
> > +.long_name  = NULL_IF_CONFIG_SMALL("VP9 video (Intel
> Quick
> > Sync Video acceleration)"),
> > +.priv_data_size = sizeof(QSVOtherContext),
> > +.type   = AVMEDIA_TYPE_VIDEO,
> > +.id = AV_CODEC_ID_VP9,
> > +.init   = qsv_decode_init,
> > +.decode = qsv_decode_frame,
> > +.flush  = qsv_decode_flush,
> > +.close  = qsv_decode_close,
> > +.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 |
> > AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
> > +.priv_class = _qsv_class,
> > +.pix_fmts   = (const enum
> AVPixelFormat[]){ AV_PIX_FMT_NV12,
> >
> +
>   AV_PIX_FMT_P010,
> 
> Order of formats in pix_fmts declarations start to frighten me even more...
> To the concern I raised in patches #3,4 of this series...

This array here is just to declare the pix_fmt capability list,
But in qsvdec.c, the pix_fmts array is to init qsv HW and SW format for frame 
allocation. It can't be a list for a specified clip, it should be NV12 OR (not 
and ) P010 format . 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v3 5/6] lavc/qsvdec: Add mjpeg decoder support

2019-03-08 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 Changelog |  1 +
 configure |  1 +
 libavcodec/Makefile   |  1 +
 libavcodec/allcodecs.c|  1 +
 libavcodec/qsvdec_other.c | 28 +++-
 5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 4d80e5b54f..f289812bfc 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ version :
 - ARBC decoder
 - libaribb24 based ARIB STD-B24 caption support (profiles A and C)
 - Support decoding of HEVC 4:4:4 content in nvdec and cuviddec
+- Intel QSV-accelerated MJPEG decoding
 
 
 version 4.1:
diff --git a/configure b/configure
index eaa56c07cf..de994673a0 100755
--- a/configure
+++ b/configure
@@ -2997,6 +2997,7 @@ hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
 mjpeg_cuvid_decoder_deps="cuvid"
+mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 15c43a8a6a..fed4a13fe5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -423,6 +423,7 @@ OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o 
metasound_data.o \
 OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o
+OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec_other.o
 OBJS-$(CONFIG_MJPEG_ENCODER)   += mjpegenc.o mjpegenc_common.o \
   mjpegenc_huffman.o
 OBJS-$(CONFIG_MJPEGB_DECODER)  += mjpegbdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b26aeca239..391619c38c 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -759,6 +759,7 @@ extern AVCodec ff_hevc_videotoolbox_encoder;
 extern AVCodec ff_libkvazaar_encoder;
 extern AVCodec ff_mjpeg_cuvid_decoder;
 extern AVCodec ff_mjpeg_qsv_encoder;
+extern AVCodec ff_mjpeg_qsv_decoder;
 extern AVCodec ff_mjpeg_vaapi_encoder;
 extern AVCodec ff_mpeg1_cuvid_decoder;
 extern AVCodec ff_mpeg2_cuvid_decoder;
diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index a6f1b88ca0..b0dc559d70 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -1,5 +1,5 @@
 /*
- * Intel MediaSDK QSV based MPEG-2, VC-1 and VP8 decoders
+ * Intel MediaSDK QSV based MPEG-2, VC-1, VP8 and MJPEG decoders
  *
  * copyright (c) 2015 Anton Khirnov
  *
@@ -256,3 +256,29 @@ AVCodec ff_vp8_qsv_decoder = {
 .wrapper_name   = "qsv",
 };
 #endif
+
+#if CONFIG_MJPEG_QSV_DECODER
+static const AVClass mjpeg_qsv_class = {
+.class_name = "mjpeg_qsv",
+.item_name  = av_default_item_name,
+.option = options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_mjpeg_qsv_decoder = {
+.name   = "mjpeg_qsv",
+.long_name  = NULL_IF_CONFIG_SMALL("MJPEG video (Intel Quick Sync 
Video acceleration)"),
+.priv_data_size = sizeof(QSVOtherContext),
+.type   = AVMEDIA_TYPE_VIDEO,
+.id = AV_CODEC_ID_MJPEG,
+.init   = qsv_decode_init,
+.decode = qsv_decode_frame,
+.flush  = qsv_decode_flush,
+.close  = qsv_decode_close,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING,
+.priv_class = _qsv_class,
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
+AV_PIX_FMT_QSV,
+AV_PIX_FMT_NONE },
+};
+#endif
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v3 6/6] lavc/qsvdec: Add VP9 decoder support

2019-03-08 Thread Zhong Li
VP9 decoder is supported on Intel kabyLake+ platforms with MSDK Version 1.19+

Signed-off-by: Zhong Li 
---
 Changelog |  2 +-
 configure |  6 ++
 libavcodec/allcodecs.c|  1 +
 libavcodec/qsv.c  |  5 +
 libavcodec/qsvdec_other.c | 31 ++-
 5 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index f289812bfc..483cd6b27a 100644
--- a/Changelog
+++ b/Changelog
@@ -19,7 +19,7 @@ version :
 - ARBC decoder
 - libaribb24 based ARIB STD-B24 caption support (profiles A and C)
 - Support decoding of HEVC 4:4:4 content in nvdec and cuviddec
-- Intel QSV-accelerated MJPEG decoding
+- Intel QSV-accelerated MJPEG decoding and VP9 decoding
 
 
 version 4.1:
diff --git a/configure b/configure
index de994673a0..9baf498d97 100755
--- a/configure
+++ b/configure
@@ -3037,6 +3037,8 @@ vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp9_cuvid_decoder_deps="cuvid"
 vp9_mediacodec_decoder_deps="mediacodec"
+vp9_qsv_decoder_deps="MFX_CODEC_VP9"
+vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
 vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
@@ -6142,6 +6144,10 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # can find the libraries and headers through other means.
 enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
{ require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+if enabled libmfx; then
+   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+fi
+
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
 enabled libmp3lame&& require "libmp3lame >= 3.98.3" lame/lame.h 
lame_set_VBR_quality -lmp3lame $libm_extralibs
 enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h 
mysofa_load ||
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 391619c38c..248b8f15b8 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -776,6 +776,7 @@ extern AVCodec ff_vp8_v4l2m2m_encoder;
 extern AVCodec ff_vp8_vaapi_encoder;
 extern AVCodec ff_vp9_cuvid_decoder;
 extern AVCodec ff_vp9_mediacodec_decoder;
+extern AVCodec ff_vp9_qsv_decoder;
 extern AVCodec ff_vp9_vaapi_encoder;
 
 // The iterate API is not usable with ossfuzz due to the excessive size of 
binaries created
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 711fd3df1e..7dcfb04316 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -60,6 +60,11 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 #endif
 case AV_CODEC_ID_MJPEG:
 return MFX_CODEC_JPEG;
+#if QSV_VERSION_ATLEAST(1, 19)
+case AV_CODEC_ID_VP9:
+return MFX_CODEC_VP9;
+#endif
+
 default:
 break;
 }
diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index b0dc559d70..0ffc1f1245 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -1,5 +1,5 @@
 /*
- * Intel MediaSDK QSV based MPEG-2, VC-1, VP8 and MJPEG decoders
+ * Intel MediaSDK QSV based MPEG-2, VC-1, VP8, MJPEG and VP9 decoders
  *
  * copyright (c) 2015 Anton Khirnov
  *
@@ -282,3 +282,32 @@ AVCodec ff_mjpeg_qsv_decoder = {
 AV_PIX_FMT_NONE },
 };
 #endif
+
+#if CONFIG_VP9_QSV_DECODER
+static const AVClass vp9_qsv_class = {
+.class_name = "vp9_qsv",
+.item_name  = av_default_item_name,
+.option = options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_vp9_qsv_decoder = {
+.name   = "vp9_qsv",
+.long_name  = NULL_IF_CONFIG_SMALL("VP9 video (Intel Quick Sync Video 
acceleration)"),
+.priv_data_size = sizeof(QSVOtherContext),
+.type   = AVMEDIA_TYPE_VIDEO,
+.id = AV_CODEC_ID_VP9,
+.init   = qsv_decode_init,
+.decode = qsv_decode_frame,
+.flush  = qsv_decode_flush,
+.close  = qsv_decode_close,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
+.priv_class = _qsv_class,
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_QSV,
+AV_PIX_FMT_NONE },
+.hw_configs = ff_qsv_hw_configs,
+.wrapper_name   = "qsv",
+};
+#endif
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v3 2/6] lavc/qsv: make function qsv_map_fourcc() can be called externally

2019-03-08 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavcodec/qsv.c  | 4 ++--
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 224bc00ce4..711fd3df1e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -158,7 +158,7 @@ int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
 return ret;
 }
 
-static enum AVPixelFormat qsv_map_fourcc(uint32_t fourcc)
+enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
 {
 switch (fourcc) {
 case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
@@ -469,7 +469,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 frames_hwctx = frames_ctx->hwctx;
 
 frames_ctx->format= AV_PIX_FMT_QSV;
-frames_ctx->sw_format = qsv_map_fourcc(i->FourCC);
+frames_ctx->sw_format = ff_qsv_map_fourcc(i->FourCC);
 frames_ctx->width = i->Width;
 frames_ctx->height= i->Height;
 frames_ctx->initial_pool_size = req->NumFrameSuggested;
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 51c23d5c7b..c432ac8a3f 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -91,6 +91,8 @@ int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile);
 
+enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc);
+
 int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
 enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
 
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v3 4/6] lavc/qsvdec: remove orignal parser code since not needed now

2019-03-08 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 configure   | 10 +-
 libavcodec/qsvdec.c | 28 +---
 libavcodec/qsvdec.h |  3 ---
 3 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/configure b/configure
index bf40c1dcb9..eaa56c07cf 100755
--- a/configure
+++ b/configure
@@ -2973,7 +2973,7 @@ h264_mediacodec_decoder_select="h264_mp4toannexb_bsf 
h264_parser"
 h264_mmal_decoder_deps="mmal"
 h264_nvenc_encoder_deps="nvenc"
 h264_omx_encoder_deps="omx"
-h264_qsv_decoder_select="h264_mp4toannexb_bsf h264_parser qsvdec"
+h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
 h264_qsv_encoder_select="qsvenc"
 h264_rkmpp_decoder_deps="rkmpp"
 h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
@@ -2987,7 +2987,7 @@ hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
 hevc_mediacodec_decoder_deps="mediacodec"
 hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
 hevc_nvenc_encoder_deps="nvenc"
-hevc_qsv_decoder_select="hevc_mp4toannexb_bsf hevc_parser qsvdec"
+hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
@@ -3007,7 +3007,7 @@ mpeg2_crystalhd_decoder_select="crystalhd"
 mpeg2_cuvid_decoder_deps="cuvid"
 mpeg2_mmal_decoder_deps="mmal"
 mpeg2_mediacodec_decoder_deps="mediacodec"
-mpeg2_qsv_decoder_select="qsvdec mpegvideo_parser"
+mpeg2_qsv_decoder_select="qsvdec"
 mpeg2_qsv_encoder_select="qsvenc"
 mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
 mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m"
@@ -3024,11 +3024,11 @@ nvenc_hevc_encoder_select="hevc_nvenc_encoder"
 vc1_crystalhd_decoder_select="crystalhd"
 vc1_cuvid_decoder_deps="cuvid"
 vc1_mmal_decoder_deps="mmal"
-vc1_qsv_decoder_select="qsvdec vc1_parser"
+vc1_qsv_decoder_select="qsvdec"
 vc1_v4l2m2m_decoder_deps="v4l2_m2m vc1_v4l2_m2m"
 vp8_cuvid_decoder_deps="cuvid"
 vp8_mediacodec_decoder_deps="mediacodec"
-vp8_qsv_decoder_select="qsvdec vp8_parser"
+vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
 vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index b78026e14d..eda3c9625e 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -498,9 +498,6 @@ int ff_qsv_decode_close(QSVContext *q)
 av_fifo_free(q->async_fifo);
 q->async_fifo = NULL;
 
-av_parser_close(q->parser);
-avcodec_free_context(>avctx_internal);
-
 if (q->internal_session)
 MFXClose(q->internal_session);
 
@@ -513,38 +510,15 @@ int ff_qsv_decode_close(QSVContext *q)
 int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
 AVFrame *frame, int *got_frame, AVPacket *pkt)
 {
-uint8_t *dummy_data;
-int dummy_size;
 int ret;
 mfxVideoParam param = { 0 };
 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
AV_PIX_FMT_NV12,
AV_PIX_FMT_NONE };
 
-if (!q->avctx_internal) {
-q->avctx_internal = avcodec_alloc_context3(NULL);
-if (!q->avctx_internal)
-return AVERROR(ENOMEM);
-
-q->avctx_internal->codec_id = avctx->codec_id;
-
-q->parser = av_parser_init(avctx->codec_id);
-if (!q->parser)
-return AVERROR(ENOMEM);
-
-q->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
-}
-
 if (!pkt->size)
 return qsv_decode(avctx, q, frame, got_frame, pkt);
 
-/* we assume the packets are already split properly and want
- * just the codec parameters here */
-av_parser_parse2(q->parser, q->avctx_internal,
- _data, _size,
- pkt->data, pkt->size, pkt->pts, pkt->dts,
- pkt->pos);
-
 /* TODO: flush delayed frames on reinit */
 
 // sw_pix_fmt was initialized as NV12, will be updated after header 
decoded if not true.
@@ -587,7 +561,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 return qsv_decode(avctx, q, frame, got_frame, pkt);
 
 reinit_fail:
-q->orig_pix_fmt = q->parser->format = avctx->pix_fmt = AV_PIX_FMT_NONE;
+q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
 return ret;
 }
 
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 4812fb2a6b..c057bc6722 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -56,9 +56,6 @@ typedef struct QSVContext {
 int buffered_count;
 int reinit_flag;
 
-// the internal parser and codec context for parsing the data
-AVCodecParserContext *parser;
-AVCodecContext *avctx_internal;
 enum AVPixelFormat orig_pix_fmt;
 uint32_t fourcc;
 mfxFrameInfo frame_info;
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-08 Thread Zhong Li
Using MSDK parser can improve qsv decoder pass rate in some cases (E.g:
sps declares a wrong level_idc, smaller than it should be).
And it is necessary for adding new qsv decoders such as MJPEG and VP9
since current parser can't provide enough information.
Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and merged as 
commit 1acb19d,
but was overwritten when merged libav patches (commit: 1f26a23) without any 
explain.

v2: split decode header from decode_init, and call it for everyframe to
detect format/resoultion change. It can fix some regression issues such
as hevc 10bits decoding.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvdec.c   | 172 --
 libavcodec/qsvdec.h   |   2 +
 libavcodec/qsvdec_h2645.c |   1 +
 libavcodec/qsvdec_other.c |   1 +
 4 files changed, 93 insertions(+), 83 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 4a0be811fb..b78026e14d 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const 
AVFifoBuffer* fifo)
 return av_fifo_size(fifo) / qsv_fifo_item_size();
 }
 
-static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
+static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum 
AVPixelFormat *pix_fmts, mfxVideoParam *param)
 {
-const AVPixFmtDescriptor *desc;
 mfxSession session = NULL;
 int iopattern = 0;
-mfxVideoParam param = { 0 };
-int frame_width  = avctx->coded_width;
-int frame_height = avctx->coded_height;
 int ret;
 
-desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
-if (!desc)
-return AVERROR_BUG;
+ret = ff_get_format(avctx, pix_fmts);
+if (ret < 0) {
+q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
+return ret;
+}
 
 if (!q->async_fifo) {
 q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
@@ -170,48 +168,72 @@ static int qsv_decode_init(AVCodecContext *avctx, 
QSVContext *q)
 return ret;
 }
 
-ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
-if (ret < 0)
-return ret;
+param->IOPattern   = q->iopattern;
+param->AsyncDepth  = q->async_depth;
+param->ExtParam= q->ext_buffers;
+param->NumExtParam = q->nb_ext_buffers;
 
-param.mfx.CodecId  = ret;
-param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id, 
avctx->profile);
-param.mfx.CodecLevel   = avctx->level == FF_LEVEL_UNKNOWN ? 
MFX_LEVEL_UNKNOWN : avctx->level;
-
-param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
-param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
-param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
-param.mfx.FrameInfo.FourCC = q->fourcc;
-param.mfx.FrameInfo.Width  = frame_width;
-param.mfx.FrameInfo.Height = frame_height;
-param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
-
-switch (avctx->field_order) {
-case AV_FIELD_PROGRESSIVE:
-param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
-break;
-case AV_FIELD_TT:
-param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
-break;
-case AV_FIELD_BB:
-param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
-break;
-default:
-param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
-break;
-}
+return 0;
+ }
 
-param.IOPattern   = q->iopattern;
-param.AsyncDepth  = q->async_depth;
-param.ExtParam= q->ext_buffers;
-param.NumExtParam = q->nb_ext_buffers;
+static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxVideoParam 
*param)
+{
+int ret;
 
-ret = MFXVideoDECODE_Init(q->session, );
+avctx->width= param->mfx.FrameInfo.CropW;
+avctx->height   = param->mfx.FrameInfo.CropH;
+avctx->coded_width  = param->mfx.FrameInfo.Width;
+avctx->coded_height = param->mfx.FrameInfo.Height;
+avctx->level= param->mfx.CodecLevel;
+avctx->profile  = param->mfx.CodecProfile;
+avctx->field_order  = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
+avctx->pix_fmt  = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
+
+ret = MFXVideoDECODE_Init(q->session, param);
 if (ret < 0)
 return ff_qsv_print_error(avctx, ret,
   "Error initializing the MFX video decoder");
 
-q->frame_info = param.mfx.FrameInfo;
+q->frame_info = param->mfx.FrameInfo;
+
+return 0;
+}
+
+static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket 
*avpkt, enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
+{
+int ret;
+
+mfxBitstream bs = { { { 0 } } };
+
+if (avpkt->size) {
+bs.Data   = avpkt->data;
+bs.DataLength = avpkt->size;
+bs.MaxLength  = bs.DataLength;
+bs.TimeStamp  = avpkt->pts;
+  

[FFmpeg-devel] [PATCH v3 1/6] lavc/qsv: add function ff_qsv_map_picstruct()

2019-03-08 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavcodec/qsv.c  | 18 ++
 libavcodec/qsv_internal.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index bb0d79588c..224bc00ce4 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -196,6 +196,24 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, 
QSVFrame *frame)
 return AVERROR_BUG;
 }
 
+enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct)
+{
+enum AVFieldOrder field = AV_FIELD_UNKNOWN;
+switch (mfx_pic_struct & 0xF) {
+case MFX_PICSTRUCT_PROGRESSIVE:
+field = AV_FIELD_PROGRESSIVE;
+break;
+case MFX_PICSTRUCT_FIELD_TFF:
+field = AV_FIELD_TT;
+break;
+case MFX_PICSTRUCT_FIELD_BFF:
+field = AV_FIELD_BB;
+break;
+}
+
+return field;
+}
+
 enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 {
 enum AVPictureType type;
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 394c558883..51c23d5c7b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -94,6 +94,8 @@ int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int 
profile);
 int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
 enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
 
+enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct);
+
 int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,
  const char *load_plugins);
 
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v3 0/6] Refact qsv decoder parser and add new decoders

2019-03-08 Thread Zhong Li
Replace current parser with MFXVideoDECODE_DecodeHeader(),
and add MJPEG/VP9 decoders.

V2: Fix hevc 10bit decoding regression
V3: 1. Disable VP9 if not defined in libmfx header file
2. Avoid to use vp9 plugin but init it direct
3. Avoid a dangerous static definition

Zhong Li (6):
  lavc/qsv: add function ff_qsv_map_picstruct()
  lavc/qsv: make function qsv_map_fourcc() can be called externally
  lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()
  lavc/qsvdec: remove orignal parser code since not needed now
  lavc/qsvdec: Add mjpeg decoder support
  lavc/qsvdec: Add VP9 decoder support

 Changelog |   1 +
 configure |  17 +++-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   2 +
 libavcodec/qsv.c  |  27 -
 libavcodec/qsv_internal.h |   4 +
 libavcodec/qsvdec.c   | 200 +-
 libavcodec/qsvdec.h   |   5 +-
 libavcodec/qsvdec_h2645.c |   1 +
 libavcodec/qsvdec_other.c |  58 ++-
 10 files changed, 195 insertions(+), 121 deletions(-)

-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH] pngdec: add ability to check chunk CRC

2019-03-08 Thread Lynne
7 Mar 2019, 21:22 by mich...@niedermayer.cc:

> On Thu, Mar 07, 2019 at 07:26:32PM +0100, Lynne wrote:
>
>> By default now, if AV_EF_CRCCHECK or AV_EF_IGNORE_ERR are enabled the decoder
>> will skip the chunk and carry on with the next one. This should make the 
>>   
>> decoder able to decode more corrupt files because the functions which decode
>> individual chunks will very likely error out if fed invalid data and stop the
>> decoding of the entire image.
>> Should this be made default? CRC verification doesn't take long even for very
>> large files.  
>> Also fix the length check for chunk size. It needs to take into account the
>> 4 byte tag as well as the 4 byte CRC.
>>
>> pngdec.c |   19 ++-
>>  1 file changed, 18 insertions(+), 1 deletion(-)
>> 4255c91468cee2bc2fa757fae69762ff5ee5774a  
>> 0001-pngdec-add-ability-to-check-chunk-CRC.patch
>> From 7aff99d12faf557753c5ee860a9672c7a09a26e3 Mon Sep 17 00:00:00 2001
>> From: Lynne <>> d...@lynne.ee >> >
>> Date: Thu, 7 Mar 2019 18:15:23 +
>> Subject: [PATCH] pngdec: add ability to check chunk CRC
>>
>> By default now, if AV_EF_CRCCHECK or AV_EF_IGNORE_ERR are enabled the decoder
>> will skip the chunk and carry on with the next one. This should make the
>> decoder able to decode more corrupt files because the functions which decode
>> individual chunks will very likely error out if fed invalid data and stop the
>> decoding of the entire image.
>> Should this be made default? CRC verification doesn't take long even for very
>> large files.
>>
>
> i would tend toward enabling it by default but maybe first post some
> numbers of how much this changes decode time 
>

For the largest png I found: 
https://vk.com/doc218587497_437472325?hash=51300ca9ba40f462ac=1bcf9a57b0d989da1f
 


There was no increase in decoding time, it took 2.3 seconds on my machine
with and without -err_detect crccheck.

With -err_detect crccheck perf reported 2.52% spent in av_crc


>> Also fix the length check for chunk size. It needs to take into account the
>> 4 byte tag as well as the 4 byte CRC.
>>
>
> this should be a seperate patch as its unrelated
>

removed and attached new patch file

Maybe always enabling the CRC check isn't worth it since if you download from
the internet you could either get a full error-free file or an incomplete one
rather than a corrupt one. Maybe only for torrents with huge png files where
not all chunks have been downloaded yet, or broken hard drives, but the 
ignore_err
flag could be manually enabled in those cases.
>From b911d3cb36828ad3c910ca6bf8b96a58ce398191 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Thu, 7 Mar 2019 18:15:23 +
Subject: [PATCH] pngdec: add ability to check chunk CRC

By default now, if AV_EF_CRCCHECK or AV_EF_IGNORE_ERR are enabled the decoder
will skip the chunk and carry on with the next one. This should make the
decoder able to decode more corrupt files because the functions which decode
individual chunks will very likely error out if fed invalid data and stop the
decoding of the entire image.
---
 libavcodec/pngdec.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 189bb9a4c1..9743f1cb76 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/bprint.h"
+#include "libavutil/crc.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/mastering_display_metadata.h"
@@ -1169,6 +1170,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
 static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
AVFrame *p, AVPacket *avpkt)
 {
+const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
 AVDictionary **metadatap = NULL;
 uint32_t tag, length;
 int decode_next_dat = 0;
@@ -1203,6 +1205,21 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
 ret = AVERROR_INVALIDDATA;
 goto fail;
 }
+if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_IGNORE_ERR)) {
+uint32_t crc_sig = AV_RB32(s->gb.buffer + length + 4);
+uint32_t crc_cal = ~av_crc(crc_tab, UINT32_MAX, s->gb.buffer, length + 4);
+if (crc_sig ^ crc_cal) {
+av_log(avctx, AV_LOG_ERROR, "CRC mismatch in chunk");
+if (avctx->err_recognition & AV_EF_EXPLODE) {
+av_log(avctx, AV_LOG_ERROR, ", quitting\n");
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+av_log(avctx, AV_LOG_ERROR, ", skipping\n");
+bytestream2_skip(>gb, 4); /* tag */
+goto skip_tag;
+}
+}
 tag = 

Re: [FFmpeg-devel] [PATCH] libavcodec/zmbvenc: Add support for RGB formats

2019-03-08 Thread Tomas Härdin
tor 2019-03-07 klockan 14:42 + skrev Matthew Fearnley:
> This consists mostly of the following changes:
> - add newly supported pixel formats (RGB555LE, RGB565LE, BGR0)
> - select the ZMBV format (c->fmt) and bytes per pixel (c->bypp) based on
>   avctx->pix_fmt
> - multiply widths/x-values by c->bypp, in places where bytes, not pixels, are
>   expected
> - disable palette-writing code for non-palette pix_fmts
> - make a note about histogram[]'s datatype (it could need increasing if
>   ZMBV_BLOCK is increased)
> - adjust the c->score_tab length to take up to (and including) 4 times the
>   number of pixels in a block
> - initialise c->score_tab up to c->bypp * the number of pixels
> 
> Note: the ZmbvFormat enum allows for additional bit depths:
> - 1,2,4-bit (palette)
> - 24-bit (RGB)
> 
> At time of writing the specifics of these (e.g. channel order, bit alignment)
> are not currently defined, and DOSBox only implements support for 8/15/16/32
> bpp.
> One might expect the 24-bit format - if implemented - to be BGR24, to have the
> same channel order as BGR0.
> However, the decoder in zmbv.c has been guessed to use RGB24, so I have chosen
> to not contradict this, and omitted specific support for this format.

Sounds good. Maybe we could coordinate 1/2/4/24-bit support with the
dosbox devs? And maybe we should do something about the RGB24 thing in
the decoder..

It seems the decoder performs quite well. I did a little test with
different me_range for the three not-broken zmbv samples in FATE:

  $ for RANGE in 1 2 4 8 16 24 32; do mkdir -p zmbv/$RANGE ; for f in
fate-suite/zmbv/zmbv_*.avi ; do ./ffmpeg -i $f -y -vcodec zmbv
-me_range $RANGE zmbv/$RANGE/$(basename $f) ; done ; done
  $ cd zmbv && du --bytes --max-depth=1 | sort -n
  501874  ./32
  508140  ./24
  513372  ./16
  524550  ./8
  533856  ./4
  548282  ./2
  653010  ./fate  <-- original samples
  735854  ./1

So even -me_range 2 outperforms whatever encoder produced the samples.

Maybe future work could be to try to figure out the optimal block size
based on some heuristic?

Patch looks good to me.

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


[FFmpeg-devel] [PATCH] lavu/qsv: allow surface size larger than requirement

2019-03-08 Thread Zhong Li
Just like commit 6829a079444e10818a847e153121fb458cc5c0a8,
surface size larger than requirement should not be treated as error.

Signed-off-by: Zhong Li 
---
 libavutil/hwcontext_qsv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 814ce215ce..b6d8bfe2bf 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -389,7 +389,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
 return MFX_ERR_UNSUPPORTED;
-if (i->Width  != i1->Width || i->Height != i1->Height ||
+if (i->Width  > i1->Width || i->Height > i1->Height ||
 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
 av_log(ctx, AV_LOG_ERROR, "Mismatching surface properties in an "
"allocation request: %dx%d %d %d vs %dx%d %d %d\n",
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH]lavf/mxfdec: Allow MXF parser to identify the Canon XF-HEVC codec/format for video essence

2019-03-08 Thread Tomas Härdin
ons 2019-03-06 klockan 15:05 +0100 skrev Carl Eugen Hoyos:
> 2019-03-06 14:38 GMT+01:00, Tomas Härdin :
> 
> > I have generated new samples, sourced with test pattern,
> > some as short as 1 second, about 1.2 megabytes per file.
> > If real-life clips are required, or if the expectation is for me
> > to perform the FATE tests, let me know.
> 
> Could this get committed without fate test first, and we can
> discuss later if they are really required?
> 
> (Assuming there is no "parsing" involved, just a new UL which
> reminds me you could remove the word parser from the
> commit message.)

Pushed the first patch. Creating a new thread for FATE discussions.

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


Re: [FFmpeg-devel] How to filter private folders from GIT patch

2019-03-08 Thread Ulf Zibis

Am 08.03.19 um 10:59 schrieb Tobias Rapp:
> On 08.03.2019 10:49, Ulf Zibis wrote:
>> [...]
>> Can some other developer please give me a practical hint how to deal
>> with private folders not to appear in GIT patches?
>
> I'm using .git/info/exclude to ignore files that are only found within
> my private developing environment.
This is a valuable hint, thanks. But  I suspect it is easy to manage
ignores project-wise with this approach.

Are there other possibilities which are directly project-bounded?

-Ulf

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


[FFmpeg-devel] [PATCH V4] avcodec/libvpxenc: add VP8 support for ROI-based encoding

2019-03-08 Thread Guo, Yejun
Signed-off-by: Guo, Yejun 
---
 libavcodec/libvpxenc.c | 150 +
 1 file changed, 150 insertions(+)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index c823b8a..2984c7a 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1057,6 +1057,153 @@ static int queue_frames(AVCodecContext *avctx, AVPacket 
*pkt_out)
 return size;
 }
 
+static int vp8_encode_set_roi(AVCodecContext *avctx, const AVFrame *frame)
+{
+/* range of vpx_roi_map_t.delta_q[i] is [-63, 63] */
+#define MAX_DELTA_Q 63
+
+const AVRegionOfInterest *roi = NULL;
+vpx_roi_map_t roi_map;
+int ret = 0;
+int nb_rois;
+AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_REGIONS_OF_INTEREST);
+VPxContext *ctx = avctx->priv_data;
+vpx_active_map_t active_map = { 0 };
+int max_segment_cnt = 4;/* VP8 ROI only support 4 segments. */
+int segment_id = 0;
+
+/* record the mapping from delta_q to "segment id + 1".
+ * delta_q is shift with MAX_DELTA_Q, and so the range is [0, 
2*MAX_DELTA_Q].
+ * add 1 to segment id, so no mapping if the value of array element is 
zero.
+ */
+int segment_mapping[2 * MAX_DELTA_Q + 1] = { 0 };
+
+/* segment id 0 in roi_map is reserved for the areas not covered by 
AVRegionOfInterest.
+ * segment id 0 in roi_map is also for the areas with 
AVRegionOfInterest.qoffset near 0.
+ */
+segment_mapping[MAX_DELTA_Q] = segment_id + 1;
+segment_id++;
+
+active_map.rows = (frame->height + 15) / 16;
+active_map.cols = (frame->width  + 15) / 16;
+
+if (!sd) {
+/* For the case that some middle frames do not have ROI while other 
frames have ROIs.
+ * Due to libvpx behavior, we have to reset VP8E_SET_ACTIVEMAP, 
otherwise the previous
+ * ROIs continue working for frames without ROIs.
+ */
+if (vpx_codec_control(>encoder, VP8E_SET_ACTIVEMAP, _map)) 
{
+log_encoder_error(avctx, "Failed to set VP8E_SET_ACTIVEMAP codec 
control.\n");
+return AVERROR_INVALIDDATA;
+}
+return 0;
+}
+
+memset(_map, 0, sizeof(roi_map));
+roi_map.rows = active_map.rows;
+roi_map.cols = active_map.cols;
+roi_map.roi_map = av_mallocz(roi_map.rows * roi_map.cols);
+if (!roi_map.roi_map) {
+av_log(avctx, AV_LOG_ERROR, "roi_map alloc failed.\n");
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+active_map.active_map = av_malloc(active_map.rows * active_map.cols);
+if (!active_map.active_map) {
+av_log(avctx, AV_LOG_ERROR, "active_map alloc failed.\n");
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+/* set 1 to enable the corresponding element of vpx_roi_map_t.roi_map. */
+memset(active_map.active_map, 1, active_map.rows * active_map.cols);
+
+roi = (const AVRegionOfInterest*)sd->data;
+if (!roi->self_size || sd->size % roi->self_size != 0) {
+av_log(ctx, AV_LOG_ERROR, "Invalid AVRegionOfInterest.self_size.\n");
+ret = AVERROR(EINVAL);
+goto fail;
+}
+nb_rois = sd->size / roi->self_size;
+
+/* This list must be iterated from zero because regions are
+ * defined in order of decreasing importance. So discard less
+ * important areas if they exceed the segment count.
+ */
+for (int i = 0; i < nb_rois; i++) {
+int qoffset;
+int mapping_index;
+
+roi = (const AVRegionOfInterest*)(sd->data + roi->self_size * i);
+if (roi->qoffset.den == 0) {
+av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den must not 
be zero.\n");
+ret = AVERROR(EINVAL);
+goto fail;
+}
+
+qoffset = (int)(roi->qoffset.num * 1.0f / roi->qoffset.den * 
MAX_DELTA_Q);
+qoffset = av_clip(qoffset, -MAX_DELTA_Q, MAX_DELTA_Q);
+
+mapping_index = qoffset + MAX_DELTA_Q;
+if (!segment_mapping[mapping_index]) {
+if (segment_id > max_segment_cnt - 1) {
+av_log(ctx, AV_LOG_WARNING,
+   "ROI only supports %d segments (and segment 0 is 
reserved for non-ROIs), skipping this one.\n",
+   max_segment_cnt);
+roi = (AVRegionOfInterest*)((char*)roi + roi->self_size);
+continue;
+}
+
+segment_mapping[mapping_index] = segment_id + 1;
+roi_map.delta_q[segment_id] = qoffset;
+segment_id++;
+}
+}
+
+/* This list must be iterated in reverse, so for the case that
+ * two regions overlapping, the more important area takes effect.
+ */
+for (int i = nb_rois - 1; i >= 0; i--) {
+int qoffset;
+int mapping_value;
+int starty, endy, startx, endx;
+
+roi = (const AVRegionOfInterest*)(sd->data + roi->self_size * i);
+
+starty = FFMIN(roi_map.rows, roi->top / 16);
+endy   = FFMIN(roi_map.rows, (roi->bottom + 

Re: [FFmpeg-devel] [PATCH V3] avcodec/libvpxenc: add VP8 support for ROI-based encoding

2019-03-08 Thread Guo, Yejun


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of James Zern
> Sent: Friday, March 08, 2019 9:53 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH V3] avcodec/libvpxenc: add VP8
> support for ROI-based encoding
> 
> On Thu, Feb 28, 2019 at 11:23 PM Guo, Yejun  wrote:
> >
> > Signed-off-by: Guo, Yejun 
> > ---
> >  libavcodec/libvpxenc.c | 150
> +
> >  1 file changed, 150 insertions(+)
> >
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index c823b8a..fc9b1fd 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -1057,6 +1057,153 @@ static int queue_frames(AVCodecContext
> *avctx, AVPacket *pkt_out)
> >  return size;
> >  }
> >
> > +static int vp8_encode_set_roi(AVCodecContext *avctx, const AVFrame
> *frame)
> > +{
> > +/* range of vpx_roi_map_t.delta_q[i] is [-63, 63] */
> > +#define MAX_DELTA_Q 63
> > +
> > +const AVRegionOfInterest *roi = NULL;
> > +vpx_roi_map_t roi_map;
> > +int ret = 0;
> > +int nb_rois;
> > +AVFrameSideData *sd = av_frame_get_side_data(frame,
> AV_FRAME_DATA_REGIONS_OF_INTEREST);
> > +VPxContext *ctx = avctx->priv_data;
> > +vpx_active_map_t active_map = { 0, 0, 0 };
> 
> { 0 } will work.

thanks, will fix.

> 
> > +int max_segment_cnt = 4;/* VP8 ROI only support 4 segments. */
> > +int segment_id = 0;
> > +
> > +/* record the mapping from delta_q to "segment id + 1".
> > + * delta_q is shift with MAX_DELTA_Q, and so the range is [0,
> 2*MAX_DELTA_Q].
> > + * add 1 to segment id, so no mapping if the value of array element is
> zero.
> > + */
> > +int segment_mapping[2 * MAX_DELTA_Q + 1] = {0};
> > +
> 
> { 0 } would be more consistent with this file.

will fix

> 
> > +/* segment id 0 in roi_map is reserved for the areas not covered by
> AVRegionOfInterest.
> > + * segment id 0 in roi_map is also for the areas with
> AVRegionOfInterest.qoffset near 0.
> > + */
> > +segment_mapping[MAX_DELTA_Q] = segment_id + 1;
> > +segment_id++;
> > +
> > +active_map.rows = (frame->height + 15) / 16;
> > +active_map.cols = (frame->width  + 15) / 16;
> > +
> > +if (!sd) {
> > +/* For the case that some middle frames do not have ROI while other
> frames have ROIs.
> > + * Due to libvpx behaivor, we have to reset VP8E_SET_ACTIVEMAP,
> otherwise the previous
> 
> behavior

will fix

> 
> > + * ROIs continue working for frames without ROIs.
> > + */
> > +if (vpx_codec_control(>encoder, VP8E_SET_ACTIVEMAP,
> _map)) {
> > +log_encoder_error(avctx, "Failed to set VP8E_SET_ACTIVEMAP
> codec control.\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +return 0;
> > +}
> > +
> > +memset(_map, 0, sizeof(roi_map));
> > +roi_map.rows = active_map.rows;
> > +roi_map.cols = active_map.cols;
> > +roi_map.roi_map = av_mallocz(roi_map.rows * roi_map.cols);
> > +if (!roi_map.roi_map) {
> > +av_log(avctx, AV_LOG_ERROR, "roi_map alloc failed.\n");
> > +ret = AVERROR(ENOMEM);
> > +goto fail;
> > +}
> > +
> > +active_map.active_map = av_malloc(active_map.rows *
> active_map.cols);
> > +if (!active_map.active_map) {
> > +av_log(avctx, AV_LOG_ERROR, "active_map alloc failed.\n");
> > +ret = AVERROR(ENOMEM);
> > +goto fail;
> > +}
> > +/* set 1 to enable the corresponding element of
> vpx_roi_map_t.roi_map. */
> > +memset(active_map.active_map, 1, active_map.rows *
> active_map.cols);
> > +
> > +roi = (const AVRegionOfInterest*)sd->data;
> > +if (!roi->self_size || sd->size % roi->self_size != 0) {
> > +av_log(ctx, AV_LOG_ERROR, "Invalid
> AVRegionOfInterest.self_size.\n");
> > +ret = AVERROR(EINVAL);
> > +goto fail;
> > +}
> > +nb_rois = sd->size / roi->self_size;
> > +
> > +/* This list must be iterated from zero because regions are
> > + * defined in order of decreasing importance. So discard less
> > + * important areas if exceeding the supported segment count.
> 
> ...if they exceed the segment count

will fix

> 
> > + */
> > +for (int i = 0; i < nb_rois; i++) {
> > +int qoffset;
> > +int mapping_index;
> > +
> > +roi = (const AVRegionOfInterest*)(sd->data + roi->self_size * i);
> > +if (roi->qoffset.den == 0) {
> > +av_log(ctx, AV_LOG_ERROR, "AVRegionOfInterest.qoffset.den
> must not be zero.\n");
> > +ret = AVERROR(EINVAL);
> > +goto fail;
> > +}
> > +
> > +qoffset = (int)(roi->qoffset.num * 1.0f / roi->qoffset.den *
> MAX_DELTA_Q);
> > +qoffset = av_clip(qoffset, -MAX_DELTA_Q, MAX_DELTA_Q);
> > +
> > +mapping_index = qoffset + MAX_DELTA_Q;
> > +if 

Re: [FFmpeg-devel] [PATCH] avformat/mpegtsenc: added support for the write_data_type callback

2019-03-08 Thread Oliver Collyer
[Apols for sending this again, but I realised the subject didn't describe the 
change, which was unhelpful)

This patch makes it possible to do stuff like write a custom in-memory TS 
segmenter, which was what I needed it for.

> Hi
> 
> I needed to be able to use the write_data_type callback when reading data 
> from the mpegts muxer, to make my application aware of key frames in the data 
> so I added support. I used the matroska implementation as a reference.
> 
> If this is accepted, I will format this as a proper patch after feedback.
> 
> Regards
> 
> Oliver
> 
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index fc0ea225c6..e5d1a64b4c 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -1815,6 +1815,12 @@ static int mpegts_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
>mpegts_write_flush(s);
>return 1;
>} else {
> +if (s->pb && s->pb->write_data_type) {
> +AVStream *st = s->streams[pkt->stream_index];
> +avio_write_marker(s->pb,
> +av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q),
> +(pkt->flags & AV_PKT_FLAG_KEY) && st->codecpar->codec_type 
> == AVMEDIA_TYPE_VIDEO ? AVIO_DATA_MARKER_SYNC_POINT : 
> AVIO_DATA_MARKER_BOUNDARY_POINT);
> +}
>return mpegts_write_packet_internal(s, pkt);
>}
> }
> 

So I've created a patch for this.



0001-mpegtsenc-added-support-for-the-write_data_type-call.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Reconfigure resolution on-the-fly

2019-03-08 Thread Timo Rothenpieler

On 08/03/2019 00:57, Carl Eugen Hoyos wrote:

2019-03-06 15:57 GMT+01:00, Oliver Collyer :

Hi

I needed the dynamic resolution changing feature of NVENC to be accessible
through the ffmpeg libraries for a hobby project, so I added support and
here is a patch.

I will format this as a proper patch after any changes necessary following
feedback.

To use this feature you would need to:

1. Specify max_width and max_height before opening the encoder


Can't they be set to a maximum number to be as flexible as possible?


That'd be a bad idea, as it will allocate that amount of memory for 
every frame, no matter how large it actually ends up being.




smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH V4 1/2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-08 Thread Paul B Mahol
On 3/8/19, myp...@gmail.com  wrote:
> On Fri, Mar 8, 2019 at 5:26 PM Paul B Mahol  wrote:
>>
>> On 3/8/19, Jun Zhao  wrote:
>> > From: Jun Zhao 
>> >
>> > accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
>> > data type, it will have a risk of an integral value becoming larger than
>> > the 32-bits integer capacity and resulting in an integer overflow. For
>> > this risk, add a checking with warning message.
>> >
>> > Signed-off-by: Jun Zhao 
>> > ---
>> >  libavfilter/vf_nlmeans.c |   11 +++
>> >  1 files changed, 11 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
>> > index dcb5a03..8d47f9d 100644
>> > --- a/libavfilter/vf_nlmeans.c
>> > +++ b/libavfilter/vf_nlmeans.c
>> > @@ -477,6 +477,17 @@ static int filter_frame(AVFilterLink *inlink,
>> > AVFrame
>> > *in)
>> >  NLMeansContext *s = ctx->priv;
>> >  AVFilterLink *outlink = ctx->outputs[0];
>> >
>> > +// accumulation of 8-bits uint_8 into 32-bits data type, it will
>> > have
>> > +// a risk of an integral value becoming larger than the 32-bits
>> > integer
>> > +// capacity and resulting in an integer overflow, so limit the
>> > image
>> > size
>> > +if ((UINT32_MAX / (uint64_t)inlink->w) < (255 *
>> > (uint64_t)inlink->h)) {
>> > +av_log(ctx, AV_LOG_ERROR,
>> > +   "image size (%d x %d) integral value may overflow.\n",
>> > +   inlink->w, inlink->h);
>> > +av_frame_free();
>> > +return AVERROR(EINVAL);
>> > +}
>> > +
>> >  AVFrame *out = ff_get_video_buffer(outlink, outlink->w,
>> > outlink->h);
>> >  if (!out) {
>> >  av_frame_free();
>>
>> I see no point in this warning, if overflow is real issue should be
>> fixed instead of giving
>> pointless warning.
> In fact, this is a potential overflow problems depend on image
> value/width/height when calculating integral image(Summed-area_table
> is the other name https://en.wikipedia.org/wiki/Summed-area_table),
> this is the reason to limit the image size in this patch to avoid this
> potential overflow problems, I don't know what's the mean for " should
> be fixed instead of giving pointless warning.", can you give more
> information for this? thx.

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


Re: [FFmpeg-devel] How to filter private folders from GIT patch

2019-03-08 Thread Tobias Rapp

On 08.03.2019 10:49, Ulf Zibis wrote:

[...]
Can some other developer please give me a practical hint how to deal
with private folders not to appear in GIT patches?


I'm using .git/info/exclude to ignore files that are only found within 
my private developing environment.


Regards,
Tobias

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


Re: [FFmpeg-devel] How to filter private folders from GIT patch

2019-03-08 Thread Ulf Zibis
Hi Michael,

Am 08.03.19 um 00:53 schrieb Michael Niedermayer:
> On Thu, Mar 07, 2019 at 12:52:32AM +0100, Ulf Zibis wrote:
>> diff --git a/.gitignore b/.gitignore
>> index 0e57cb0..7819c84 100644
>> --- a/.gitignore
>> +++ b/.gitignore
>> @@ -36,3 +36,5 @@
>>  /lcov/
>>  /src
>>  /mapfile
>> +/nbproject
>> +/debug
> this shouldnt be in the patch

Thanks for your note.

/nbproject is automatically created by NetBeans IDE I'm using to develop.
I think this ignore tag could be useful for other developers using
NetBeans IDE.

/debug is a private folder for my testing.
Can some other developer please give me a practical hint how to deal
with private folders not to appear in GIT patches?

-Ulf


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


Re: [FFmpeg-devel] Patch for vf_fillborders.c – Bug?

2019-03-08 Thread Ulf Zibis

Am 08.03.19 um 00:53 schrieb Michael Niedermayer:
> On Thu, Mar 07, 2019 at 12:52:32AM +0100, Ulf Zibis wrote:
>> Hi,
>>
>> I think there is a bug in vf_fillborders.c 16 bit routines.
>>
>> When using memset or memcopy, I think, correct linesize instead
>> s->planewidth[p] should be used.
>> When using arrray syntax, I think, correct s->planewidth[p] instead
>> linesize should be used.
>>
>> See my proposed patch.
>>
>> -Ulf

Please ignore the patch.
In the meantime I've found a misunderstanding from my side.

-Ulf



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


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

2019-03-08 Thread Jing SUN
From: Jing Sun 

base on patch by Huang, Zhengxu from https://github.com/intel/SVT-HEVC

V4: - Fix the build error with new API in PR#52
- Fix the encoding hang issue by API change in PR#52
- Fix the last frame dropping issue
- Fix the invalid parameter causing segmentation fault issue
- Add the support to svt hevc and av1 plugins coexistance
- Add the VMAF optimized mode to "-tune"
- Add the "-hdr" parameter

V3: - Fix the build error with new API

V2: - Change the config options (didn't need to enable-gpl for BSD+Patent,
  it's can compatible with LGPL2+, thanks Xavier correct this part),
  now just need to "--enable-libsvthevc" option
- Add force_idr option
- Remove default GoP size setting in the wrapper, SVT-HEVC will calc
  the the GoP size internal
- Refine the code as the FFmpeg community's comments
  (https://patchwork.ffmpeg.org/patch/11347/)

V1: - base on patch by Huang, Zhengxu, then refine some code.

Change-Id: If0dcc5044ab9effd6847a8f48797b985d02b0816
Signed-off-by: Huang, Zhengxu 
Signed-off-by: hassene 
Signed-off-by: Jun Zhao 
Signed-off-by: Jing Sun 
Signed-off-by: Jing SUN 
---
 configure|   4 +
 libavcodec/Makefile  |   1 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/libsvt_hevc.c | 528 +++
 4 files changed, 534 insertions(+)
 create mode 100644 libavcodec/libsvt_hevc.c

diff --git a/configure b/configure
index dcead3a..36bc8c1 100755
--- a/configure
+++ b/configure
@@ -264,6 +264,7 @@ External library support:
   --enable-libspeexenable Speex de/encoding via libspeex [no]
   --enable-libsrt  enable Haivision SRT protocol via libsrt [no]
   --enable-libssh  enable SFTP protocol via libssh [no]
+  --enable-libsvthevc  enable HEVC encoding via svt [no]
   --enable-libtensorflow   enable TensorFlow as a DNN module backend
for DNN based filters like sr [no]
   --enable-libtesseractenable Tesseract, needed for ocr filter [no]
@@ -1784,6 +1785,7 @@ EXTERNAL_LIBRARY_LIST="
 libspeex
 libsrt
 libssh
+libsvthevc
 libtensorflow
 libtesseract
 libtheora
@@ -3173,6 +3175,7 @@ libshine_encoder_select="audio_frame_queue"
 libspeex_decoder_deps="libspeex"
 libspeex_encoder_deps="libspeex"
 libspeex_encoder_select="audio_frame_queue"
+libsvt_hevc_encoder_deps="libsvthevc"
 libtheora_encoder_deps="libtheora"
 libtwolame_encoder_deps="libtwolame"
 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
@@ -6209,6 +6212,7 @@ enabled libsoxr   && require libsoxr soxr.h 
soxr_create -lsoxr
 enabled libssh&& require_pkg_config libssh libssh libssh/sftp.h 
sftp_init
 enabled libspeex  && require_pkg_config libspeex speex speex/speex.h 
speex_decoder_init
 enabled libsrt&& require_pkg_config libsrt "srt >= 1.3.0" 
srt/srt.h srt_socket
+enabled libsvthevc&& require_pkg_config libsvthevc SvtHevcEnc 
svt-hevc/EbApi.h EbInitHandle
 enabled libtensorflow && require libtensorflow tensorflow/c/c_api.h 
TF_Version -ltensorflow
 enabled libtesseract  && require_pkg_config libtesseract tesseract 
tesseract/capi.h TessBaseAPICreate
 enabled libtheora && require libtheora theora/theoraenc.h th_info_init 
-ltheoraenc -ltheoradec -logg
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 15c43a8..c93e545 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -987,6 +987,7 @@ OBJS-$(CONFIG_LIBOPUS_ENCODER)+= libopusenc.o 
libopus.o \
 OBJS-$(CONFIG_LIBSHINE_ENCODER)   += libshine.o
 OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
 OBJS-$(CONFIG_LIBSPEEX_ENCODER)   += libspeexenc.o
+OBJS-$(CONFIG_LIBSVT_HEVC_ENCODER)+= libsvt_hevc.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)  += libtheoraenc.o
 OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o
 OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b26aeca..e93f66f 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -703,6 +703,7 @@ extern AVCodec ff_librsvg_decoder;
 extern AVCodec ff_libshine_encoder;
 extern AVCodec ff_libspeex_encoder;
 extern AVCodec ff_libspeex_decoder;
+extern AVCodec ff_libsvt_hevc_encoder;
 extern AVCodec ff_libtheora_encoder;
 extern AVCodec ff_libtwolame_encoder;
 extern AVCodec ff_libvo_amrwbenc_encoder;
diff --git a/libavcodec/libsvt_hevc.c b/libavcodec/libsvt_hevc.c
new file mode 100644
index 000..de11a19
--- /dev/null
+++ b/libavcodec/libsvt_hevc.c
@@ -0,0 +1,528 @@
+/*
+* Scalable Video Technology for HEVC encoder library plugin
+*
+* Copyright (c) 2018 Intel Corporation
+*
+* This file is part of FFmpeg.
+*
+* FFmpeg is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or 

Re: [FFmpeg-devel] [PATCH V4 1/2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-08 Thread myp...@gmail.com
On Fri, Mar 8, 2019 at 5:26 PM Paul B Mahol  wrote:
>
> On 3/8/19, Jun Zhao  wrote:
> > From: Jun Zhao 
> >
> > accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
> > data type, it will have a risk of an integral value becoming larger than
> > the 32-bits integer capacity and resulting in an integer overflow. For
> > this risk, add a checking with warning message.
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  libavfilter/vf_nlmeans.c |   11 +++
> >  1 files changed, 11 insertions(+), 0 deletions(-)
> >
> > diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> > index dcb5a03..8d47f9d 100644
> > --- a/libavfilter/vf_nlmeans.c
> > +++ b/libavfilter/vf_nlmeans.c
> > @@ -477,6 +477,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> > *in)
> >  NLMeansContext *s = ctx->priv;
> >  AVFilterLink *outlink = ctx->outputs[0];
> >
> > +// accumulation of 8-bits uint_8 into 32-bits data type, it will have
> > +// a risk of an integral value becoming larger than the 32-bits integer
> > +// capacity and resulting in an integer overflow, so limit the image
> > size
> > +if ((UINT32_MAX / (uint64_t)inlink->w) < (255 * (uint64_t)inlink->h)) {
> > +av_log(ctx, AV_LOG_ERROR,
> > +   "image size (%d x %d) integral value may overflow.\n",
> > +   inlink->w, inlink->h);
> > +av_frame_free();
> > +return AVERROR(EINVAL);
> > +}
> > +
> >  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
> >  if (!out) {
> >  av_frame_free();
>
> I see no point in this warning, if overflow is real issue should be
> fixed instead of giving
> pointless warning.
In fact, this is a potential overflow problems depend on image
value/width/height when calculating integral image(Summed-area_table
is the other name https://en.wikipedia.org/wiki/Summed-area_table),
this is the reason to limit the image size in this patch to avoid this
potential overflow problems, I don't know what's the mean for " should
be fixed instead of giving pointless warning.", can you give more
information for this? thx.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2019-03-08 Thread Sun, Jing A
On 05/03/2019 07:43, Jing SUN wrote:
> From: Jing Sun 
> 
> base on patch by Huang, Zhengxu from https://github.com/intel/SVT-HEVC
> 
> V4: - Fix the build error with new API in PR#52
> - Fix the encoding hang issue by API change in PR#52
> - Fix the last frame dropping issue
> - Fix the invalid parameter causing segmentation fault issue
> - Add the support to svt hevc and av1 plugins coexistance
> - Add the VMAF optimized mode to "-tune"
> - Add the "-hdr" parameter
> 
> V3: - Fix the build error with new API
> 
> V2: - Change the config options (didn't need to enable-gpl for BSD+Patent,
>   it's can compatible with LGPL2+, thanks Xavier correct this part),
>   now just need to "--enable-libsvthevc" option
> - Add force_idr option
> - Remove default GoP size setting in the wrapper, SVT-HEVC will calc
>   the the GoP size internal
> - Refine the code as the FFmpeg community's comments
>   (https://patchwork.ffmpeg.org/patch/11347/)
> 
> V1: - base on patch by Huang, Zhengxu, then refine some code.
> 
> Change-Id: If0dcc5044ab9effd6847a8f48797b985d02b0816
> Signed-off-by: Huang, Zhengxu 
> Signed-off-by: hassene 
> Signed-off-by: Jun Zhao 
> Signed-off-by: Jing Sun 
> ---
>  configure|   4 +
>  libavcodec/Makefile  |   1 +
>  libavcodec/allcodecs.c   |   1 +
>  libavcodec/libsvt_hevc.c | 546 
> +++
>  4 files changed, 552 insertions(+)
>  create mode 100644 libavcodec/libsvt_hevc.c
> 
> ...
> 
> diff --git a/libavcodec/libsvt_hevc.c b/libavcodec/libsvt_hevc.c new 
> file mode 100644 index 000..97bd204
> --- /dev/null
> +++ b/libavcodec/libsvt_hevc.c
> @@ -0,0 +1,546 @@
> +/*
> +* Scalable Video Technology for HEVC encoder library plugin
> +*
> +* Copyright (c) 2018 Intel Corporation
> +*
> +* This file is part of FFmpeg.
> +*
> +* FFmpeg is free software; you can redistribute it and/or
> +* modify it under the terms of the GNU Lesser General Public
> +* License as published by the Free Software Foundation; either
> +* version 2.1 of the License, or (at your option) any later version.
> +*
> +* FFmpeg is distributed in the hope that it will be useful,
> +* but WITHOUT ANY WARRANTY; without even the implied warranty of
> +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +* Lesser General Public License for more details.
> +*
> +* You should have received a copy of the GNU Lesser General Public
> +* License along with this program; if not, write to the Free Software
> +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
> +02110-1301 USA */
> +
> +#include "svt-hevc/EbErrorCodes.h"
> +#include "svt-hevc/EbTime.h"
> +#include "svt-hevc/EbApi.h"
> +
> +#include "libavutil/common.h"
> +#include "libavutil/frame.h"
> +#include "libavutil/opt.h"
> +
> +#include "internal.h"
> +#include "avcodec.h"
> +
> +typedef enum eos_status {
> +EOS_NOT_REACHED = 0,
> +EOS_REACHED,
> +EOS_TOTRIGGER
> +}EOS_STATUS;
> +
> +typedef struct SvtContext {
> +AVClass *class;
> +
> +EB_H265_ENC_CONFIGURATION  enc_params;
> +EB_COMPONENTTYPE   *svt_handle;
> +
> +EB_BUFFERHEADERTYPE*in_buf;

This structure appears have exactly the same lifetime as the encoder itself - 
can you just put it directly in the SvtContext rather than allocating/freeing 
it separately?
[SUN, Jing] To be modified in v7.

> +int raw_size;

This variable seems to be write-only.
[SUN, Jing] To be modified in v7.

> +
> +EOS_STATUS eos_flag;
> +
> +// User options.
> +int vui_info;
> +int hierarchical_level;
> +int la_depth;
> +int enc_mode;
> +int rc_mode;
> +int scd;
> +int tune;
> +int qp;
> +int hdr;
> +
> +int forced_idr;
> +
> +int aud;
> +
> +int profile;
> +int tier;
> +int level;
> +
> +int base_layer_switch_mode;
> +} SvtContext;
> +
> +static int error_mapping(EB_ERRORTYPE svt_ret) {
> +int err;
> +
> +switch (svt_ret) {
> +case EB_ErrorInsufficientResources:
> +err = AVERROR(ENOMEM);
> +break;
> +
> +case EB_ErrorUndefined:
> +case EB_ErrorInvalidComponent:
> +case EB_ErrorBadParameter:
> +err = AVERROR(EINVAL);
> +break;
> +
> +case EB_ErrorDestroyThreadFailed:
> +case EB_ErrorSemaphoreUnresponsive:
> +case EB_ErrorDestroySemaphoreFailed:
> +case EB_ErrorCreateMutexFailed:
> +case EB_ErrorMutexUnresponsive:
> +case EB_ErrorDestroyMutexFailed:
> +err = AVERROR_EXTERNAL;
> +break;
> +
> +case EB_NoErrorEmptyQueue:
> +err = AVERROR(EAGAIN);
> +
> +case EB_ErrorNone:
> +err = 0;
> +break;
> +
> +default:
> +err = AVERROR_UNKNOWN;
> +}
> +
> +return err;
> +}
> +
> +static void free_buffer(SvtContext *svt_enc) {
> +if (svt_enc->in_buf) {
> +EB_H265_ENC_INPUT *in_data = (EB_H265_ENC_INPUT 
> 

[FFmpeg-devel] [PATCH 05/10] avformat/matroskadec: Remove non-incremental parsing of clusters

2019-03-08 Thread Andreas Rheinhardt
When the new incremental parser was introduced, the old parser was
kept, because the new parser was unable to handle the way SSA packets
are put into Matroska. But since 2014 (since
c7d8dbad14ed5fa3c217a4fc1790021d6c0b6416) this is no longer needed, so
that the old parser can be completely removed.

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 55a153d982..6ab9ef7a3e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -360,9 +360,6 @@ typedef struct MatroskaDemuxContext {
 int64_t current_cluster_pos;
 MatroskaCluster current_cluster;
 
-/* File has SSA subtitles which prevent incremental cluster parsing. */
-int contains_ssa;
-
 /* WebM DASH Manifest live flag */
 int is_live;
 
@@ -707,25 +704,7 @@ static const EbmlSyntax matroska_blockgroup[] = {
 { 0 }
 };
 
-static const EbmlSyntax matroska_cluster[] = {
-{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, 
offsetof(MatroskaCluster, timecode) },
-{ MATROSKA_ID_BLOCKGROUP,  EBML_NEST, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
-{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
-{ MATROSKA_ID_CLUSTERPOSITION, EBML_NONE },
-{ MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE },
-{ 0 }
-};
-
-static const EbmlSyntax matroska_clusters[] = {
-{ MATROSKA_ID_CLUSTER,  EBML_NEST, 0, 0, { .n = matroska_cluster } },
-{ MATROSKA_ID_INFO, EBML_NONE },
-{ MATROSKA_ID_CUES, EBML_NONE },
-{ MATROSKA_ID_TAGS, EBML_NONE },
-{ MATROSKA_ID_SEEKHEAD, EBML_NONE },
-{ 0 }
-};
-
-static const EbmlSyntax matroska_cluster_incremental_parsing[] = {
+static const EbmlSyntax matroska_cluster_parsing[] = {
 { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, 
offsetof(MatroskaCluster, timecode) },
 { MATROSKA_ID_BLOCKGROUP,  EBML_NEST, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
 { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
@@ -739,7 +718,7 @@ static const EbmlSyntax 
matroska_cluster_incremental_parsing[] = {
 { 0 }
 };
 
-static const EbmlSyntax matroska_cluster_incremental[] = {
+static const EbmlSyntax matroska_cluster[] = {
 { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, 
timecode) },
 { MATROSKA_ID_BLOCKGROUP,  EBML_STOP },
 { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP },
@@ -748,8 +727,8 @@ static const EbmlSyntax matroska_cluster_incremental[] = {
 { 0 }
 };
 
-static const EbmlSyntax matroska_clusters_incremental[] = {
-{ MATROSKA_ID_CLUSTER,  EBML_NEST, 0, 0, { .n = 
matroska_cluster_incremental } },
+static const EbmlSyntax matroska_clusters[] = {
+{ MATROSKA_ID_CLUSTER,  EBML_NEST, 0, 0, { .n = matroska_cluster } },
 { MATROSKA_ID_INFO, EBML_NONE },
 { MATROSKA_ID_CUES, EBML_NONE },
 { MATROSKA_ID_TAGS, EBML_NONE },
@@ -2584,8 +2563,6 @@ static int matroska_parse_tracks(AVFormatContext *s)
 }
 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
-if (st->codecpar->codec_id == AV_CODEC_ID_ASS)
-matroska->contains_ssa = 1;
 }
 }
 
@@ -3450,19 +3427,19 @@ end:
 return res;
 }
 
-static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
+static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
 {
 EbmlList *blocks_list;
 MatroskaBlock *blocks;
 int i, res;
 res = ebml_parse(matroska,
- matroska_cluster_incremental_parsing,
+ matroska_cluster_parsing,
  >current_cluster);
 if (res == 1) {
 /* New Cluster */
 if (matroska->current_cluster_pos)
 ebml_level_end(matroska);
-ebml_free(matroska_cluster, >current_cluster);
+ebml_free(matroska_cluster_parsing, >current_cluster);
 memset(>current_cluster, 0, sizeof(MatroskaCluster));
 matroska->current_cluster_num_blocks = 0;
 matroska->current_cluster_pos= avio_tell(matroska->ctx->pb);
@@ -3470,12 +3447,12 @@ static int 
matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
 if (matroska->current_id)
 matroska->current_cluster_pos -= 4;
 res = ebml_parse(matroska,
- matroska_clusters_incremental,
+ matroska_clusters,
  >current_cluster);
 /* Try parsing the block again. */
 if (res == 1)
 res = ebml_parse(matroska,
-  

[FFmpeg-devel] [PATCH 00/10] avformat/matroskadec: Various patches

2019-03-08 Thread Andreas Rheinhardt
The check introduced in 9326117bf63b04a466d9e787224e56ba8cdbb215 had
the unintended consequence of introducing an error message after one
has reached the end of the last cluster if there is another element
after the last cluster (and if the last cluster was not an unknown-size
encoded cluster). This happens only when using incremental parsing
(i.e. currently when there are no SSA subtitles in the input) and it
happens because incremental parsing takes a lot of liberties wrt levels:

matroska_cluster_incremental_parsing includes elements that actually
exist at different levels, namely several level 1 elements (declared
to be EBML_NONE and EBML_STOP) and also the elements typically found
in clusters. There is no check via ebml_level_end before every call to
ebml_parse like in ebml_parse_nest (that is used implicitly by the
non-incremental parser); instead, when a new cluster is found (detected
via the return value), ebml_level_end is called and that's it. If the
check introduced in 9326117bf63b04a466d9e787224e56ba8cdbb215 were to
be applied to every EBML_STOP element, every cluster whose preceding
cluster was not unknown-sized would cause the error. But the way things
are, the cues and tags at the end of most files (which are not of type
EBML_STOP in matroska_cluster_incremental_parsing) trigger this error.

I am working on a fix, but in the course of reading and understanding
the Matroska demuxer I have also found several other things to improve;
I want to share them with you so that the review process for them doesn't
need to wait unnecessarily. Besides no-brainers like removing a variable
that is unused for more than ten years the most important things are the
elimination of the list containing all the blocks from a cluster (The
blocks are now directly parsed and freed. There is no need at all to keep
them (which also means that no longer does a list have to be dynamically
reallocated for them).) and of the special status of the SimpleBlock
(the only element of type EBML_PASS). It is now a simple EBML_BIN.

Andreas Rheinhardt (10):
  avformat/matroskadec: Remove an unused variable
  avformat/matroskadec: Don't zero unnecessarily
  avformat/matroskadec: Don't make unnecessary assumptions
  avformat/matroskadec: Use generic size check for signed integers
  avformat/matroskadec: Remove non-incremental parsing of clusters
  avformat/matroskadec: Don't keep old blocks
  avformat/matroskadec: Treat SimpleBlock as EBML_BIN
  avformat/matroskadec: Remove redundant variable declaration
  avformat/matroskadec: Improve length check
  avformat/matroskadec: Typos and cosmetics

 libavformat/matroskadec.c | 205 +-
 1 file changed, 72 insertions(+), 133 deletions(-)

-- 
2.19.2

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


[FFmpeg-devel] [PATCH 07/10] avformat/matroskadec: Treat SimpleBlock as EBML_BIN

2019-03-08 Thread Andreas Rheinhardt
Up until now, the SimpleBlock was treated specially: It basically had
its own EBML category and it was also included in the BlockGroup EBML
syntax (although a SimpleBlock must not exist in a BlockGroup according
to the Matroska specifications). The latter fact also meant that
a MatroskaBlock's buffer was always unreferenced twice.
This has been changed: The type of a SimpleBlock is now an EBML_BIN.
The only way in which SimpleBlocks are still different is that they
share their associated structure with another unit (namely BlockGroup).
This is also used to unref the block: It is always unreferenced via the
BlockGroup syntax.

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index e7f84d545c..0e76fd828d 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -79,7 +79,6 @@ typedef enum {
 EBML_BIN,
 EBML_NEST,
 EBML_LEVEL1,
-EBML_PASS,
 EBML_STOP,
 EBML_SINT,
 EBML_TYPE_COUNT
@@ -694,7 +693,6 @@ static const EbmlSyntax matroska_blockadditions[] = {
 static const EbmlSyntax matroska_blockgroup[] = {
 { MATROSKA_ID_BLOCK,  EBML_BIN,  0, offsetof(MatroskaBlock, bin) },
 { MATROSKA_ID_BLOCKADDITIONS, EBML_NEST, 0, 0, { .n = 
matroska_blockadditions} },
-{ MATROSKA_ID_SIMPLEBLOCK,EBML_BIN,  0, offsetof(MatroskaBlock, bin) },
 { MATROSKA_ID_BLOCKDURATION,  EBML_UINT, 0, offsetof(MatroskaBlock, 
duration) },
 { MATROSKA_ID_DISCARDPADDING, EBML_SINT, 0, offsetof(MatroskaBlock, 
discard_padding) },
 { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, 
reference), { .i = INT64_MIN } },
@@ -706,7 +704,7 @@ static const EbmlSyntax matroska_blockgroup[] = {
 static const EbmlSyntax matroska_cluster_parsing[] = {
 { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, 
timecode) },
 { MATROSKA_ID_BLOCKGROUP,  EBML_NEST, 0, 0, { .n = matroska_blockgroup 
} },
-{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, 0, 0, { .n = matroska_blockgroup 
} },
+{ MATROSKA_ID_SIMPLEBLOCK, EBML_BIN,  0, offsetof(MatroskaBlock, bin) 
},
 { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE },
 { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE },
 { MATROSKA_ID_INFO,EBML_NONE },
@@ -1161,7 +1159,7 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
 list->nb_elem++;
 }
 
-if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {
+if (syntax->type != EBML_STOP) {
 matroska->current_id = 0;
 if ((res = ebml_read_length(matroska, pb, )) < 0)
 return res;
@@ -1217,8 +1215,6 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
 level1_elem->parsed = 1;
 }
 return ebml_parse_nest(matroska, syntax->def.n, data);
-case EBML_PASS:
-return ebml_parse_id(matroska, syntax->def.n, id, data);
 case EBML_STOP:
 return 1;
 default:
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 09/10] avformat/matroskadec: Improve length check

2019-03-08 Thread Andreas Rheinhardt
The earlier code had three flaws:

1. The case of an unknown-sized element inside a finite-sized element
(which is against the specifications) was not caught.

2. The error message wasn't helpful: It compared the length of the child
with the offset of the end of the parent and claimed that the first
exceeds the latter, although that is not necessarily true.

3. Unknown-sized elements that are not parsed can't be skipped. Given
that according to the Matroska specifications only the segment and the
clusters can be of unknown-size, this is handled by not allowing any
other units to have infinite size whereas the earlier code would seek
back by 1 byte upon encountering an infinite-size element that ought
to be skipped.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d899ee5744..6c796e8a4a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1172,11 +1172,22 @@ static int ebml_parse_elem(MatroskaDemuxContext 
*matroska,
 if (matroska->num_levels > 0) {
 MatroskaLevel *level = >levels[matroska->num_levels - 1];
 int64_t pos = avio_tell(pb);
-if (level->length != EBML_UNKNOWN_LENGTH &&
+if (length == EBML_UNKNOWN_LENGTH &&
+level->length != EBML_UNKNOWN_LENGTH) {
+av_log(matroska->ctx, AV_LOG_ERROR, "Unknown-sized element "
+   "inside parent with finite size\n");
+return AVERROR_INVALIDDATA;
+} else if (level->length != EBML_UNKNOWN_LENGTH &&
 (pos + length) > (level->start + level->length)) {
 av_log(matroska->ctx, AV_LOG_ERROR,
-   "Invalid length 0x%"PRIx64" > 0x%"PRIx64" in parent\n",
-   length, level->start + level->length);
+   "Element ending at 0x%"PRIx64" exceeds containing "
+   "master element ending at 0x%"PRIx64"\n",
+pos + length, level->start + level->length);
+return AVERROR_INVALIDDATA;
+} else if (length == EBML_UNKNOWN_LENGTH && id != 
MATROSKA_ID_CLUSTER) {
+av_log(matroska->ctx, AV_LOG_ERROR,
+   "Found unknown-sized element other than a cluster"
+   " in a segment. Dropping the invalid element.\n");
 return AVERROR_INVALIDDATA;
 }
 }
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 06/10] avformat/matroskadec: Don't keep old blocks

2019-03-08 Thread Andreas Rheinhardt
Before this commit, the Matroska muxer would read a block when required
to do so, parse the block, create and return the necessary AVPackets and
yet keep the blocks (in a dynamically allocated list), although they
aren't used at all any more. This has been changed. There is no list any
more and the block is immediately discarded after parsing.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 76 +--
 1 file changed, 32 insertions(+), 44 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6ab9ef7a3e..e7f84d545c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -304,9 +304,19 @@ typedef struct MatroskaLevel {
 uint64_t length;
 } MatroskaLevel;
 
+typedef struct MatroskaBlock {
+uint64_t duration;
+int64_t  reference;
+uint64_t non_simple;
+EbmlBin  bin;
+uint64_t additional_id;
+EbmlBin  additional;
+int64_t discard_padding;
+} MatroskaBlock;
+
 typedef struct MatroskaCluster {
+MatroskaBlock block;
 uint64_t timecode;
-EbmlList blocks;
 } MatroskaCluster;
 
 typedef struct MatroskaLevel1Element {
@@ -356,7 +366,6 @@ typedef struct MatroskaDemuxContext {
 MatroskaLevel1Element level1_elems[64];
 int num_level1_elems;
 
-int current_cluster_num_blocks;
 int64_t current_cluster_pos;
 MatroskaCluster current_cluster;
 
@@ -367,16 +376,6 @@ typedef struct MatroskaDemuxContext {
 int bandwidth;
 } MatroskaDemuxContext;
 
-typedef struct MatroskaBlock {
-uint64_t duration;
-int64_t  reference;
-uint64_t non_simple;
-EbmlBin  bin;
-uint64_t additional_id;
-EbmlBin  additional;
-int64_t discard_padding;
-} MatroskaBlock;
-
 static const EbmlSyntax ebml_header[] = {
 { EBML_ID_EBMLREADVERSION,EBML_UINT, 0, offsetof(Ebml, version),   
  { .u = EBML_VERSION } },
 { EBML_ID_EBMLMAXSIZELENGTH,  EBML_UINT, 0, offsetof(Ebml, max_size),  
  { .u = 8 } },
@@ -705,9 +704,9 @@ static const EbmlSyntax matroska_blockgroup[] = {
 };
 
 static const EbmlSyntax matroska_cluster_parsing[] = {
-{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, 
offsetof(MatroskaCluster, timecode) },
-{ MATROSKA_ID_BLOCKGROUP,  EBML_NEST, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
-{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } },
+{ MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, 
timecode) },
+{ MATROSKA_ID_BLOCKGROUP,  EBML_NEST, 0, 0, { .n = matroska_blockgroup 
} },
+{ MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, 0, 0, { .n = matroska_blockgroup 
} },
 { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE },
 { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE },
 { MATROSKA_ID_INFO,EBML_NONE },
@@ -3429,9 +3428,8 @@ end:
 
 static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
 {
-EbmlList *blocks_list;
-MatroskaBlock *blocks;
-int i, res;
+MatroskaBlock *block = >current_cluster.block;
+int res;
 res = ebml_parse(matroska,
  matroska_cluster_parsing,
  >current_cluster);
@@ -3439,10 +3437,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext 
*matroska)
 /* New Cluster */
 if (matroska->current_cluster_pos)
 ebml_level_end(matroska);
-ebml_free(matroska_cluster_parsing, >current_cluster);
-memset(>current_cluster, 0, sizeof(MatroskaCluster));
-matroska->current_cluster_num_blocks = 0;
-matroska->current_cluster_pos= avio_tell(matroska->ctx->pb);
+matroska->current_cluster_pos = avio_tell(matroska->ctx->pb);
 /* sizeof the ID which was already read */
 if (matroska->current_id)
 matroska->current_cluster_pos -= 4;
@@ -3456,31 +3451,25 @@ static int matroska_parse_cluster(MatroskaDemuxContext 
*matroska)
  >current_cluster);
 }
 
-if (!res &&
-matroska->current_cluster_num_blocks <
-matroska->current_cluster.blocks.nb_elem) {
-blocks_list = >current_cluster.blocks;
-blocks  = blocks_list->elem;
-
-matroska->current_cluster_num_blocks = blocks_list->nb_elem;
-i= blocks_list->nb_elem - 1;
-if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
-int is_keyframe = blocks[i].non_simple ? blocks[i].reference == 
INT64_MIN : -1;
-uint8_t* additional = blocks[i].additional.size > 0 ?
-blocks[i].additional.data : NULL;
-if (!blocks[i].non_simple)
-blocks[i].duration = 0;
-res = matroska_parse_block(matroska, blocks[i].bin.buf, 
blocks[i].bin.data,
-   blocks[i].bin.size, blocks[i].bin.pos,
+

[FFmpeg-devel] [PATCH 10/10] avformat/matroskadec: Typos and cosmetics

2019-03-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6c796e8a4a..0f04389a4e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1571,7 +1571,7 @@ static void matroska_convert_tags(AVFormatContext *s)
 static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
  uint64_t pos)
 {
-uint32_t saved_id   = matroska->current_id;
+uint32_t saved_id  = matroska->current_id;
 int64_t before_pos = avio_tell(matroska->ctx->pb);
 MatroskaLevel level;
 int64_t offset;
@@ -2625,7 +2625,7 @@ static int matroska_read_header(AVFormatContext *s)
 /* The next thing is a segment. */
 pos = avio_tell(matroska->ctx->pb);
 res = ebml_parse(matroska, matroska_segments, matroska);
-// try resyncing until we find a EBML_STOP type element.
+// try resyncing until we find an EBML_STOP type element.
 while (res != 1) {
 res = matroska_resync(matroska, pos);
 if (res < 0)
@@ -3458,19 +3458,19 @@ static int matroska_parse_cluster(MatroskaDemuxContext 
*matroska)
 }
 
 if (!res && block->bin.size > 0) {
-int is_keyframe = block->non_simple ? block->reference == 
INT64_MIN : -1;
-uint8_t* additional = block->additional.size > 0 ?
-block->additional.data : NULL;
-if (!block->non_simple)
-block->duration = 0;
-res = matroska_parse_block(matroska, block->bin.buf, 
block->bin.data,
-   block->bin.size, block->bin.pos,
-   matroska->current_cluster.timecode,
-   block->duration, is_keyframe,
-   additional, block->additional_id,
-   block->additional.size,
-   matroska->current_cluster_pos,
-   block->discard_padding);
+int is_keyframe = block->non_simple ? block->reference == INT64_MIN : 
-1;
+uint8_t* additional = block->additional.size > 0 ?
+block->additional.data : NULL;
+if (!block->non_simple)
+block->duration = 0;
+res = matroska_parse_block(matroska, block->bin.buf, block->bin.data,
+   block->bin.size, block->bin.pos,
+   matroska->current_cluster.timecode,
+   block->duration, is_keyframe,
+   additional, block->additional_id,
+   block->additional.size,
+   matroska->current_cluster_pos,
+   block->discard_padding);
 }
 
 ebml_free(matroska_blockgroup, block);
@@ -3869,7 +3869,7 @@ static int webm_dash_manifest_cues(AVFormatContext *s, 
int64_t init_range)
 // cues end
 av_dict_set_int(>streams[0]->metadata, CUES_END, cues_end, 0);
 
-// if the file has cues at the start, fix up the init range so tht
+// if the file has cues at the start, fix up the init range so that
 // it does not include it
 if (cues_start <= init_range)
 av_dict_set_int(>streams[0]->metadata, INITIALIZATION_RANGE, 
cues_start - 1, 0);
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 04/10] avformat/matroskadec: Use generic size check for signed integers

2019-03-08 Thread Andreas Rheinhardt
and drop the redundant checks contained in ebml_read_uint and
ebml_read_sint.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 88e80b2fda..55a153d982 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -882,9 +882,6 @@ static int ebml_read_uint(AVIOContext *pb, int size, 
uint64_t *num)
 {
 int n = 0;
 
-if (size > 8)
-return AVERROR_INVALIDDATA;
-
 /* big-endian ordering; build up number */
 *num = 0;
 while (n++ < size)
@@ -901,9 +898,6 @@ static int ebml_read_sint(AVIOContext *pb, int size, 
int64_t *num)
 {
 int n = 1;
 
-if (size > 8)
-return AVERROR_INVALIDDATA;
-
 if (size == 0) {
 *num = 0;
 } else {
@@ -1161,6 +1155,7 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
 {
 static const uint64_t max_lengths[EBML_TYPE_COUNT] = {
 [EBML_UINT]  = 8,
+[EBML_SINT]  = 8,
 [EBML_FLOAT] = 8,
 // max. 16 MB for strings
 [EBML_STR]   = 0x100,
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 08/10] avformat/matroskadec: Remove redundant variable declaration

2019-03-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 0e76fd828d..d899ee5744 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1171,7 +1171,6 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
 }
 if (matroska->num_levels > 0) {
 MatroskaLevel *level = >levels[matroska->num_levels - 1];
-AVIOContext *pb = matroska->ctx->pb;
 int64_t pos = avio_tell(pb);
 if (level->length != EBML_UNKNOWN_LENGTH &&
 (pos + length) > (level->start + level->length)) {
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 01/10] avformat/matroskadec: Remove an unused variable

2019-03-08 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskadec.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 0e3a6890c1..de27d63b17 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -322,7 +322,6 @@ typedef struct MatroskaDemuxContext {
 /* EBML stuff */
 int num_levels;
 MatroskaLevel levels[EBML_MAX_DEPTH];
-int level_up;
 uint32_t current_id;
 
 uint64_t time_scale;
@@ -1593,7 +1592,6 @@ static void matroska_convert_tags(AVFormatContext *s)
 static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
  uint64_t pos)
 {
-uint32_t level_up   = matroska->level_up;
 uint32_t saved_id   = matroska->current_id;
 int64_t before_pos = avio_tell(matroska->ctx->pb);
 MatroskaLevel level;
@@ -1629,7 +1627,6 @@ static int 
matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
 }
 /* seek back */
 avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
-matroska->level_up   = level_up;
 matroska->current_id = saved_id;
 
 return ret;
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 03/10] avformat/matroskadec: Don't make unnecessary assumptions

2019-03-08 Thread Andreas Rheinhardt
regarding the length of a cluster's size field.

The earlier code relied on the length of clusters always being coded on
eight bytes (as is current Matroska muxer behaviour). But there is no
need to rely on this and this commit changes it.

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 8a14764d1a..88e80b2fda 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3695,14 +3695,16 @@ static int 
webm_clusters_start_with_keyframe(AVFormatContext *s)
 before_pos = avio_tell(s->pb);
 while (1) {
 int64_t cluster_id = 0, cluster_length = 0;
+int read;
 AVPacket *pkt;
 avio_seek(s->pb, cluster_pos, SEEK_SET);
 // read cluster id and length
-ebml_read_num(matroska, matroska->ctx->pb, 4, _id);
-ebml_read_length(matroska, matroska->ctx->pb, _length);
-if (cluster_id != 0xF43B675) { // done with all clusters
+read = ebml_read_num(matroska, matroska->ctx->pb, 4, _id);
+if (read < 0 || cluster_id != 0xF43B675) // done with all clusters
+break;
+read = ebml_read_length(matroska, matroska->ctx->pb, _length);
+if (read < 0)
 break;
-}
 avio_seek(s->pb, cluster_pos, SEEK_SET);
 matroska->current_id = 0;
 matroska_clear_queue(matroska);
@@ -3711,7 +3713,8 @@ static int 
webm_clusters_start_with_keyframe(AVFormatContext *s)
 break;
 }
 pkt = >queue->pkt;
-cluster_pos += cluster_length + 12; // 12 is the offset of the cluster 
id and length.
+// 4 + read is the length of the cluster id and the cluster length 
field.
+cluster_pos += 4 + read + cluster_length;
 if (!(pkt->flags & AV_PKT_FLAG_KEY)) {
 rv = 0;
 break;
-- 
2.19.2

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


[FFmpeg-devel] [PATCH 02/10] avformat/matroskadec: Don't zero unnecessarily

2019-03-08 Thread Andreas Rheinhardt
It is only necessary to zero the initial allocated memory used to store
the size of laced frames if the block used Xiph lacing. Otherwise no
unintialized data was ever used, so use av_malloc instead of av_mallocz.

Also use the correct type for the allocations.

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index de27d63b17..8a14764d1a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2796,7 +2796,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 
 if (!type) {
 *laces= 1;
-*lace_buf = av_mallocz(sizeof(int));
+*lace_buf = av_malloc(sizeof(**lace_buf));
 if (!*lace_buf)
 return AVERROR(ENOMEM);
 
@@ -2808,7 +2808,7 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 *laces= *data + 1;
 data += 1;
 size -= 1;
-lace_size = av_mallocz(*laces * sizeof(int));
+lace_size = av_malloc(*laces * sizeof(*lace_size));
 if (!lace_size)
 return AVERROR(ENOMEM);
 
@@ -2818,6 +2818,8 @@ static int matroska_parse_laces(MatroskaDemuxContext 
*matroska, uint8_t **buf,
 uint8_t temp;
 uint32_t total = 0;
 for (n = 0; res == 0 && n < *laces - 1; n++) {
+lace_size[n] = 0;
+
 while (1) {
 if (size <= total) {
 res = AVERROR_INVALIDDATA;
-- 
2.19.2

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


Re: [FFmpeg-devel] [PATCH V4 1/2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-08 Thread Paul B Mahol
On 3/8/19, Jun Zhao  wrote:
> From: Jun Zhao 
>
> accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
> data type, it will have a risk of an integral value becoming larger than
> the 32-bits integer capacity and resulting in an integer overflow. For
> this risk, add a checking with warning message.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/vf_nlmeans.c |   11 +++
>  1 files changed, 11 insertions(+), 0 deletions(-)
>
> diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> index dcb5a03..8d47f9d 100644
> --- a/libavfilter/vf_nlmeans.c
> +++ b/libavfilter/vf_nlmeans.c
> @@ -477,6 +477,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *in)
>  NLMeansContext *s = ctx->priv;
>  AVFilterLink *outlink = ctx->outputs[0];
>
> +// accumulation of 8-bits uint_8 into 32-bits data type, it will have
> +// a risk of an integral value becoming larger than the 32-bits integer
> +// capacity and resulting in an integer overflow, so limit the image
> size
> +if ((UINT32_MAX / (uint64_t)inlink->w) < (255 * (uint64_t)inlink->h)) {
> +av_log(ctx, AV_LOG_ERROR,
> +   "image size (%d x %d) integral value may overflow.\n",
> +   inlink->w, inlink->h);
> +av_frame_free();
> +return AVERROR(EINVAL);
> +}
> +
>  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
>  if (!out) {
>  av_frame_free();

I see no point in this warning, if overflow is real issue should be
fixed instead of giving
pointless warning.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] fate/proresenc_aw : Add fate test for interlace and 444 encoding

2019-03-08 Thread Peter Ross
On Fri, Mar 08, 2019 at 12:11:47AM +0100, Martin Vignali wrote:
> >> Can you check that and fix it?
> >>
> >>
> >
> Patch in attach fix for me vsynth3 interlace prores test :
> make fate-vsynth3-prores_int;make fate-vsynth3-prores_444_int
> 
> Pass fate test for me (os x X86_64) with and without
> --enable-memory-poisoning

With this patch applied, the vsynth3 test no longer fails on my systems.
Please apply!

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


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


[FFmpeg-devel] [PATCH V4 2/2] lavfi/nlmeans: fix mixed declarations and code

2019-03-08 Thread Jun Zhao
From: Jun Zhao 

fix mixed declarations and code in C90 after last change

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

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 8d47f9d..7497df2 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -476,6 +476,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFilterContext *ctx = inlink->dst;
 NLMeansContext *s = ctx->priv;
 AVFilterLink *outlink = ctx->outputs[0];
+AVFrame *out;
 
 // accumulation of 8-bits uint_8 into 32-bits data type, it will have
 // a risk of an integral value becoming larger than the 32-bits integer
@@ -488,7 +489,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 return AVERROR(EINVAL);
 }
 
-AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out) {
 av_frame_free();
 return AVERROR(ENOMEM);
-- 
1.7.1

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


[FFmpeg-devel] [PATCH V4 1/2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-08 Thread Jun Zhao
From: Jun Zhao 

accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
data type, it will have a risk of an integral value becoming larger than
the 32-bits integer capacity and resulting in an integer overflow. For
this risk, add a checking with warning message.

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_nlmeans.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index dcb5a03..8d47f9d 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -477,6 +477,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 NLMeansContext *s = ctx->priv;
 AVFilterLink *outlink = ctx->outputs[0];
 
+// accumulation of 8-bits uint_8 into 32-bits data type, it will have
+// a risk of an integral value becoming larger than the 32-bits integer
+// capacity and resulting in an integer overflow, so limit the image size
+if ((UINT32_MAX / (uint64_t)inlink->w) < (255 * (uint64_t)inlink->h)) {
+av_log(ctx, AV_LOG_ERROR,
+   "image size (%d x %d) integral value may overflow.\n",
+   inlink->w, inlink->h);
+av_frame_free();
+return AVERROR(EINVAL);
+}
+
 AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
 if (!out) {
 av_frame_free();
-- 
1.7.1

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