[FFmpeg-devel] [PATCH] avformat/dashenc: Add documentation for http method option

2018-05-06 Thread Karthick J
From: Karthick Jeyapal 

---
 doc/muxers.texi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 2429f8e..ea80296 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -252,6 +252,8 @@ DASH-templated name to used for the initialization segment. 
Default is "init-str
 DASH-templated name to used for the media segments. Default is 
"chunk-stream$RepresentationID$-$Number%05d$.m4s"
 @item -utc_timing_url @var{utc_url}
 URL of the page that will return the UTC timestamp in ISO format. Example: 
"https://time.akamai.com/?iso;
+@item method @var{method}
+Use the given HTTP method to create output files. Generally set to PUT or POST.
 @item -http_user_agent @var{user_agent}
 Override User-Agent field in HTTP header. Applicable only for HTTP output.
 @item -http_persistent @var{http_persistent}
-- 
2.7.4

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


Re: [FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

2018-05-06 Thread Steven Liu
Hi Sergey,

How should i test this filter?
I tested it some days ago, the picture get worse from 2nd frame.
input resolution 640x480 to 1280x720;

ffmpeg -i input -vf srcnn output

> On May 7, 2018, at 09:33, Pedro Arthur  wrote:
> 
> 2018-05-06 17:27 GMT-03:00 James Almer :
>> On 5/5/2018 5:38 PM, James Almer wrote:
>>> On 4/10/2018 2:16 PM, Sergey Lavrushkin wrote:
 diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
 new file mode 100644
 index 00..d9b4891f7f
 --- /dev/null
 +++ b/libavfilter/vf_srcnn.c
 @@ -0,0 +1,420 @@
 +/*
 + * Copyright (c) 2018 Sergey Lavrushkin
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301 USA
 + */
 +
 +/**
 + * @file
 + * Filter implementing image super-resolution using deep convolutional 
 networks.
 + * https://arxiv.org/abs/1501.00092
 + */
 +
 +#include "avfilter.h"
 +#include "formats.h"
 +#include "internal.h"
 +#include "libavutil/opt.h"
 +#include "unistd.h"
>>> 
>>> This broke msvc. It should be (if anything) , and wrapped
>>> inside a HAVE_UNISTD_H preprocessor check.
>> 
>> I (accidentally) applied this change as part of an unrelated commit, so
>> that's dealt with at least.
>> 
>>> 
 +static av_cold int init(AVFilterContext* context)
 +{
 +SRCNNContext *srcnn_context = context->priv;
 +AVIOContext* config_file_context;
 +int64_t file_size, srcnn_size;
 +
 +/// Check specified confguration file name and read network weights 
 from it
 +if (!srcnn_context->config_file_path){
 +av_log(context, AV_LOG_INFO, "configuration file for network was 
 not specified, using default weights for x2 upsampling\n");
 +
 +/// Create convolution kernels and copy default weights
 +srcnn_context->conv1.input_channels = 1;
 +srcnn_context->conv1.output_channels = 64;
 +srcnn_context->conv1.size = 9;
 +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv1, 
 conv1_kernel, conv1_biases), )
 +
 +srcnn_context->conv2.input_channels = 64;
 +srcnn_context->conv2.output_channels = 32;
 +srcnn_context->conv2.size = 1;
 +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv2, 
 conv2_kernel, conv2_biases), )
 +
 +srcnn_context->conv3.input_channels = 32;
 +srcnn_context->conv3.output_channels = 1;
 +srcnn_context->conv3.size = 5;
 +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv3, 
 conv3_kernel, conv3_biases), )
 +}
 +else if (access(srcnn_context->config_file_path, R_OK) != -1){
>>> 
>>> This seems to be the function needed from unistd.h
>>> 
>>> Looking at configure and libavformat/file.c it's apparently not
>>> available everywhere (we have a HAVE_ACCESS define, and also check for
>>> mode constants like R_OK).
>> 
>> MSVC does not have access(), so i have temporarily made this filter
>> depend on its presence until a proper fix is applied. That target has
>> been broken for a few days now and that shouldn't be the case.
>> It should be a matter or doing the same thing as in libavformat/file.c,
>> i guess, or perhaps use _access() instead, which is available in MSVC.
> Thanks.
> 
> 
> @Sergey can you provide a definitive fix?
> 
>> ___
>> 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

Thanks
Steven



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


Re: [FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

2018-05-06 Thread Pedro Arthur
2018-05-06 17:27 GMT-03:00 James Almer :
> On 5/5/2018 5:38 PM, James Almer wrote:
>> On 4/10/2018 2:16 PM, Sergey Lavrushkin wrote:
>>> diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
>>> new file mode 100644
>>> index 00..d9b4891f7f
>>> --- /dev/null
>>> +++ b/libavfilter/vf_srcnn.c
>>> @@ -0,0 +1,420 @@
>>> +/*
>>> + * Copyright (c) 2018 Sergey Lavrushkin
>>> + *
>>> + * This file is part of FFmpeg.
>>> + *
>>> + * FFmpeg is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2.1 of the License, or (at your option) any later version.
>>> + *
>>> + * FFmpeg is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU Lesser General Public
>>> + * License along with FFmpeg; if not, write to the Free Software
>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
>>> 02110-1301 USA
>>> + */
>>> +
>>> +/**
>>> + * @file
>>> + * Filter implementing image super-resolution using deep convolutional 
>>> networks.
>>> + * https://arxiv.org/abs/1501.00092
>>> + */
>>> +
>>> +#include "avfilter.h"
>>> +#include "formats.h"
>>> +#include "internal.h"
>>> +#include "libavutil/opt.h"
>>> +#include "unistd.h"
>>
>> This broke msvc. It should be (if anything) , and wrapped
>> inside a HAVE_UNISTD_H preprocessor check.
>
> I (accidentally) applied this change as part of an unrelated commit, so
> that's dealt with at least.
>
>>
>>> +static av_cold int init(AVFilterContext* context)
>>> +{
>>> +SRCNNContext *srcnn_context = context->priv;
>>> +AVIOContext* config_file_context;
>>> +int64_t file_size, srcnn_size;
>>> +
>>> +/// Check specified confguration file name and read network weights 
>>> from it
>>> +if (!srcnn_context->config_file_path){
>>> +av_log(context, AV_LOG_INFO, "configuration file for network was 
>>> not specified, using default weights for x2 upsampling\n");
>>> +
>>> +/// Create convolution kernels and copy default weights
>>> +srcnn_context->conv1.input_channels = 1;
>>> +srcnn_context->conv1.output_channels = 64;
>>> +srcnn_context->conv1.size = 9;
>>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv1, 
>>> conv1_kernel, conv1_biases), )
>>> +
>>> +srcnn_context->conv2.input_channels = 64;
>>> +srcnn_context->conv2.output_channels = 32;
>>> +srcnn_context->conv2.size = 1;
>>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv2, 
>>> conv2_kernel, conv2_biases), )
>>> +
>>> +srcnn_context->conv3.input_channels = 32;
>>> +srcnn_context->conv3.output_channels = 1;
>>> +srcnn_context->conv3.size = 5;
>>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv3, 
>>> conv3_kernel, conv3_biases), )
>>> +}
>>> +else if (access(srcnn_context->config_file_path, R_OK) != -1){
>>
>> This seems to be the function needed from unistd.h
>>
>> Looking at configure and libavformat/file.c it's apparently not
>> available everywhere (we have a HAVE_ACCESS define, and also check for
>> mode constants like R_OK).
>
> MSVC does not have access(), so i have temporarily made this filter
> depend on its presence until a proper fix is applied. That target has
> been broken for a few days now and that shouldn't be the case.
> It should be a matter or doing the same thing as in libavformat/file.c,
> i guess, or perhaps use _access() instead, which is available in MSVC.
Thanks.


@Sergey can you provide a definitive fix?

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


Re: [FFmpeg-devel] [PATCH 3/3] doc/protocols: documents tcp_mss

2018-05-06 Thread myp...@gmail.com
2018-05-06 23:16 GMT+08:00 Gyan Doshi :
>
>
> On 5/6/2018 8:42 PM, Jun Zhao wrote:
>
>> +@item tcp_mss=@var{bytes}
>> +Set maximum segment size for outgoing TCP packets, expressed bytes.
>
>
> 'expressed bytes' --> 'expressed in bytes'
>
> or just 'in bytes'  (preferred).
>
>
Sounds good, will update in the V2. tks.
> Thanks,
> Gyan
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] lavf/tcp: add option to setting Maximum Segment Size

2018-05-06 Thread myp...@gmail.com
2018-05-07 5:17 GMT+08:00 Michael Niedermayer :
> On Sun, May 06, 2018 at 11:12:13PM +0800, Jun Zhao wrote:
>> This can change the the MSS value announced to the other end in
>> the initial TCP packet, it's can be used when failed Path MTU
>> discovery.
>>
>> Signed-off-by: Jun Zhao 
>> ---
>>  libavformat/tcp.c | 5 +
>>  1 file changed, 5 insertions(+)
>
> breaks build on mingw64
>
> CC  libavformat/tcp.o
> src/libavformat/tcp.c: In function ‘tcp_open’:
> src/libavformat/tcp.c:159:27: error: ‘TCP_MAXSEG’ undeclared (first use in 
> this function)
>  setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, >tcp_mss, sizeof 
> (s->tcp_mss));
>^
> src/libavformat/tcp.c:159:27: note: each undeclared identifier is reported 
> only once for each function it appears in
> make: *** [libavformat/tcp.o] Error 1
> make: Target `all' not remade because of errors.
Will fix the mingw64 build fail, tks
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> No great genius has ever existed without some touch of madness. -- Aristotle
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>



-- 
===
Pixelworks
Room 301-303 No. 88,Lane 887 Zuchongzhi Road, Zhangjiang Hi-tech Park,
Shanghai 201203, China
Best Regards,
Jun zhao/赵军
+++
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] mdct15: simplify the fft15 x86 SIMD

2018-05-06 Thread Rostislav Pehlivanov
Saves 1 gpr and 2 instructions and simplifies the macros a bit.

Signed-off-by: Rostislav Pehlivanov 
---
 libavcodec/x86/mdct15.asm | 37 +
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/libavcodec/x86/mdct15.asm b/libavcodec/x86/mdct15.asm
index 0309112538..2a2cdbd21b 100644
--- a/libavcodec/x86/mdct15.asm
+++ b/libavcodec/x86/mdct15.asm
@@ -76,7 +76,7 @@ SECTION .text
 addps   m%3,  m%3,  m0  ; Finally offset with DCs
 %endmacro
 
-%macro BUTTERFLIES_DC 2 ; %1 - exptab_offset, %2 - out
+%macro BUTTERFLIES_DC 1 ; %1 - exptab_offset
 mulps xm0,  xm9, [exptabq + %1 + 16*0]
 mulps xm1, xm10, [exptabq + %1 + 16*1]
 
@@ -86,10 +86,10 @@ SECTION .text
 addps   xm0,  xm1
 addps   xm0,  xm8
 
-movsd [%2q], xm0
+movsd [outq], xm0
 %endmacro
 
-%macro BUTTERFLIES_AC 2 ; exptab, exptab_offset, src1, src2, src3, out (uses 
m0-m3)
+%macro BUTTERFLIES_AC 1 ; %1 - exptab_offset
 mulps  m0, m12, [exptabq + 64*0 + 0*mmsize + %1]
 mulps  m1, m12, [exptabq + 64*0 + 1*mmsize + %1]
 mulps  m2, m13, [exptabq + 64*1 + 0*mmsize + %1]
@@ -104,15 +104,14 @@ SECTION .text
 
 vextractf128 xm1, m0, 1
 
-movlps [%2q + strideq*1], xm0
-movhps [%2q + strideq*2], xm0
-movlps [%2q +  stride3q], xm1
-movhps [%2q + strideq*4], xm1
+movlps [outq + strideq*1], xm0
+movhps [outq + strideq*2], xm0
+movlps [outq +  stride3q], xm1
+movhps [outq + strideq*4], xm1
 %endmacro
 
 INIT_YMM avx
-cglobal fft15, 4, 6, 14, out, in, exptab, stride, stride3, stride5
-%define out0q inq
+cglobal fft15, 4, 5, 14, out, in, exptab, stride, stride5
 shl strideq, 3
 
 movaps xm5, [exptabq + 480 + 16*0]
@@ -123,22 +122,20 @@ cglobal fft15, 4, 6, 14, out, in, exptab, stride, 
stride3, stride5
 FFT5  8,  xm9, 12
 FFT5 16, xm10, 13
 
+%define stride3q inq
 lea stride3q, [strideq + strideq*2]
 lea stride5q, [strideq + strideq*4]
 
-mov out0q, outq
+BUTTERFLIES_DC (8*6 + 4*0)*2*4
+BUTTERFLIES_AC (8*0 + 0*0)*2*4
 
-BUTTERFLIES_DC (8*6 + 4*0)*2*4, out0
-lea outq, [out0q + stride5q*1]
-BUTTERFLIES_DC (8*6 + 4*1)*2*4, out
-lea outq, [out0q + stride5q*2]
-BUTTERFLIES_DC (8*6 + 4*2)*2*4, out
+add outq, stride5q
+BUTTERFLIES_DC (8*6 + 4*1)*2*4
+BUTTERFLIES_AC (8*2 + 0*0)*2*4
 
-BUTTERFLIES_AC (8*0)*2*4, out0
-lea outq, [out0q + stride5q*1]
-BUTTERFLIES_AC (8*2)*2*4, out
-lea outq, [out0q + stride5q*2]
-BUTTERFLIES_AC (8*4)*2*4, out
+add outq, stride5q
+BUTTERFLIES_DC (8*6 + 4*2)*2*4
+BUTTERFLIES_AC (8*4 + 0*0)*2*4
 
 RET
 
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH 2/9] lavfi/nlmeans: add SIMD-friendly assumptions for compute_safe_ssd_integral_image

2018-05-06 Thread Michael Niedermayer
On Sun, May 06, 2018 at 01:40:53PM +0200, Clément Bœsch wrote:
> SIMD code will not have to deal with padding itself. Overwriting in that
> function may have been possible but involve large overreading of the
> sources. Instead, we simply make sure the width to process is always a
> multiple of 16. Additionally, there must be some actual area to process
> so the SIMD code can have its boundary checks after processing the first
> pixels.
> ---
>  libavfilter/vf_nlmeans.c | 25 ++---
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> index d222d3913e..21f981a605 100644
> --- a/libavfilter/vf_nlmeans.c
> +++ b/libavfilter/vf_nlmeans.c
> @@ -157,6 +157,9 @@ static void compute_safe_ssd_integral_image_c(uint32_t 
> *dst, int dst_linesize_32
>  {
>  int x, y;
>  
> +/* SIMD-friendly assumptions allowed here */
> +av_assert2(!(w & 0xf) && w >= 16 && h >= 1);
> +
>  for (y = 0; y < h; y++) {
>  uint32_t acc = dst[-1] - dst[-dst_linesize_32 - 1];
>  
> @@ -257,9 +260,16 @@ static void compute_ssd_integral_image(uint32_t *ii, int 
> ii_linesize_32,
>  // to compare the 2 sources pixels
>  const int startx_safe = FFMAX(s1x, s2x);
>  const int starty_safe = FFMAX(s1y, s2y);
> -const int endx_safe   = FFMIN(s1x + w, s2x + w);
> +const int u_endx_safe = FFMIN(s1x + w, s2x + w); // unaligned
>  const int endy_safe   = FFMIN(s1y + h, s2y + h);
>  
> +// deduce the safe area width and height
> +const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
> +const int safe_ph = endy_safe - starty_safe;
> +
> +// adjusted end x position of the safe area after width of the safe area 
> gets aligned
> +const int endx_safe = startx_safe + safe_pw;
> +
>  // top part where only one of s1 and s2 is still readable, or none at all
>  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
>0, 0,
> @@ -273,24 +283,25 @@ static void compute_ssd_integral_image(uint32_t *ii, 
> int ii_linesize_32,
>0, starty_safe,
>src, linesize,
>offx, offy, e, w, h,
> -  startx_safe, endy_safe - starty_safe);
> +  startx_safe, safe_ph);
>  
>  // main and safe part of the integral
>  av_assert1(startx_safe - s1x >= 0); av_assert1(startx_safe - s1x < w);
>  av_assert1(starty_safe - s1y >= 0); av_assert1(starty_safe - s1y < h);
>  av_assert1(startx_safe - s2x >= 0); av_assert1(startx_safe - s2x < w);
>  av_assert1(starty_safe - s2y >= 0); av_assert1(starty_safe - s2y < h);
> -compute_safe_ssd_integral_image_c(ii + starty_safe*ii_linesize_32 + 
> startx_safe, ii_linesize_32,
> -  src + (starty_safe - s1y) * linesize + 
> (startx_safe - s1x), linesize,
> -  src + (starty_safe - s2y) * linesize + 
> (startx_safe - s2x), linesize,
> -  endx_safe - startx_safe, endy_safe - 
> starty_safe);
> +if (safe_pw && safe_ph)
> +dsp->compute_safe_ssd_integral_image(ii + starty_safe*ii_linesize_32 
> + startx_safe, ii_linesize_32,
> + src + (starty_safe - s1y) * 
> linesize + (startx_safe - s1x), linesize,
> + src + (starty_safe - s2y) * 
> linesize + (startx_safe - s2x), linesize,
> + safe_pw, safe_ph);


i think this is or i am missing some change

libavfilter/vf_nlmeans.c: In function ‘compute_ssd_integral_image’:
libavfilter/vf_nlmeans.c:294:9: error: ‘dsp’ undeclared (first use in this 
function)
 dsp->compute_safe_ssd_integral_image(ii + starty_safe*ii_linesize_32 + 
startx_safe, ii_linesize_32,
 ^
libavfilter/vf_nlmeans.c:294:9: note: each undeclared identifier is reported 
only once for each function it appears in
libavfilter/vf_nlmeans.c: At top level:
libavfilter/vf_nlmeans.c:153:13: warning: ‘compute_safe_ssd_integral_image_c’ 
defined but not used [-Wunused-function]
 static void compute_safe_ssd_integral_image_c(uint32_t *dst, int 
dst_linesize_32,
 ^
make: *** [libavfilter/vf_nlmeans.o] Error 1
make: *** Waiting for unfinished jobs

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


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


Re: [FFmpeg-devel] [PATCH 2/3] lavf/tcp: add option to setting Maximum Segment Size

2018-05-06 Thread Michael Niedermayer
On Sun, May 06, 2018 at 11:12:13PM +0800, Jun Zhao wrote:
> This can change the the MSS value announced to the other end in
> the initial TCP packet, it's can be used when failed Path MTU
> discovery.
> 
> Signed-off-by: Jun Zhao 
> ---
>  libavformat/tcp.c | 5 +
>  1 file changed, 5 insertions(+)

breaks build on mingw64

CC  libavformat/tcp.o
src/libavformat/tcp.c: In function ‘tcp_open’:
src/libavformat/tcp.c:159:27: error: ‘TCP_MAXSEG’ undeclared (first use in this 
function)
 setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, >tcp_mss, sizeof 
(s->tcp_mss));
   ^
src/libavformat/tcp.c:159:27: note: each undeclared identifier is reported only 
once for each function it appears in
make: *** [libavformat/tcp.o] Error 1
make: Target `all' not remade because of errors.

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

No great genius has ever existed without some touch of madness. -- Aristotle


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


[FFmpeg-devel] [PATCH 2/2] avcodec/libzvbi-teletextdec: formatted ass output

2018-05-06 Thread Marton Balint
Inspired by the VideoLAN text decoder and its port to FFmpeg made by Aman
Gupta.

Signed-off-by: Marton Balint 
---
 doc/decoders.texi|  18 ++-
 libavcodec/libzvbi-teletextdec.c | 265 +--
 2 files changed, 270 insertions(+), 13 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index 8f07bc1afb..cc9b2ef123 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -255,12 +255,18 @@ Default value is *.
 @item txt_chop_top
 Discards the top teletext line. Default value is 1.
 @item txt_format
-Specifies the format of the decoded subtitles. The teletext decoder is capable
-of decoding the teletext pages to bitmaps or to simple text, you should use
-"bitmap" for teletext pages, because certain graphics and colors cannot be
-expressed in simple text. You might use "text" for teletext based subtitles if
-your application can handle simple text based subtitles. Default value is
-bitmap.
+Specifies the format of the decoded subtitles.
+@table @option
+@item bitmap
+The default format, you should use this for teletext pages, because certain
+graphics and colors cannot be expressed in simple text or even ASS.
+@item text
+Simple text based output without formatting.
+@item ass
+Formatted ASS output, subtitle pages and teletext pages are returned in
+different styles, subtitle pages are stripped down to text, but an effort is
+made to keep the text alignment and the formatting.
+@end table
 @item txt_left
 X offset of generated bitmaps, default is 0.
 @item txt_top
diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index 56a7182882..7541de0d53 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
+#include "libavutil/common.h"
 
 #include 
 
@@ -56,7 +57,7 @@ typedef struct TeletextContext
 char   *pgno;
 int x_offset;
 int y_offset;
-int format_id; /* 0 = bitmap, 1 = text/ass */
+int format_id; /* 0 = bitmap, 1 = text/ass, 2 = ass */
 int chop_top;
 int sub_duration; /* in msec */
 int transparent_bg;
@@ -74,8 +75,55 @@ typedef struct TeletextContext
 
 int readorder;
 uint8_t subtitle_map[2048];
+int last_ass_alignment;
 } TeletextContext;
 
+static int my_ass_subtitle_header(AVCodecContext *avctx)
+{
+int ret = ff_ass_subtitle_header_default(avctx);
+char *new_header;
+uint8_t *event_pos;
+
+if (ret < 0)
+return ret;
+
+event_pos = strstr(avctx->subtitle_header, "\r\n[Events]\r\n");
+if (!event_pos)
+return AVERROR_BUG;
+
+new_header = av_asprintf("%.*s%s%s",
+(int)(event_pos - avctx->subtitle_header), avctx->subtitle_header,
+"Style: "
+"Teletext,"/* Name */
+"Monospace,11,"/* Font{name,size} */
+"" /* {Primary,Secondary,Outline,Back}Colour 
*/
+"0,0,0,0," /* Bold, Italic, Underline, StrikeOut */
+"160,100," /* Scale{X,Y} */
+"0,0," /* Spacing, Angle */
+"3,0.1,0," /* BorderStyle, Outline, Shadow */
+"5,1,1,1," /* Alignment, Margin[LRV] */
+"0\r\n"/* Encoding */
+"Style: "
+"Subtitle,"/* Name */
+"Monospace,16,"/* Font{name,size} */
+"" /* {Primary,Secondary,Outline,Back}Colour 
*/
+"0,0,0,0," /* Bold, Italic, Underline, StrikeOut */
+"100,100," /* Scale{X,Y} */
+"0,0," /* Spacing, Angle */
+"1,1,1,"   /* BorderStyle, Outline, Shadow */
+"8,48,48,20,"  /* Alignment, Margin[LRV] */
+"0\r\n"/* Encoding */
+, event_pos);
+
+if (!new_header)
+return AVERROR(ENOMEM);
+
+av_free(avctx->subtitle_header);
+avctx->subtitle_header = new_header;
+avctx->subtitle_header_size = strlen(new_header);
+return 0;
+}
+
 static int chop_spaces_utf8(const unsigned char* t, int len)
 {
 t += len;
@@ -179,6 +227,186 @@ static int gen_sub_text(TeletextContext *ctx, 
AVSubtitleRect *sub_rect, vbi_page
 return 0;
 }
 
+static void bprint_color(const char *type, AVBPrint *buf, vbi_page *page, 
unsigned ci)
+{
+int r = VBI_R(page->color_map[ci]);
+int g = VBI_G(page->color_map[ci]);
+int b = VBI_B(page->color_map[ci]);
+av_bprintf(buf, "{\\%s%02X%02X%02X&}", type, b, g, r);
+}
+
+#define IS_TXT_SPACE(ch) ((ch).unicode < 0x0020 || (ch).unicode >= 0xe000 || 
(ch).unicode == 0x00a0 ||\
+  (ch).size > VBI_DOUBLE_SIZE || (ch).opacity == 
VBI_TRANSPARENT_SPACE)
+
+static void get_trim_info(vbi_page *page, vbi_char *row, int *leading, 

[FFmpeg-devel] [PATCH 1/2] avcodec/libzvbi-teletextdec: add support for selecting subtitle pages only

2018-05-06 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/decoders.texi|  5 +++--
 libavcodec/libzvbi-teletextdec.c | 31 ++-
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index a551d5d0fd..8f07bc1afb 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -248,8 +248,9 @@ configuration. You need to explicitly configure the build 
with
 
 @table @option
 @item txt_page
-List of teletext page numbers to decode. You may use the special * string to
-match all pages. Pages that do not match the specified list are dropped.
+List of teletext page numbers to decode. Pages that do not match the specified
+list are dropped. You may use the special @code{*} string to match all pages,
+or @code{subtitle} to match all subtitle pages.
 Default value is *.
 @item txt_chop_top
 Discards the top teletext line. Default value is 1.
diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index a800ad34ae..56a7182882 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -73,6 +73,7 @@ typedef struct TeletextContext
 vbi_sliced  sliced[MAX_SLICES];
 
 int readorder;
+uint8_t subtitle_map[2048];
 } TeletextContext;
 
 static int chop_spaces_utf8(const unsigned char* t, int len)
@@ -281,16 +282,14 @@ static void handler(vbi_event *ev, void *user_data)
 vbi_page page;
 int res;
 char pgno_str[12];
-vbi_subno subno;
-vbi_page_type vpt;
 int chop_top;
-char *lang;
+int is_subtitle_page = ctx->subtitle_map[ev->ev.ttx_page.pgno & 0x7ff];
 
 snprintf(pgno_str, sizeof pgno_str, "%03x", ev->ev.ttx_page.pgno);
 av_log(ctx, AV_LOG_DEBUG, "decoded page %s.%02x\n",
pgno_str, ev->ev.ttx_page.subno & 0xFF);
 
-if (strcmp(ctx->pgno, "*") && !strstr(ctx->pgno, pgno_str))
+if (strcmp(ctx->pgno, "*") && (strcmp(ctx->pgno, "subtitle") || 
!is_subtitle_page) && !strstr(ctx->pgno, pgno_str))
 return;
 if (ctx->handler_ret < 0)
 return;
@@ -303,9 +302,7 @@ static void handler(vbi_event *ev, void *user_data)
 if (!res)
 return;
 
-vpt = vbi_classify_page(ctx->vbi, ev->ev.ttx_page.pgno, , );
-chop_top = ctx->chop_top ||
-((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
+chop_top = ctx->chop_top || ((page.rows > 1) && is_subtitle_page);
 
 av_log(ctx, AV_LOG_DEBUG, "%d x %d page chop:%d\n",
page.columns, page.rows, chop_top);
@@ -357,11 +354,26 @@ static int slice_to_vbi_lines(TeletextContext *ctx, 
uint8_t* buf, int size)
 else {
 int line_offset  = buf[2] & 0x1f;
 int field_parity = buf[2] & 0x20;
-int i;
+uint8_t *p = ctx->sliced[lines].data;
+int i, pmag;
 ctx->sliced[lines].id = VBI_SLICED_TELETEXT_B;
 ctx->sliced[lines].line = (line_offset > 0 ? (line_offset + 
(field_parity ? 0 : 313)) : 0);
 for (i = 0; i < 42; i++)
-ctx->sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
+p[i] = vbi_rev8(buf[4 + i]);
+/* Unfortunately libzvbi does not expose page flags, and
+ * vbi_classify_page only checks MIP, so we have to manually
+ * decode the page flags and store the results. */
+pmag = vbi_unham16p(p);
+if (pmag >= 0 && pmag >> 3 == 0) {   // We found a row 0 header
+int page = vbi_unham16p(p + 2);
+int flags1 = vbi_unham16p(p + 6);
+int flags2 = vbi_unham16p(p + 8);
+if (page >= 0 && flags1 >= 0 && flags2 >= 0) {
+int pgno = ((pmag & 7) << 8) + page;
+// Check for disabled NEWSFLASH flag and enabled 
SUBTITLE and SUPRESS_HEADER flags
+ctx->subtitle_map[pgno] = (!(flags1 & 0x40) && flags1 
& 0x80 && flags2 & 0x01);
+}
+}
 lines++;
 }
 }
@@ -502,6 +514,7 @@ static int teletext_close_decoder(AVCodecContext *avctx)
 vbi_decoder_delete(ctx->vbi);
 ctx->vbi = NULL;
 ctx->pts = AV_NOPTS_VALUE;
+memset(ctx->subtitle_map, 0, sizeof(ctx->subtitle_map));
 if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
 ctx->readorder = 0;
 return 0;
-- 
2.13.6

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


Re: [FFmpeg-devel] [PATCH 1/3] avformat/utils: function to get the formatted ntp time

2018-05-06 Thread Michael Niedermayer
On Sun, May 06, 2018 at 06:04:35PM +, Dixit, Vishwanath wrote:
> 
> 
> On 4/28/18 6:38 AM, Michael Niedermayer wrote:
> > On Fri, Apr 27, 2018 at 08:00:23AM +, Dixit, Vishwanath wrote:
> >>
> >>
> >> On 4/27/18 5:15 AM, Michael Niedermayer wrote:
> >>> On Thu, Apr 26, 2018 at 11:05:59AM +, Dixit, Vishwanath wrote:
> 
> 
>  On 4/26/18 1:04 AM, Michael Niedermayer wrote:
> > On Tue, Apr 24, 2018 at 02:46:56PM +0530, vdi...@akamai.com wrote:
> >> From: Vishwanath Dixit 
> >>
> >> This utility function creates 64-bit NTP time format as per the RFC
> >> 5905.
> >> A simple explaination of 64-bit NTP time format is here
> >> http://www.beaglesoft.com/Manual/page53.htm
> >> ---
> >>  libavformat/internal.h |  8 
> >>  libavformat/utils.c| 20 
> >>  2 files changed, 28 insertions(+)
> >>
> >> diff --git a/libavformat/internal.h b/libavformat/internal.h
> >> index 3582682..e9f758f 100644
> >> --- a/libavformat/internal.h
> >> +++ b/libavformat/internal.h
> >> @@ -240,6 +240,14 @@ void ff_read_frame_flush(AVFormatContext *s);
> >>  uint64_t ff_ntp_time(void);
> >>  
> >>  /**
> >> + * Get the NTP time stamp formatted as per the RFC-5905.
> >> + *
> >> + * @param ntp_time NTP time in micro seconds (since NTP epoch)
> >> + * @return the formatted NTP time stamp
> >> + */
> >> +uint64_t ff_time_ntp_format(uint64_t ntp_time);
> >> +
> >> +/**
> >>   * Append the media-specific SDP fragment for the media stream c
> >>   * to the buffer buff.
> >>   *
> >> diff --git a/libavformat/utils.c b/libavformat/utils.c
> >> index c25eab4..b59d426 100644
> >> --- a/libavformat/utils.c
> >> +++ b/libavformat/utils.c
> >> @@ -4637,6 +4637,26 @@ uint64_t ff_ntp_time(void)
> >>  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
> >>  }
> >>  
> >> +uint64_t ff_time_ntp_format(uint64_t ntp_time)
> >> +{
> >> +uint64_t ntp_ts, frac_part;
> >> +uint32_t sec, usec;
> >> +
> >> +//current ntp time in seconds and micro seconds
> >
> >> +sec = ntp_time / 100;
> >
> > This can be truncated
>  Yes, but the truncated part is not getting discarded, as the following 
>  line is taking care of that. Please correct me if I have not understood 
>  what you have intended to say here.
> >>>
> >>> ok, correcting you then :)
> >>> sec is 32bit
> >>> not all values of "ntp_time / 100;" fit in 32bit
> >>> there is no check for this it just produces a wrong result
> >> Yes, you are right. But, I can use only the LS 32bits of the result in the 
> >> following code. It is a limitation of 64-bit NTP time format and the issue 
> >> is going to occur in 2036. Not sure how to handle it here. At most, I can 
> >> print a warning message when the result gets truncated. Could you please 
> >> suggest any alternative option?
> >
> > i cant make it work after 2036 as that seems what the design is limited at.
> > But the error can be detected and handled
> Yes, the error can be detected and one possible way I can think of handling 
> that error, is to truncate LS bits instead of MS bits. But, this solution 
> also will not be completely error free. Honestly, I am not able to find any 
> useful ways of handling the error, apart from displaying a warning message. 
> Request you to let me know if you have any solution in mind.

I dont know the oppinion of others, but a warning message seems usefull
in this case

thx

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

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued


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


Re: [FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

2018-05-06 Thread James Almer
On 5/5/2018 5:38 PM, James Almer wrote:
> On 4/10/2018 2:16 PM, Sergey Lavrushkin wrote:
>> diff --git a/libavfilter/vf_srcnn.c b/libavfilter/vf_srcnn.c
>> new file mode 100644
>> index 00..d9b4891f7f
>> --- /dev/null
>> +++ b/libavfilter/vf_srcnn.c
>> @@ -0,0 +1,420 @@
>> +/*
>> + * Copyright (c) 2018 Sergey Lavrushkin
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
>> USA
>> + */
>> +
>> +/**
>> + * @file
>> + * Filter implementing image super-resolution using deep convolutional 
>> networks.
>> + * https://arxiv.org/abs/1501.00092
>> + */
>> +
>> +#include "avfilter.h"
>> +#include "formats.h"
>> +#include "internal.h"
>> +#include "libavutil/opt.h"
>> +#include "unistd.h"
> 
> This broke msvc. It should be (if anything) , and wrapped
> inside a HAVE_UNISTD_H preprocessor check.

I (accidentally) applied this change as part of an unrelated commit, so
that's dealt with at least.

> 
>> +static av_cold int init(AVFilterContext* context)
>> +{
>> +SRCNNContext *srcnn_context = context->priv;
>> +AVIOContext* config_file_context;
>> +int64_t file_size, srcnn_size;
>> +
>> +/// Check specified confguration file name and read network weights 
>> from it
>> +if (!srcnn_context->config_file_path){
>> +av_log(context, AV_LOG_INFO, "configuration file for network was 
>> not specified, using default weights for x2 upsampling\n");
>> +
>> +/// Create convolution kernels and copy default weights
>> +srcnn_context->conv1.input_channels = 1;
>> +srcnn_context->conv1.output_channels = 64;
>> +srcnn_context->conv1.size = 9;
>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv1, 
>> conv1_kernel, conv1_biases), )
>> +
>> +srcnn_context->conv2.input_channels = 64;
>> +srcnn_context->conv2.output_channels = 32;
>> +srcnn_context->conv2.size = 1;
>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv2, 
>> conv2_kernel, conv2_biases), )
>> +
>> +srcnn_context->conv3.input_channels = 32;
>> +srcnn_context->conv3.output_channels = 1;
>> +srcnn_context->conv3.size = 5;
>> +CHECK_ALLOCATION(allocate_copy_conv_data(_context->conv3, 
>> conv3_kernel, conv3_biases), )
>> +}
>> +else if (access(srcnn_context->config_file_path, R_OK) != -1){
> 
> This seems to be the function needed from unistd.h
> 
> Looking at configure and libavformat/file.c it's apparently not
> available everywhere (we have a HAVE_ACCESS define, and also check for
> mode constants like R_OK).

MSVC does not have access(), so i have temporarily made this filter
depend on its presence until a proper fix is applied. That target has
been broken for a few days now and that shouldn't be the case.
It should be a matter or doing the same thing as in libavformat/file.c,
i guess, or perhaps use _access() instead, which is available in MSVC.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/bluray: translate a read of 0 to EOF

2018-05-06 Thread Michael Niedermayer
On Sun, May 06, 2018 at 06:55:01PM +0300, Jan Ekström wrote:
> On Sun, May 6, 2018 at 5:32 PM, wm4  wrote:
> >
> > Hilarious, another of those EOf issues. Too bad we didn't just revert
> > that crap. I wonder how many years it'll take until we got all of them.
> >
> > LGTM.
> 
> Thanks, pushed. This should be back-ported to release/4.0 I guess?

probably yes

thanks


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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/libzvbi-teletextdec: allow -1 subtitle duration and make it the default

2018-05-06 Thread Marton Balint



On Wed, 2 May 2018, Marton Balint wrote:


Most decoders (pgssubdec, ccaption_dec) are using -1 or UINT32_MAX for a
subtitle event which should be cleared at the next event.


Applied this and the next patch, I will re-send the third.

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


Re: [FFmpeg-devel] [PATCH v3] avformat/mxfenc: add h264 profiles

2018-05-06 Thread Thomas Mundt
2018-05-06 13:32 GMT+02:00 Tomas Härdin :

> fre 2018-05-04 klockan 01:52 +0200 skrev Thomas Mundt:
> > Hi,
> >
> > this is a better version of the patch.
> > 10 bit and TFF are mandatory for AVC Intra only. Other profiles
> > differ.
> >
>
> > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> > index 3bb7032..81513dc 100644
> > --- a/libavformat/mxfenc.c
> > +++ b/libavformat/mxfenc.c
> > @@ -1947,22 +1947,31 @@ static const struct {
> >  int frame_size;
> >  int profile;
> >  uint8_t interlaced;
> > +int long_gop;
>
> A comment here explaining the difference between -1, 0 and 1 would be
> nice. The rest looks OK, but I didn't read the relevant specs to be
> 100% sure
> 
>

New patch attached.

Regards,
Thomas


0001-avformat-mxfenc-add-h264-profiles.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/4] avcodec/g2meet: Change order of operations to avoid undefined behavior

2018-05-06 Thread Michael Niedermayer
On Fri, May 04, 2018 at 07:43:45PM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 65280 * 196032 cannot be represented in type 
> 'int'
> Fixes: 
> 7279/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_G2M_fuzzer-5977332473921536
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/g2meet.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)

will apply patchset

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

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle


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


Re: [FFmpeg-devel] [PATCH 1/3] avformat/utils: function to get the formatted ntp time

2018-05-06 Thread Dixit, Vishwanath


On 4/28/18 6:38 AM, Michael Niedermayer wrote:
> On Fri, Apr 27, 2018 at 08:00:23AM +, Dixit, Vishwanath wrote:
>>
>>
>> On 4/27/18 5:15 AM, Michael Niedermayer wrote:
>>> On Thu, Apr 26, 2018 at 11:05:59AM +, Dixit, Vishwanath wrote:


 On 4/26/18 1:04 AM, Michael Niedermayer wrote:
> On Tue, Apr 24, 2018 at 02:46:56PM +0530, vdi...@akamai.com wrote:
>> From: Vishwanath Dixit 
>>
>> This utility function creates 64-bit NTP time format as per the RFC
>> 5905.
>> A simple explaination of 64-bit NTP time format is here
>> http://www.beaglesoft.com/Manual/page53.htm
>> ---
>>  libavformat/internal.h |  8 
>>  libavformat/utils.c| 20 
>>  2 files changed, 28 insertions(+)
>>
>> diff --git a/libavformat/internal.h b/libavformat/internal.h
>> index 3582682..e9f758f 100644
>> --- a/libavformat/internal.h
>> +++ b/libavformat/internal.h
>> @@ -240,6 +240,14 @@ void ff_read_frame_flush(AVFormatContext *s);
>>  uint64_t ff_ntp_time(void);
>>  
>>  /**
>> + * Get the NTP time stamp formatted as per the RFC-5905.
>> + *
>> + * @param ntp_time NTP time in micro seconds (since NTP epoch)
>> + * @return the formatted NTP time stamp
>> + */
>> +uint64_t ff_time_ntp_format(uint64_t ntp_time);
>> +
>> +/**
>>   * Append the media-specific SDP fragment for the media stream c
>>   * to the buffer buff.
>>   *
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index c25eab4..b59d426 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -4637,6 +4637,26 @@ uint64_t ff_ntp_time(void)
>>  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
>>  }
>>  
>> +uint64_t ff_time_ntp_format(uint64_t ntp_time)
>> +{
>> +uint64_t ntp_ts, frac_part;
>> +uint32_t sec, usec;
>> +
>> +//current ntp time in seconds and micro seconds
>
>> +sec = ntp_time / 100;
>
> This can be truncated
 Yes, but the truncated part is not getting discarded, as the following 
 line is taking care of that. Please correct me if I have not understood 
 what you have intended to say here.
>>>
>>> ok, correcting you then :)
>>> sec is 32bit
>>> not all values of "ntp_time / 100;" fit in 32bit
>>> there is no check for this it just produces a wrong result
>> Yes, you are right. But, I can use only the LS 32bits of the result in the 
>> following code. It is a limitation of 64-bit NTP time format and the issue 
>> is going to occur in 2036. Not sure how to handle it here. At most, I can 
>> print a warning message when the result gets truncated. Could you please 
>> suggest any alternative option?
>
> i cant make it work after 2036 as that seems what the design is limited at.
> But the error can be detected and handled
Yes, the error can be detected and one possible way I can think of handling 
that error, is to truncate LS bits instead of MS bits. But, this solution also 
will not be completely error free. Honestly, I am not able to find any useful 
ways of handling the error, apart from displaying a warning message. Request 
you to let me know if you have any solution in mind.
>
> [...]
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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


Re: [FFmpeg-devel] [PATCH] configure: add pkg-config check for zlib

2018-05-06 Thread Jan Ekström
On Sun, May 6, 2018 at 7:41 PM, James Almer  wrote:
>
> LGTM.

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


Re: [FFmpeg-devel] [PATCH 1/2] ffmpeg: handling copyts use case in forced key frames functionality

2018-05-06 Thread Dixit, Vishwanath


On 4/27/18 6:24 AM, Michael Niedermayer wrote:
> On Thu, Apr 26, 2018 at 10:33:59AM +0530, vdi...@akamai.com wrote:
>> From: Vishwanath Dixit 
>>
>> Forced key frames creation functionality was assuming the first PTS
>> value to be zero, but, when 'copyts' is enalbed, the first PTS can
>> be any big number. This was eventually forcing all the frames as
>> key frames. To overcome this issue, the actual first PTS value has
>> to be considered.
>> ---
>>  fftools/ffmpeg.c | 5 -
>>  fftools/ffmpeg_opt.c | 1 +
>>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> breaks fate
> --- ./tests/ref/fate/pva-demux2018-04-26 01:45:19.589231218 +0200
> +++ tests/data/fate/pva-demux 2018-04-27 02:50:51.828844428 +0200
> @@ -34,3 +34,18 @@
>  1,  47520,  47520, 2160,  384, 0xfddbb7df
>  1,  49680,  49680, 2160,  384, 0xbbb2af0c
>  1,  51840,  51840, 2160,  384, 0x8f03b5fc
> +0, 26, 26,1,   470016, 0xead57e3f
> +0, 27, 27,1,   470016, 0x787085d0
> +0, 28, 28,1,   470016, 0x3d529159
> +0, 29, 29,1,   470016, 0xed32986b
> +0, 30, 30,1,   470016, 0xcdd2c5a7
> +0, 31, 31,1,   470016, 0xb271d212
> +0, 32, 32,1,   470016, 0x838cad86
> +0, 33, 33,1,   470016, 0xdb992f3f
> +0, 34, 34,1,   470016, 0x88779a1e
> +0, 35, 35,1,   470016, 0x6a73db7b
> +0, 36, 36,1,   470016, 0x7b4e6ace
> +0, 37, 37,1,   470016, 0x72d14489
> +0, 38, 38,1,   470016, 0xd5b17c4d
> +0, 39, 39,1,   470016, 0x1f62ed78
> +0, 40, 40,1,   470016, 0x97f98fff
> Test pva-demux failed. Look at tests/data/fate/pva-demux.err for details.
> make: *** [fate-pva-demux] Error 1
>
The patch was affecting the 'recording time' (-t) functionality. Sorry for not 
conducting fate tests before submitting the patch. I have updated the patch and 
have run the fate tests. Apart from the issue fix updates, I have modified the 
commit name and message for better clarity. Please find the revised version 
here https://patchwork.ffmpeg.org/patch/8814/ .

>
> [...]
>
>
> ___
> 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 1/1] fftools/ffmpeg: fix for all forced key frames when 'copyts' is enabled

2018-05-06 Thread vdixit
From: Vishwanath Dixit 

Forced key frames generation functionality was assuming the first PTS
value as zero, but, when 'copyts' is enabled, the first PTS can be any
big number. This was eventually forcing all the frames as key frames.
To resolve this issue, update has been made to use first input pts as
reference pts.
---
 fftools/ffmpeg.c | 6 +-
 fftools/ffmpeg.h | 1 +
 fftools/ffmpeg_opt.c | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5a19a09..10f3012 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1236,8 +1236,12 @@ static void do_video_out(OutputFile *of,
 in_picture->quality = enc->global_quality;
 in_picture->pict_type = 0;
 
+if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&
+in_picture->pts != AV_NOPTS_VALUE)
+ost->forced_kf_ref_pts = in_picture->pts;
+
 pts_time = in_picture->pts != AV_NOPTS_VALUE ?
-in_picture->pts * av_q2d(enc->time_base) : NAN;
+(in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base) : NAN;
 if (ost->forced_kf_index < ost->forced_kf_count &&
 in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
 ost->forced_kf_index++;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d44b7a5..eb1eaf6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -484,6 +484,7 @@ typedef struct OutputStream {
 AVRational frame_aspect_ratio;
 
 /* forced key frames */
+int64_t forced_kf_ref_pts;
 int64_t *forced_kf_pts;
 int forced_kf_count;
 int forced_kf_index;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 8ae68ae..36bce44 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1324,6 +1324,7 @@ static OutputStream *new_output_stream(OptionsContext *o, 
AVFormatContext *oc, e
 ost->file_index = nb_output_files - 1;
 ost->index  = idx;
 ost->st = st;
+ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
 st->codecpar->codec_type = type;
 
 ret = choose_encoder(o, oc, ost);
-- 
1.9.1

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


Re: [FFmpeg-devel] [PATCH] configure: add pkg-config check for zlib

2018-05-06 Thread James Almer
On 5/5/2018 4:12 PM, Jan Ekström wrote:
> It exists, so why not use it? Helps one get rid of additional
> search path related flags in addition to PKG_CONFIG_{PATH,LIBDIR}
> when utilizing a cross-prefix separate from the sysroot.
> ---
>  configure | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index f78853cc6c..2d99c8ea85 100755
> --- a/configure
> +++ b/configure
> @@ -5933,7 +5933,8 @@ if ! disabled pthreads && ! enabled w32threads && ! 
> enabled os2threads; then
>  fi
>  fi
>  
> -enabled  zlib && check_lib zlib   zlib.h  zlibVersion-lz
> +enabled  zlib && { check_pkg_config zlib zlib "zlib.h" zlibVersion ||
> +   check_lib zlib   zlib.h  zlibVersion-lz; }
>  enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion-lbz2
>  enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzma

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


Re: [FFmpeg-devel] [PATCH] lavf/bluray: translate a read of 0 to EOF

2018-05-06 Thread Jan Ekström
On Sun, May 6, 2018 at 5:32 PM, wm4  wrote:
>
> Hilarious, another of those EOf issues. Too bad we didn't just revert
> that crap. I wonder how many years it'll take until we got all of them.
>
> LGTM.

Thanks, pushed. This should be back-ported to release/4.0 I guess?

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


Re: [FFmpeg-devel] [PATCH 3/3] doc/protocols: documents tcp_mss

2018-05-06 Thread Gyan Doshi



On 5/6/2018 8:42 PM, Jun Zhao wrote:


+@item tcp_mss=@var{bytes}
+Set maximum segment size for outgoing TCP packets, expressed bytes.


'expressed bytes' --> 'expressed in bytes'

or just 'in bytes'  (preferred).


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


[FFmpeg-devel] [PATCH 2/3] lavf/tcp: add option to setting Maximum Segment Size

2018-05-06 Thread Jun Zhao
This can change the the MSS value announced to the other end in
the initial TCP packet, it's can be used when failed Path MTU
discovery.

Signed-off-by: Jun Zhao 
---
 libavformat/tcp.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index b0289f8..1d51710 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -42,6 +42,7 @@ typedef struct TCPContext {
 int recv_buffer_size;
 int send_buffer_size;
 int tcp_nodelay;
+int tcp_mss;
 } TCPContext;
 
 #define OFFSET(x) offsetof(TCPContext, x)
@@ -54,6 +55,7 @@ static const AVOption options[] = {
 { "send_buffer_size", "Socket send buffer size (in bytes)",
OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
 { "recv_buffer_size", "Socket receive buffer size (in bytes)", 
OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
 { "tcp_nodelay", "Use TCP_NODELAY to disable nagle's algorithm",   
OFFSET(tcp_nodelay), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = 
D|E },
+{ "tcp_mss", "Maximum segment size for outgoing TCP packets",  
OFFSET(tcp_mss), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
 { NULL }
 };
 
@@ -153,6 +155,9 @@ static int tcp_open(URLContext *h, const char *uri, int 
flags)
 if (s->tcp_nodelay > 0) {
 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, >tcp_nodelay, sizeof 
(s->tcp_nodelay));
 }
+if (s->tcp_mss > 0) {
+setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, >tcp_mss, sizeof 
(s->tcp_mss));
+}
 
 if (s->listen == 2) {
 // multi-client
-- 
2.7.4

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


[FFmpeg-devel] [PATCH 1/3] lavf/network: fix doxygen comments.

2018-05-06 Thread Jun Zhao
Signed-off-by: Jun Zhao 
---
 libavformat/network.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/network.h b/libavformat/network.h
index e3fda4d..efaa789 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -87,9 +87,9 @@ int ff_network_wait_fd(int fd, int write);
  * This works similarly to ff_network_wait_fd, but waits up to 'timeout' 
microseconds
  * Uses ff_network_wait_fd in a loop
  *
- * @fd Socket descriptor
- * @write Set 1 to wait for socket able to be read, 0 to be written
- * @timeout Timeout interval, in microseconds. Actual precision is 10 mcs, 
due to ff_network_wait_fd usage
+ * @param fd Socket descriptor
+ * @param write Set 1 to wait for socket able to be read, 0 to be written
+ * @param timeout Timeout interval, in microseconds. Actual precision is 
10 mcs, due to ff_network_wait_fd usage
  * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd 
call
  * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout 
expired, or negative error code
  */
@@ -98,7 +98,7 @@ int ff_network_wait_fd_timeout(int fd, int write, int64_t 
timeout, AVIOInterrupt
 /**
  * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and
  * triggered, return before that.
- * @timeout Timeout in microseconds. Maybe have lower actual precision.
+ * @param timeout Timeout in microseconds. Maybe have lower actual precision.
  * @param int_cb Interrupt callback, is checked regularly.
  * @return AVERROR(ETIMEDOUT) if timeout expirted, AVERROR_EXIT if interrupted 
by int_cb
  */
-- 
2.7.4

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


[FFmpeg-devel] [PATCH 3/3] doc/protocols: documents tcp_mss

2018-05-06 Thread Jun Zhao
Signed-off-by: Jun Zhao 
---
 doc/protocols.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index e19504d..4a0bbc8 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1397,6 +1397,9 @@ Set send buffer size, expressed bytes.
 
 @item tcp_nodelay=@var{1|0}
 Set TCP_NODELAY to disable Nagle's algorithm. Default value is 0.
+
+@item tcp_mss=@var{bytes}
+Set maximum segment size for outgoing TCP packets, expressed bytes.
 @end table
 
 The following example shows how to setup a listening TCP connection
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 7/9] lavfi/nlmeans: switch from double to float

2018-05-06 Thread Moritz Barsnick
On Sun, May 06, 2018 at 13:40:58 +0200, Clément Bœsch wrote:
> Overall speed appears to be 1.1x faster with no noticeable quality impact.

Probably platform dependant?

>  struct weighted_avg {
> -double total_weight;
> -double sum;
> +float total_weight;
> +float sum;
>  };

I believe these calculaions in nlmeans_plane() will promote to double
before being cast back to float:

   // Also weight the centered pixel
wa->total_weight += 1.0;
wa->sum += 1.0 * src[y*src_linesize + x];

(At least the second one. The first one - just an assignment of a
constant - is covered by the preprocessor, IIUC.) They need to use
"1.0f".

(There are others, but only in init(), which don't matter for
performance.)

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


Re: [FFmpeg-devel] [PATCH] lavf/bluray: translate a read of 0 to EOF

2018-05-06 Thread wm4
On Sun,  6 May 2018 17:19:44 +0300
Jan Ekström  wrote:

> Yet another case of forgotten 0 =! EOF translation. The libbluray
> documentation specifically mentions that a read of 0 is EOF.
> 
> Reported by Fyr on IRC.
> ---
>  libavformat/bluray.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/bluray.c b/libavformat/bluray.c
> index 9282bf9956..635c4f1b87 100644
> --- a/libavformat/bluray.c
> +++ b/libavformat/bluray.c
> @@ -198,7 +198,7 @@ static int bluray_read(URLContext *h, unsigned char *buf, 
> int size)
>  
>  len = bd_read(bd->bd, buf, size);
>  
> -return len;
> +return len == 0 ? AVERROR_EOF : len;
>  }
>  
>  static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)

Hilarious, another of those EOf issues. Too bad we didn't just revert
that crap. I wonder how many years it'll take until we got all of them.

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


[FFmpeg-devel] [PATCH] lavf/bluray: translate a read of 0 to EOF

2018-05-06 Thread Jan Ekström
Yet another case of forgotten 0 =! EOF translation. The libbluray
documentation specifically mentions that a read of 0 is EOF.

Reported by Fyr on IRC.
---
 libavformat/bluray.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/bluray.c b/libavformat/bluray.c
index 9282bf9956..635c4f1b87 100644
--- a/libavformat/bluray.c
+++ b/libavformat/bluray.c
@@ -198,7 +198,7 @@ static int bluray_read(URLContext *h, unsigned char *buf, 
int size)
 
 len = bd_read(bd->bd, buf, size);
 
-return len;
+return len == 0 ? AVERROR_EOF : len;
 }
 
 static int64_t bluray_seek(URLContext *h, int64_t pos, int whence)
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH] opt: print a deprecation indicator when listing options

2018-05-06 Thread Clément Bœsch
On Sat, May 05, 2018 at 09:45:26PM +0100, Rostislav Pehlivanov wrote:
> Signed-off-by: Rostislav Pehlivanov 
> ---
>  libavutil/opt.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 99282605f5..73295356a1 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -1276,6 +1276,8 @@ static void opt_list(void *obj, void *av_log_obj, const 
> char *unit,
>  }
>  av_log(av_log_obj, AV_LOG_INFO, ")");
>  }
> +if (opt->flags & AV_OPT_FLAG_DEPRECATED)
> +av_log(av_log_obj, AV_LOG_INFO, " (deprecated)");
>  

does this fit well with the help message that is supposed to be updated to
say what to use instead of that deprecated field?

-- 
Clément B.


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


[FFmpeg-devel] [PATCH 7/9] lavfi/nlmeans: switch from double to float

2018-05-06 Thread Clément Bœsch
Overall speed appears to be 1.1x faster with no noticeable quality impact.
---
 libavfilter/vf_nlmeans.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index f37f1183f7..201e4feb41 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -40,8 +40,8 @@
 #include "video.h"
 
 struct weighted_avg {
-double total_weight;
-double sum;
+float total_weight;
+float sum;
 };
 
 #define WEIGHT_LUT_NBITS 9
@@ -63,8 +63,8 @@ typedef struct NLMeansContext {
 ptrdiff_t ii_lz_32; // linesize in 32-bit units of 
the integral image
 struct weighted_avg *wa;// weighted average of every 
pixel
 ptrdiff_t wa_linesize;  // linesize for wa in struct 
size unit
-double weight_lut[WEIGHT_LUT_SIZE]; // lookup table mapping 
(scaled) patch differences to their associated weights
-double pdiff_lut_scale; // scale factor for patch 
differences before looking into the LUT
+float weight_lut[WEIGHT_LUT_SIZE];  // lookup table mapping 
(scaled) patch differences to their associated weights
+float pdiff_lut_scale;  // scale factor for patch 
differences before looking into the LUT
 int max_meaningful_diff;// maximum difference 
considered (if the patch difference is too high we ignore the pixel)
 NLMeansDSPContext dsp;
 } NLMeansContext;
@@ -206,7 +206,7 @@ static void compute_safe_ssd_integral_image_c(uint32_t 
*dst, ptrdiff_t dst_lines
  * @param w width to compute
  * @param h height to compute
  */
-static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
+static void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
  int startx, int starty,
  const uint8_t *src, 
ptrdiff_t linesize,
  int offx, int offy, int 
r, int sw, int sh,
@@ -402,7 +402,7 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 const int patch_diff_sq = get_integral_patch_value(td->ii_start, 
s->ii_lz_32, x, y, td->p);
 if (patch_diff_sq < s->max_meaningful_diff) {
 const int weight_lut_idx = patch_diff_sq * s->pdiff_lut_scale;
-const double weight = s->weight_lut[weight_lut_idx]; // 
exp(-patch_diff_sq * s->pdiff_scale)
+const float weight = s->weight_lut[weight_lut_idx]; // 
exp(-patch_diff_sq * s->pdiff_scale)
 wa[x].total_weight += weight;
 wa[x].sum += weight * src[x];
 }
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 8/9] lavfi/nlmeans: move final weighted averaging out of nlmeans_plane

2018-05-06 Thread Clément Bœsch
This helps figuring out where the filter is slow:

  70.53%  ffmpeg_g  ffmpeg_g  [.] nlmeans_slice
  25.73%  ffmpeg_g  ffmpeg_g  [.] compute_safe_ssd_integral_image_c
   1.74%  ffmpeg_g  ffmpeg_g  [.] compute_unsafe_ssd_integral_image
   0.82%  ffmpeg_g  ffmpeg_g  [.] ff_mjpeg_decode_sos
   0.51%  ffmpeg_g  [unknown] [k] 0x91800a80
   0.24%  ffmpeg_g  ffmpeg_g  [.] weight_averages

(Tested with a large image that takes several seconds to process)

Since this function is irrelevant speed wise, the file's TODO is
updated.
---
 libavfilter/vf_nlmeans.c | 33 ++---
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 201e4feb41..abe708a2fc 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -20,7 +20,6 @@
 
 /**
  * @todo
- * - SIMD for final weighted averaging
  * - better automatic defaults? see "Parameters" @ 
http://www.ipol.im/pub/art/2011/bcm_nlm/
  * - temporal support (probably doesn't need any displacement according to
  *   "Denoising image sequences does not require motion estimation")
@@ -411,11 +410,30 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 return 0;
 }
 
+static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize,
+const uint8_t *src, ptrdiff_t src_linesize,
+struct weighted_avg *wa, ptrdiff_t wa_linesize,
+int w, int h)
+{
+int x, y;
+
+for (y = 0; y < h; y++) {
+for (x = 0; x < w; x++) {
+// Also weight the centered pixel
+wa[x].total_weight += 1.0;
+wa[x].sum += 1.0 * src[x];
+dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight);
+}
+dst += dst_linesize;
+src += src_linesize;
+wa += wa_linesize;
+}
+}
+
 static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r,
  uint8_t *dst, ptrdiff_t dst_linesize,
  const uint8_t *src, ptrdiff_t src_linesize)
 {
-int x, y;
 int offx, offy;
 NLMeansContext *s = ctx->priv;
 /* patches center points cover the whole research window so the patches
@@ -448,17 +466,10 @@ static int nlmeans_plane(AVFilterContext *ctx, int w, int 
h, int p, int r,
 }
 }
 }
-for (y = 0; y < h; y++) {
-for (x = 0; x < w; x++) {
-struct weighted_avg *wa = >wa[y*s->wa_linesize + x];
 
-// Also weight the centered pixel
-wa->total_weight += 1.0;
-wa->sum += 1.0 * src[y*src_linesize + x];
+weight_averages(dst, dst_linesize, src, src_linesize,
+s->wa, s->wa_linesize, w, h);
 
-dst[y*dst_linesize + x] = av_clip_uint8(wa->sum / 
wa->total_weight);
-}
-}
 return 0;
 }
 
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 6/9] lavfi/nlmeans: make compute_safe_ssd_integral_image_c faster

2018-05-06 Thread Clément Bœsch
before:  ssd_integral_image_c: 49204.6
after:   ssd_integral_image_c: 44272.8

Unrolling by 4 for made the biggest different on odroid-c2 (aarch64);
unrolling by 2 or 8 both raised 46k cycles vs 44k for 4.

Additionally, this is a much better reference when writing SIMD (SIMD
vectorization will just target 16 instead of 4).
---
 libavfilter/vf_nlmeans.c | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index c30e44498f..f37f1183f7 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -146,10 +146,6 @@ static inline int get_integral_patch_value(const uint32_t 
*ii, int ii_lz_32, int
  * function, we do not need any clipping here.
  *
  * The line above dst and the column to its left are always readable.
- *
- * This C version computes the SSD integral image using a scalar accumulator,
- * while for SIMD implementation it is likely more interesting to use the
- * two-loops algorithm variant.
  */
 static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
   const uint8_t *s1, ptrdiff_t 
linesize1,
@@ -157,21 +153,32 @@ static void compute_safe_ssd_integral_image_c(uint32_t 
*dst, ptrdiff_t dst_lines
   int w, int h)
 {
 int x, y;
+const uint32_t *dst_top = dst - dst_linesize_32;
 
 /* SIMD-friendly assumptions allowed here */
 av_assert2(!(w & 0xf) && w >= 16 && h >= 1);
 
 for (y = 0; y < h; y++) {
-uint32_t acc = dst[-1] - dst[-dst_linesize_32 - 1];
-
-for (x = 0; x < w; x++) {
-const int d  = s1[x] - s2[x];
-acc += d * d;
-dst[x] = dst[-dst_linesize_32 + x] + acc;
+for (x = 0; x < w; x += 4) {
+const int d0 = s1[x] - s2[x];
+const int d1 = s1[x + 1] - s2[x + 1];
+const int d2 = s1[x + 2] - s2[x + 2];
+const int d3 = s1[x + 3] - s2[x + 3];
+
+dst[x] = dst_top[x] - dst_top[x - 1] + d0*d0;
+dst[x + 1] = dst_top[x + 1] - dst_top[x] + d1*d1;
+dst[x + 2] = dst_top[x + 2] - dst_top[x + 1] + d2*d2;
+dst[x + 3] = dst_top[x + 3] - dst_top[x + 2] + d3*d3;
+
+dst[x] += dst[x - 1];
+dst[x + 1] += dst[x];
+dst[x + 2] += dst[x + 1];
+dst[x + 3] += dst[x + 2];
 }
 s1  += linesize1;
 s2  += linesize2;
 dst += dst_linesize_32;
+dst_top += dst_linesize_32;
 }
 }
 
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 9/9] lavfi/nlmeans: reorder memory accesses in get_integral_patch_value

2018-05-06 Thread Clément Bœsch
This doesn't seem to make much of a difference but it can't hurt.
---
 libavfilter/vf_nlmeans.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index abe708a2fc..38c50bc94a 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -131,10 +131,10 @@ static int query_formats(AVFilterContext *ctx)
  */
 static inline int get_integral_patch_value(const uint32_t *ii, int ii_lz_32, 
int x, int y, int p)
 {
-const int e = ii[(y + p) * ii_lz_32 + (x + p)];
-const int d = ii[(y + p) * ii_lz_32 + (x - p - 1)];
-const int b = ii[(y - p - 1) * ii_lz_32 + (x + p)];
 const int a = ii[(y - p - 1) * ii_lz_32 + (x - p - 1)];
+const int b = ii[(y - p - 1) * ii_lz_32 + (x + p)];
+const int d = ii[(y + p) * ii_lz_32 + (x - p - 1)];
+const int e = ii[(y + p) * ii_lz_32 + (x + p)];
 return e - d - b + a;
 }
 
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 4/9] lavfi/nlmeans: add AArch64 SIMD for compute_safe_ssd_integral_image

2018-05-06 Thread Clément Bœsch
ssd_integral_image_c: 49204.6
ssd_integral_image_neon: 28346.8
---
 libavfilter/aarch64/Makefile  |  3 ++
 libavfilter/aarch64/vf_nlmeans_init.c | 33 
 libavfilter/aarch64/vf_nlmeans_neon.S | 78 +++
 libavfilter/vf_nlmeans.c  | 18 +--
 libavfilter/vf_nlmeans.h  | 35 
 5 files changed, 164 insertions(+), 3 deletions(-)
 create mode 100644 libavfilter/aarch64/Makefile
 create mode 100644 libavfilter/aarch64/vf_nlmeans_init.c
 create mode 100644 libavfilter/aarch64/vf_nlmeans_neon.S
 create mode 100644 libavfilter/vf_nlmeans.h

diff --git a/libavfilter/aarch64/Makefile b/libavfilter/aarch64/Makefile
new file mode 100644
index 00..b58daa3a3f
--- /dev/null
+++ b/libavfilter/aarch64/Makefile
@@ -0,0 +1,3 @@
+OBJS-$(CONFIG_NLMEANS_FILTER)+= aarch64/vf_nlmeans_init.o
+
+NEON-OBJS-$(CONFIG_NLMEANS_FILTER)   += aarch64/vf_nlmeans_neon.o
diff --git a/libavfilter/aarch64/vf_nlmeans_init.c 
b/libavfilter/aarch64/vf_nlmeans_init.c
new file mode 100644
index 00..a1edefb144
--- /dev/null
+++ b/libavfilter/aarch64/vf_nlmeans_init.c
@@ -0,0 +1,33 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/cpu.h"
+#include "libavfilter/vf_nlmeans.h"
+
+void ff_compute_safe_ssd_integral_image_neon(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
+ const uint8_t *s1, ptrdiff_t 
linesize1,
+ const uint8_t *s2, ptrdiff_t 
linesize2,
+ int w, int h);
+
+av_cold void ff_nlmeans_init_aarch64(NLMeansDSPContext *dsp)
+{
+int cpu_flags = av_get_cpu_flags();
+
+if (have_neon(cpu_flags))
+dsp->compute_safe_ssd_integral_image = 
ff_compute_safe_ssd_integral_image_neon;
+}
diff --git a/libavfilter/aarch64/vf_nlmeans_neon.S 
b/libavfilter/aarch64/vf_nlmeans_neon.S
new file mode 100644
index 00..4de573cf7f
--- /dev/null
+++ b/libavfilter/aarch64/vf_nlmeans_neon.S
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2018 Clément Bœsch 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+// acc_sum_store(ABCD) = {X+A, X+A+B, X+A+B+C, X+A+B+C+D}
+.macro acc_sum_store x, xb
+dup v24.4S, v24.4S[3]   // 
...X -> 
+ext v25.16B, v26.16B, \xb, #12  // 
ext(,ABCD,12)=0ABC
+add v24.4S, v24.4S, \x  // 
+ABCD={X+A,X+B,X+C,X+D}
+add v24.4S, v24.4S, v25.4S  // 
{X+A,X+B+A,X+C+B,X+D+C}   (+0ABC)
+ext v25.16B, v26.16B, v25.16B, #12  // 
ext(,0ABC,12)=00AB
+add v24.4S, v24.4S, v25.4S  // 
{X+A,X+B+A,X+C+B+A,X+D+C+B}   (+00AB)
+ext v25.16B, v26.16B, v25.16B, #12  // 
ext(,00AB,12)=000A
+add v24.4S, v24.4S, v25.4S  // 
{X+A,X+B+A,X+C+B+A,X+D+C+B+A} (+000A)
+st1 {v24.4S}, [x0], #16 // 
write 4x32-bit final values
+.endm
+
+function ff_compute_safe_ssd_integral_image_neon, export=1
+moviv26.4S, #0  // 
used as zero for the "rotations" in acc_sum_store
+sub x3, x3, w6, UXTW// s1 
padding (s1_linesize - 

[FFmpeg-devel] [PATCH 5/9] checkasm: add vf_nlmeans test for ssd_integral_image

2018-05-06 Thread Clément Bœsch
---
 tests/checkasm/Makefile |   1 +
 tests/checkasm/checkasm.c   |   3 +
 tests/checkasm/checkasm.h   |   1 +
 tests/checkasm/vf_nlmeans.c | 113 
 4 files changed, 118 insertions(+)
 create mode 100644 tests/checkasm/vf_nlmeans.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 0233d2f989..9484acbbd7 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -35,6 +35,7 @@ AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o
 AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o
 AVFILTEROBJS-$(CONFIG_HFLIP_FILTER)  += vf_hflip.o
 AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER)  += vf_threshold.o
+AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER)+= vf_nlmeans.o
 
 CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index ba1d1d0253..721a0912fb 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -159,6 +159,9 @@ static const struct {
 #if CONFIG_HFLIP_FILTER
 { "vf_hflip", checkasm_check_vf_hflip },
 #endif
+#if CONFIG_NLMEANS_FILTER
+{ "vf_nlmeans", checkasm_check_nlmeans },
+#endif
 #if CONFIG_THRESHOLD_FILTER
 { "vf_threshold", checkasm_check_vf_threshold },
 #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index dcab74de06..c45cfb46f8 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -62,6 +62,7 @@ void checkasm_check_huffyuvdsp(void);
 void checkasm_check_jpeg2000dsp(void);
 void checkasm_check_llviddsp(void);
 void checkasm_check_llviddspenc(void);
+void checkasm_check_nlmeans(void);
 void checkasm_check_pixblockdsp(void);
 void checkasm_check_sbrdsp(void);
 void checkasm_check_synth_filter(void);
diff --git a/tests/checkasm/vf_nlmeans.c b/tests/checkasm/vf_nlmeans.c
new file mode 100644
index 00..5e2c934226
--- /dev/null
+++ b/tests/checkasm/vf_nlmeans.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2018 Clément Bœsch 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "checkasm.h"
+#include "libavfilter/vf_nlmeans.h"
+#include "libavutil/avassert.h"
+
+#define randomize_buffer(buf, size) do {\
+int i;  \
+for (i = 0; i < size / 4; i++)  \
+((uint32_t *)buf)[i] = rnd();   \
+} while (0)
+
+void checkasm_check_nlmeans(void)
+{
+NLMeansDSPContext dsp = {0};
+
+const int w = 123;  // source width
+const int h = 45;   // source height
+const int p = 3;// patch half size
+const int r = 2;// research window half size
+
+ff_nlmeans_init();
+
+/* See the filter's code for the explanations on the variables */
+if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) 
{
+int offx, offy;
+const int e = p + r;
+const int ii_w = w + e*2;
+const int ii_h = h + e*2;
+const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
+uint32_t *ii_orig_ref = av_mallocz_array(ii_h + 1, ii_lz_32 * 
sizeof(*ii_orig_ref));
+uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
+uint32_t *ii_orig_new = av_mallocz_array(ii_h + 1, ii_lz_32 * 
sizeof(*ii_orig_new));
+uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
+const int src_lz = FFALIGN(w, 16);
+uint8_t *src = av_mallocz_array(h, src_lz);
+
+declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32,
+ const uint8_t *s1, ptrdiff_t linesize1,
+ const uint8_t *s2, ptrdiff_t linesize2,
+ int w, int h);
+
+randomize_buffer(src, h * src_lz);
+
+for (offy = -r; offy <= r; offy++) {
+for (offx = -r; offx <= r; offx++) {
+if (offx || offy) {
+const int s1x = e;
+const int s1y = e;
+const int s2x = e + offx;
+const int s2y = e + offy;
+const int startx_safe = FFMAX(s1x, s2x);
+const int starty_safe = FFMAX(s1y, s2y);
+const int u_endx_safe = FFMIN(s1x + w, s2x + w);
+const int endy_safe   = FFMIN(s1y + h, s2y + h);
+const int safe_pw = 

[FFmpeg-devel] [PATCH 3/9] lavfi/nlmeans: use ptrdiff_t for linesizes

2018-05-06 Thread Clément Bœsch
Similarly to previous commit, this will help writing SIMD code by not
having manual zero-extension in SIMD code
---
 libavfilter/vf_nlmeans.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 21f981a605..4119fa3e01 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -60,9 +60,9 @@ typedef struct NLMeansContext {
 uint32_t *ii_orig;  // integral image
 uint32_t *ii;   // integral image starting 
after the 0-line and 0-column
 int ii_w, ii_h; // width and height of the 
integral image
-int ii_lz_32;   // linesize in 32-bit units of 
the integral image
+ptrdiff_t ii_lz_32; // linesize in 32-bit units of 
the integral image
 struct weighted_avg *wa;// weighted average of every 
pixel
-int wa_linesize;// linesize for wa in struct 
size unit
+ptrdiff_t wa_linesize;  // linesize for wa in struct 
size unit
 double weight_lut[WEIGHT_LUT_SIZE]; // lookup table mapping 
(scaled) patch differences to their associated weights
 double pdiff_lut_scale; // scale factor for patch 
differences before looking into the LUT
 int max_meaningful_diff;// maximum difference 
considered (if the patch difference is too high we ignore the pixel)
@@ -150,9 +150,9 @@ static inline int get_integral_patch_value(const uint32_t 
*ii, int ii_lz_32, int
  * while for SIMD implementation it is likely more interesting to use the
  * two-loops algorithm variant.
  */
-static void compute_safe_ssd_integral_image_c(uint32_t *dst, int 
dst_linesize_32,
-  const uint8_t *s1, int linesize1,
-  const uint8_t *s2, int linesize2,
+static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
+  const uint8_t *s1, ptrdiff_t 
linesize1,
+  const uint8_t *s2, ptrdiff_t 
linesize2,
   int w, int h)
 {
 int x, y;
@@ -198,9 +198,9 @@ static void compute_safe_ssd_integral_image_c(uint32_t 
*dst, int dst_linesize_32
  * @param w width to compute
  * @param h height to compute
  */
-static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, int 
dst_linesize_32,
+static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t 
dst_linesize_32,
  int startx, int starty,
- const uint8_t *src, int 
linesize,
+ const uint8_t *src, 
ptrdiff_t linesize,
  int offx, int offy, int 
r, int sw, int sh,
  int w, int h)
 {
@@ -240,8 +240,8 @@ static inline void 
compute_unsafe_ssd_integral_image(uint32_t *dst, int dst_line
  * @param h source height
  * @param e research padding edge
  */
-static void compute_ssd_integral_image(uint32_t *ii, int ii_linesize_32,
-   const uint8_t *src, int linesize, int 
offx, int offy,
+static void compute_ssd_integral_image(uint32_t *ii, ptrdiff_t ii_linesize_32,
+   const uint8_t *src, ptrdiff_t linesize, 
int offx, int offy,
int e, int w, int h)
 {
 // ii has a surrounding padding of thickness "e"
@@ -367,7 +367,7 @@ static int config_input(AVFilterLink *inlink)
 
 struct thread_data {
 const uint8_t *src;
-int src_linesize;
+ptrdiff_t src_linesize;
 int startx, starty;
 int endx, endy;
 const uint32_t *ii_start;
@@ -379,7 +379,7 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 int x, y;
 NLMeansContext *s = ctx->priv;
 const struct thread_data *td = arg;
-const int src_linesize = td->src_linesize;
+const ptrdiff_t src_linesize = td->src_linesize;
 const int process_h = td->endy - td->starty;
 const int slice_start = (process_h *  jobnr   ) / nb_jobs;
 const int slice_end   = (process_h * (jobnr+1)) / nb_jobs;
@@ -403,8 +403,8 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 }
 
 static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r,
- uint8_t *dst, int dst_linesize,
- const uint8_t *src, int src_linesize)
+ uint8_t *dst, ptrdiff_t dst_linesize,
+ const uint8_t *src, ptrdiff_t 

[FFmpeg-devel] [PATCH 2/9] lavfi/nlmeans: add SIMD-friendly assumptions for compute_safe_ssd_integral_image

2018-05-06 Thread Clément Bœsch
SIMD code will not have to deal with padding itself. Overwriting in that
function may have been possible but involve large overreading of the
sources. Instead, we simply make sure the width to process is always a
multiple of 16. Additionally, there must be some actual area to process
so the SIMD code can have its boundary checks after processing the first
pixels.
---
 libavfilter/vf_nlmeans.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index d222d3913e..21f981a605 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -157,6 +157,9 @@ static void compute_safe_ssd_integral_image_c(uint32_t 
*dst, int dst_linesize_32
 {
 int x, y;
 
+/* SIMD-friendly assumptions allowed here */
+av_assert2(!(w & 0xf) && w >= 16 && h >= 1);
+
 for (y = 0; y < h; y++) {
 uint32_t acc = dst[-1] - dst[-dst_linesize_32 - 1];
 
@@ -257,9 +260,16 @@ static void compute_ssd_integral_image(uint32_t *ii, int 
ii_linesize_32,
 // to compare the 2 sources pixels
 const int startx_safe = FFMAX(s1x, s2x);
 const int starty_safe = FFMAX(s1y, s2y);
-const int endx_safe   = FFMIN(s1x + w, s2x + w);
+const int u_endx_safe = FFMIN(s1x + w, s2x + w); // unaligned
 const int endy_safe   = FFMIN(s1y + h, s2y + h);
 
+// deduce the safe area width and height
+const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
+const int safe_ph = endy_safe - starty_safe;
+
+// adjusted end x position of the safe area after width of the safe area 
gets aligned
+const int endx_safe = startx_safe + safe_pw;
+
 // top part where only one of s1 and s2 is still readable, or none at all
 compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
   0, 0,
@@ -273,24 +283,25 @@ static void compute_ssd_integral_image(uint32_t *ii, int 
ii_linesize_32,
   0, starty_safe,
   src, linesize,
   offx, offy, e, w, h,
-  startx_safe, endy_safe - starty_safe);
+  startx_safe, safe_ph);
 
 // main and safe part of the integral
 av_assert1(startx_safe - s1x >= 0); av_assert1(startx_safe - s1x < w);
 av_assert1(starty_safe - s1y >= 0); av_assert1(starty_safe - s1y < h);
 av_assert1(startx_safe - s2x >= 0); av_assert1(startx_safe - s2x < w);
 av_assert1(starty_safe - s2y >= 0); av_assert1(starty_safe - s2y < h);
-compute_safe_ssd_integral_image_c(ii + starty_safe*ii_linesize_32 + 
startx_safe, ii_linesize_32,
-  src + (starty_safe - s1y) * linesize + 
(startx_safe - s1x), linesize,
-  src + (starty_safe - s2y) * linesize + 
(startx_safe - s2x), linesize,
-  endx_safe - startx_safe, endy_safe - 
starty_safe);
+if (safe_pw && safe_ph)
+dsp->compute_safe_ssd_integral_image(ii + starty_safe*ii_linesize_32 + 
startx_safe, ii_linesize_32,
+ src + (starty_safe - s1y) * 
linesize + (startx_safe - s1x), linesize,
+ src + (starty_safe - s2y) * 
linesize + (startx_safe - s2x), linesize,
+ safe_pw, safe_ph);
 
 // right part of the integral
 compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
   endx_safe, starty_safe,
   src, linesize,
   offx, offy, e, w, h,
-  ii_w - endx_safe, endy_safe - 
starty_safe);
+  ii_w - endx_safe, safe_ph);
 
 // bottom part where only one of s1 and s2 is still readable, or none at 
all
 compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/9] lavfi/nlmeans: random code shuffling to help compiler

2018-05-06 Thread Clément Bœsch
This makes nlmeans_slice() slightly faster at least on GCC 7.3.
---
 libavfilter/vf_nlmeans.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index e4952e187e..d222d3913e 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -368,7 +368,6 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 int x, y;
 NLMeansContext *s = ctx->priv;
 const struct thread_data *td = arg;
-const uint8_t *src = td->src;
 const int src_linesize = td->src_linesize;
 const int process_h = td->endy - td->starty;
 const int slice_start = (process_h *  jobnr   ) / nb_jobs;
@@ -377,14 +376,15 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 const int endy   = td->starty + slice_end;
 
 for (y = starty; y < endy; y++) {
+const uint8_t *src = td->src + y*src_linesize;
+struct weighted_avg *wa = s->wa + y*s->wa_linesize;
 for (x = td->startx; x < td->endx; x++) {
 const int patch_diff_sq = get_integral_patch_value(td->ii_start, 
s->ii_lz_32, x, y, td->p);
 if (patch_diff_sq < s->max_meaningful_diff) {
-struct weighted_avg *wa = >wa[y*s->wa_linesize + x];
 const int weight_lut_idx = patch_diff_sq * s->pdiff_lut_scale;
 const double weight = s->weight_lut[weight_lut_idx]; // 
exp(-patch_diff_sq * s->pdiff_scale)
-wa->total_weight += weight;
-wa->sum += weight * src[y*src_linesize + x];
+wa[x].total_weight += weight;
+wa[x].sum += weight * src[x];
 }
 }
 }
-- 
2.17.0

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


[FFmpeg-devel] Misc improvements in nlmeans filter

2018-05-06 Thread Clément Bœsch
The biggest change is the introduction of the dsp infrastructure such
that more SIMD can be added, in particular x86 version(s) of the
integral computation function. Only aarch64 was added so far (because
the ASM is easy), and I don't plan to work on other arch for now.

The filter is still pretty slow, so I'm open to suggestions.

Regards,


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


Re: [FFmpeg-devel] [PATCH v2] avformat/mxfenc: add h264 profiles

2018-05-06 Thread Tomas Härdin
fre 2018-05-04 klockan 01:52 +0200 skrev Thomas Mundt:
> Hi,
> 
> this is a better version of the patch.
> 10 bit and TFF are mandatory for AVC Intra only. Other profiles
> differ.
> 

> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index 3bb7032..81513dc 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -1947,22 +1947,31 @@ static const struct {
>  int frame_size;
>  int profile;
>  uint8_t interlaced;
> +int long_gop;

A comment here explaining the difference between -1, 0 and 1 would be
nice. The rest looks OK, but I didn't read the relevant specs to be
100% sure

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


Re: [FFmpeg-devel] [PATCH] avcodec/vp3: Check that there will be sufficient input for the coded fragments in unpack_superblocks()

2018-05-06 Thread Paul B Mahol
On 5/6/18, Michael Niedermayer  wrote:
> On Sat, May 05, 2018 at 09:14:52PM +0200, wm4 wrote:
>> On Sat,  5 May 2018 21:10:06 +0200
>> Michael Niedermayer  wrote:
>>
>> > Fixes: Timeout
>> > Fixes:
>> > 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080
>> >
>> > Found-by: continuous fuzzing process
>> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> > Signed-off-by: Michael Niedermayer 
>> > ---
>> >  libavcodec/vp3.c | 6 +-
>> >  1 file changed, 5 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
>> > index 1d83753314..fcc19a627b 100644
>> > --- a/libavcodec/vp3.c
>> > +++ b/libavcodec/vp3.c
>> > @@ -543,7 +543,11 @@ static int unpack_superblocks(Vp3DecodeContext *s,
>> > GetBitContext *gb)
>> >   : s->y_superblock_count);
>> >  int num_coded_frags = 0;
>> >
>> > -for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
>> > +for (i = sb_start; i < sb_end; i++) {
>> > +if (get_bits_left(gb) < ((s->total_num_coded_frags +
>> > num_coded_frags) >> 2)) {
>> > +av_log(s->avctx, AV_LOG_ERROR, "Insufficient input data
>> > for coded fragments\n");
>> > +return AVERROR_INVALIDDATA;
>> > +}
>> >  /* iterate through all 16 fragments in a superblock */
>> >  for (j = 0; j < 16; j++) {
>> >  /* if the fragment is in bounds, check its coding
>> > status */
>>
>> The log message is pointless bloat.
>
> All error returns of this function print a log message.

Please remove log function, it is not needed at all.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel