[FFmpeg-devel] [PATCH] avfilter/vf_fade: fix start/duration max value

2018-11-11 Thread Mark Harris
A fade out (usually at the end of a video) can easily start beyond
INT32_MAX (about 36 minutes).  Regression since d40dc64173.
---
 libavfilter/vf_fade.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c
index c30c41db0d..17eca109b6 100644
--- a/libavfilter/vf_fade.c
+++ b/libavfilter/vf_fade.c
@@ -386,13 +386,13 @@ static const AVOption fade_options[] = {
 OFFSET(nb_frames),   
AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS },
 { "alpha",   "fade alpha if it is available on the input", 
OFFSET(alpha),   AV_OPT_TYPE_BOOL, {.i64 = 0}, 0,   1, FLAGS },
 { "start_time",  "Number of seconds of the beginning of the effect.",
-OFFSET(start_time),  
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS },
+OFFSET(start_time),  
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS },
 { "st",  "Number of seconds of the beginning of the effect.",
-OFFSET(start_time),  
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS },
+OFFSET(start_time),  
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS },
 { "duration","Duration of the effect in seconds.",
-OFFSET(duration),
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS },
+OFFSET(duration),
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS },
 { "d",   "Duration of the effect in seconds.",
-OFFSET(duration),
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT32_MAX, FLAGS },
+OFFSET(duration),
AV_OPT_TYPE_DURATION, {.i64 = 0. }, 0, INT64_MAX, FLAGS },
 { "color",   "set color",   OFFSET(color_rgba),  
AV_OPT_TYPE_COLOR,{.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
 { "c",   "set color",   OFFSET(color_rgba),  
AV_OPT_TYPE_COLOR,{.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
 { NULL }
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Add support for per-stream container type selection.

2018-11-11 Thread Jeyapal, Karthick

On 11/8/18 10:27 PM, Andrey Semashev wrote:
> This commit restores the ability to create DASH streams with codecs
> that require different containers that was lost after commit
> 2efdbf7367989cf9d296c25fa3d2aff8d6e25fdd. It extends the dash_segment_type
> option syntax to allow to specify segment container types for individual
> streams, in addition to the default container type that is applied to
> all streams. The extended syntax is backward compatible with the previous
> syntax.
Thanks for sending the patch. I understand your requirement completely.
But I feel that this option for mapping streams with container format is little 
confusing. Also, the relevant code is relatively big, and thus difficult to 
maintain in future.
I have a middle ground suggestion. If your goal is to achieve the earlier 
behavior broken commits, then I propose the following.
Option "dash_segment_type" could take one more option "auto" (instead of mp4 or 
webm).
When "auto" is chosen, the muxer could choose webm format for VP8, VP9, vorbis, 
opus streams and mp4 format for all other streams. 
In this method the previous behavior of dashenc muxer could be restored with 
little addition to the overall code. Also it's usage will be simpler and easier 
to understand.
> ---
>  doc/muxers.texi   |   8 ++-
>  libavformat/dashenc.c | 161 +++---
>  2 files changed, 140 insertions(+), 29 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 62f4091e31..4418b38c76 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -289,8 +289,12 @@ Set container format (mp4/webm) options using a @code{:} 
> separated list of
>  key=value parameters. Values containing @code{:} special characters must be
>  escaped.
>  
> -@item dash_segment_type @var{dash_segment_type}
> -Possible values:
> +@item -dash_segment_type @var{dash_segment_type}
> +Sets the container type for dash segment files. Syntax is " 
> :a,b,c :d,e" where  is
> +the container type and a, b, c, d and e are the indices of the mapped 
> streams. When no indices are specified,
> +the container type is set for all streams.
> +
> +Possible container type values:
>  @item mp4
>  If this flag is set, the dash segment files will be in in ISOBMFF format. 
> This is the default format.
>  
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index f8b3d106d5..626dc76413 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -84,6 +84,8 @@ typedef struct OutputStream {
>  int64_t first_pts, start_pts, max_pts;
>  int64_t last_dts, last_pts;
>  int bit_rate;
> +SegmentType segment_type;
> +const char *format_name;
>  
>  char codec_str[100];
>  int written_len;
> @@ -131,8 +133,7 @@ typedef struct DASHContext {
>  int64_t timeout;
>  int index_correction;
>  char *format_options_str;
> -SegmentType segment_type;
> -const char *format_name;
> +const char *segment_types_str;
>  } DASHContext;
>  
>  static struct codec_string {
> @@ -188,14 +189,6 @@ static void dashenc_io_close(AVFormatContext *s, 
> AVIOContext **pb, char *filenam
>  }
>  }
>  
> -static const char *get_format_str(SegmentType segment_type) {
> -int i;
> -for (i = 0; i < SEGMENT_TYPE_NB; i++)
> -if (formats[i].segment_type == segment_type)
> -return formats[i].str;
> -return NULL;
> -}
> -
>  static int check_file_extension(const char *filename, const char *extension) 
> {
>  char *dot;
>  if (!filename || !extension)
> @@ -375,6 +368,8 @@ static void dash_free(AVFormatContext *s)
>  c->nb_as = 0;
>  }
>  
> +av_freep(>segment_types_str);
> +
>  if (!c->streams)
>  return;
>  for (i = 0; i < s->nb_streams; i++) {
> @@ -621,13 +616,13 @@ static int write_adaptation_set(AVFormatContext *s, 
> AVIOContext *out, int as_ind
>  if (as->media_type == AVMEDIA_TYPE_VIDEO) {
>  AVStream *st = s->streams[i];
>  avio_printf(out, "\t\t\t mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
> -i, c->format_name, os->codec_str, bandwidth_str, 
> s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
> +i, os->format_name, os->codec_str, bandwidth_str, 
> s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
>  if (st->avg_frame_rate.num)
>  avio_printf(out, " frameRate=\"%d/%d\"", 
> st->avg_frame_rate.num, st->avg_frame_rate.den);
>  avio_printf(out, ">\n");
>  } else {
>  avio_printf(out, "\t\t\t mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
> -i, c->format_name, os->codec_str, bandwidth_str, 
> s->streams[i]->codecpar->sample_rate);
> +i, os->format_name, os->codec_str, bandwidth_str, 
> s->streams[i]->codecpar->sample_rate);
>  avio_printf(out, "\t\t\t\t 

Re: [FFmpeg-devel] [PATCH] fate: Add test for vc1test demuxer

2018-11-11 Thread myp...@gmail.com
On Wed, Oct 24, 2018 at 11:10 PM Jun Zhao  wrote:
>
> Signed-off-by: Jun Zhao 
> ---
>  tests/fate/microsoft.mak   |6 ++
>  tests/ref/fate/vc1test_smm0005 |   29 +
>  tests/ref/fate/vc1test_smm0015 |   30 ++
>  3 files changed, 65 insertions(+), 0 deletions(-)
>  create mode 100644 tests/ref/fate/vc1test_smm0005
>  create mode 100644 tests/ref/fate/vc1test_smm0015
>
> diff --git a/tests/fate/microsoft.mak b/tests/fate/microsoft.mak
> index c450c0d..a2c3b62 100644
> --- a/tests/fate/microsoft.mak
> +++ b/tests/fate/microsoft.mak
> @@ -71,6 +71,12 @@ fate-vc1_sa20021: CMD = framecrc -i 
> $(TARGET_SAMPLES)/vc1/SA20021.vc1
>  FATE_VC1-$(CONFIG_VC1_DEMUXER) += fate-vc1_ilaced_twomv
>  fate-vc1_ilaced_twomv: CMD = framecrc -flags +bitexact -i 
> $(TARGET_SAMPLES)/vc1/ilaced_twomv.vc1
>
> +FATE_VC1-$(CONFIG_VC1T_DEMUXER) += fate-vc1test_smm0005
> +fate-vc1test_smm0005: CMD = framecrc -i $(TARGET_SAMPLES)/vc1/SMM0005.rcv
> +
> +FATE_VC1-$(CONFIG_VC1T_DEMUXER) += fate-vc1test_smm0015
> +fate-vc1test_smm0015: CMD = framecrc -i $(TARGET_SAMPLES)/vc1/SMM0015.rcv
> +
>  FATE_VC1-$(CONFIG_MOV_DEMUXER) += fate-vc1-ism
>  fate-vc1-ism: CMD = framecrc -i $(TARGET_SAMPLES)/isom/vc1-wmapro.ism -an
>
> diff --git a/tests/ref/fate/vc1test_smm0005 b/tests/ref/fate/vc1test_smm0005
> new file mode 100644
> index 000..670dd8d
> --- /dev/null
> +++ b/tests/ref/fate/vc1test_smm0005
> @@ -0,0 +1,29 @@
> +#tb 0: 1/1
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 720x480
> +#sar 0: 0/1
> +0,  0,  0,1,   518400, 0xfc2e6c0f
> +0,  1,  1,1,   518400, 0xb6fa68ba
> +0,  2,  2,1,   518400, 0x0c13a4c9
> +0,  3,  3,1,   518400, 0x351e940d
> +0,  4,  4,1,   518400, 0x07ad35cb
> +0,  5,  5,1,   518400, 0x0c2b1413
> +0,  6,  6,1,   518400, 0xf770b86b
> +0,  7,  7,1,   518400, 0xb1ec5f47
> +0,  8,  8,1,   518400, 0xee591da8
> +0,  9,  9,1,   518400, 0x18046c55
> +0, 10, 10,1,   518400, 0xcfe7bb62
> +0, 11, 11,1,   518400, 0x260e7ecd
> +0, 12, 12,1,   518400, 0x3a3034cc
> +0, 13, 13,1,   518400, 0xee7800dd
> +0, 14, 14,1,   518400, 0xdc4176b4
> +0, 15, 15,1,   518400, 0x7bb037db
> +0, 16, 16,1,   518400, 0x4d4721d1
> +0, 17, 17,1,   518400, 0xbd5cc3b4
> +0, 18, 18,1,   518400, 0x678acc34
> +0, 19, 19,1,   518400, 0xb3ffba44
> +0, 20, 20,1,   518400, 0xda9ebefb
> +0, 21, 21,1,   518400, 0xb810bc59
> +0, 22, 22,1,   518400, 0xc79fc02d
> +0, 23, 23,1,   518400, 0x28d9ad0d
> \ No newline at end of file
> diff --git a/tests/ref/fate/vc1test_smm0015 b/tests/ref/fate/vc1test_smm0015
> new file mode 100644
> index 000..3183d6b
> --- /dev/null
> +++ b/tests/ref/fate/vc1test_smm0015
> @@ -0,0 +1,30 @@
> +#tb 0: 1/25
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 720x576
> +#sar 0: 0/1
> +0,  0,  0,1,   622080, 0x68c84e70
> +0,  1,  1,1,   622080, 0xc29f7155
> +0,  2,  2,1,   622080, 0x78900210
> +0,  3,  3,1,   622080, 0x4d44c353
> +0,  4,  4,1,   622080, 0xd230b3dd
> +0,  5,  5,1,   622080, 0xd72a029c
> +0,  6,  6,1,   622080, 0xc76acb50
> +0,  7,  7,1,   622080, 0xf90816ab
> +0,  8,  8,1,   622080, 0x56996b77
> +0,  9,  9,1,   622080, 0x1784890f
> +0, 10, 10,1,   622080, 0xbc4c81f2
> +0, 11, 11,1,   622080, 0xab5f02ac
> +0, 12, 12,1,   622080, 0x539bb59c
> +0, 13, 13,1,   622080, 0xa34bf120
> +0, 14, 14,1,   622080, 0xa671eaac
> +0, 15, 15,1,   622080, 0x51d77a74
> +0, 16, 16,1,   622080, 0x6d15c7b0
> +0, 17, 17,1,   622080, 0x1bf7535a
> +0, 18, 18,1,   622080, 0x8ed2e73c
> +0, 19, 19,1,   622080, 0x9f4f86a6
> +0, 20, 20,1,   622080, 0x95e05b22
> +0, 21, 21,1,   622080, 0x29c570a0
> +0, 22, 22,1,   622080, 0xc612f057
> +0, 23, 23,1,   622080, 0xe782d106
> +0, 24, 24,1,   622080, 0xeee9a3b7
> --
> 1.7.1
>
Will push the patch, now the test clips have been updated to fate
server by Micheal. 

Re: [FFmpeg-devel] [PATCH] vaapi_encode: fix slices number check.

2018-11-11 Thread myp...@gmail.com
On Tue, Oct 30, 2018 at 1:25 PM Jun Zhao  wrote:
>
> fix slice number check logic.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/vaapi_encode.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 2fe8501..bf8f37b 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1571,7 +1571,7 @@ static av_cold int 
> vaapi_encode_init_slice_structure(AVCodecContext *avctx)
>  return AVERROR(EINVAL);
>  }
>
> -if (ctx->nb_slices > avctx->slices) {
> +if (ctx->nb_slices < avctx->slices) {
>  av_log(avctx, AV_LOG_WARNING, "Slice count rounded up to "
> "%d (from %d) due to driver constraints on slice "
> "structure.\n", ctx->nb_slices, avctx->slices);
> --
> 1.7.1
>
Ping ?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH V2 1/3] fftools/ffmpeg: Remove the micor like "#if 1"

2018-11-11 Thread myp...@gmail.com
On Sun, Nov 11, 2018 at 4:47 AM Michael Niedermayer
 wrote:
>
> On Fri, Nov 09, 2018 at 09:11:31PM +0800, Jun Zhao wrote:
> > They are come from 2003 and delete them.
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  fftools/ffmpeg.c |6 --
> >  1 files changed, 0 insertions(+), 6 deletions(-)
>
> LGTM
>
> thx
>
Thanks the review, pushed
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH V2 2/3] fftools/ffmpeg: Put the variable declaration at uppper for block.

2018-11-11 Thread myp...@gmail.com
On Fri, Nov 9, 2018 at 11:11 PM Carl Eugen Hoyos  wrote:
>
> 2018-11-09 14:11 GMT+01:00, Jun Zhao :
> > move the variable declaration at start of upper for block and
> > remove the redundant brace.
>
> Why?
>
> (You never had to use git blame and were unhappy about the
> necessary iterations?)
>
> No objections here, Carl Eugen

I am always confused with this brace and the coding style in this
part, this is the reason why I try to remove the brace.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] cbs_h2645: Improve performance of writing slices

2018-11-11 Thread Mark Thompson
On 11/11/18 22:43, Andreas Rheinhardt wrote:
> Instead of using a combination of bitreader and -writer for copying data,
> one can byte-align the (obsolete and removed) bitreader to improve 
> performance.
> With the right alignment one can even use memcpy. The right alignment
> normally exists for CABAC and hence for H.265 in general.
> For aligned data this reduced the time to copy the slicedata from
> 776520 decicycles to 33889 with 262144 runs and a 6.5mb/s H.264 video.
> For unaligned data the number went down from 279196 to 97739 decicycles.
> ---
>  libavcodec/cbs_h2645.c | 119 -
>  1 file changed, 69 insertions(+), 50 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index e55bd00183..416d3fd32a 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1050,6 +1050,64 @@ static int 
> cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
>  return 0;
>  }
>  
> +static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx,
> +  PutBitContext *pbc, const uint8_t 
> *data,
> +  size_t data_size, int data_bit_start)
> +{
> +size_t rest  = data_size - (data_bit_start + 7) / 8;
> +const uint8_t *pos = data + data_bit_start / 8;
> +
> +av_assert0(data_bit_start >= 0 &&
> +   8 * data_size > data_bit_start);
> +
> +if (data_size * 8 + 8 > put_bits_left(pbc))
> +return AVERROR(ENOSPC);
> +
> +if (!rest)
> +goto rbsp_stop_one_bit;
> +
> +// First copy the remaining bits of the first byte
> +// The above check ensures that we do not accidentally
> +// copy beyond the rbsp_stop_one_bit.
> +if (data_bit_start % 8)
> +put_bits(pbc, 8 - data_bit_start % 8,
> +*pos++ & MAX_UINT_BITS(8 - data_bit_start % 8));
> +
> +if (put_bits_count(pbc) % 8 == 0) {
> +// If the writer is aligned at this point,
> +// memcpy can be used to improve performance.
> +// This happens normally for CABAC.
> +flush_put_bits(pbc);
> +memcpy(put_bits_ptr(pbc), pos, rest);
> +skip_put_bytes(pbc, rest);
> +} else {
> +// If not, we have to copy manually.
> +// rbsp_stop_one_bit forces us to special-case
> +// the last byte.
> +uint8_t temp;
> +int i;
> +
> +for (; rest > 4; rest -= 4, pos += 4)
> +put_bits32(pbc, AV_RB32(pos));
> +
> +for (; rest > 1; rest--, pos++)
> +put_bits(pbc, 8, *pos);
> +
> +rbsp_stop_one_bit:
> +temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8);
> +
> +av_assert0(temp);
> +i = ff_ctz(*pos);
> +temp = temp >> i;
> +i = rest ? (8 - i) : (8 - i - data_bit_start % 8);
> +put_bits(pbc, i, temp);
> +if (put_bits_count(pbc) % 8)
> +put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0U);
> +}
> +
> +return 0;
> +}
> +
>  static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
> CodedBitstreamUnit *unit,
> PutBitContext *pbc)
> @@ -1100,37 +1158,17 @@ static int 
> cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
>  case H264_NAL_AUXILIARY_SLICE:
>  {
>  H264RawSlice *slice = unit->content;
> -GetBitContext gbc;
> -int bits_left, end, zeroes;
>  
>  err = cbs_h264_write_slice_header(ctx, pbc, >header);
>  if (err < 0)
>  return err;
>  
>  if (slice->data) {
> -if (slice->data_size * 8 + 8 > put_bits_left(pbc))
> -return AVERROR(ENOSPC);
> -
> -init_get_bits(, slice->data, slice->data_size * 8);
> -skip_bits_long(, slice->data_bit_start);
> -
> -// Copy in two-byte blocks, but stop before copying the
> -// rbsp_stop_one_bit in the final byte.
> -while (get_bits_left() > 23)
> -put_bits(pbc, 16, get_bits(, 16));
> -
> -bits_left = get_bits_left();
> -end = get_bits(, bits_left);
> -
> -// rbsp_stop_one_bit must be present here.
> -av_assert0(end);
> -zeroes = ff_ctz(end);
> -if (bits_left > zeroes + 1)
> -put_bits(pbc, bits_left - zeroes - 1,
> - end >> (zeroes + 1));
> -put_bits(pbc, 1, 1);
> -while (put_bits_count(pbc) % 8 != 0)
> -put_bits(pbc, 1, 0);
> +err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
> + slice->data_size,
> + slice->data_bit_start);
> +if (err < 0)
> +return err;
>  } 

[FFmpeg-devel] [PATCH] cbs_h2645: Improve performance of writing slices

2018-11-11 Thread Andreas Rheinhardt
Instead of using a combination of bitreader and -writer for copying data,
one can byte-align the (obsolete and removed) bitreader to improve performance.
With the right alignment one can even use memcpy. The right alignment
normally exists for CABAC and hence for H.265 in general.
For aligned data this reduced the time to copy the slicedata from
776520 decicycles to 33889 with 262144 runs and a 6.5mb/s H.264 video.
For unaligned data the number went down from 279196 to 97739 decicycles.
---
 libavcodec/cbs_h2645.c | 119 -
 1 file changed, 69 insertions(+), 50 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e55bd00183..416d3fd32a 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1050,6 +1050,64 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 return 0;
 }
 
+static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx,
+  PutBitContext *pbc, const uint8_t *data,
+  size_t data_size, int data_bit_start)
+{
+size_t rest  = data_size - (data_bit_start + 7) / 8;
+const uint8_t *pos = data + data_bit_start / 8;
+
+av_assert0(data_bit_start >= 0 &&
+   8 * data_size > data_bit_start);
+
+if (data_size * 8 + 8 > put_bits_left(pbc))
+return AVERROR(ENOSPC);
+
+if (!rest)
+goto rbsp_stop_one_bit;
+
+// First copy the remaining bits of the first byte
+// The above check ensures that we do not accidentally
+// copy beyond the rbsp_stop_one_bit.
+if (data_bit_start % 8)
+put_bits(pbc, 8 - data_bit_start % 8,
+*pos++ & MAX_UINT_BITS(8 - data_bit_start % 8));
+
+if (put_bits_count(pbc) % 8 == 0) {
+// If the writer is aligned at this point,
+// memcpy can be used to improve performance.
+// This happens normally for CABAC.
+flush_put_bits(pbc);
+memcpy(put_bits_ptr(pbc), pos, rest);
+skip_put_bytes(pbc, rest);
+} else {
+// If not, we have to copy manually.
+// rbsp_stop_one_bit forces us to special-case
+// the last byte.
+uint8_t temp;
+int i;
+
+for (; rest > 4; rest -= 4, pos += 4)
+put_bits32(pbc, AV_RB32(pos));
+
+for (; rest > 1; rest--, pos++)
+put_bits(pbc, 8, *pos);
+
+rbsp_stop_one_bit:
+temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8);
+
+av_assert0(temp);
+i = ff_ctz(*pos);
+temp = temp >> i;
+i = rest ? (8 - i) : (8 - i - data_bit_start % 8);
+put_bits(pbc, i, temp);
+if (put_bits_count(pbc) % 8)
+put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0U);
+}
+
+return 0;
+}
+
 static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
CodedBitstreamUnit *unit,
PutBitContext *pbc)
@@ -1100,37 +1158,17 @@ static int 
cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
 case H264_NAL_AUXILIARY_SLICE:
 {
 H264RawSlice *slice = unit->content;
-GetBitContext gbc;
-int bits_left, end, zeroes;
 
 err = cbs_h264_write_slice_header(ctx, pbc, >header);
 if (err < 0)
 return err;
 
 if (slice->data) {
-if (slice->data_size * 8 + 8 > put_bits_left(pbc))
-return AVERROR(ENOSPC);
-
-init_get_bits(, slice->data, slice->data_size * 8);
-skip_bits_long(, slice->data_bit_start);
-
-// Copy in two-byte blocks, but stop before copying the
-// rbsp_stop_one_bit in the final byte.
-while (get_bits_left() > 23)
-put_bits(pbc, 16, get_bits(, 16));
-
-bits_left = get_bits_left();
-end = get_bits(, bits_left);
-
-// rbsp_stop_one_bit must be present here.
-av_assert0(end);
-zeroes = ff_ctz(end);
-if (bits_left > zeroes + 1)
-put_bits(pbc, bits_left - zeroes - 1,
- end >> (zeroes + 1));
-put_bits(pbc, 1, 1);
-while (put_bits_count(pbc) % 8 != 0)
-put_bits(pbc, 1, 0);
+err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
+ slice->data_size,
+ slice->data_bit_start);
+if (err < 0)
+return err;
 } else {
 // No slice data - that was just the header.
 // (Bitstream may be unaligned!)
@@ -1254,39 +1292,20 @@ static int 
cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
 case HEVC_NAL_CRA_NUT:
 {
 H265RawSlice *slice = unit->content;

Re: [FFmpeg-devel] [PATCH 2/3] cbs_h264: Improve performance of writing slices

2018-11-11 Thread Andreas Rheinhardt
I have created a new version that addresses all your concerns. Will send it in 
a moment.
I actually wanted to make a separate function, but decided against it because 
the code already contained the duplication, so I thought that is how you liked 
it.
Thanks for the review. Btw: What was the normal speedup you got when copying in 
the aligned mode?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avcodec : add prores_metadata bsf and fate test

2018-11-11 Thread James Almer
On 11/11/2018 7:20 PM, James Almer wrote:
> On 11/8/2018 6:31 PM, Martin Vignali wrote:
>> Le dim. 28 oct. 2018 à 12:59, Martin Vignali  a
>> écrit :
>>
>>> Thanks for the comments
>>>
>>> New patch in attach
>>>
>>> - Change the options, to only authorized few value in prores frame (based
>>> on rdd36).
>>> - Change option name to match setparams filter
>>> - Include intreadwrite instead of bytestream
>>> - Do not modify the property if set to -1
>>> - Move av_packet_make_writable at the start of the func
>>>
>>> Martin
>>>
>>>
>>>
>> i will pushed in few days, if no one is against.
>>
>> Martin
> 
> This broke fate.
> 
> --- /home/fate/ffmpeg/tests/ref/fate/prores-metadata  2018-11-11
> 20:20:19.486707760 +
> +++ tests/data/fate/prores-metadata   2018-11-11 20:23:35.356712028 +
> @@ -1 +1 @@
> -84814393e25b673e8ebd6a94f3d07349
> +b4e2c801d594b9614433b284b886be0d

Ah, nevermind, i missed you pushed a fix.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avcodec : add prores_metadata bsf and fate test

2018-11-11 Thread James Almer
On 11/8/2018 6:31 PM, Martin Vignali wrote:
> Le dim. 28 oct. 2018 à 12:59, Martin Vignali  a
> écrit :
> 
>> Thanks for the comments
>>
>> New patch in attach
>>
>> - Change the options, to only authorized few value in prores frame (based
>> on rdd36).
>> - Change option name to match setparams filter
>> - Include intreadwrite instead of bytestream
>> - Do not modify the property if set to -1
>> - Move av_packet_make_writable at the start of the func
>>
>> Martin
>>
>>
>>
> i will pushed in few days, if no one is against.
> 
> Martin

This broke fate.

--- /home/fate/ffmpeg/tests/ref/fate/prores-metadata2018-11-11
20:20:19.486707760 +
+++ tests/data/fate/prores-metadata 2018-11-11 20:23:35.356712028 +
@@ -1 +1 @@
-84814393e25b673e8ebd6a94f3d07349
+b4e2c801d594b9614433b284b886be0d
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread Michael Niedermayer
On Sun, Nov 11, 2018 at 10:47:58AM -0300, James Almer wrote:
> On 11/11/2018 8:57 AM, Michael Niedermayer wrote:
> > Hi all
> > 
> > I think we need another volunteer to help with uploading fate samples
> > why i think so, well, if i dont do it it seems to not happen currently
> > until i do it ...
> > This is worsened as james has technical problems with uploads ATM
> > 
> > Do we have anyone who wants to help upload fate samples for contributors?
> 
> There are several people with access to the server for this purpose. If
> i currently can't you shouldn't be the only one left to do it.
> 
> I'm not against asking for new contributors, but try contacting the
> others first and see if they still can take care of uploading a sample
> every other month.

thats what this mail was trying to accomplish while also raising awareness
of the situation and finding out if anyone without an account would volunteer
in case noone with an account would volunteer.

no question i could have serialized this, but yeah that would have been
more work. Trying the easy solution first, if it fails then start asking
people one by one privatly if they can help starting with the ones who have
access already ...

[...]


-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.


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


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread Michael Niedermayer
On Sun, Nov 11, 2018 at 03:47:42PM +0100, Paul B Mahol wrote:
> On 11/11/18, James Almer  wrote:
> > On 11/11/2018 11:01 AM, Paul B Mahol wrote:
> >> On 11/11/18, Michael Niedermayer  wrote:
> >>> Hi all
> >>>
> >>> I think we need another volunteer to help with uploading fate samples
> >>> why i think so, well, if i dont do it it seems to not happen currently
> >>> until i do it ...
> >>> This is worsened as james has technical problems with uploads ATM
> >>>
> >>> Do we have anyone who wants to help upload fate samples for contributors?
> >>>
> >>> What would that person need to do ?
> >>> * Have some time (maybe an hour or 2 a week at average, but this should
> >>> be
> >>>   ideally flexible and available when someone needs a sample uploaded.
> >>> * follow the mailing list to spot patches which require sample uploads
> >>> * Ability to judge if the filesize is reasonable (the file needs to be
> >>>   on every machine testing fate, both users, fate clients, some on VMs,
> >>>   some on low endish ARM boards.
> >>> * Locally apply patches to test if the fate tests using a sample,
> >>> function
> >>>   correctly before uploading. (preferrably on multiple platforms)
> >>> * not mess up fate samples in a way that breaks releases or older
> >>> checkouts
> >>
> >> I think I have account, but I dunno how to use it.
> >
> > https://ffmpeg.org/fate.html Section 4. Make sure to always do a dry run
> > first for both uploading and updating your local folder to make sure
> > only the changes you want will be take effect.
> 
> Thanks, but what is my user name and pass?

user name sent privatly to paul

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

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


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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_freezedetect: add filter to detect frozen input

2018-11-11 Thread Paul B Mahol
On 11/11/18, Marton Balint  wrote:
> Signed-off-by: Marton Balint 
> ---
>  Changelog |   1 +
>  configure |   1 +
>  doc/filters.texi  |  29 +
>  libavfilter/Makefile  |   1 +
>  libavfilter/allfilters.c  |   1 +
>  libavfilter/version.h |   2 +-
>  libavfilter/vf_freezedetect.c | 282
> ++
>  7 files changed, 316 insertions(+), 1 deletion(-)
>  create mode 100644 libavfilter/vf_freezedetect.c
>
> diff --git a/Changelog b/Changelog
> index e38a607025..0eba82b477 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
>  version :
>  - tpad filter
>  - AV1 decoding support through libdav1d
> +- freezedetect filter
>
>
>  version 4.1:
> diff --git a/configure b/configure
> index b02b4ccb2e..e42957ba9d 100755
> --- a/configure
> +++ b/configure
> @@ -3402,6 +3402,7 @@ firequalizer_filter_deps="avcodec"
>  firequalizer_filter_select="rdft"
>  flite_filter_deps="libflite"
>  framerate_filter_select="scene_sad"
> +freezedetect_filter_select="scene_sad"
>  frei0r_filter_deps="frei0r libdl"
>  frei0r_src_filter_deps="frei0r libdl"
>  fspp_filter_deps="gpl"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index fb1dd8f353..bdc9aca2dd 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -10016,6 +10016,35 @@ Select frame after every @code{step} frames.
>  Allowed values are positive integers higher than 0. Default value is
> @code{1}.
>  @end table
>
> +@section freezedetect
> +
> +Detect frozen video.
> +
> +This filter logs a message and sets frame metadata when it detects that the
> +input video has no significant change in content during a specified
> duration.
> +Video freeze detection calculates the mean average absolute difference of
> all
> +the components of video frames and compares it to a noise floor.
> +
> +The printed times and duration are expressed in seconds. The
> +@code{lavfi.freezedetect.freeze_start} metadata key is set on the first
> frame
> +whose timestamp equals or exceeds the detection duration and it contains
> the
> +timstamp of the first frame of the freeze. The
> +@code{lavfi.freezedetect.freeze_duration} and
> +@code{lavfi.freezedetect.freeze_end} metadata keys are set on the first
> frame
> +after the freeze.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +@item noise, n
> +Set noise tolerance. Can be specified in dB (in case "dB" is appended to
> the
> +specified value) or as a difference ratio between 0 and 1. Default is
> -60dB, or
> +0.001.
> +
> +@item duration, d
> +Set freeze duration until notification (default is 2 seconds).
> +@end table
> +
>  @anchor{frei0r}
>  @section frei0r
>
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 7c6fc836e5..30a8b8f921 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -236,6 +236,7 @@ OBJS-$(CONFIG_FPS_FILTER)+= vf_fps.o
>  OBJS-$(CONFIG_FRAMEPACK_FILTER)  += vf_framepack.o
>  OBJS-$(CONFIG_FRAMERATE_FILTER)  += vf_framerate.o
>  OBJS-$(CONFIG_FRAMESTEP_FILTER)  += vf_framestep.o
> +OBJS-$(CONFIG_FREEZEDETECT_FILTER)   += vf_freezedetect.o
>  OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
>  OBJS-$(CONFIG_FSPP_FILTER)   += vf_fspp.o
>  OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 484b080dea..f0f0521dee 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -222,6 +222,7 @@ extern AVFilter ff_vf_fps;
>  extern AVFilter ff_vf_framepack;
>  extern AVFilter ff_vf_framerate;
>  extern AVFilter ff_vf_framestep;
> +extern AVFilter ff_vf_freezedetect;
>  extern AVFilter ff_vf_frei0r;
>  extern AVFilter ff_vf_fspp;
>  extern AVFilter ff_vf_gblur;
> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index 83b18008ce..b4bb8f7bab 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -30,7 +30,7 @@
>  #include "libavutil/version.h"
>
>  #define LIBAVFILTER_VERSION_MAJOR   7
> -#define LIBAVFILTER_VERSION_MINOR  43
> +#define LIBAVFILTER_VERSION_MINOR  44
>  #define LIBAVFILTER_VERSION_MICRO 100
>
>  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c
> new file mode 100644
> index 00..df59eb2134
> --- /dev/null
> +++ b/libavfilter/vf_freezedetect.c
> @@ -0,0 +1,282 @@
> +/*
> + * 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; 

Re: [FFmpeg-devel] [PATCH 2/3] cbs_h264: Improve performance of writing slices

2018-11-11 Thread Mark Thompson
On 04/11/18 04:48, Andreas Rheinhardt wrote:
> Instead of using a combination of bitreader and -writer for copying data,
> one can byte-align the (obsolete and removed) bitreader to improve 
> performance.
> With the right alignment one can even use memcpy. The right alignment
> normally exists for CABAC.
> For aligned data this reduced the time to copy the slicedata from
> 776520 decicycles to 33889 with 262144 runs and a 6.5mb/s H.264 video.
> For unaligned data the number went down from 279196 to 97739 decicycles.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs_h2645.c | 67 +-
>  1 file changed, 46 insertions(+), 21 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index e55bd00183..d3a41fbdf0 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1100,37 +1100,62 @@ static int 
> cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
>  case H264_NAL_AUXILIARY_SLICE:
>  {
>  H264RawSlice *slice = unit->content;
> -GetBitContext gbc;
> -int bits_left, end, zeroes;
>  
>  err = cbs_h264_write_slice_header(ctx, pbc, >header);
>  if (err < 0)
>  return err;
>  
>  if (slice->data) {
> -if (slice->data_size * 8 + 8 > put_bits_left(pbc))
> -return AVERROR(ENOSPC);
> +size_t rest = slice->data_size - (slice->data_bit_start + 7) 
> / 8;
> +uint8_t *pos = slice->data + slice->data_bit_start / 8;
>  
> -init_get_bits(, slice->data, slice->data_size * 8);
> -skip_bits_long(, slice->data_bit_start);
> +av_assert0(slice->data_bit_start >= 0 &&
> +   8 * slice->data_size > slice->data_bit_start);
>  
> -// Copy in two-byte blocks, but stop before copying the
> -// rbsp_stop_one_bit in the final byte.
> -while (get_bits_left() > 23)
> -put_bits(pbc, 16, get_bits(, 16));
> +if (slice->data_size * 8 + 8 > put_bits_left(pbc))
> +return AVERROR(ENOSPC);
>  
> -bits_left = get_bits_left();
> -end = get_bits(, bits_left);
> +if (!rest)
> +goto rbsp_stop_one_bit;
> +
> +// First copy the remaining bits of the first byte
> +// The above check ensures that we do not accidentally
> +// copy beyond the rbsp_stop_one_bit.
> +if (slice->data_bit_start % 8)
> +put_bits(pbc, 8 - slice->data_bit_start % 8,
> +*pos++ & MAX_UINT_BITS(8 - slice->data_bit_start 
> % 8));
> +
> +if (put_bits_count(pbc) % 8 == 0) {
> +// If the writer is aligned at this point,
> +// memcpy can be used to improve performance.
> +// This happens normally for CABAC.
> +flush_put_bits(pbc);
> +memcpy(put_bits_ptr(pbc), pos, rest);
> +skip_put_bytes(pbc, rest);
> +break;

From reading the code I find this break slightly surprising, because it jumps 
out of the switch which is a layer above the code being changed.  I think a 
little rearrangement would avoid it and make the code simpler to understand?  
(Alternatively, the change suggested below would have the same effect.)

> +} else {
> +// If not, we have to copy manually.
> +// rbsp_stop_one_bit forces us to special-case
> +// the last byte.
> +for (; rest > 4; rest -= 4, pos += 4)
> +put_bits32(pbc, AV_RB32(pos));
> +
> +for (; rest > 1; rest--, pos++)
> +put_bits(pbc, 8, *pos);
> +}
>  
> -// rbsp_stop_one_bit must be present here.
> -av_assert0(end);
> -zeroes = ff_ctz(end);
> -if (bits_left > zeroes + 1)
> -put_bits(pbc, bits_left - zeroes - 1,
> - end >> (zeroes + 1));
> -put_bits(pbc, 1, 1);
> -while (put_bits_count(pbc) % 8 != 0)
> -put_bits(pbc, 1, 0);
> +rbsp_stop_one_bit: {
> +int i;
> +uint8_t temp = rest ? *pos : *pos & MAX_UINT_BITS(8 -
> + slice->data_bit_start % 8);
> +av_assert0(temp);
> +i = ff_ctz(*pos);
> +temp = temp >> i;
> +i = rest ? (8 - i) : (8 - i - slice->data_bit_start % 8);
> +put_bits(pbc, i, temp);
> +if (put_bits_count(pbc) % 8)
> +  

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_bwdif: Use common yadif frame management logic

2018-11-11 Thread Philip Langdale
After adding field type management to the common yadif logic, we can
remove the duplicate copy of that logic from bwdif.
---
 libavfilter/bwdif.h |  34 +
 libavfilter/vf_bwdif.c  | 235 +---
 libavfilter/x86/vf_bwdif_init.c |   3 +-
 3 files changed, 41 insertions(+), 231 deletions(-)

diff --git a/libavfilter/bwdif.h b/libavfilter/bwdif.h
index 8b42c760a0..889ff772ed 100644
--- a/libavfilter/bwdif.h
+++ b/libavfilter/bwdif.h
@@ -21,36 +21,10 @@
 
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
-
-enum BWDIFMode {
-BWDIF_MODE_SEND_FRAME = 0, ///< send 1 frame for each frame
-BWDIF_MODE_SEND_FIELD = 1, ///< send 1 frame for each field
-};
-
-enum BWDIFParity {
-BWDIF_PARITY_TFF  =  0, ///< top field first
-BWDIF_PARITY_BFF  =  1, ///< bottom field first
-BWDIF_PARITY_AUTO = -1, ///< auto detection
-};
-
-enum BWDIFDeint {
-BWDIF_DEINT_ALL= 0, ///< deinterlace all frames
-BWDIF_DEINT_INTERLACED = 1, ///< only deinterlace frames marked as 
interlaced
-};
+#include "yadif.h"
 
 typedef struct BWDIFContext {
-const AVClass *class;
-
-int mode;   ///< BWDIFMode
-int parity; ///< BWDIFParity
-int deint;  ///< BWDIFDeint
-
-int frame_pending;
-
-AVFrame *cur;
-AVFrame *next;
-AVFrame *prev;
-AVFrame *out;
+YADIFContext yadif;
 
 void (*filter_intra)(void *dst1, void *cur1, int w, int prefs, int mrefs,
  int prefs3, int mrefs3, int parity, int clip_max);
@@ -61,10 +35,6 @@ typedef struct BWDIFContext {
 void (*filter_edge)(void *dst, void *prev, void *cur, void *next,
 int w, int prefs, int mrefs, int prefs2, int mrefs2,
 int parity, int clip_max, int spat);
-
-const AVPixFmtDescriptor *csp;
-int inter_field;
-int eof;
 } BWDIFContext;
 
 void ff_bwdif_init_x86(BWDIFContext *bwdif);
diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c
index b691983611..37165584cf 100644
--- a/libavfilter/vf_bwdif.c
+++ b/libavfilter/vf_bwdif.c
@@ -216,10 +216,11 @@ static void filter_edge_16bit(void *dst1, void *prev1, 
void *cur1, void *next1,
 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
 {
 BWDIFContext *s = ctx->priv;
+YADIFContext *yadif = >yadif;
 ThreadData *td  = arg;
-int linesize = s->cur->linesize[td->plane];
-int clip_max = (1 << (s->csp->comp[td->plane].depth)) - 1;
-int df = (s->csp->comp[td->plane].depth + 7) / 8;
+int linesize = yadif->cur->linesize[td->plane];
+int clip_max = (1 << (yadif->csp->comp[td->plane].depth)) - 1;
+int df = (yadif->csp->comp[td->plane].depth + 7) / 8;
 int refs = linesize / df;
 int slice_start = (td->h *  jobnr   ) / nb_jobs;
 int slice_end   = (td->h * (jobnr+1)) / nb_jobs;
@@ -227,11 +228,11 @@ static int filter_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs)
 
 for (y = slice_start; y < slice_end; y++) {
 if ((y ^ td->parity) & 1) {
-uint8_t *prev = >prev->data[td->plane][y * linesize];
-uint8_t *cur  = >cur ->data[td->plane][y * linesize];
-uint8_t *next = >next->data[td->plane][y * linesize];
+uint8_t *prev = >prev->data[td->plane][y * linesize];
+uint8_t *cur  = >cur ->data[td->plane][y * linesize];
+uint8_t *next = >next->data[td->plane][y * linesize];
 uint8_t *dst  = >frame->data[td->plane][y * 
td->frame->linesize[td->plane]];
-if (!s->inter_field) {
+if (yadif->current_field == YADIF_FIELD_END) {
 s->filter_intra(dst, cur, td->w, (y + df) < td->h ? refs : 
-refs,
 y > (df - 1) ? -refs : refs,
 (y + 3*df) < td->h ? 3 * refs : -refs,
@@ -252,7 +253,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs)
 }
 } else {
 memcpy(>frame->data[td->plane][y * 
td->frame->linesize[td->plane]],
-   >cur->data[td->plane][y * linesize], td->w * df);
+   >cur->data[td->plane][y * linesize], td->w * df);
 }
 }
 return 0;
@@ -262,16 +263,17 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
int parity, int tff)
 {
 BWDIFContext *bwdif = ctx->priv;
+YADIFContext *yadif = >yadif;
 ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
 int i;
 
-for (i = 0; i < bwdif->csp->nb_components; i++) {
+for (i = 0; i < yadif->csp->nb_components; i++) {
 int w = dstpic->width;
 int h = dstpic->height;
 
 if (i == 1 || i == 2) {
-w = AV_CEIL_RSHIFT(w, bwdif->csp->log2_chroma_w);
-h = AV_CEIL_RSHIFT(h, bwdif->csp->log2_chroma_h);
+w = AV_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w);
+h = AV_CEIL_RSHIFT(h, 

[FFmpeg-devel] [PATCH 1/2] avfilter/yadif_common: Add field type tracking to help bwdif

2018-11-11 Thread Philip Langdale
The bwdif filter can use common yadif frame management if we track
when a field is the first or last field in a sequence. While this
information is not used by yadif, the added benefit of removing the
duplicated frame management logic makes it worth tracking this state
in the common code.
---
 libavfilter/yadif.h| 14 ++
 libavfilter/yadif_common.c | 12 +---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 32d6f4a0d4..c928911b35 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -41,6 +41,12 @@ enum YADIFDeint {
 YADIF_DEINT_INTERLACED = 1, ///< only deinterlace frames marked as 
interlaced
 };
 
+enum YADIFCurrentField {
+YADIF_FIELD_BACK_END = -1, ///< The last frame in a sequence
+YADIF_FIELD_END  =  0, ///< The first or last field in a sequence
+YADIF_FIELD_NORMAL   =  1, ///< A normal field in the middle of a sequence
+};
+
 typedef struct YADIFContext {
 const AVClass *class;
 
@@ -70,6 +76,14 @@ typedef struct YADIFContext {
 int eof;
 uint8_t *temp_line;
 int temp_line_size;
+
+/*
+ * An algorithm that treats first and/or last fields in a sequence
+ * differently can use this to detect those cases. It is the algorithm's
+ * responsibility to set the value to YADIF_FIELD_NORMAL after processing
+ * the first field.
+ */
+int current_field;  ///< YADIFCurrentField
 } YADIFContext;
 
 void ff_yadif_init_x86(YADIFContext *yadif);
diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
index 19e8ac5281..a10cf7a17f 100644
--- a/libavfilter/yadif_common.c
+++ b/libavfilter/yadif_common.c
@@ -44,6 +44,8 @@ static int return_frame(AVFilterContext *ctx, int is_second)
 
 av_frame_copy_props(yadif->out, yadif->cur);
 yadif->out->interlaced_frame = 0;
+if (yadif->current_field == YADIF_FIELD_BACK_END)
+yadif->current_field = YADIF_FIELD_END;
 }
 
 yadif->filter(ctx, yadif->out, tff ^ !is_second, tff);
@@ -103,9 +105,12 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame 
*frame)
 yadif->cur  = yadif->next;
 yadif->next = frame;
 
-if (!yadif->cur &&
-!(yadif->cur = av_frame_clone(yadif->next)))
-return AVERROR(ENOMEM);
+if (!yadif->cur) {
+yadif->cur = av_frame_clone(yadif->next);
+if (!yadif->cur)
+return AVERROR(ENOMEM);
+yadif->current_field = YADIF_FIELD_END;
+}
 
 if (checkstride(yadif, yadif->next, yadif->cur)) {
 av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing 
stride\n");
@@ -173,6 +178,7 @@ int ff_yadif_request_frame(AVFilterLink *link)
 if (!next)
 return AVERROR(ENOMEM);
 
+yadif->current_field = YADIF_FIELD_BACK_END;
 next->pts = yadif->next->pts * 2 - yadif->cur->pts;
 
 ff_yadif_filter_frame(ctx->inputs[0], next);
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 0/2] Update vf_bwdif to use yadif_common v2

2018-11-11 Thread Philip Langdale
vf_bwdif's frame management logic is almost identical to that of yadif.
The only difference is that it tracks the first and last fields in a
sequence, and that requires slight changes to the common code.

Assuming it's reasonable to do that tracking even though yadif doesn't
need it, we can then remove all the duplicated logic.

v2: Rename enum values as recommened by Thomas Mundt.

Philip Langdale (2):
  avfilter/yadif_common: Add field type tracking to help bwdif
  avfilter/vf_bwdif: Use common yadif frame management logic

 libavfilter/bwdif.h |  34 +
 libavfilter/vf_bwdif.c  | 235 +---
 libavfilter/x86/vf_bwdif_init.c |   3 +-
 libavfilter/yadif.h |  14 ++
 libavfilter/yadif_common.c  |  12 +-
 5 files changed, 64 insertions(+), 234 deletions(-)

-- 
2.19.1

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


[FFmpeg-devel] [PATCH] avfilter/vf_freezedetect: add filter to detect frozen input

2018-11-11 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 Changelog |   1 +
 configure |   1 +
 doc/filters.texi  |  29 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/version.h |   2 +-
 libavfilter/vf_freezedetect.c | 282 ++
 7 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/vf_freezedetect.c

diff --git a/Changelog b/Changelog
index e38a607025..0eba82b477 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
 version :
 - tpad filter
 - AV1 decoding support through libdav1d
+- freezedetect filter
 
 
 version 4.1:
diff --git a/configure b/configure
index b02b4ccb2e..e42957ba9d 100755
--- a/configure
+++ b/configure
@@ -3402,6 +3402,7 @@ firequalizer_filter_deps="avcodec"
 firequalizer_filter_select="rdft"
 flite_filter_deps="libflite"
 framerate_filter_select="scene_sad"
+freezedetect_filter_select="scene_sad"
 frei0r_filter_deps="frei0r libdl"
 frei0r_src_filter_deps="frei0r libdl"
 fspp_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index fb1dd8f353..bdc9aca2dd 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10016,6 +10016,35 @@ Select frame after every @code{step} frames.
 Allowed values are positive integers higher than 0. Default value is @code{1}.
 @end table
 
+@section freezedetect
+
+Detect frozen video.
+
+This filter logs a message and sets frame metadata when it detects that the
+input video has no significant change in content during a specified duration.
+Video freeze detection calculates the mean average absolute difference of all
+the components of video frames and compares it to a noise floor.
+
+The printed times and duration are expressed in seconds. The
+@code{lavfi.freezedetect.freeze_start} metadata key is set on the first frame
+whose timestamp equals or exceeds the detection duration and it contains the
+timstamp of the first frame of the freeze. The
+@code{lavfi.freezedetect.freeze_duration} and
+@code{lavfi.freezedetect.freeze_end} metadata keys are set on the first frame
+after the freeze.
+
+The filter accepts the following options:
+
+@table @option
+@item noise, n
+Set noise tolerance. Can be specified in dB (in case "dB" is appended to the
+specified value) or as a difference ratio between 0 and 1. Default is -60dB, or
+0.001.
+
+@item duration, d
+Set freeze duration until notification (default is 2 seconds).
+@end table
+
 @anchor{frei0r}
 @section frei0r
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7c6fc836e5..30a8b8f921 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -236,6 +236,7 @@ OBJS-$(CONFIG_FPS_FILTER)+= vf_fps.o
 OBJS-$(CONFIG_FRAMEPACK_FILTER)  += vf_framepack.o
 OBJS-$(CONFIG_FRAMERATE_FILTER)  += vf_framerate.o
 OBJS-$(CONFIG_FRAMESTEP_FILTER)  += vf_framestep.o
+OBJS-$(CONFIG_FREEZEDETECT_FILTER)   += vf_freezedetect.o
 OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
 OBJS-$(CONFIG_FSPP_FILTER)   += vf_fspp.o
 OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 484b080dea..f0f0521dee 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -222,6 +222,7 @@ extern AVFilter ff_vf_fps;
 extern AVFilter ff_vf_framepack;
 extern AVFilter ff_vf_framerate;
 extern AVFilter ff_vf_framestep;
+extern AVFilter ff_vf_freezedetect;
 extern AVFilter ff_vf_frei0r;
 extern AVFilter ff_vf_fspp;
 extern AVFilter ff_vf_gblur;
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 83b18008ce..b4bb8f7bab 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR   7
-#define LIBAVFILTER_VERSION_MINOR  43
+#define LIBAVFILTER_VERSION_MINOR  44
 #define LIBAVFILTER_VERSION_MICRO 100
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c
new file mode 100644
index 00..df59eb2134
--- /dev/null
+++ b/libavfilter/vf_freezedetect.c
@@ -0,0 +1,282 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * 

Re: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_framerate: factorize SAD functions which compute SAD for a whole frame

2018-11-11 Thread Marton Balint



On Sat, 10 Nov 2018, Marton Balint wrote:



On Sun, 4 Nov 2018, Marton Balint wrote:



On Sun, 4 Nov 2018, James Almer wrote:


On 11/4/2018 9:06 AM, Marton Balint wrote:
Also add SIMD which works on lines because it is faster then calculating 

it on

8x8 blocks using pixelutils.

Signed-off-by: Marton Balint 
---
 configure|  3 +-
 libavfilter/Makefile |  1 +
 libavfilter/framerate.h  |  4 +--
 libavfilter/scene_sad.c  | 72 

++

 libavfilter/scene_sad.h  | 44 
 libavfilter/vf_framerate.c   | 61 -
 libavfilter/x86/Makefile |  4 +++
 libavfilter/x86/scene_sad.asm| 74 



 libavfilter/x86/scene_sad_init.c | 52 
 9 files changed, 257 insertions(+), 58 deletions(-)
 create mode 100644 libavfilter/scene_sad.c
 create mode 100644 libavfilter/scene_sad.h
 create mode 100644 libavfilter/x86/scene_sad.asm
 create mode 100644 libavfilter/x86/scene_sad_init.c

diff --git a/configure b/configure
index 2606b885b0..f5bec9fd62 100755
--- a/configure
+++ b/configure
@@ -2335,6 +2335,7 @@ CONFIG_EXTRA="
 rtpdec
 rtpenc_chain
 rv34dsp
+scene_sad
 sinewin
 snappy
 srtp
@@ -3395,7 +3396,7 @@ find_rect_filter_deps="avcodec avformat gpl"
 firequalizer_filter_deps="avcodec"
 firequalizer_filter_select="rdft"
 flite_filter_deps="libflite"
-framerate_filter_select="pixelutils"
+framerate_filter_select="scene_sad"
 frei0r_filter_deps="frei0r libdl"
 frei0r_src_filter_deps="frei0r libdl"
 fspp_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 51e48efc2e..390c2b7997 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -28,6 +28,7 @@ OBJS-$(HAVE_THREADS) += 

pthread.o

 OBJS-$(CONFIG_QSVVPP)+= qsvvpp.o
 DNN-OBJS-$(CONFIG_LIBTENSORFLOW) += dnn_backend_tf.o
 OBJS-$(CONFIG_DNN)   += dnn_interface.o 

dnn_backend_native.o $(DNN-OBJS-yes)

+OBJS-$(CONFIG_SCENE_SAD) += scene_sad.o

 # audio filters
 OBJS-$(CONFIG_ABENCH_FILTER) += f_bench.o


Can't you expand pixeutils instead? Adding a new set of functions that
work on lines rather than blocks.


That is kind of intentional, because it is only used by libavfilter, so I 
did not want to bloat libavutil with it. Also if I put it into libavutil 
then the interfaces have to be public. I tried to avoid that because for a 
generic scene SAD function bitdepth is not enough, you need endianness, 
float/int color support, etc. Public API should be finalized when 
something actually uses it IMHO.


I plan to push this soon.


Pushed.

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


Re: [FFmpeg-devel] [PATCH 1/3] cbs_mpeg2: Improve performance of writing slices

2018-11-11 Thread Mark Thompson
On 04/11/18 04:48, Andreas Rheinhardt wrote:
> Instead of using a combination of bitreader and -writer for copying data,
> one can byte-align the (obsolete and removed) bitreader to improve 
> performance.
> One can even use memcpy in the normal case.
> This improved the time needed for writing the slicedata from 33618 to
> 2370 decicycles when tested on a video originating from a DVD (4194394
> runs).
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs_mpeg2.c | 39 +++
>  1 file changed, 27 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 0df4234b12..7161f1ee80 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -264,8 +264,6 @@ static int cbs_mpeg2_write_slice(CodedBitstreamContext 
> *ctx,
>   PutBitContext *pbc)
>  {
>  MPEG2RawSlice *slice = unit->content;
> -GetBitContext gbc;
> -size_t bits_left;
>  int err;
>  
>  err = cbs_mpeg2_write_slice_header(ctx, pbc, >header);
> @@ -273,21 +271,38 @@ static int cbs_mpeg2_write_slice(CodedBitstreamContext 
> *ctx,
>  return err;
>  
>  if (slice->data) {
> +size_t rest = slice->data_size - (slice->data_bit_start + 7) / 8;
> +uint8_t *pos = slice->data + slice->data_bit_start / 8;
> +
> +av_assert0(slice->data_bit_start >= 0 &&
> +   8* slice->data_size > slice->data_bit_start);
> +
>  if (slice->data_size * 8 + 8 > put_bits_left(pbc))
>  return AVERROR(ENOSPC);
>  
> -init_get_bits(, slice->data, slice->data_size * 8);
> -skip_bits_long(, slice->data_bit_start);
> -
> -while (get_bits_left() > 15)
> -put_bits(pbc, 16, get_bits(, 16));
> +// First copy the remaining bits of the first byte
> +if (slice->data_bit_start % 8)
> +put_bits(pbc, 8 - slice->data_bit_start % 8,
> +*pos++ & MAX_UINT_BITS(8 - slice->data_bit_start % 8));
> +
> +if (put_bits_count(pbc) % 8 == 0) {
> +// If the writer is aligned at this point,
> +// memcpy can be used to improve performance.
> +// This is the normal case.
> +flush_put_bits(pbc);
> +memcpy(put_bits_ptr(pbc), pos, rest);
> +skip_put_bytes(pbc, rest);
> +} else {
> +// If not, we have to copy manually:
> +for (; rest > 3; rest -= 4, pos += 4)
> +put_bits32(pbc, AV_RB32(pos));
>  
> -bits_left = get_bits_left();
> -put_bits(pbc, bits_left, get_bits(, bits_left));
> +for (; rest; rest--, pos++)
> +put_bits(pbc, 8, *pos);
>  
> -// Align with zeroes.
> -while (put_bits_count(pbc) % 8 != 0)
> -put_bits(pbc, 1, 0);
> +// Align with zeros
> +put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0U);
> +}
>  }
>  
>  return 0;
> 

LGTM, tested and applied.

(I'm not sure that there is much value in handling the case of 
slice->data_bit_start >= 8 since that currently never happens, but I guess it 
worked for the old code so I don't mind the extra complexity.)

Thanks!

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


Re: [FFmpeg-devel] [PATCH v2] cbs_h265: Add a lot more SEI parsing support

2018-11-11 Thread Mark Thompson
On 11/11/18 17:32, James Almer wrote:
> On 11/11/2018 2:27 PM, Mark Thompson wrote:
>> Supports both prefix and suffix SEI, decoding all of the common SEI
>> types and some more obscure ones.  Most of this is tested by the
>> existing tests in fate.
>> ---
>> On 11/11/18 15:57, James Almer wrote:
>>> On 10/27/2018 6:39 PM, Mark Thompson wrote:
 Supports both prefix and suffix SEI, decoding all of the common SEI
 types and some more obscure ones.  Most of this is tested by the
 existing tests in fate.
>>>
>>> It would be neat to make the *_metadata filters not decompose unit types
>>> it doesn't care about (based on user options). Before this patch, all
>>> these SEI messages were simply copied as is, but after it they will be
>>> fully parsed even in pass through mode, potentially slowing down the
>>> process.
>>>
>>> Of course, doing that would make the cbs tests useless. Maybe the
>>> default behavior could be to not decompose what's not going to be
>>> modified, and an option to enable it could be added that the test would use.
>>>
 ---
  libavcodec/cbs_h2645.c|  20 +-
  libavcodec/cbs_h265.h | 124 +++
  libavcodec/cbs_h265_syntax_template.c | 497 +-
  libavcodec/hevc.h |   3 +
  libavcodec/hevc_sei.h |   1 +
  5 files changed, 625 insertions(+), 20 deletions(-)

>>>
 diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
 index e92da25bbf..2fec00ace0 100644
 --- a/libavcodec/hevc_sei.h
 +++ b/libavcodec/hevc_sei.h
 @@ -52,6 +52,7 @@ typedef enum {
  HEVC_SEI_TYPE_DECODED_PICTURE_HASH = 132,
  HEVC_SEI_TYPE_SCALABLE_NESTING = 133,
  HEVC_SEI_TYPE_REGION_REFRESH_INFO  = 134,
 +HEVC_SEI_TYPE_TIME_CODE= 136,
  HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO   = 137,
  HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO = 144,
  HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,
>>>
>>> Adding this one should be trivial, btw. It's a single field, and there
>>> are real world samples out there. Support for it was added to the
>>> decoder some time ago.
>>
>> Sure, here's a v2 with that added.
>>
>> Thanks,
>>
>> - Mark
>>
>>
>>  libavcodec/cbs_h2645.c|  20 +-
>>  libavcodec/cbs_h265.h | 130 +++
>>  libavcodec/cbs_h265_syntax_template.c | 512 +-
>>  libavcodec/hevc.h |   3 +
>>  libavcodec/hevc_sei.h |   1 +
>>  5 files changed, 646 insertions(+), 20 deletions(-)
>>
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index e55bd00183..86baf129ce 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -490,9 +490,21 @@ static void cbs_h265_free_slice(void *unit, uint8_t 
>> *content)
>>  static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
>>  {
>>  switch (payload->payload_type) {
>> +case HEVC_SEI_TYPE_BUFFERING_PERIOD:
>> +case HEVC_SEI_TYPE_PICTURE_TIMING:
>> +case HEVC_SEI_TYPE_PAN_SCAN_RECT:
>> +case HEVC_SEI_TYPE_RECOVERY_POINT:
>> +case HEVC_SEI_TYPE_DISPLAY_ORIENTATION:
>> +case HEVC_SEI_TYPE_DECODED_PICTURE_HASH:
>>  case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
>>  case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
> 
> Shouldn't atc be listed here?

Yes!  And so should active-parameter-sets and time-code.

Added locally.

Thanks,

- Mark

>>  break;
>> +case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
>> +av_buffer_unref(>payload.user_data_registered.data_ref);
>> +break;
>> +case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
>> +av_buffer_unref(>payload.user_data_unregistered.data_ref);
>> +break;
>>  default:
>>  av_buffer_unref(>payload.other.data_ref);
>>  break;
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2] cbs_h265: Add a lot more SEI parsing support

2018-11-11 Thread James Almer
On 11/11/2018 2:27 PM, Mark Thompson wrote:
> Supports both prefix and suffix SEI, decoding all of the common SEI
> types and some more obscure ones.  Most of this is tested by the
> existing tests in fate.
> ---
> On 11/11/18 15:57, James Almer wrote:
>> On 10/27/2018 6:39 PM, Mark Thompson wrote:
>>> Supports both prefix and suffix SEI, decoding all of the common SEI
>>> types and some more obscure ones.  Most of this is tested by the
>>> existing tests in fate.
>>
>> It would be neat to make the *_metadata filters not decompose unit types
>> it doesn't care about (based on user options). Before this patch, all
>> these SEI messages were simply copied as is, but after it they will be
>> fully parsed even in pass through mode, potentially slowing down the
>> process.
>>
>> Of course, doing that would make the cbs tests useless. Maybe the
>> default behavior could be to not decompose what's not going to be
>> modified, and an option to enable it could be added that the test would use.
>>
>>> ---
>>>  libavcodec/cbs_h2645.c|  20 +-
>>>  libavcodec/cbs_h265.h | 124 +++
>>>  libavcodec/cbs_h265_syntax_template.c | 497 +-
>>>  libavcodec/hevc.h |   3 +
>>>  libavcodec/hevc_sei.h |   1 +
>>>  5 files changed, 625 insertions(+), 20 deletions(-)
>>>
>>
>>> diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
>>> index e92da25bbf..2fec00ace0 100644
>>> --- a/libavcodec/hevc_sei.h
>>> +++ b/libavcodec/hevc_sei.h
>>> @@ -52,6 +52,7 @@ typedef enum {
>>>  HEVC_SEI_TYPE_DECODED_PICTURE_HASH = 132,
>>>  HEVC_SEI_TYPE_SCALABLE_NESTING = 133,
>>>  HEVC_SEI_TYPE_REGION_REFRESH_INFO  = 134,
>>> +HEVC_SEI_TYPE_TIME_CODE= 136,
>>>  HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO   = 137,
>>>  HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO = 144,
>>>  HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,
>>
>> Adding this one should be trivial, btw. It's a single field, and there
>> are real world samples out there. Support for it was added to the
>> decoder some time ago.
> 
> Sure, here's a v2 with that added.
> 
> Thanks,
> 
> - Mark
> 
> 
>  libavcodec/cbs_h2645.c|  20 +-
>  libavcodec/cbs_h265.h | 130 +++
>  libavcodec/cbs_h265_syntax_template.c | 512 +-
>  libavcodec/hevc.h |   3 +
>  libavcodec/hevc_sei.h |   1 +
>  5 files changed, 646 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index e55bd00183..86baf129ce 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -490,9 +490,21 @@ static void cbs_h265_free_slice(void *unit, uint8_t 
> *content)
>  static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
>  {
>  switch (payload->payload_type) {
> +case HEVC_SEI_TYPE_BUFFERING_PERIOD:
> +case HEVC_SEI_TYPE_PICTURE_TIMING:
> +case HEVC_SEI_TYPE_PAN_SCAN_RECT:
> +case HEVC_SEI_TYPE_RECOVERY_POINT:
> +case HEVC_SEI_TYPE_DISPLAY_ORIENTATION:
> +case HEVC_SEI_TYPE_DECODED_PICTURE_HASH:
>  case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
>  case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:

Shouldn't atc be listed here?

>  break;
> +case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
> +av_buffer_unref(>payload.user_data_registered.data_ref);
> +break;
> +case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
> +av_buffer_unref(>payload.user_data_unregistered.data_ref);
> +break;
>  default:
>  av_buffer_unref(>payload.other.data_ref);
>  break;
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] cbs_h265: Add a lot more SEI parsing support

2018-11-11 Thread Mark Thompson
Supports both prefix and suffix SEI, decoding all of the common SEI
types and some more obscure ones.  Most of this is tested by the
existing tests in fate.
---
On 11/11/18 15:57, James Almer wrote:
> On 10/27/2018 6:39 PM, Mark Thompson wrote:
>> Supports both prefix and suffix SEI, decoding all of the common SEI
>> types and some more obscure ones.  Most of this is tested by the
>> existing tests in fate.
> 
> It would be neat to make the *_metadata filters not decompose unit types
> it doesn't care about (based on user options). Before this patch, all
> these SEI messages were simply copied as is, but after it they will be
> fully parsed even in pass through mode, potentially slowing down the
> process.
> 
> Of course, doing that would make the cbs tests useless. Maybe the
> default behavior could be to not decompose what's not going to be
> modified, and an option to enable it could be added that the test would use.
> 
>> ---
>>  libavcodec/cbs_h2645.c|  20 +-
>>  libavcodec/cbs_h265.h | 124 +++
>>  libavcodec/cbs_h265_syntax_template.c | 497 +-
>>  libavcodec/hevc.h |   3 +
>>  libavcodec/hevc_sei.h |   1 +
>>  5 files changed, 625 insertions(+), 20 deletions(-)
>>
> 
>> diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
>> index e92da25bbf..2fec00ace0 100644
>> --- a/libavcodec/hevc_sei.h
>> +++ b/libavcodec/hevc_sei.h
>> @@ -52,6 +52,7 @@ typedef enum {
>>  HEVC_SEI_TYPE_DECODED_PICTURE_HASH = 132,
>>  HEVC_SEI_TYPE_SCALABLE_NESTING = 133,
>>  HEVC_SEI_TYPE_REGION_REFRESH_INFO  = 134,
>> +HEVC_SEI_TYPE_TIME_CODE= 136,
>>  HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO   = 137,
>>  HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO = 144,
>>  HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,
> 
> Adding this one should be trivial, btw. It's a single field, and there
> are real world samples out there. Support for it was added to the
> decoder some time ago.

Sure, here's a v2 with that added.

Thanks,

- Mark


 libavcodec/cbs_h2645.c|  20 +-
 libavcodec/cbs_h265.h | 130 +++
 libavcodec/cbs_h265_syntax_template.c | 512 +-
 libavcodec/hevc.h |   3 +
 libavcodec/hevc_sei.h |   1 +
 5 files changed, 646 insertions(+), 20 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e55bd00183..86baf129ce 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -490,9 +490,21 @@ static void cbs_h265_free_slice(void *unit, uint8_t 
*content)
 static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
 {
 switch (payload->payload_type) {
+case HEVC_SEI_TYPE_BUFFERING_PERIOD:
+case HEVC_SEI_TYPE_PICTURE_TIMING:
+case HEVC_SEI_TYPE_PAN_SCAN_RECT:
+case HEVC_SEI_TYPE_RECOVERY_POINT:
+case HEVC_SEI_TYPE_DISPLAY_ORIENTATION:
+case HEVC_SEI_TYPE_DECODED_PICTURE_HASH:
 case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
 case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
 break;
+case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
+av_buffer_unref(>payload.user_data_registered.data_ref);
+break;
+case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
+av_buffer_unref(>payload.user_data_unregistered.data_ref);
+break;
 default:
 av_buffer_unref(>payload.other.data_ref);
 break;
@@ -1029,6 +1041,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 break;
 
 case HEVC_NAL_SEI_PREFIX:
+case HEVC_NAL_SEI_SUFFIX:
 {
 err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(H265RawSEI),
 _h265_free_sei);
@@ -1036,7 +1049,8 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
-err = cbs_h265_read_sei(ctx, , unit->content);
+err = cbs_h265_read_sei(ctx, , unit->content,
+unit->type == HEVC_NAL_SEI_PREFIX);
 
 if (err < 0)
 return err;
@@ -1300,8 +1314,10 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext 
*ctx,
 break;
 
 case HEVC_NAL_SEI_PREFIX:
+case HEVC_NAL_SEI_SUFFIX:
 {
-err = cbs_h265_write_sei(ctx, pbc, unit->content);
+err = cbs_h265_write_sei(ctx, pbc, unit->content,
+ unit->type == HEVC_NAL_SEI_PREFIX);
 
 if (err < 0)
 return err;
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index 97c9444cb4..d216caca2b 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -548,6 +548,120 @@ typedef struct H265RawSlice {
 AVBufferRef *data_ref;
 } H265RawSlice;
 
+
+typedef struct H265RawSEIBufferingPeriod {
+   

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/yadif_common: Add field type tracking to help bwdif

2018-11-11 Thread Thomas Mundt
Am Sa., 10. Nov. 2018 um 18:47 Uhr schrieb Philip Langdale <
phil...@overt.org>:

> The bwdif filter can use common yadif frame management if we track
> when a field is the first or last field in a sequence. While this
> information is not used by yadif, the added benefit of removing the
> duplicated frame management logic makes it worth tracking this state
> in the common code.
> ---
>  libavfilter/yadif.h| 14 ++
>  libavfilter/yadif_common.c | 12 +---
>  2 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
> index 32d6f4a0d4..02240a4dac 100644
> --- a/libavfilter/yadif.h
> +++ b/libavfilter/yadif.h
> @@ -41,6 +41,12 @@ enum YADIFDeint {
>  YADIF_DEINT_INTERLACED = 1, ///< only deinterlace frames marked as
> interlaced
>  };
>
> +enum YADIFCurrentField {
> +YADIF_FIELD_LAST   = -1, ///< The last field in a sequence
> +YADIF_FIELD_FIRST  =  0, ///< The first field in a sequence
> +YADIF_FIELD_NORMAL =  1, ///< A normal field in the middle of a
> sequence
> +};
>

These names are confusing for the bwdif code.
current_field == 0 means first or last field detected.
current_field == -1 means last frame detected.
Suggestion:
YADIF_FIELD_BACK_END = -1, ///   typedef struct YADIFContext {
>  const AVClass *class;
>
> @@ -70,6 +76,14 @@ typedef struct YADIFContext {
>  int eof;
>  uint8_t *temp_line;
>  int temp_line_size;
> +
> +/*
> + * An algorithm that treats first and/or last fields in a sequence
> + * differently can use this to detect those cases. It is the
> algorithm's
> + * responsibility to set the value to YADIF_FIELD_NORMAL after
> processing
> + * the first field.
> + */
> +int current_field;  ///< YADIFCurrentField
>  } YADIFContext;
>
>  void ff_yadif_init_x86(YADIFContext *yadif);
> diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
> index 19e8ac5281..213eca5396 100644
> --- a/libavfilter/yadif_common.c
> +++ b/libavfilter/yadif_common.c
> @@ -44,6 +44,8 @@ static int return_frame(AVFilterContext *ctx, int
> is_second)
>
>  av_frame_copy_props(yadif->out, yadif->cur);
>  yadif->out->interlaced_frame = 0;
> +if (yadif->current_field == YADIF_FIELD_LAST)
> +yadif->current_field = YADIF_FIELD_FIRST;
>  }
>
>  yadif->filter(ctx, yadif->out, tff ^ !is_second, tff);
> @@ -103,9 +105,12 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame
> *frame)
>  yadif->cur  = yadif->next;
>  yadif->next = frame;
>
> -if (!yadif->cur &&
> -!(yadif->cur = av_frame_clone(yadif->next)))
> -return AVERROR(ENOMEM);
> +if (!yadif->cur) {
> +yadif->cur = av_frame_clone(yadif->next);
> +if (!yadif->cur)
> +return AVERROR(ENOMEM);
> +yadif->current_field = YADIF_FIELD_FIRST;
> +}
>
>  if (checkstride(yadif, yadif->next, yadif->cur)) {
>  av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing
> stride\n");
> @@ -173,6 +178,7 @@ int ff_yadif_request_frame(AVFilterLink *link)
>  if (!next)
>  return AVERROR(ENOMEM);
>
> +yadif->current_field = YADIF_FIELD_LAST;
>  next->pts = yadif->next->pts * 2 - yadif->cur->pts;
>
>  ff_yadif_filter_frame(ctx->inputs[0], next);
> --
> 2.19.1
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] lavu: add locale-independent sscanf implementation

2018-11-11 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavutil/avstring.c | 938 +++
 libavutil/avstring.h |   6 +
 2 files changed, 944 insertions(+)

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index f03dd25141..d33153a8f3 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -30,6 +30,7 @@
 #include "avassert.h"
 #include "avstring.h"
 #include "bprint.h"
+#include "float.h"
 
 int av_strstart(const char *str, const char *pfx, const char **ptr)
 {
@@ -458,3 +459,940 @@ int av_match_list(const char *name, const char *list, 
char separator)
 
 return 0;
 }
+
+typedef struct FFFILE {
+size_t buf_size;
+unsigned char *buf;
+unsigned char *rpos, *rend;
+unsigned char *wend, *wpos;
+unsigned char *wbase;
+unsigned char *shend;
+off_t shlim, shcnt;
+void *cookie;
+int mode;
+size_t (*read)(struct FFFILE *, unsigned char *, size_t);
+size_t (*write)(struct FFFILE *, const unsigned char *, size_t);
+} FFFILE;
+
+#define SIZE_hh -2
+#define SIZE_h  -1
+#define SIZE_def 0
+#define SIZE_l   1
+#define SIZE_L   2
+#define SIZE_ll  3
+
+#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))
+
+static int fftoread(FFFILE *f)
+{
+f->mode |= f->mode-1;
+if (f->wpos != f->wbase) f->write(f, 0, 0);
+f->wpos = f->wbase = f->wend = 0;
+f->rpos = f->rend = f->buf + f->buf_size;
+return 0;
+}
+
+static size_t ffstring_read(FFFILE *f, unsigned char *buf, size_t len)
+{
+char *src = f->cookie;
+size_t k = len+256;
+char *end = memchr(src, 0, k);
+
+if (end) k = end-src;
+if (k < len) len = k;
+memcpy(buf, src, len);
+f->rpos = (void *)(src+len);
+f->rend = (void *)(src+k);
+f->cookie = src+k;
+
+return len;
+}
+
+static int ffuflow(FFFILE *f)
+{
+unsigned char c;
+if (!fftoread(f) && f->read(f, , 1)==1) return c;
+return EOF;
+}
+
+static void ffshlim(FFFILE *f, off_t lim)
+{
+f->shlim = lim;
+f->shcnt = f->buf - f->rpos;
+/* If lim is nonzero, rend must be a valid pointer. */
+if (lim && f->rend - f->rpos > lim)
+f->shend = f->rpos + lim;
+else
+f->shend = f->rend;
+}
+
+static int ffshgetc(FFFILE *f)
+{
+int c;
+off_t cnt = shcnt(f);
+if (f->shlim && cnt >= f->shlim || (c=ffuflow(f)) < 0) {
+f->shcnt = f->buf - f->rpos + cnt;
+f->shend = 0;
+return EOF;
+}
+cnt++;
+if (f->shlim && f->rend - f->rpos > f->shlim - cnt)
+f->shend = f->rpos + (f->shlim - cnt);
+else
+f->shend = f->rend;
+f->shcnt = f->buf - f->rpos + cnt;
+if (f->rpos[-1] != c) f->rpos[-1] = c;
+return c;
+}
+
+#define shlim(f, lim) ffshlim((f), (lim))
+#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : ffshgetc(f))
+#define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0)
+
+static const unsigned char table[] = { -1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
+-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
+25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
+-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
+25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+};
+
+static unsigned long long ffintscan(FFFILE *f, unsigned base, int pok, 
unsigned long long lim)
+{
+const unsigned char *val = table+1;
+int c, neg=0;
+unsigned x;
+unsigned long long y;
+if (base > 36 || base == 1) {
+errno = EINVAL;
+return 0;
+}
+while (av_isspace((c=shgetc(f;
+if (c=='+' || c=='-') {
+neg = -(c=='-');
+c = shgetc(f);
+}
+if ((base == 0 || base == 16) && c=='0') {
+c = shgetc(f);
+if ((c|32)=='x') {
+c = shgetc(f);
+if (val[c]>=16) {
+shunget(f);
+if (pok) shunget(f);
+else shlim(f, 0);
+return 0;
+}
+base = 16;
+} else if (base == 0) {
+base = 8;
+}
+} else {
+if (base == 0) base = 10;
+if (val[c] >= base) {
+shunget(f);
+shlim(f, 0);
+errno = EINVAL;
+return 0;
+}
+}
+if (base == 10) {
+for (x=0; c-'0'<10U && x<=UINT_MAX/10-1; c=shgetc(f))
+x = x*10 + (c-'0');
+for (y=x; c-'0'<10U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(c-'0'); 
c=shgetc(f))
+ 

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: use av_sscanf

2018-11-11 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_lut3d.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
index e7601a05ac..93053ed263 100644
--- a/libavfilter/vf_lut3d.c
+++ b/libavfilter/vf_lut3d.c
@@ -367,7 +367,7 @@ static int parse_dat(AVFilterContext *ctx, FILE *f)
 struct rgbvec *vec = >lut[k][j][i];
 if (k != 0 || j != 0 || i != 0)
 NEXT_LINE(skip_line(line));
-if (sscanf(line, "%f %f %f", >r, >g, >b) != 3)
+if (av_sscanf(line, "%f %f %f", >r, >g, >b) != 
3)
 return AVERROR_INVALIDDATA;
 }
 }
@@ -407,7 +407,7 @@ try_again:
 else if (!strncmp(line + 7, "MAX ", 4)) vals = 
max;
 if (!vals)
 return AVERROR_INVALIDDATA;
-sscanf(line + 11, "%f %f %f", vals, vals + 1, 
vals + 2);
+av_sscanf(line + 11, "%f %f %f", vals, vals + 
1, vals + 2);
 av_log(ctx, AV_LOG_DEBUG, "min: %f %f %f | 
max: %f %f %f\n",
min[0], min[1], min[2], max[0], max[1], 
max[2]);
 goto try_again;
@@ -415,7 +415,7 @@ try_again:
 goto try_again;
 }
 } while (skip_line(line));
-if (sscanf(line, "%f %f %f", >r, >g, 
>b) != 3)
+if (av_sscanf(line, "%f %f %f", >r, >g, 
>b) != 3)
 return AVERROR_INVALIDDATA;
 vec->r *= max[0] - min[0];
 vec->g *= max[1] - min[1];
@@ -448,7 +448,7 @@ static int parse_3dl(AVFilterContext *ctx, FILE *f)
 struct rgbvec *vec = >lut[k][j][i];
 
 NEXT_LINE(skip_line(line));
-if (sscanf(line, "%d %d %d", , , ) != 3)
+if (av_sscanf(line, "%d %d %d", , , ) != 3)
 return AVERROR_INVALIDDATA;
 vec->r = r / scale;
 vec->g = g / scale;
@@ -512,7 +512,7 @@ static int parse_m3d(AVFilterContext *ctx, FILE *f)
 float val[3];
 
 NEXT_LINE(0);
-if (sscanf(line, "%f %f %f", val, val + 1, val + 2) != 3)
+if (av_sscanf(line, "%f %f %f", val, val + 1, val + 2) != 3)
 return AVERROR_INVALIDDATA;
 vec->r = val[rgb_map[0]] * scale;
 vec->g = val[rgb_map[1]] * scale;
@@ -1046,12 +1046,12 @@ try_again:
 else if (!strncmp(line + 7, "MAX ", 4)) vals = max;
 if (!vals)
 return AVERROR_INVALIDDATA;
-sscanf(line + 11, "%f %f %f", vals, vals + 1, vals + 
2);
+av_sscanf(line + 11, "%f %f %f", vals, vals + 1, vals 
+ 2);
 av_log(ctx, AV_LOG_DEBUG, "min: %f %f %f | max: %f %f 
%f\n",
min[0], min[1], min[2], max[0], max[1], max[2]);
 goto try_again;
 } else if (!strncmp(line, "LUT_1D_INPUT_RANGE ", 19)) {
-sscanf(line + 19, "%f %f", min, max);
+av_sscanf(line + 19, "%f %f", min, max);
 min[1] = min[2] = min[0];
 max[1] = max[2] = max[0];
 goto try_again;
@@ -1059,7 +1059,7 @@ try_again:
 goto try_again;
 }
 } while (skip_line(line));
-if (sscanf(line, "%f %f %f", >lut[0][i], 
>lut[1][i], >lut[2][i]) != 3)
+if (av_sscanf(line, "%f %f %f", >lut[0][i], 
>lut[1][i], >lut[2][i]) != 3)
 return AVERROR_INVALIDDATA;
 lut1d->lut[0][i] *= max[0] - min[0];
 lut1d->lut[1][i] *= max[1] - min[1];
-- 
2.17.1

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


[FFmpeg-devel] [PATCH] mjpegdec: Fill raw huffman tables with default values too

2018-11-11 Thread Mark Thompson
These may be used by hwaccel decoders when the standard tables are not
otherwise available.  At the same time, clean up that code into an array
so it's a little less repetitive.
---
On 29/10/18 10:26, Jun Zhao wrote:
> From: Jun Zhao 
> 
> Now VA-API HWAccel MJPEG decoding uninitialized huffman table, it's
> will lead to the decoding error like"Failed to sync surface 0x5: 23
> (internal decoding error)." in iHD open source driver.
> 
> Signed-off-by: dlin2 
> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/mjpegdec.c |   19 +++
>  1 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index b0cb3ff..89effb6 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -75,6 +75,25 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table,
>  static int build_basic_mjpeg_vlc(MJpegDecodeContext *s)
>  {
>  int ret;
> +int i;
> +
> +/* initialize default huffman tables */
> +for (i = 0; i < 16; i++)
> +s->raw_huffman_lengths[0][0][i] = avpriv_mjpeg_bits_dc_luminance[i + 
> 1];
> +for (i = 0; i < 12; i++)
> +s->raw_huffman_values[0][0][i] = avpriv_mjpeg_val_dc[i];
> +for (i = 0; i < 16; i++)
> +s->raw_huffman_lengths[0][1][i] = avpriv_mjpeg_bits_dc_chrominance[i 
> + 1];
> +for (i = 0; i < 12; i++)
> +s->raw_huffman_values[0][1][i] = avpriv_mjpeg_val_dc[i];
> +for (i = 0; i < 16; i++)
> +s->raw_huffman_lengths[1][0][i] = avpriv_mjpeg_bits_ac_luminance[i + 
> 1];
> +for (i = 0; i < 162; i++)
> +s->raw_huffman_values[1][0][i] = avpriv_mjpeg_val_ac_luminance[i];
> +for (i = 0; i < 16; i++)
> +s->raw_huffman_lengths[1][1][i] = avpriv_mjpeg_bits_ac_chrominance[i 
> + 1];
> +for (i = 0; i < 162; i++)
> +s->raw_huffman_values[1][1][i] = avpriv_mjpeg_val_ac_chrominance[i];
>  
>  if ((ret = build_vlc(>vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
>   avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
> 

Seems reasonable, but perhaps the enclosed patch instead makes it clearer what 
is going on and easier to verify correctness?

(Even better: the builtin tables would be in DHT form and we would just call 
decode_dht() on them and avoid messing around with separate code, but since 
they are used in multiple places that looks more inconvenient to arrange.)

- Mark


 libavcodec/mjpegdec.c | 67 +--
 1 file changed, 39 insertions(+), 28 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 96c425515a..2f1635838a 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -73,34 +73,45 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table,
   huff_code, 2, 2, huff_sym, 2, 2, use_static);
 }
 
-static int build_basic_mjpeg_vlc(MJpegDecodeContext *s)
+static int init_default_huffman_tables(MJpegDecodeContext *s)
 {
-int ret;
-
-if ((ret = build_vlc(>vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
- avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
-return ret;
-
-if ((ret = build_vlc(>vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
- avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
-return ret;
-
-if ((ret = build_vlc(>vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
- avpriv_mjpeg_val_ac_luminance, 251, 0, 1)) < 0)
-return ret;
-
-if ((ret = build_vlc(>vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
- avpriv_mjpeg_val_ac_chrominance, 251, 0, 1)) < 0)
-return ret;
-
-if ((ret = build_vlc(>vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
- avpriv_mjpeg_val_ac_luminance, 251, 0, 0)) < 0)
-return ret;
-
-if ((ret = build_vlc(>vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
- avpriv_mjpeg_val_ac_chrominance, 251, 0, 0)) < 0)
-return ret;
+static const struct {
+int class;
+int index;
+const uint8_t *bits;
+const uint8_t *values;
+int codes;
+int length;
+} ht[] = {
+{ 0, 0, avpriv_mjpeg_bits_dc_luminance,
+avpriv_mjpeg_val_dc, 12, 12 },
+{ 0, 1, avpriv_mjpeg_bits_dc_chrominance,
+avpriv_mjpeg_val_dc, 12, 12 },
+{ 1, 0, avpriv_mjpeg_bits_ac_luminance,
+avpriv_mjpeg_val_ac_luminance,   251, 162 },
+{ 1, 1, avpriv_mjpeg_bits_ac_chrominance,
+avpriv_mjpeg_val_ac_chrominance, 251, 162 },
+{ 2, 0, avpriv_mjpeg_bits_ac_luminance,
+avpriv_mjpeg_val_ac_luminance,   251, 162 },
+{ 2, 1, avpriv_mjpeg_bits_ac_chrominance,
+avpriv_mjpeg_val_ac_chrominance, 251, 162 },
+};
+int i, ret;
+
+for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
+ret = build_vlc(>vlcs[ht[i].class][ht[i].index],
+ht[i].bits, ht[i].values, ht[i].codes,
+  

Re: [FFmpeg-devel] [PATCH 4/4] cbs_h265: Add a lot more SEI parsing support

2018-11-11 Thread James Almer
On 10/27/2018 6:39 PM, Mark Thompson wrote:
> Supports both prefix and suffix SEI, decoding all of the common SEI
> types and some more obscure ones.  Most of this is tested by the
> existing tests in fate.

It would be neat to make the *_metadata filters not decompose unit types
it doesn't care about (based on user options). Before this patch, all
these SEI messages were simply copied as is, but after it they will be
fully parsed even in pass through mode, potentially slowing down the
process.

Of course, doing that would make the cbs tests useless. Maybe the
default behavior could be to not decompose what's not going to be
modified, and an option to enable it could be added that the test would use.

> ---
>  libavcodec/cbs_h2645.c|  20 +-
>  libavcodec/cbs_h265.h | 124 +++
>  libavcodec/cbs_h265_syntax_template.c | 497 +-
>  libavcodec/hevc.h |   3 +
>  libavcodec/hevc_sei.h |   1 +
>  5 files changed, 625 insertions(+), 20 deletions(-)
> 

> diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
> index e92da25bbf..2fec00ace0 100644
> --- a/libavcodec/hevc_sei.h
> +++ b/libavcodec/hevc_sei.h
> @@ -52,6 +52,7 @@ typedef enum {
>  HEVC_SEI_TYPE_DECODED_PICTURE_HASH = 132,
>  HEVC_SEI_TYPE_SCALABLE_NESTING = 133,
>  HEVC_SEI_TYPE_REGION_REFRESH_INFO  = 134,
> +HEVC_SEI_TYPE_TIME_CODE= 136,
>  HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO   = 137,
>  HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO = 144,
>  HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,

Adding this one should be trivial, btw. It's a single field, and there
are real world samples out there. Support for it was added to the
decoder some time ago.

In any case, set looks good if FATE passes. Thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3 1/6] fate/libavcodec: Fix config dependency of h264-levels test

2018-11-11 Thread James Almer
On 10/27/2018 7:19 PM, Mark Thompson wrote:
> ---
>  tests/fate/libavcodec.mak | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
> index aa4c36b112..5dde1243fa 100644
> --- a/tests/fate/libavcodec.mak
> +++ b/tests/fate/libavcodec.mak
> @@ -46,7 +46,7 @@ fate-dct8x8: libavcodec/tests/dct$(EXESUF)
>  fate-dct8x8: CMD = run libavcodec/tests/dct
>  fate-dct8x8: CMP = null
>  
> -FATE_LIBAVCODEC-$(CONFIG_H264_VAAPI_ENCODER) += fate-h264-levels
> +FATE_LIBAVCODEC-$(CONFIG_H264_METADATA_BSF) += fate-h264-levels
>  fate-h264-levels: libavcodec/tests/h264_levels$(EXESUF)
>  fate-h264-levels: CMD = run libavcodec/tests/h264_levels
>  fate-h264-levels: REF = /dev/null

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


[FFmpeg-devel] [PATCH 1/3] ffmpeg_qsv: Remove format-specific get_buffer

2018-11-11 Thread Mark Thompson
It does exactly the same thing as the default get_buffer.
---
 fftools/ffmpeg_qsv.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/fftools/ffmpeg_qsv.c b/fftools/ffmpeg_qsv.c
index 9c4285b6c7..aef0c26bcc 100644
--- a/fftools/ffmpeg_qsv.c
+++ b/fftools/ffmpeg_qsv.c
@@ -30,13 +30,6 @@
 
 char *qsv_device = NULL;
 
-static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
-{
-InputStream *ist = s->opaque;
-
-return av_hwframe_get_buffer(ist->hw_frames_ctx, frame, 0);
-}
-
 static void qsv_uninit(AVCodecContext *s)
 {
 InputStream *ist = s->opaque;
@@ -102,7 +95,6 @@ int qsv_init(AVCodecContext *s)
 return ret;
 }
 
-ist->hwaccel_get_buffer = qsv_get_buffer;
 ist->hwaccel_uninit = qsv_uninit;
 
 return 0;
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 3/3] qsvdec: Fix running with assert_level > 0

2018-11-11 Thread Mark Thompson
Assertion avctx->codec_id != AV_CODEC_ID_NONE failed at 
src/libavcodec/parser.c:128

The setting on the internal AVCodecContext used for parsing only is
otherwise irrelevant, so just set it to avoid the assert.
---
 libavcodec/qsvdec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 6753e596a1..4a0be811fb 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -501,6 +501,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 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);
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 2/3] ffmpeg: Remove get_buffer override

2018-11-11 Thread Mark Thompson
Since nothing sets hwaccel_get_buffer any more, this is always equivalent
to the default case.
---
 fftools/ffmpeg.c | 11 ---
 fftools/ffmpeg.h |  1 -
 2 files changed, 12 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38c21e944a..e0ffd1b779 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2875,16 +2875,6 @@ static enum AVPixelFormat get_format(AVCodecContext *s, 
const enum AVPixelFormat
 return *p;
 }
 
-static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
-{
-InputStream *ist = s->opaque;
-
-if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
-return ist->hwaccel_get_buffer(s, frame, flags);
-
-return avcodec_default_get_buffer2(s, frame, flags);
-}
-
 static int init_input_stream(int ist_index, char *error, int error_len)
 {
 int ret;
@@ -2900,7 +2890,6 @@ static int init_input_stream(int ist_index, char *error, 
int error_len)
 
 ist->dec_ctx->opaque= ist;
 ist->dec_ctx->get_format= get_format;
-ist->dec_ctx->get_buffer2   = get_buffer;
 ist->dec_ctx->thread_safe_callbacks = 1;
 
 av_opt_set_int(ist->dec_ctx, "refcounted_frames", 1, 0);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index eb1eaf6363..ae406aae2f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -369,7 +369,6 @@ typedef struct InputStream {
 /* hwaccel context */
 void  *hwaccel_ctx;
 void (*hwaccel_uninit)(AVCodecContext *s);
-int  (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
 int  (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
 enum AVPixelFormat hwaccel_pix_fmt;
 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

2018-11-11 Thread Mark Thompson
On 09/11/18 09:05, Linjie Fu wrote:
> Currently ff_get_format will go through all usable choices if the chosen
> format was not supported. It will fallback to software path if the hardware
> init fails.
> 
> Provided an option "-require_hwaccel 1" in user-code to detect frame->format 
> and
> hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.
> 
> Signed-off-by: Linjie Fu 
> ---
> [v2] detect hardware init failures in get_buffer and modify in user-code
> [v3] changed the option name, add error message
> 
>  fftools/ffmpeg.c | 4 
>  fftools/ffmpeg.h | 3 +++
>  fftools/ffmpeg_opt.c | 4 
>  3 files changed, 11 insertions(+)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index da4259a9a8..113ab6312a 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2890,6 +2890,10 @@ static int get_buffer(AVCodecContext *s, AVFrame 
> *frame, int flags)
>  
>  if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
>  return ist->hwaccel_get_buffer(s, frame, flags);
> +else if (ist->require_hwaccel) {
> +av_log(s, AV_LOG_ERROR, "Hardware acceleration is required and will 
> not fallback to try software path.\n");
> +return AVERROR(EINVAL);
> +}

Um, doesn't this just break every hardware case except QSV?  The 
hwaccel_get_buffer function is only used for QSV, and will be unset for any 
other cases.  (In fact, I don't think it does anything useful there anyway - 
maybe it can be removed completely, I'll have a look.)

I think the right place to make this decision (to force a hardware format) is 
in get_format(), rather than after when the decoder is already configured - 
this avoids cases where the format you actually wanted was available but you 
didn't pick it and then fail later.  I had a patch lying around for another 
purpose which gives you some support for this, just sent if you'd like to have 
a look.

>  
>  return avcodec_default_get_buffer2(s, frame, flags);
>  }
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index eb1eaf6363..a5c85daa67 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -133,6 +133,8 @@ typedef struct OptionsContext {
>  intnb_hwaccel_output_formats;
>  SpecifierOpt *autorotate;
>  intnb_autorotate;
> +SpecifierOpt *require_hwaccel;
> +intnb_require_hwaccel;
>  
>  /* output options */
>  StreamMap *stream_maps;
> @@ -365,6 +367,7 @@ typedef struct InputStream {
>  enum AVHWDeviceType hwaccel_device_type;
>  char  *hwaccel_device;
>  enum AVPixelFormat hwaccel_output_format;
> +int require_hwaccel;
>  
>  /* hwaccel context */
>  void  *hwaccel_ctx;
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index d4851a2cd8..6890bb7fcf 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -730,6 +730,7 @@ static void add_input_streams(OptionsContext *o, 
> AVFormatContext *ic)
>  ist->autorotate = 1;
>  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
>  
> +MATCH_PER_STREAM_OPT(require_hwaccel, i, ist->require_hwaccel, ic, 
> st);
>  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>  if (codec_tag) {
>  uint32_t tag = strtol(codec_tag, , 0);
> @@ -3600,6 +3601,9 @@ const OptionDef options[] = {
>  { "autorotate",   HAS_ARG | OPT_BOOL | OPT_SPEC |
>OPT_EXPERT | OPT_INPUT,
> { .off = OFFSET(autorotate) },
>  "automatically insert correct rotate filters" },
> +{ "require_hwaccel",  HAS_ARG | OPT_BOOL | OPT_SPEC |
> +  OPT_EXPERT | OPT_INPUT,
> { .off = OFFSET(require_hwaccel)},
> +  "forbid the fallback to default software path when hardware init 
> fails"},
>  
>  /* audio options */
>  { "aframes",OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT, 
>   { .func_arg = opt_audio_frames },
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2018-11-11 Thread Mark Thompson
Fixes #7519.
---
I've had this lying around for a bit with intent to use it to support 
non-hwaccel hardware decoders (in particular, v4l2m2m), but it actually fixes 
the force-hwaccel use-case too in a sensible way.


 doc/ffmpeg.texi  | 12 
 fftools/ffmpeg.c |  4 
 fftools/ffmpeg.h |  4 
 fftools/ffmpeg_opt.c | 15 +++
 4 files changed, 35 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..9f9e693898 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -920,6 +920,18 @@ would be more efficient.
 When doing stream copy, copy also non-key frames found at the
 beginning.
 
+@item -decode_format[:@var{stream_specifier}] @var{pixfmt} 
(@emph{input,per-stream})
+Set the output format to be used by the decoder for this stream.  If the
+decoder does not natively support this format for the input stream then
+decoding will fail rather than continuing with a different format.
+
+In general this should not be set - the decoder will select an output
+format based on the input stream parameters and available components, and
+that will be automatically converted to whatever the output requires.  It
+may be useful to force a hardware decoder supporting output in multiple
+different memory types to pick the desired one, or to ensure that a
+hardware decoder is used when software fallback is also available.
+
 @item -init_hw_device 
@var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]
 Initialise a new hardware device of type @var{type} called @var{name}, using 
the
 given device parameters.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38c21e944a..73bed55e4d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2800,6 +2800,10 @@ static enum AVPixelFormat get_format(AVCodecContext *s, 
const enum AVPixelFormat
 const AVCodecHWConfig  *config = NULL;
 int i;
 
+if (ist->decode_format != AV_PIX_FMT_NONE &&
+ist->decode_format != *p)
+continue;
+
 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
 break;
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index eb1eaf6363..88e0aa60ea 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -125,6 +125,8 @@ typedef struct OptionsContext {
 intnb_ts_scale;
 SpecifierOpt *dump_attachment;
 intnb_dump_attachment;
+SpecifierOpt *decode_formats;
+intnb_decode_formats;
 SpecifierOpt *hwaccels;
 intnb_hwaccels;
 SpecifierOpt *hwaccel_devices;
@@ -334,6 +336,8 @@ typedef struct InputStream {
 int top_field_first;
 int guess_layout_max;
 
+enum AVPixelFormat decode_format;
+
 int autorotate;
 
 int fix_sub_duration;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index d4851a2cd8..0e3e8b99fe 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -701,6 +701,7 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 AVStream *st = ic->streams[i];
 AVCodecParameters *par = st->codecpar;
 InputStream *ist = av_mallocz(sizeof(*ist));
+char *decode_format = NULL;
 char *framerate = NULL, *hwaccel_device = NULL;
 const char *hwaccel = NULL;
 char *hwaccel_output_format = NULL;
@@ -797,6 +798,17 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 ist->top_field_first = -1;
 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, 
st);
 
+MATCH_PER_STREAM_OPT(decode_formats, str, decode_format, ic, st);
+if (decode_format) {
+ist->decode_format = av_get_pix_fmt(decode_format);
+if (ist->decode_format == AV_PIX_FMT_NONE) {
+av_log(NULL, AV_LOG_FATAL, "Unrecognised decode format: 
%s",
+   decode_format);
+}
+} else {
+ist->decode_format = AV_PIX_FMT_NONE;
+}
+
 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
 if (hwaccel) {
 // The NVDEC hwaccels use a CUDA device, so remap the name 
here.
@@ -3583,6 +3595,9 @@ const OptionDef options[] = {
 "audio bitrate (please use -b:a)", "bitrate" },
 { "b",OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT,  
  { .func_arg = opt_bitrate },
 "video bitrate (please use -b:v)", "bitrate" },
+{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
+OPT_SPEC | OPT_INPUT,  
  { .off = OFFSET(decode_formats) },
+"set output format used by decoder, fail if this format is not 
available", "format" },
 { "hwaccel",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
   OPT_SPEC | OPT_INPUT,
  { .off = OFFSET(hwaccels) },
 "use HW accelerated decoding", "hwaccel name" },
-- 
2.19.1


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread James Almer
On 11/11/2018 11:47 AM, Paul B Mahol wrote:
> On 11/11/18, James Almer  wrote:
>> On 11/11/2018 11:01 AM, Paul B Mahol wrote:
>>> On 11/11/18, Michael Niedermayer  wrote:
 Hi all

 I think we need another volunteer to help with uploading fate samples
 why i think so, well, if i dont do it it seems to not happen currently
 until i do it ...
 This is worsened as james has technical problems with uploads ATM

 Do we have anyone who wants to help upload fate samples for contributors?

 What would that person need to do ?
 * Have some time (maybe an hour or 2 a week at average, but this should
 be
   ideally flexible and available when someone needs a sample uploaded.
 * follow the mailing list to spot patches which require sample uploads
 * Ability to judge if the filesize is reasonable (the file needs to be
   on every machine testing fate, both users, fate clients, some on VMs,
   some on low endish ARM boards.
 * Locally apply patches to test if the fate tests using a sample,
 function
   correctly before uploading. (preferrably on multiple platforms)
 * not mess up fate samples in a way that breaks releases or older
 checkouts
>>>
>>> I think I have account, but I dunno how to use it.
>>
>> https://ffmpeg.org/fate.html Section 4. Make sure to always do a dry run
>> first for both uploading and updating your local folder to make sure
>> only the changes you want will be take effect.
> 
> Thanks, but what is my user name and pass?

Whatever ssh key you gave Michael when he set up your account should
authenticate you.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread Paul B Mahol
On 11/11/18, James Almer  wrote:
> On 11/11/2018 11:01 AM, Paul B Mahol wrote:
>> On 11/11/18, Michael Niedermayer  wrote:
>>> Hi all
>>>
>>> I think we need another volunteer to help with uploading fate samples
>>> why i think so, well, if i dont do it it seems to not happen currently
>>> until i do it ...
>>> This is worsened as james has technical problems with uploads ATM
>>>
>>> Do we have anyone who wants to help upload fate samples for contributors?
>>>
>>> What would that person need to do ?
>>> * Have some time (maybe an hour or 2 a week at average, but this should
>>> be
>>>   ideally flexible and available when someone needs a sample uploaded.
>>> * follow the mailing list to spot patches which require sample uploads
>>> * Ability to judge if the filesize is reasonable (the file needs to be
>>>   on every machine testing fate, both users, fate clients, some on VMs,
>>>   some on low endish ARM boards.
>>> * Locally apply patches to test if the fate tests using a sample,
>>> function
>>>   correctly before uploading. (preferrably on multiple platforms)
>>> * not mess up fate samples in a way that breaks releases or older
>>> checkouts
>>
>> I think I have account, but I dunno how to use it.
>
> https://ffmpeg.org/fate.html Section 4. Make sure to always do a dry run
> first for both uploading and updating your local folder to make sure
> only the changes you want will be take effect.

Thanks, but what is my user name and pass?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread James Almer
On 11/11/2018 11:01 AM, Paul B Mahol wrote:
> On 11/11/18, Michael Niedermayer  wrote:
>> Hi all
>>
>> I think we need another volunteer to help with uploading fate samples
>> why i think so, well, if i dont do it it seems to not happen currently
>> until i do it ...
>> This is worsened as james has technical problems with uploads ATM
>>
>> Do we have anyone who wants to help upload fate samples for contributors?
>>
>> What would that person need to do ?
>> * Have some time (maybe an hour or 2 a week at average, but this should be
>>   ideally flexible and available when someone needs a sample uploaded.
>> * follow the mailing list to spot patches which require sample uploads
>> * Ability to judge if the filesize is reasonable (the file needs to be
>>   on every machine testing fate, both users, fate clients, some on VMs,
>>   some on low endish ARM boards.
>> * Locally apply patches to test if the fate tests using a sample, function
>>   correctly before uploading. (preferrably on multiple platforms)
>> * not mess up fate samples in a way that breaks releases or older checkouts
> 
> I think I have account, but I dunno how to use it.

https://ffmpeg.org/fate.html Section 4. Make sure to always do a dry run
first for both uploading and updating your local folder to make sure
only the changes you want will be take effect.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter/vf_alphamerge: switch to activate

2018-11-11 Thread Paul B Mahol
On 11/11/18, Gyan  wrote:
> On Sun, Nov 11, 2018 at 5:00 PM Paul B Mahol  wrote:
>
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavfilter/vf_alphamerge.c | 88 ++---
>>  1 file changed, 44 insertions(+), 44 deletions(-)
>>
>
> Does this fix  #7543?

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


Re: [FFmpeg-devel] [PATCH 2/4] lavfi/opencl: Handle overlay input formats correctly.

2018-11-11 Thread Mark Thompson
On 29/10/18 05:56, Ruiling Song wrote:
> The main input may have alpha channel, we just ignore it.

This doesn't ignore it - it leaves it uninitialised in the output, so a YUVA or 
GBRAP output will never write to the A plane.  I don't think that's what you're 
intending.

> Also add some checks for incompatible input formats.
> 
> Signed-off-by: Ruiling Song 
> ---
>  libavfilter/vf_overlay_opencl.c | 58 
> -
>  1 file changed, 46 insertions(+), 12 deletions(-)
> 
> diff --git a/libavfilter/vf_overlay_opencl.c b/libavfilter/vf_overlay_opencl.c
> index e9c8532..320c1a5 100644
> --- a/libavfilter/vf_overlay_opencl.c
> +++ b/libavfilter/vf_overlay_opencl.c
> @@ -37,7 +37,7 @@ typedef struct OverlayOpenCLContext {
>  
>  FFFrameSync  fs;
>  
> -int  nb_planes;
> +int  nb_color_planes;

This name change seems wrong - it includes the luma plane, which does not 
contain colour information.

>  int  x_subsample;
>  int  y_subsample;
>  int  alpha_separate;
> @@ -46,6 +46,22 @@ typedef struct OverlayOpenCLContext {
>  int  y_position;
>  } OverlayOpenCLContext;
>  
> +static int has_planar_alpha(const AVPixFmtDescriptor *fmt) {

{ on new line.

> +int nb_components;
> +int has_alpha = !!(fmt->flags & AV_PIX_FMT_FLAG_ALPHA);
> +if (!has_alpha) return 0;

So, if the format does not not not contain alpha?  Perhaps instead write:

if (!(fmt->flags & AV_PIX_FMT_FLAG_ALPHA))
return 0;

> +
> +nb_components = fmt->nb_components;
> +// PAL8
> +if (nb_components < 2) return 0;

Check AV_PIX_FMT_FLAG_PAL instead?

> +
> +if (fmt->comp[nb_components - 1].plane >
> +fmt->comp[nb_components - 2].plane)
> +return 1;
> +else
> +return 0;
> +}
> +
>  static int overlay_opencl_load(AVFilterContext *avctx,
> enum AVPixelFormat main_format,
> enum AVPixelFormat overlay_format)
> @@ -55,10 +71,13 @@ static int overlay_opencl_load(AVFilterContext *avctx,
>  const char *source = ff_opencl_source_overlay;
>  const char *kernel;
>  const AVPixFmtDescriptor *main_desc, *overlay_desc;
> -int err, i, main_planes, overlay_planes;
> +int err, i, main_planes, overlay_planes, overlay_alpha,
> +main_planar_alpha, overlay_planar_alpha;
>  
>  main_desc= av_pix_fmt_desc_get(main_format);
>  overlay_desc = av_pix_fmt_desc_get(overlay_format);
> +overlay_alpha = !!(overlay_desc->flags & AV_PIX_FMT_FLAG_ALPHA);
> +main_planar_alpha = has_planar_alpha(main_desc);
>  
>  main_planes = overlay_planes = 0;
>  for (i = 0; i < main_desc->nb_components; i++)
> @@ -68,7 +87,7 @@ static int overlay_opencl_load(AVFilterContext *avctx,
>  overlay_planes = FFMAX(overlay_planes,
> overlay_desc->comp[i].plane + 1);
>  
> -ctx->nb_planes = main_planes;
> +ctx->nb_color_planes = main_planar_alpha ? (main_planes - 1) : 
> main_planes;
>  ctx->x_subsample = 1 << main_desc->log2_chroma_w;
>  ctx->y_subsample = 1 << main_desc->log2_chroma_h;
>  
> @@ -80,15 +99,30 @@ static int overlay_opencl_load(AVFilterContext *avctx,
> ctx->x_subsample, ctx->y_subsample);
>  }
>  
> -if (main_planes == overlay_planes) {
> -if (main_desc->nb_components == overlay_desc->nb_components)
> -kernel = "overlay_no_alpha";
> -else
> -kernel = "overlay_internal_alpha";
> +if ((main_desc->flags & AV_PIX_FMT_FLAG_RGB) !=
> +(overlay_desc->flags & AV_PIX_FMT_FLAG_RGB)) {
> +av_log(avctx, AV_LOG_ERROR, "mixed YUV/RGB input formats.\n");
> +return AVERROR(EINVAL);
> +}
> +
> +if (main_desc->log2_chroma_w != overlay_desc->log2_chroma_w ||
> +main_desc->log2_chroma_h != overlay_desc->log2_chroma_h) {
> +av_log(avctx, AV_LOG_ERROR, "incompatible chroma sub-sampling.\n");
> +return AVERROR(EINVAL);
> +}
> +
> +if (!overlay_alpha) {
>  ctx->alpha_separate = 0;
> +kernel = "overlay_no_alpha";
>  } else {
> -kernel = "overlay_external_alpha";
> -ctx->alpha_separate = 1;
> +overlay_planar_alpha = has_planar_alpha(overlay_desc);
> +if (overlay_planar_alpha) {
> +ctx->alpha_separate = 1;
> +kernel = "overlay_external_alpha";
> +} else {
> +ctx->alpha_separate = 0;
> +kernel = "overlay_internal_alpha";
> +}
>  }
>  
>  av_log(avctx, AV_LOG_DEBUG, "Using kernel %s.\n", kernel);
> @@ -155,7 +189,7 @@ static int overlay_opencl_blend(FFFrameSync *fs)
>  goto fail;
>  }
>  
> -for (plane = 0; plane < ctx->nb_planes; plane++) {
> +for (plane = 0; plane < ctx->nb_color_planes; plane++) {
>  kernel_arg = 0;
>  
>  mem = (cl_mem)output->data[plane];
> @@ 

Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread Paul B Mahol
On 11/11/18, Michael Niedermayer  wrote:
> Hi all
>
> I think we need another volunteer to help with uploading fate samples
> why i think so, well, if i dont do it it seems to not happen currently
> until i do it ...
> This is worsened as james has technical problems with uploads ATM
>
> Do we have anyone who wants to help upload fate samples for contributors?
>
> What would that person need to do ?
> * Have some time (maybe an hour or 2 a week at average, but this should be
>   ideally flexible and available when someone needs a sample uploaded.
> * follow the mailing list to spot patches which require sample uploads
> * Ability to judge if the filesize is reasonable (the file needs to be
>   on every machine testing fate, both users, fate clients, some on VMs,
>   some on low endish ARM boards.
> * Locally apply patches to test if the fate tests using a sample, function
>   correctly before uploading. (preferrably on multiple platforms)
> * not mess up fate samples in a way that breaks releases or older checkouts

I think I have account, but I dunno how to use it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter/vf_alphamerge: switch to activate

2018-11-11 Thread Gyan
On Sun, Nov 11, 2018 at 5:00 PM Paul B Mahol  wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_alphamerge.c | 88 ++---
>  1 file changed, 44 insertions(+), 44 deletions(-)
>

Does this fix  #7543?

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


Re: [FFmpeg-devel] Fate samples

2018-11-11 Thread James Almer
On 11/11/2018 8:57 AM, Michael Niedermayer wrote:
> Hi all
> 
> I think we need another volunteer to help with uploading fate samples
> why i think so, well, if i dont do it it seems to not happen currently
> until i do it ...
> This is worsened as james has technical problems with uploads ATM
> 
> Do we have anyone who wants to help upload fate samples for contributors?

There are several people with access to the server for this purpose. If
i currently can't you shouldn't be the only one left to do it.

I'm not against asking for new contributors, but try contacting the
others first and see if they still can take care of uploading a sample
every other month.

> 
> What would that person need to do ?
> * Have some time (maybe an hour or 2 a week at average, but this should be
>   ideally flexible and available when someone needs a sample uploaded.
> * follow the mailing list to spot patches which require sample uploads
> * Ability to judge if the filesize is reasonable (the file needs to be
>   on every machine testing fate, both users, fate clients, some on VMs, 
>   some on low endish ARM boards.
> * Locally apply patches to test if the fate tests using a sample, function
>   correctly before uploading. (preferrably on multiple platforms)
> * not mess up fate samples in a way that breaks releases or older checkouts
> 
> 
> Thanks
> 
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: removed specific filename format code for non-zero segment sizes

2018-11-11 Thread Stephen Dawkins
This patch removes some duplicate code in hls_start that prevents the usage
of strftime base filenames in conjuction with hls_segment_size.

Signed-off-by: Stephen Dawkins 
---
 libavformat/hlsenc.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f8f060d065..4557951f0b 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1468,19 +1468,6 @@ static int hls_start(AVFormatContext *s, VariantStream 
*vs)
 return AVERROR(ENOMEM);
 ff_format_set_url(vtt_oc, new_name);
 }
-} else if (c->max_seg_size > 0) {
-char *filename = NULL;
-if (replace_int_data_in_filename(,
-#if FF_API_HLS_WRAP
-vs->basename, 'd', c->wrap ? vs->sequence % c->wrap : 
vs->sequence) < 1) {
-#else
-vs->basename, 'd', vs->sequence) < 1) {
-#endif
-av_free(filename);
-av_log(oc, AV_LOG_ERROR, "Invalid segment filename template 
'%s', you can try to use -strftime 1 with it\n", vs->basename);
-return AVERROR(EINVAL);
-}
-ff_format_set_url(oc, filename);
 } else {
 if (c->use_localtime) {
 time_t now0;
-- 
2.19.1

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


[FFmpeg-devel] Fate samples

2018-11-11 Thread Michael Niedermayer
Hi all

I think we need another volunteer to help with uploading fate samples
why i think so, well, if i dont do it it seems to not happen currently
until i do it ...
This is worsened as james has technical problems with uploads ATM

Do we have anyone who wants to help upload fate samples for contributors?

What would that person need to do ?
* Have some time (maybe an hour or 2 a week at average, but this should be
  ideally flexible and available when someone needs a sample uploaded.
* follow the mailing list to spot patches which require sample uploads
* Ability to judge if the filesize is reasonable (the file needs to be
  on every machine testing fate, both users, fate clients, some on VMs, 
  some on low endish ARM boards.
* Locally apply patches to test if the fate tests using a sample, function
  correctly before uploading. (preferrably on multiple platforms)
* not mess up fate samples in a way that breaks releases or older checkouts


Thanks

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


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


[FFmpeg-devel] [PATCH] avfilter/vf_alphamerge: switch to activate

2018-11-11 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_alphamerge.c | 88 ++---
 1 file changed, 44 insertions(+), 44 deletions(-)

diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c
index 45fa340fcc..b0a590adb3 100644
--- a/libavfilter/vf_alphamerge.c
+++ b/libavfilter/vf_alphamerge.c
@@ -28,9 +28,9 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/pixfmt.h"
 #include "avfilter.h"
-#include "bufferqueue.h"
 #include "drawutils.h"
 #include "formats.h"
+#include "filters.h"
 #include "internal.h"
 #include "video.h"
 
@@ -39,17 +39,10 @@ enum { Y, U, V, A };
 typedef struct AlphaMergeContext {
 int is_packed_rgb;
 uint8_t rgba_map[4];
-struct FFBufQueue queue_main;
-struct FFBufQueue queue_alpha;
+AVFrame *main_frame;
+AVFrame *alpha_frame;
 } AlphaMergeContext;
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-AlphaMergeContext *merge = ctx->priv;
-ff_bufqueue_discard_all(>queue_main);
-ff_bufqueue_discard_all(>queue_alpha);
-}
-
 static int query_formats(AVFilterContext *ctx)
 {
 static const enum AVPixelFormat main_fmts[] = {
@@ -140,44 +133,54 @@ static void draw_frame(AVFilterContext *ctx,
 }
 }
 
-static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
+static int activate(AVFilterContext *ctx)
 {
-AVFilterContext *ctx = inlink->dst;
-AlphaMergeContext *merge = ctx->priv;
+AVFilterLink *outlink = ctx->outputs[0];
+AlphaMergeContext *s = ctx->priv;
+int ret;
 
-int ret = 0;
-int is_alpha = (inlink == ctx->inputs[1]);
-struct FFBufQueue *queue =
-(is_alpha ? >queue_alpha : >queue_main);
-ff_bufqueue_add(ctx, queue, buf);
+FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, ctx);
 
-do {
-AVFrame *main_buf, *alpha_buf;
+if (!s->main_frame) {
+ret = ff_inlink_consume_frame(ctx->inputs[0], >main_frame);
+if (ret < 0)
+return ret;
+}
 
-if (!ff_bufqueue_peek(>queue_main, 0) ||
-!ff_bufqueue_peek(>queue_alpha, 0)) break;
+if (!s->alpha_frame) {
+ret = ff_inlink_consume_frame(ctx->inputs[1], >alpha_frame);
+if (ret < 0)
+return ret;
+}
 
-main_buf = ff_bufqueue_get(>queue_main);
-alpha_buf = ff_bufqueue_get(>queue_alpha);
+if (s->main_frame && s->alpha_frame) {
+if (ret > 0) {
+draw_frame(ctx, s->main_frame, s->alpha_frame);
+ret = ff_filter_frame(outlink, s->main_frame);
+s->main_frame = NULL;
+s->alpha_frame = NULL;
+return ret;
+}
+}
 
-draw_frame(ctx, main_buf, alpha_buf);
-ret = ff_filter_frame(ctx->outputs[0], main_buf);
-av_frame_free(_buf);
-} while (ret >= 0);
-return ret;
-}
+FF_FILTER_FORWARD_STATUS(ctx->inputs[0], outlink);
+FF_FILTER_FORWARD_STATUS(ctx->inputs[1], outlink);
 
-static int request_frame(AVFilterLink *outlink)
-{
-AVFilterContext *ctx = outlink->src;
-AlphaMergeContext *merge = ctx->priv;
-int in, ret;
+if (ff_outlink_frame_wanted(ctx->outputs[0]) &&
+!ff_outlink_get_status(ctx->inputs[0]) &&
+!s->main_frame) {
+ff_inlink_request_frame(ctx->inputs[0]);
+return 0;
+}
 
-in = ff_bufqueue_peek(>queue_main, 0) ? 1 : 0;
-ret = ff_request_frame(ctx->inputs[in]);
-if (ret < 0)
-return ret;
-return 0;
+if (ff_outlink_frame_wanted(ctx->outputs[0]) &&
+!ff_outlink_get_status(ctx->inputs[1]) &&
+!s->alpha_frame) {
+ff_inlink_request_frame(ctx->inputs[1]);
+return 0;
+}
+
+return FFERROR_NOT_READY;
 }
 
 static const AVFilterPad alphamerge_inputs[] = {
@@ -185,12 +188,10 @@ static const AVFilterPad alphamerge_inputs[] = {
 .name = "main",
 .type = AVMEDIA_TYPE_VIDEO,
 .config_props = config_input_main,
-.filter_frame = filter_frame,
 .needs_writable   = 1,
 },{
 .name = "alpha",
 .type = AVMEDIA_TYPE_VIDEO,
-.filter_frame = filter_frame,
 },
 { NULL }
 };
@@ -200,7 +201,6 @@ static const AVFilterPad alphamerge_outputs[] = {
 .name  = "default",
 .type  = AVMEDIA_TYPE_VIDEO,
 .config_props  = config_output,
-.request_frame = request_frame,
 },
 { NULL }
 };
@@ -209,9 +209,9 @@ AVFilter ff_vf_alphamerge = {
 .name   = "alphamerge",
 .description= NULL_IF_CONFIG_SMALL("Copy the luma value of the second "
   "input into the alpha channel of the first input."),
-.uninit = uninit,
 .priv_size  = sizeof(AlphaMergeContext),
 .query_formats  = query_formats,
 .inputs = alphamerge_inputs,
 .outputs= alphamerge_outputs,
+.activate   = activate,
 };
-- 
2.17.1

___
ffmpeg-devel 

[FFmpeg-devel] [RFC] Try to improve 1:N transcode performance with thread.

2018-11-11 Thread Jun Zhao
Add a new option "abr_pipeline" with mutil-thread to improve the 1:N
transcode performance, currently, the code just as a PoC(proof of 
concept) prototype, and post it to maillist for RFC(Requect for 
Comment).

Jun Zhao (1):
  ffmpeg: Improved the performance of 1:N for adaptive bitrate
scenario.

 fftools/ffmpeg.c|  236 ---
 fftools/ffmpeg.h|   12 +++
 fftools/ffmpeg_filter.c |6 +
 fftools/ffmpeg_opt.c|6 +-
 4 files changed, 246 insertions(+), 14 deletions(-)

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


[FFmpeg-devel] [RFC] ffmpeg: Improved the performance of 1:N for adaptive bitrate scenario.

2018-11-11 Thread Jun Zhao
Improved the performance of 1 decode + N filter graphs and adaptive
bitrate scenario.

With new option "-abr_pipeline"
1. It enabled multiple filter graph concurrency, which bring above
about 5%~20% improvement in some 1:N scenario by CPU or GPU
acceleration
2. Next step will continue to improve the concurrency of complex
filter graph which can support high efficiency of filter net

Below are some test cases and test result as reference.
(Hardware platform: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz)
(Software: Intel iHD driver - 16.9.00100, CentOS 7)

Command for Intel GPU acceleration case, 1 decode to N scaling:
ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi \
-hwaccel_output_format vaapi \
-i ~/Videos/1920x1080p_30.00_x264_qp28.h264 \
-vf "scale_vaapi=1280:720:format=nv12,hwdownload" \
-pix_fmt nv12 -f null /dev/null \
-vf "scale_vaapi=720:480:format=nv12,hwdownload" \
-pix_fmt nv12 -f null /dev/null \
-abr_pipeline

test results:
2 scale
Improved   ~34%

Command for CPU only 1 decode to N scaling:
ffmpeg -i ~/Videos/1920x1080p_30.00_x264_qp28.h264 \
-vf "scale=1280:720" -pix_fmt nv12 -f null /dev/null \
-vf "scale=720:480" -pix_fmt nv12 -f null /dev/null \
-abr_pipeline

test results:
2 scale
Improved   ~25%

Command for 1:N transcode by GPU acceleration:
./ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi \
-hwaccel_output_format vaapi \
-i ~/Videos/1920x1080p_30.00_x264_qp28.h264 \
-vf "scale_vaapi=1280:720" -c:v h264_vaapi -f null /dev/null \
-vf "scale_vaapi=720:480" -c:v h264_vaapi -f null /dev/null \
-abr_pipeline

test results:
2 scale+enc
Improved  ~6.1%

Signed-off-by: Wang, Shaofei 
Signed-off-by: Jun Zhao 
---
 fftools/ffmpeg.c|  236 ---
 fftools/ffmpeg.h|   12 +++
 fftools/ffmpeg_filter.c |6 +
 fftools/ffmpeg_opt.c|6 +-
 4 files changed, 246 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38c21e9..5dc80fd 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1523,6 +1523,110 @@ static int reap_filters(int flush)
 return 0;
 }
 
+static int pipeline_reap_filters(int flush, InputFilter * ifilter)
+{
+AVFrame *filtered_frame = NULL;
+int i;
+
+for (i = 0; i < nb_output_streams; i++) {
+if (ifilter == output_streams[i]->filter->graph->inputs[0]) break;
+}
+OutputStream *ost = output_streams[i];
+OutputFile*of = output_files[ost->file_index];
+AVFilterContext *filter;
+AVCodecContext *enc = ost->enc_ctx;
+int ret = 0;
+
+if (!ost->filter || !ost->filter->graph->graph)
+return 0;
+filter = ost->filter->filter;
+
+if (!ost->initialized) {
+char error[1024] = "";
+ret = init_output_stream(ost, error, sizeof(error));
+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d 
-- %s\n",
+   ost->file_index, ost->index, error);
+exit_program(1);
+}
+}
+
+if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) {
+return AVERROR(ENOMEM);
+}
+filtered_frame = ost->filtered_frame;
+
+while (1) {
+double float_pts = AV_NOPTS_VALUE; // this is identical to 
filtered_frame.pts but with higher precision
+ret = av_buffersink_get_frame_flags(filter, filtered_frame,
+   AV_BUFFERSINK_FLAG_NO_REQUEST);
+if (ret < 0) {
+if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
+av_log(NULL, AV_LOG_WARNING,
+   "Error in av_buffersink_get_frame_flags(): %s\n", 
av_err2str(ret));
+} else if (flush && ret == AVERROR_EOF) {
+if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
+do_video_out(of, ost, NULL, AV_NOPTS_VALUE);
+}
+break;
+}
+if (ost->finished) {
+av_frame_unref(filtered_frame);
+continue;
+}
+if (filtered_frame->pts != AV_NOPTS_VALUE) {
+int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : 
of->start_time;
+AVRational filter_tb = av_buffersink_get_time_base(filter);
+AVRational tb = enc->time_base;
+int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
+
+tb.den <<= extra_bits;
+float_pts =
+av_rescale_q(filtered_frame->pts, filter_tb, tb) -
+av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
+float_pts /= 1 << extra_bits;
+// avoid exact midoints to reduce the chance of rounding 
differences, this can be removed in case the fps code is changed to work with 
integers
+float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
+
+filtered_frame->pts =
+