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

2019-03-07 Thread Hendrik Leppkes
On Wed, Feb 27, 2019 at 6:05 PM Martin Vignali  wrote:
>
> > works here
> >
> >
>  Pushed, thanks.
>

These tests fail on all FATE boxes. http://fate.ffmpeg.org/

Can you check that and fix it?

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


Re: [FFmpeg-devel] [PATCH v1] avformat/smoothstreamingenc:add bitrate calculate

2019-03-07 Thread Steven Liu
Jun Li  于2019年3月6日周三 上午3:25写道:
>
> From: jun 
>
> Calculate bitrate based on fragment size, only applied when
> bitrate is not set, for example rtsp source.
>
> Signed-off-by: Jun Li 
> ---
>  libavformat/smoothstreamingenc.c | 30 +-
>  1 file changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/smoothstreamingenc.c 
> b/libavformat/smoothstreamingenc.c
> index 094712af27..1d969ab037 100644
> --- a/libavformat/smoothstreamingenc.c
> +++ b/libavformat/smoothstreamingenc.c
> @@ -320,11 +320,12 @@ static int ism_write_header(AVFormatContext *s)
>  AVDictionary *opts = NULL;
>
>  if (!s->streams[i]->codecpar->bit_rate) {
> -av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
> -ret = AVERROR(EINVAL);
> -goto fail;
> +av_log(s, AV_LOG_WARNING, "No bit rate set for stream %d\n", i);
> +snprintf(os->dirname, sizeof(os->dirname), 
> "%s/QualityLevels(Tmp_%"PRId64")", s->url, i);
> +} else {
> +snprintf(os->dirname, sizeof(os->dirname), 
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
>  }
> -snprintf(os->dirname, sizeof(os->dirname), 
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
> +
>  if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
>  ret = AVERROR(errno);
>  av_log(s, AV_LOG_ERROR, "mkdir failed\n");
> @@ -519,7 +520,7 @@ static int ism_flush(AVFormatContext *s, int final)
>
>  for (i = 0; i < s->nb_streams; i++) {
>  OutputStream *os = &c->streams[i];
> -char filename[1024], target_filename[1024], header_filename[1024];
> +char filename[1024], target_filename[1024], header_filename[1024], 
> curr_dirname[1024];
>  int64_t size;
>  int64_t start_ts, duration, moof_size;
>  if (!os->packets_written)
> @@ -541,6 +542,25 @@ static int ism_flush(AVFormatContext *s, int final)
>  size = os->tail_pos - os->cur_start_pos;
>  if ((ret = parse_fragment(s, filename, &start_ts, &duration, 
> &moof_size, size)) < 0)
>  break;
> +
> +if (!s->streams[i]->codecpar->bit_rate) {
> +int64_t bitrate = (int64_t) size * 8 * AV_TIME_BASE / 
> av_rescale_q(duration, s->streams[i]->time_base, AV_TIME_BASE_Q);
> +if (!bitrate) {
> +av_log(s, AV_LOG_ERROR, "calculating bitrate get zero.");
> +ret = AVERROR(EINVAL);
> +return ret;
> +}
> +
> +av_log(s, AV_LOG_INFO, "calculated bitrate: %ld\n", bitrate);
maybe use AV_LOG_DEBUG or AV_LOG_WARNING is better than AV_LOG_INFO
here, this should unnecessary message default.
> +s->streams[i]->codecpar->bit_rate = bitrate;
> +memcpy(curr_dirname, os->dirname, sizeof(os->dirname));
> +snprintf(os->dirname, sizeof(os->dirname), 
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
> +snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
> +
> +if ((ret = ff_rename((const char*)curr_dirname,  os->dirname, 
> s)) < 0)
> +return ret;
> +}
> +
>  snprintf(header_filename, sizeof(header_filename), 
> "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
>  snprintf(target_filename, sizeof(target_filename), 
> "%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
>  copy_moof(s, filename, header_filename, moof_size);
> --
> 2.17.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
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-07 Thread Martin Vignali
>
> These tests fail on all FATE boxes. http://fate.ffmpeg.org/
>
> Can you check that and fix it?
>
>
Seems to be related to memory poisoning (pass when disable) :
http://fate.ffmpeg.org/report.cgi?time=20190307033138&slot=x86_64-archlinux-gcc-valgrind-no-undef

Will take a look.

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


[FFmpeg-devel] ProRes Bitstream Version

2019-03-07 Thread Vincent Lai
Hi,

I'm new to the list, so I would like to first thank you for the great work
of ffmpeg.

I would like to report a bug on bitstream version on encoded ProRes output.
Currently, ffmpeg always encode with bitstream version 0 even for 
(with alpha channel). According to RDD36-2015:

> Version 0 bitstreams will have a value of 2 (4:2:2 sampling) for the
chroma_format syntax element and a value of 0 (no encoded alpha) for the
alpha_channel_type element; version 1 bitstreams can have any permissible
value for those elements.

In other words, if alpha channel is encoded, it should have bitstream
version 1. Thanks!

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


[FFmpeg-devel] How to make a mp4 file have AVCC box

2019-03-07 Thread Yufei He
Hi James

Thanks. I got the extradata from first encoded frame with functions in 
avcodec.h and examples in ffmpeg.c.

My problem is that the trancoded MP4 file does not have valid AVCC box. It's 
supposed to have the extradata from the codec.

I can only get the extradata after I receive the first encoded frame, while I 
don't have any frame in my encoder's init function.

It seems ffmpeg can only generate AVCC box if I set extradata in my encoder's 
init function, it does not take the extradata if I make it in receive_packet 
function.

Please help.

Yufei.
if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER && !avctx->extradata) {
const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
ret = av_bsf_alloc(filter, &ctx);
if (ret < 0)
return ret;
ret = avcodec_parameters_from_context(ctx->par_in, avctx);
if (ret < 0)
return ret;
ret = av_bsf_init(ctx);
if (ret < 0)
return ret;
ctx->time_base_in = avctx->time_base;
ret = av_bsf_send_packet(ctx, avpkt);
if (ret < 0)
return ret;
ret = av_bsf_receive_packet(ctx, avpkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return 0;
if (avpkt->side_data_elems > 0 )
{
avctx->extradata = av_mallocz(avpkt->side_data->size + 
AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
memcpy(avctx->extradata, avpkt->side_data->data, avpkt->side_data->size);
avctx->extradata_size = avpkt->side_data->size;
}
av_bsf_free(&ctx);
}

On 03/06/2019 02:10 PM, James Almer wrote:

On 3/6/2019 4:04 PM, Yufei He wrote:


Hi

I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.

Here is the code.

AVPacket *avpkt; // there is valid data.
AVBSFContext *ctx = NULL;
ret = av_bsf_alloc(&ff_extract_extradata_bsf, &ctx);
ret = ff_extract_extradata_bsf.init(ctx);
ret = ff_extract_extradata_bsf.filter(ctx, avpkt);

ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref because 
 ctx->internal->buffer+pkt->data is NULL.

int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
{
AVBSFInternal *in = ctx->internal;
if (in->eof)
return AVERROR_EOF;
if (!ctx->internal->buffer_pkt->data &&
!ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);

How should ctx->internal->buffer+pkt->data be set?

Thanks.

Yufei.



You're not using the bsf API correctly. You're accessing internal
callbacks like init() and filter() directly. Use the public functions
defined in avcodec.h, and look at usage examples like in ffmpeg.c if needed.

Also, any further questions or emails about this should go to the
libav-user list at https://lists.ffmpeg.org/mailman/listinfo/libav-user/
This list is for actual ffmpeg development, not for usage questions.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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


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

2019-03-07 Thread 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.
---
 libavcodec/zmbvenc.c | 104 ---
 1 file changed, 77 insertions(+), 27 deletions(-)

diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index c9d50b6adf..98029de5f6 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -34,11 +34,29 @@
 
 #include 
 
+/* Frame header flags */
 #define ZMBV_KEYFRAME 1
 #define ZMBV_DELTAPAL 2
 
+/* Motion block width/height (maximum allowed value is 255)
+ * Note: histogram datatype in block_cmp() must be big enough to hold values
+ * up to (4 * ZMBV_BLOCK * ZMBV_BLOCK)
+ */
 #define ZMBV_BLOCK 16
 
+/* Keyframe header format values */
+enum ZmbvFormat {
+ZMBV_FMT_NONE  = 0,
+ZMBV_FMT_1BPP  = 1,
+ZMBV_FMT_2BPP  = 2,
+ZMBV_FMT_4BPP  = 3,
+ZMBV_FMT_8BPP  = 4,
+ZMBV_FMT_15BPP = 5,
+ZMBV_FMT_16BPP = 6,
+ZMBV_FMT_24BPP = 7,
+ZMBV_FMT_32BPP = 8
+};
+
 /**
  * Encoder context
  */
@@ -53,9 +71,11 @@ typedef struct ZmbvEncContext {
 int pstride;
 int comp_size;
 int keyint, curfrm;
+int bypp;
+enum ZmbvFormat fmt;
 z_stream zstream;
 
-int score_tab[ZMBV_BLOCK * ZMBV_BLOCK + 1];
+int score_tab[ZMBV_BLOCK * ZMBV_BLOCK * 4 + 1];
 } ZmbvEncContext;
 
 
@@ -69,10 +89,11 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t 
*src, int stride,
 int sum = 0;
 int i, j;
 uint16_t histogram[256] = {0};
+int bw_bytes = bw * c->bypp;
 
 /* Build frequency histogram of byte values for src[] ^ src2[] */
 for(j = 0; j < bh; j++){
-for(i = 0; i < bw; i++){
+for(i = 0; i < bw_bytes; i++){
 int t = src[i] ^ src2[i];
 histogram[t]++;
 }
@@ -81,7 +102,7 @@ static inline int block_cmp(ZmbvEncContext *c, uint8_t *src, 
int stride,
 }
 
 /* If not all the xored values were 0, then the blocks are different */
-*xored = (histogram[0] < bw * bh);
+*xored = (histogram[0] < bw_bytes * bh);
 
 /* Exit early if blocks are equal */
 if (!*xored) return 0;
@@ -114,7 +135,7 @@ static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int 
sstride, uint8_t *prev,
 
 /* Try previous block's MV (if not 0,0) */
 if (mx0 || my0){
-tv = block_cmp(c, src, sstride, prev + mx0 + my0 * pstride, pstride, 
bw, bh, &txored);
+tv = block_cmp(c, src, sstride, prev + mx0 * c->bypp + my0 * pstride, 
pstride, bw, bh, &txored);
 if(tv < bv){
 bv = tv;
 *mx = mx0;
@@ -129,7 +150,7 @@ static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int 
sstride, uint8_t *prev,
 for(dx = -c->lrange; dx <= c->urange; dx++){
 if(!dx && !dy) continue; // we already tested this block
 if(dx == mx0 && dy == my0) continue; // this one too
-tv = block_cmp(c, src, sstride, prev + dx + dy * pstride, pstride, 
bw, bh, &txored);
+tv = block_cmp(c, src, sstride, prev + dx * c->bypp + dy * 
pstride, pstride, bw, bh, &txored);
 if(tv < bv){
  bv = tv;
  *mx = dx;
@@ -165,9 +186,10 @@ FF_DISABLE_DEPRECATION_WARNINGS
 avctx->coded_frame->key_frame = keyframe;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024);
 
-palptr = (uint32_t*)p->data[1];
+palptr = (avctx->pix_fmt == AV_PIX_FMT_PAL8) ? (uint32_t *)p->data[1] : 
NULL;
+chpal = !keyframe && palptr && memcmp(palptr, c->pal2, 1024);
+
 src = p->data[0];
 prev = c->prev;
 if(chpal){
@@ -181,19 +203,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
 c->pal[i * 3 + 1] = tpal[1];
 c->pal[i * 3 + 2] = tpal[2];
 }
-memcpy(c->pal2, p->data[1], 1024);
+memcpy(c->pal2, palptr, 1024);
 }
 if(keyframe){
-for(i = 0; i < 256; i++){
-AV_WB24(c->pal+(i*3), palptr[i]);
+if (palptr){
+for(i = 0; 

Re: [FFmpeg-devel] ProRes Bitstream Version

2019-03-07 Thread Martin Vignali
>
> I'm new to the list, so I would like to first thank you for the great work
> of ffmpeg.
>
> I would like to report a bug on bitstream version on encoded ProRes output.
> Currently, ffmpeg always encode with bitstream version 0 even for 
> (with alpha channel). According to RDD36-2015:
>
> > Version 0 bitstreams will have a value of 2 (4:2:2 sampling) for the
> chroma_format syntax element and a value of 0 (no encoded alpha) for the
> alpha_channel_type element; version 1 bitstreams can have any permissible
> value for those elements.
>
> In other words, if alpha channel is encoded, it should have bitstream
> version 1. Thanks!
>
>
Hello,

Bug report is a better place to report this (https://trac.ffmpeg.org/)
But thanks for pointing this.
I will send a patch later for fixing bitstream version for  (with and
without alpha,   without alpha also need version 1).

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


[FFmpeg-devel] How to make a mp4 file have AVCC box

2019-03-07 Thread Yufei He
Hi

I have a problem that the trancoded MP4 file does not have valid AVCC box. It's 
supposed to have the extradata from the codec.

I can only get the extradata after I receive the first encoded frame, while I 
don't have any frame in my encoder's init function.

It seems ffmpeg can only generate AVCC box if I set extradata in my encoder's 
init function, it does not take the extradata if I make it in receive_packet 
function.

Please help.

Thanks.

Yufei.
if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER && !avctx->extradata) {
const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
ret = av_bsf_alloc(filter, &ctx);
if (ret < 0)
return ret;
ret = avcodec_parameters_from_context(ctx->par_in, avctx);
if (ret < 0)
return ret;
ret = av_bsf_init(ctx);
if (ret < 0)
return ret;
ctx->time_base_in = avctx->time_base;
ret = av_bsf_send_packet(ctx, avpkt);
if (ret < 0)
return ret;
ret = av_bsf_receive_packet(ctx, avpkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return 0;
if (avpkt->side_data_elems > 0 )
{
avctx->extradata = av_mallocz(avpkt->side_data->size + 
AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
return AVERROR(ENOMEM);
memcpy(avctx->extradata, avpkt->side_data->data, avpkt->side_data->size);
avctx->extradata_size = avpkt->side_data->size;
}
av_bsf_free(&ctx);
}

On 03/06/2019 02:10 PM, James Almer wrote:

On 3/6/2019 4:04 PM, Yufei He wrote:


Hi

I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.

Here is the code.

AVPacket *avpkt; // there is valid data.
AVBSFContext *ctx = NULL;
ret = av_bsf_alloc(&ff_extract_extradata_bsf, &ctx);
ret = ff_extract_extradata_bsf.init(ctx);
ret = ff_extract_extradata_bsf.filter(ctx, avpkt);

ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref because 
 ctx->internal->buffer+pkt->data is NULL.

int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
{
AVBSFInternal *in = ctx->internal;
if (in->eof)
return AVERROR_EOF;
if (!ctx->internal->buffer_pkt->data &&
!ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);

How should ctx->internal->buffer+pkt->data be set?

Thanks.

Yufei.


You're not using the bsf API correctly. You're accessing internal
callbacks like init() and filter() directly. Use the public functions
defined in avcodec.h, and look at usage examples like in ffmpeg.c if needed.

Also, any further questions or emails about this should go to the
libav-user list at https://lists.ffmpeg.org/mailman/listinfo/libav-user/
This list is for actual ffmpeg development, not for usage questions.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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


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

2019-03-07 Thread Lynne
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.

>From 7aff99d12faf557753c5ee860a9672c7a09a26e3 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.
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.
---
 libavcodec/pngdec.c | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 189bb9a4c1..30b6dc3166 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;
@@ -1198,11 +1200,26 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
 }
 
 length = bytestream2_get_be32(&s->gb);
-if (length > 0x7fff || length > bytestream2_get_bytes_left(&s->gb)) {
+if (length > 0x7fff || (length + 8) > bytestream2_get_bytes_left(&s->gb)) {
 av_log(avctx, AV_LOG_ERROR, "chunk too big\n");
 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(&s->gb, 4); /* tag */
+goto skip_tag;
+}
+}
 tag = bytestream2_get_le32(&s->gb);
 if (avctx->debug & FF_DEBUG_STARTCODE)
 av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n",
-- 
2.21.0

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


[FFmpeg-devel] [PATCH v2] avformat/smoothstreamingenc:add bitrate calculate

2019-03-07 Thread Jun Li
From: jun 

Calculate bitrate based on fragment size, only applied when
bitrate is not set, for example rtsp source.

Signed-off-by: Jun Li 
---
 libavformat/smoothstreamingenc.c | 30 +-
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 094712af27..75a47a9668 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -320,11 +320,12 @@ static int ism_write_header(AVFormatContext *s)
 AVDictionary *opts = NULL;
 
 if (!s->streams[i]->codecpar->bit_rate) {
-av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
-ret = AVERROR(EINVAL);
-goto fail;
+av_log(s, AV_LOG_WARNING, "No bit rate set for stream %d\n", i);
+snprintf(os->dirname, sizeof(os->dirname), 
"%s/QualityLevels(Tmp_%"PRId64")", s->url, i);
+} else {
+snprintf(os->dirname, sizeof(os->dirname), 
"%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
 }
-snprintf(os->dirname, sizeof(os->dirname), 
"%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
+
 if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
 ret = AVERROR(errno);
 av_log(s, AV_LOG_ERROR, "mkdir failed\n");
@@ -519,7 +520,7 @@ static int ism_flush(AVFormatContext *s, int final)
 
 for (i = 0; i < s->nb_streams; i++) {
 OutputStream *os = &c->streams[i];
-char filename[1024], target_filename[1024], header_filename[1024];
+char filename[1024], target_filename[1024], header_filename[1024], 
curr_dirname[1024];
 int64_t size;
 int64_t start_ts, duration, moof_size;
 if (!os->packets_written)
@@ -541,6 +542,25 @@ static int ism_flush(AVFormatContext *s, int final)
 size = os->tail_pos - os->cur_start_pos;
 if ((ret = parse_fragment(s, filename, &start_ts, &duration, 
&moof_size, size)) < 0)
 break;
+
+if (!s->streams[i]->codecpar->bit_rate) {
+int64_t bitrate = (int64_t) size * 8 * AV_TIME_BASE / 
av_rescale_q(duration, s->streams[i]->time_base, AV_TIME_BASE_Q);
+if (!bitrate) {
+av_log(s, AV_LOG_ERROR, "calculating bitrate get zero.");
+ret = AVERROR(EINVAL);
+return ret;
+}
+
+av_log(s, AV_LOG_WARNING, "calculated bitrate: %ld\n", bitrate);
+s->streams[i]->codecpar->bit_rate = bitrate;
+memcpy(curr_dirname, os->dirname, sizeof(os->dirname));
+snprintf(os->dirname, sizeof(os->dirname), 
"%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
+snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
+
+if ((ret = ff_rename((const char*)curr_dirname,  os->dirname, s)) 
< 0)
+return ret;
+}
+
 snprintf(header_filename, sizeof(header_filename), 
"%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
 snprintf(target_filename, sizeof(target_filename), 
"%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
 copy_moof(s, filename, header_filename, moof_size);
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH v1] avformat/smoothstreamingenc:add bitrate calculate

2019-03-07 Thread Jun Li
Thanks !
Updated to AV_LOG_WARNING, 2nd version patch is here
https://patchwork.ffmpeg.org/patch/12237/

On Thu, Mar 7, 2019 at 1:39 AM Steven Liu  wrote:

> Jun Li  于2019年3月6日周三 上午3:25写道:
> >
> > From: jun 
> >
> > Calculate bitrate based on fragment size, only applied when
> > bitrate is not set, for example rtsp source.
> >
> > Signed-off-by: Jun Li 
> > ---
> >  libavformat/smoothstreamingenc.c | 30 +-
> >  1 file changed, 25 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavformat/smoothstreamingenc.c
> b/libavformat/smoothstreamingenc.c
> > index 094712af27..1d969ab037 100644
> > --- a/libavformat/smoothstreamingenc.c
> > +++ b/libavformat/smoothstreamingenc.c
> > @@ -320,11 +320,12 @@ static int ism_write_header(AVFormatContext *s)
> >  AVDictionary *opts = NULL;
> >
> >  if (!s->streams[i]->codecpar->bit_rate) {
> > -av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n",
> i);
> > -ret = AVERROR(EINVAL);
> > -goto fail;
> > +av_log(s, AV_LOG_WARNING, "No bit rate set for stream
> %d\n", i);
> > +snprintf(os->dirname, sizeof(os->dirname),
> "%s/QualityLevels(Tmp_%"PRId64")", s->url, i);
> > +} else {
> > +snprintf(os->dirname, sizeof(os->dirname),
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
> >  }
> > -snprintf(os->dirname, sizeof(os->dirname),
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
> > +
> >  if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
> >  ret = AVERROR(errno);
> >  av_log(s, AV_LOG_ERROR, "mkdir failed\n");
> > @@ -519,7 +520,7 @@ static int ism_flush(AVFormatContext *s, int final)
> >
> >  for (i = 0; i < s->nb_streams; i++) {
> >  OutputStream *os = &c->streams[i];
> > -char filename[1024], target_filename[1024],
> header_filename[1024];
> > +char filename[1024], target_filename[1024],
> header_filename[1024], curr_dirname[1024];
> >  int64_t size;
> >  int64_t start_ts, duration, moof_size;
> >  if (!os->packets_written)
> > @@ -541,6 +542,25 @@ static int ism_flush(AVFormatContext *s, int final)
> >  size = os->tail_pos - os->cur_start_pos;
> >  if ((ret = parse_fragment(s, filename, &start_ts, &duration,
> &moof_size, size)) < 0)
> >  break;
> > +
> > +if (!s->streams[i]->codecpar->bit_rate) {
> > +int64_t bitrate = (int64_t) size * 8 * AV_TIME_BASE /
> av_rescale_q(duration, s->streams[i]->time_base, AV_TIME_BASE_Q);
> > +if (!bitrate) {
> > +av_log(s, AV_LOG_ERROR, "calculating bitrate get
> zero.");
> > +ret = AVERROR(EINVAL);
> > +return ret;
> > +}
> > +
> > +av_log(s, AV_LOG_INFO, "calculated bitrate: %ld\n",
> bitrate);
> maybe use AV_LOG_DEBUG or AV_LOG_WARNING is better than AV_LOG_INFO
> here, this should unnecessary message default.
> > +s->streams[i]->codecpar->bit_rate = bitrate;
> > +memcpy(curr_dirname, os->dirname, sizeof(os->dirname));
> > +snprintf(os->dirname, sizeof(os->dirname),
> "%s/QualityLevels(%"PRId64")", s->url, s->streams[i]->codecpar->bit_rate);
> > +snprintf(filename, sizeof(filename), "%s/temp",
> os->dirname);
> > +
> > +if ((ret = ff_rename((const char*)curr_dirname,
> os->dirname, s)) < 0)
> > +return ret;
> > +}
> > +
> >  snprintf(header_filename, sizeof(header_filename),
> "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag,
> start_ts);
> >  snprintf(target_filename, sizeof(target_filename),
> "%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
> >  copy_moof(s, filename, header_filename, moof_size);
> > --
> > 2.17.1
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2019-03-07 Thread Michael Niedermayer
On Wed, Mar 06, 2019 at 10:15:36PM -0500, Andriy Gelman wrote:
> From: Andriy Gelman 
> 
> Reduces buffering latency with low bitrate streams, where
> 8192 bytes can mean several seconds.
> ---
>  libavformat/mpegts.c | 60 +++-
>  1 file changed, 37 insertions(+), 23 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index b04fd7b4f4..7d03500043 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -53,6 +53,10 @@
>  (prev_dividend) = (dividend);
>   \
>  } while (0)
>  
> +#define PROBE_PACKET_MAX_BUF 8192
> +#define PROBE_PACKET_STEP 512
> +#define PROBE_PACKET_MARGIN 5
> +
>  enum MpegTSFilterType {
>  MPEGTS_PES,
>  MPEGTS_SECTION,
> @@ -591,28 +595,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_STEP <= PROBE_PACKET_MAX_BUF) {
> +ret = avio_read(pb, buf + buf_size, PROBE_PACKET_STEP);

have you tried avio_read_partial() ?
it may be better to request the full remaining size of the buffer and accept
whatever is available.

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator


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


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

2019-03-07 Thread Michael Niedermayer
On Thu, Mar 07, 2019 at 09:45:12AM +0800, 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 |7 +++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> index dcb5a03..9876aae 100644
> --- a/libavfilter/vf_nlmeans.c
> +++ b/libavfilter/vf_nlmeans.c
> @@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const 
> NLMeansDSPContext *dsp,
>  // adjusted end x position of the safe area after width of the safe area 
> gets aligned
>  const int endx_safe = startx_safe + safe_pw;
>  
> +// 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.
> +if ((UINT32_MAX / (uint64_t)w) < (255 * (uint64_t)h))
> +av_log(NULL, AV_LOG_WARNING,
> +   "image (%d x %d) integral value may overflow.\n", w ,h);

Printing a warning is not an adequate response for a integer overflow.
Such thing is undefined behavior (in case signed of signed int) and must
not occur.

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

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


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


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

2019-03-07 Thread Michael Niedermayer
On Thu, Mar 07, 2019 at 09:18:42PM +0100, Michael Niedermayer wrote:
> On Thu, Mar 07, 2019 at 09:45:12AM +0800, 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 |7 +++
> >  1 files changed, 7 insertions(+), 0 deletions(-)
> > 
> > diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> > index dcb5a03..9876aae 100644
> > --- a/libavfilter/vf_nlmeans.c
> > +++ b/libavfilter/vf_nlmeans.c
> > @@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const 
> > NLMeansDSPContext *dsp,
> >  // adjusted end x position of the safe area after width of the safe 
> > area gets aligned
> >  const int endx_safe = startx_safe + safe_pw;
> >  
> > +// 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.
> > +if ((UINT32_MAX / (uint64_t)w) < (255 * (uint64_t)h))
> > +av_log(NULL, AV_LOG_WARNING,
> > +   "image (%d x %d) integral value may overflow.\n", w ,h);
> 
> Printing a warning is not an adequate response for a integer overflow.
> Such thing is undefined behavior (in case signed of signed int) and must
> not occur.

And if no signed ints are involved, while this is then not undefined it still
gives the wrong result. Thats a bug, the bug should be fixed not a warning
be printed that the bug might be triggered

Thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.


signature.asc
Description: PGP signature
___
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-07 Thread Oliver Collyer
> 
>>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>>> index 0ce22ec4fa..7087f82ce1 100644
>>> --- a/libavcodec/avcodec.h
>>> +++ b/libavcodec/avcodec.h
>>> @@ -3357,6 +3357,12 @@ typedef struct AVCodecContext {
>>> * - encoding: unused
>>> */
>>>int discard_damaged_percentage;
>>> +
>>> +/*
>>> + * Video encoding only. Sets the maximum picture size for encoders that
>>> + * support adjusting the picture size dynamically during encoding.
>>> + */
>>> + int max_width, max_height;
>>> } AVCodecContext;
>>> 
>> 
>> I really don't like introducing public API fields for this. Maybe a
>> private nvenc option would be better at this point.
>> 
> 
> So would this be suitable?
> 
> The only thing was that I wasn't sure about exposing these options to ffmpeg 
> though, as they're useless to ffmpeg unless ffmpeg were to add features for 
> dynamically changing the encoded resolutionI just couldn't figure out how 
> you can add a private option that isn't exposed in this way though.
> 

So in the absence of any further feedback I've created a patch.



0001-nvenc-added-support-for-dynamic-resolution-encoding.patch
Description: Binary data

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


Re: [FFmpeg-devel] [PATCH] avformat/mpegtsenc:

2019-03-07 Thread Oliver Collyer

> 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 2/4] lavfi/tonemap: make use of AVFILTER_DEFINE_CLASS

2019-03-07 Thread Michael Niedermayer
On Wed, Mar 06, 2019 at 11:18:25AM +0800, Jun Zhao wrote:
> From: Jun Zhao 
> 
> use AVFILTER_DEFINE_CLASS for defining the filter classes
> 
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/vf_tonemap.c |8 +---
>  1 files changed, 1 insertions(+), 7 deletions(-)

this and similar changes should be ok assuming they change
no value of the struct

thx

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

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


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


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

2019-03-07 Thread Michael Niedermayer
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 
> 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(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
>  
> -/* skip error protection field */
> -if (s->error_protection)
> -skip_bits(&s->gb, 16);
> +if (s->error_protection) {
> +uint16_t crc = get_bits(&s->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, &buf[2], 2);
> +crc_cal = av_crc(crc_tab, crc_cal, &buf[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

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.


signature.asc
Description: PGP signature
___
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-07 Thread Michael Niedermayer
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 
> 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 


> 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

thx

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

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA


signature.asc
Description: PGP signature
___
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-07 Thread James Almer
On 3/7/2019 6:18 PM, Michael Niedermayer wrote:
> 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 
>> 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(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
>>  
>> -/* skip error protection field */
>> -if (s->error_protection)
>> -skip_bits(&s->gb, 16);
>> +if (s->error_protection) {
>> +uint16_t crc = get_bits(&s->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, &buf[2], 2);
>> +crc_cal = av_crc(crc_tab, crc_cal, &buf[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 ?

It depends on the amount of damage. Even a single bit would trigger a
crc mismatch, but be hardly noticeable.

> 
> The behavior which provides the best user experience should be the
> default

If the user enables err_recognition and explode flags, both of which are
currently disabled by default, then aborting on crc failure is the
expected behavior.

> 
> 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
> 
> thx
> 
> [...]
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 

___
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-07 Thread Michael Niedermayer
On Thu, Mar 07, 2019 at 06:32:00PM -0300, James Almer wrote:
> On 3/7/2019 6:18 PM, Michael Niedermayer wrote:
> > 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 
> >> 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(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 
> >> 8);
> >>  
> >> -/* skip error protection field */
> >> -if (s->error_protection)
> >> -skip_bits(&s->gb, 16);
> >> +if (s->error_protection) {
> >> +uint16_t crc = get_bits(&s->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, &buf[2], 2);
> >> +crc_cal = av_crc(crc_tab, crc_cal, &buf[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 ?
> 
> It depends on the amount of damage. Even a single bit would trigger a
> crc mismatch, but be hardly noticeable.

That is misleading
First, in a compressed stream a single bit especially when part of
some header tends to have quite destructive effects on what
follows. Because things downstream depend on the previous stuff in general
I would have to check how much this applies in this case here but it probably
does. I doubt the CRC would be there if it was just protecting bits you can
nilly willy flip and still decode almost ok.

Also single bit errors are probably rather the exception than the rule.
Everything these days has complex error correction, which would never
pass a single bit error either no errors or lots of errors.

Thus its really a question how real damaged files behave here
They could sound better, in which case assuming the testset was representative
that is better.
They could sound worse in which case i think we should look at our error
handling, to make sure it is working correctly and properly concealing detected
errors. And if its all correct then its better not to error out by default
though maybe the extra information can still be usefull to improve the produced
audio.
The 3rd option would be that there are files out there that are undamaged but
have mismatching CRCs this too would be a good reason not to enable this
be default.
In any case real world files are what matter

Also to return to the single bit errors, you can likely correct them with
the CRC if that is against my expectation a common real world scenario




> 
> > 
> > The behavior which provides the best user experience should be the
> > default
> 
> If the user enables err_recognition and explode flags, both of which are
> currently disabled by default, then aborting on crc failure is the
> expected behavior.

yes


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

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing 

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

2019-03-07 Thread Martin Vignali
>> 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

Martin


0001-avcodec-proresenc_aw-fix-interlace-encoding-for-unsa.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-07 Thread Timo Rothenpieler

looks good at first glance, will give it a test this weekend.



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 for vf_fillborders.c – Bug?

2019-03-07 Thread 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
> 

>  .gitignore   |2 
>  libavfilter/vf_fillborders.c |  125 
> ---
>  2 files changed, 63 insertions(+), 64 deletions(-)
> c9197f5c0215e05633f5a09071cc6ba87e74a757  
> vf_fillborders_linesize_in_16-bit.patch
> From f3513f992e0b5595f2644257b92fdea6189592de Mon Sep 17 00:00:00 2001
> From: Ulf Zibis 
> Date: 07.03.2019, 00:34:51
> 
> Correct usage of linesize and width in 16 bit depth routines.
> 

> 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


[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

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


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


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

2019-03-07 Thread Carl Eugen Hoyos
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?


> +av_log(avctx, AV_LOG_VERBOSE,
> +"resolution change: %d x %d -> %d x %d\n",
> +params.reInitEncodeParams.encodeWidth,
> +params.reInitEncodeParams.encodeHeight,

> +(uint32_t)avctx->width,
> +(uint32_t)avctx->height);

These casts look strange and should be unneeded.

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


[FFmpeg-devel] [PATCH] avcodec/clearvideo: Check remaining data in P frames

2019-03-07 Thread Michael Niedermayer
Fixes: Timeout (19sec -> 419msec)
Fixes: 
13411/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-5733153811988480

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

diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c
index ad3012f7b7..82df8f3752 100644
--- a/libavcodec/clearvideo.c
+++ b/libavcodec/clearvideo.c
@@ -555,6 +555,9 @@ static int clv_decode_frame(AVCodecContext *avctx, void 
*data,
 } else {
 int plane;
 
+if (c->pmb_width * c->pmb_height > 8LL*(buf_size - 
bytestream2_tell(&gb)))
+return AVERROR_INVALIDDATA;
+
 if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
 return ret;
 
-- 
2.21.0

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


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

2019-03-07 Thread myp...@gmail.com
On Fri, Mar 8, 2019 at 4:28 AM Michael Niedermayer 
wrote:

> On Thu, Mar 07, 2019 at 09:18:42PM +0100, Michael Niedermayer wrote:
> > On Thu, Mar 07, 2019 at 09:45:12AM +0800, 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 |7 +++
> > >  1 files changed, 7 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> > > index dcb5a03..9876aae 100644
> > > --- a/libavfilter/vf_nlmeans.c
> > > +++ b/libavfilter/vf_nlmeans.c
> > > @@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const
> NLMeansDSPContext *dsp,
> > >  // adjusted end x position of the safe area after width of the
> safe area gets aligned
> > >  const int endx_safe = startx_safe + safe_pw;
> > >
> > > +// 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.
> > > +if ((UINT32_MAX / (uint64_t)w) < (255 * (uint64_t)h))
> > > +av_log(NULL, AV_LOG_WARNING,
> > > +   "image (%d x %d) integral value may overflow.\n", w
> ,h);
> >
> > Printing a warning is not an adequate response for a integer overflow.
> > Such thing is undefined behavior (in case signed of signed int) and must
> > not occur.
>
> And if no signed ints are involved, while this is then not undefined it
> still
> gives the wrong result. Thats a bug, the bug should be fixed not a warning
> be printed that the bug might be triggered
>
> Thanks
>
>
Will give a stricter w * h check for this case, Tks
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/4] lavfi/tonemap: make use of AVFILTER_DEFINE_CLASS

2019-03-07 Thread myp...@gmail.com
On Fri, Mar 8, 2019 at 4:38 AM Michael Niedermayer
 wrote:
>
> On Wed, Mar 06, 2019 at 11:18:25AM +0800, Jun Zhao wrote:
> > From: Jun Zhao 
> >
> > use AVFILTER_DEFINE_CLASS for defining the filter classes
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  libavfilter/vf_tonemap.c |8 +---
> >  1 files changed, 1 insertions(+), 7 deletions(-)
>
> this and similar changes should be ok assuming they change
> no value of the struct
>
> thx
>
Will apply, thx
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2019-03-07 Thread James Zern
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.

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

> +/* 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

> + * ROIs continue working for frames without ROIs.
> + */
> +if (vpx_codec_control(&ctx->encoder, VP8E_SET_ACTIVEMAP, 
> &active_map)) {
> +log_encoder_error(avctx, "Failed to set VP8E_SET_ACTIVEMAP codec 
> control.\n");
> +return AVERROR_INVALIDDATA;
> +}
> +return 0;
> +}
> +
> +memset(&roi_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

> + */
> +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 support %d segments (and segment 0 is 
> reserved for non-ROIs), skipping this one.\n",

supports

> +   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++;
> +}
> +}
> +
> +

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

2019-03-07 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..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);
+
+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(pb);
 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


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

2019-03-07 Thread Oliver Collyer


> On 7 Mar 2019, at 23: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?
> 

It would allocate the output surfaces to this size if we took that approach and 
I don’t think that is particularly sensible given this feature a pretty edge 
use case?

> 
>> +av_log(avctx, AV_LOG_VERBOSE,
>> +"resolution change: %d x %d -> %d x %d\n",
>> +params.reInitEncodeParams.encodeWidth,
>> +params.reInitEncodeParams.encodeHeight,
> 
>> +(uint32_t)avctx->width,
>> +(uint32_t)avctx->height);
> 
> These casts look strange and should be unneeded.
> 

No idea where those came from, I blame my fingers. Will remove.

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

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


Re: [FFmpeg-devel] [PATCH] lavc/h264_levels: add MaxMBPS checking and update fate test.

2019-03-07 Thread Lin, Decai


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Mark Thompson
> Sent: 2019年3月7日 8:24
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/h264_levels: add MaxMBPS
> checking and update fate test.
> 
> On 06/03/2019 08:21, Decai Lin wrote:
> > 1. add MaxMBPS checking for level idc setting to align with AVC spec
> >AnnexA table A-1/A-6 level limits.
> > 2. update h264 level fate test.
> >
> > Signed-off-by: Decai Lin 
> > ---
> >  libavcodec/h264_levels.c   |  5 +
> >  libavcodec/h264_levels.h   |  1 +
> >  libavcodec/h264_metadata_bsf.c | 14 +-
> > libavcodec/tests/h264_levels.c | 41
> > ++---
> >  libavcodec/vaapi_encode_h264.c | 13 +
> >  5 files changed, 70 insertions(+), 4 deletions(-)
> 
> Nice, this is a good idea.  Some comments below.
> 
> > diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c index
> > 7a55116..e457dbe 100644
> > --- a/libavcodec/h264_levels.c
> > +++ b/libavcodec/h264_levels.c
> > @@ -89,11 +89,13 @@ const H264LevelDescriptor *ff_h264_get_level(int
> > level_idc,
> >
> >  const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
> > int64_t bitrate,
> > +   int framerate,
> > int width, int
> height,
> > int
> > max_dec_frame_buffering)  {
> >  int width_mbs  = (width  + 15) / 16;
> >  int height_mbs = (height + 15) / 16;
> > +int64_t mb_processing_rate = (int64_t) (width_mbs * height_mbs *
> > + framerate);
> 
> This doesn't work - if it overflows you've already hit undefined behaviour in
> the calculation before the cast.
> 
> >  int no_cs3f = !(profile_idc == 66 ||
> >  profile_idc == 77 ||
> >  profile_idc == 88); @@ -108,6 +110,9 @@ const
> > H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
> >  if (bitrate > (int64_t)level->max_br *
> h264_get_br_factor(profile_idc))
> >  continue;
> >
> > +if (mb_processing_rate > (int64_t)level->max_mbps)
> > +continue;
> > +
> >  if (width_mbs  * height_mbs > level->max_fs)
> >  continue;
> >  if (width_mbs  * width_mbs  > 8 * level->max_fs) diff --git
> > a/libavcodec/h264_levels.h b/libavcodec/h264_levels.h index
> > 4189fc6..0a0f410 100644
> > --- a/libavcodec/h264_levels.h
> > +++ b/libavcodec/h264_levels.h
> > @@ -46,6 +46,7 @@ const H264LevelDescriptor *ff_h264_get_level(int
> level_idc,
> >   */
> >  const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
> > int64_t bitrate,
> > +   int framerate,
> > int width, int
> height,
> > int
> > max_dec_frame_buffering);
> >
> > diff --git a/libavcodec/h264_metadata_bsf.c
> > b/libavcodec/h264_metadata_bsf.c index a17987a..61c2711 100644
> > --- a/libavcodec/h264_metadata_bsf.c
> > +++ b/libavcodec/h264_metadata_bsf.c
> > @@ -223,6 +223,7 @@ static int
> h264_metadata_update_sps(AVBSFContext *bsf,
> >  const H264LevelDescriptor *desc;
> >  int64_t bit_rate;
> >  int width, height, dpb_frames;
> > +int framerate, fr_num, fr_den;
> >
> >  if (sps->vui.nal_hrd_parameters_present_flag) {
> >  bit_rate =
> > (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) * @@ -244,7
> +245,18 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
> >  height = 16 * (sps->pic_height_in_map_units_minus1 + 1)
> *
> >  (2 - sps->frame_mbs_only_flag);
> >
> > -desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
> > +if (ctx->tick_rate.num > 0 && ctx->tick_rate.den > 0)
> > +av_reduce(&fr_num, &fr_den,
> > +ctx->tick_rate.num, ctx->tick_rate.den,
> 65535);
> > +else
> > +av_reduce(&fr_num, &fr_den,
> > +ctx->tick_rate.den, ctx->tick_rate.num,
> > + 65535);
> 
> Since the VUI fields are set above, I suggest using them instead here because
> that will include an existing rate in the stream.
> 
> Also, the tick rate is only directly usable as fieldrate if 
> fixed_frame_rate_flag
> is set.
> 
> > +if (fr_den > 0)
> > +framerate = fr_num / fr_den;
> > +else
> > +framerate = fr_num;
> 
> I'm not sure what this is trying to do.  If the number isn't valid, the
> framerate should be passed as zero to avoid constraining anything.
> 
> > +
> > +desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
> > + framerate,
> >  

[FFmpeg-devel] [PATCH v2 1/1] lavc/h264_levels: add MaxMBPS checking and update fate test.

2019-03-07 Thread Decai Lin
1. add MaxMBPS checking for level idc setting to align with AVC spec
   AnnexA table A-1/A-6 level limits.
2. update h264 level fate test.

Signed-off-by: Decai Lin 
---
 libavcodec/h264_levels.c   |  6 +
 libavcodec/h264_levels.h   |  1 +
 libavcodec/h264_metadata_bsf.c | 10 +++-
 libavcodec/tests/h264_levels.c | 58 +++---
 libavcodec/vaapi_encode_h264.c |  7 +
 5 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
index 7a55116..7fdb61d 100644
--- a/libavcodec/h264_levels.c
+++ b/libavcodec/h264_levels.c
@@ -89,6 +89,7 @@ const H264LevelDescriptor *ff_h264_get_level(int level_idc,
 
 const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
int64_t bitrate,
+   int framerate,
int width, int height,
int max_dec_frame_buffering)
 {
@@ -116,6 +117,11 @@ const H264LevelDescriptor *ff_h264_guess_level(int 
profile_idc,
 continue;
 
 if (width_mbs && height_mbs) {
+if (framerate > level->max_mbps / (width_mbs * height_mbs))
+continue;
+}
+
+if (width_mbs && height_mbs) {
 int max_dpb_frames =
 FFMIN(level->max_dpb_mbs / (width_mbs * height_mbs), 16);
 if (max_dec_frame_buffering > max_dpb_frames)
diff --git a/libavcodec/h264_levels.h b/libavcodec/h264_levels.h
index 4189fc6..0a0f410 100644
--- a/libavcodec/h264_levels.h
+++ b/libavcodec/h264_levels.h
@@ -46,6 +46,7 @@ const H264LevelDescriptor *ff_h264_get_level(int level_idc,
  */
 const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
int64_t bitrate,
+   int framerate,
int width, int height,
int max_dec_frame_buffering);
 
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index a17987a..4ad9664 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -223,6 +223,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
 const H264LevelDescriptor *desc;
 int64_t bit_rate;
 int width, height, dpb_frames;
+int framerate;
 
 if (sps->vui.nal_hrd_parameters_present_flag) {
 bit_rate = 
(sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
@@ -244,7 +245,14 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
 height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
 (2 - sps->frame_mbs_only_flag);
 
-desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
+if (sps->vui.timing_info_present_flag) {
+framerate = sps->vui.time_scale / sps->vui.num_units_in_tick;
+}
+else {
+framerate = 0;
+}
+
+desc = ff_h264_guess_level(sps->profile_idc, bit_rate, framerate,
width, height, dpb_frames);
 if (desc) {
 level_idc = desc->level_idc;
diff --git a/libavcodec/tests/h264_levels.c b/libavcodec/tests/h264_levels.c
index 0e00f05..1f2c2eb 100644
--- a/libavcodec/tests/h264_levels.c
+++ b/libavcodec/tests/h264_levels.c
@@ -62,6 +62,48 @@ static const struct {
 static const struct {
 int width;
 int height;
+int framerate;
+int level_idc;
+} test_framerate[] = {
+// Some typical sizes and frame rates.
+// (From H.264 table A-1 and table A-6)
+{  176,  144,  15, 10 },
+{  176,  144,  16, 11 },
+{  320,  240,  10, 11 },
+{  320,  240,  20, 12 },
+{  320,  240,  40, 21 },
+{  352,  288,  30, 13 },
+{  352,  288,  51, 22 },
+{  352,  576,  25, 21 },
+{  352,  576,  26, 30 },
+{  640,  480,  33, 30 },
+{  640,  480,  34, 31 },
+{  720,  480,  50, 31 },
+{  720,  576,  25, 30 },
+{  800,  600,  55, 31 },
+{ 1024,  768,  35, 31 },
+{ 1024,  768,  70, 32 },
+{ 1280,  720,  30, 31 },
+{ 1280,  720,  31, 32 },
+{ 1280,  960,  45, 32 },
+{ 1280,  960,  46, 40 },
+{ 1280, 1024,  42, 32 },
+{ 1600, 1200,  32, 40 },
+{ 1600, 1200,  33, 42 },
+{ 1920, 1088,  30, 40 },
+{ 1920, 1088,  55, 42 },
+{ 2048, 1024,  30, 40 },
+{ 2048, 1024,  62, 42 },
+{ 2048, 1088,  60, 42 },
+{ 3680, 1536,  26, 50 },
+{ 4096, 2048,  30, 51 },
+{ 4096, 2048,  59, 52 },
+{ 4096, 2160,  60, 52 },
+};
+
+static const struct {
+int width;
+int height;
 int dpb_size;
 int level_idc;
 } test_dpb[] = {
@@ -147,14 +189,23 @@ int main(void)
 } while (0)
 
 for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
-   

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

2019-03-07 Thread Li, Zhong
> More widely, I would actually suggest to revise existing mediasdk plugins
> loading path and change it from loading plugins at the first place to:
> 1. Try to initialize component directly from the library 2. If #1 fails, try 
> to
> initialize component from the plugin This will allow to avoid a cost of 
> plugins
> loading when you don't actually need to load them and will preserve
> compatibility with the old versions of mediasdk.

That could be a good idea but only based on a query interface, instead of MSDK 
initialization failure. 
There are many reasons may cause the failure but application can't what is the 
exact reason.
I haven't see MFXVideoDECODE_Query() has exposed this, this could be addressed 
if you have a plan to improve MSDK query functions. 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH, v2] lavf/deinterlace_qsv: set specific field for repeat

2019-03-07 Thread Linjie Fu
Set specific field for repeat in PicStruct if the frame has repeat
flag.

Match the CheckInputPicStruct in MSDK.

Fix #7701.

Signed-off-by: Linjie Fu 
---
 libavfilter/vf_deinterlace_qsv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index d6b02e98c5..bee10c220f 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -419,9 +419,11 @@ static int submit_frame(AVFilterContext *ctx, AVFrame 
*frame,
 qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ? 
MFX_PICSTRUCT_PROGRESSIVE :
  (qf->frame->top_field_first ? 
MFX_PICSTRUCT_FIELD_TFF :

MFX_PICSTRUCT_FIELD_BFF);
-if (qf->frame->repeat_pict == 1)
+if (qf->frame->repeat_pict == 1) {
 qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
-else if (qf->frame->repeat_pict == 2)
+qf->surface.Info.PicStruct |= qf->frame->top_field_first ? 
MFX_PICSTRUCT_FIELD_TFF :
+
MFX_PICSTRUCT_FIELD_BFF;
+} else if (qf->frame->repeat_pict == 2)
 qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
 else if (qf->frame->repeat_pict == 4)
 qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
-- 
2.17.1

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


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

2019-03-07 Thread Oliver Collyer


>>> 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?
>> 
> 
> It would allocate the output surfaces to this size if we took that approach 
> and I don’t think that is particularly sensible given this feature a pretty 
> edge use case?
> 
>> 
>>> +av_log(avctx, AV_LOG_VERBOSE,
>>> +"resolution change: %d x %d -> %d x %d\n",
>>> +params.reInitEncodeParams.encodeWidth,
>>> +params.reInitEncodeParams.encodeHeight,
>> 
>>> +(uint32_t)avctx->width,
>>> +(uint32_t)avctx->height);
>> 
>> These casts look strange and should be unneeded.
>> 
> 
> No idea where those came from, I blame my fingers. Will remove.
> 

V2 attached, with cast removed.



0001-avcodec-nvenc-Reconfigure-resolution-on-the-fly.patch
Description: Binary data

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


Re: [FFmpeg-devel] [PATCH, v2] lavf/deinterlace_qsv: set specific field for repeat

2019-03-07 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Linjie Fu
> Sent: Friday, March 8, 2019 11:34 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Fu, Linjie 
> Subject: [FFmpeg-devel] [PATCH, v2] lavf/deinterlace_qsv: set specific field
> for repeat
> 
> Set specific field for repeat in PicStruct if the frame has repeat flag.
> 
> Match the CheckInputPicStruct in MSDK.
> 
> Fix #7701.
> 
> Signed-off-by: Linjie Fu 
> ---
>  libavfilter/vf_deinterlace_qsv.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/vf_deinterlace_qsv.c 
> b/libavfilter/vf_deinterlace_qsv.c
> index d6b02e98c5..bee10c220f 100644
> --- a/libavfilter/vf_deinterlace_qsv.c
> +++ b/libavfilter/vf_deinterlace_qsv.c
> @@ -419,9 +419,11 @@ static int submit_frame(AVFilterContext *ctx,
> AVFrame *frame,
>  qf->surface.Info.PicStruct = !qf->frame->interlaced_frame ?
> MFX_PICSTRUCT_PROGRESSIVE :
>   (qf->frame->top_field_first ?
> MFX_PICSTRUCT_FIELD_TFF :
> 
> MFX_PICSTRUCT_FIELD_BFF);
> -if (qf->frame->repeat_pict == 1)
> +if (qf->frame->repeat_pict == 1) {
>  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
> -else if (qf->frame->repeat_pict == 2)
> +qf->surface.Info.PicStruct |= qf->frame->top_field_first ?
> MFX_PICSTRUCT_FIELD_TFF :
> +
> MFX_PICSTRUCT_FIELD_BFF;
> +} else if (qf->frame->repeat_pict == 2)
>  qf->surface.Info.PicStruct |=
> MFX_PICSTRUCT_FRAME_DOUBLING;
>  else if (qf->frame->repeat_pict == 4)
>  qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
> --
> 2.17.1

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