Re: [FFmpeg-devel] Type mismatch in ADPCM

2018-03-24 Thread Carlo Bramini
Hello,

> > > > However, what about the patch attached for fixing the declaration
> > > > of ff_adpcm_afc_coeffs[2][16]?
> > > 
> > > This would revert 10542491, a relatively recent change: Maybe Paul,
> > > the author, wants to comment.
> > > 
> > > Do you think the code gets more readable?
> > 
> > Excuse me... I was just wondering what to do
> 
> You could answer above question.

I'm sorry, I was thinking that you did the question to Mr. Paul, since you were 
requesting a comment from him.
For me, I would say that this change makes the code more correct rather than 
more readable, which should be a more important reason, but that's just my 
opinion.

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


Re: [FFmpeg-devel] Moving enum AVFieldOrder to libavutil?

2018-03-24 Thread Michael Niedermayer
On Sat, Mar 24, 2018 at 01:07:48AM +0100, Marton Balint wrote:
> 
> 
> On Fri, 23 Mar 2018, Devin Heitmueller wrote:
> 
> >Hello,
> >
> >I am in the process of reworking libavfilter to pass along the field order
> >across links.  For the moment I followed the model found in AVFrame where
> >there are two int fields: “interlaced_frame” and “top_field_first”.
> >However it seems like it would be more appropriate to use the enum
> >AVFieldOrder, which is a single field and provides more flexibility
> >(including being able to be set to “unknown” if appropriate).
> >
> >Does anyone have an objection to moving the definition of AVFieldOrder to
> >libavutil, so it can be taken advantage of by libavfilter?  Right now it’s
> >in libavcodec, and from what I understand libavfilter does not depend on
> >libavcodec.
> 

> AVFieldOrder is already a mess, 

+1


> so I would not use that directly. There was
> a discussion why it is currently inconsistent between codecs:
> 
> https://patchwork.ffmpeg.org/patch/4699/
> 
> Maybe cleaner to introduce a new enum which defines the semantics better.
> Also, as far as I understand, an AVFrame is always storing the fields as
> interleaved, so strictly speaking an AVFrame (AVFilter) field order and
> AVCodecParameters field order is not entirely the same thing, that is one
> more reasone for a separate (new) type.

If a new system is added it should support specifiying
not just "unknown" but also "interlaced, order unknown" as well as some
parameter about where the information comes from.
interlaced info can come from codec coding choices, metadata, or image
analysis. Files with wrong interlacing flags are not uncommon, or maybe
one should say, progressive material coded for display on interlaced devices
or standard.


[...]
-- 
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


Re: [FFmpeg-devel] Type mismatch in ADPCM

2018-03-24 Thread Michael Niedermayer
On Sat, Mar 24, 2018 at 11:10:41AM +0100, Carlo Bramini wrote:
> Hello,
> 
> > > > > However, what about the patch attached for fixing the declaration
> > > > > of ff_adpcm_afc_coeffs[2][16]?
> > > > 
> > > > This would revert 10542491, a relatively recent change: Maybe Paul,
> > > > the author, wants to comment.
> > > > 
> > > > Do you think the code gets more readable?
> > > 
> > > Excuse me... I was just wondering what to do
> > 
> > You could answer above question.
> 
> I'm sorry, I was thinking that you did the question to Mr. Paul, since you 
> were requesting a comment from him.

> For me, I would say that this change makes the code more correct rather than 
> more readable, which should be a more important reason, but that's just my 
> opinion.

then please submit a proper git patch with that.
people may have missed this change due to the more exciting extern C++ stuff


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

"I am not trying to be anyone's saviour, I'm trying to think about the
 future and not be sad" - Elon Musk



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


Re: [FFmpeg-devel] [PATCH] Revert "avcodec/vp9_superframe_bsf: cache packets by creating new references rather than moving them"

2018-03-24 Thread wm4
On Fri, 23 Mar 2018 22:26:08 -0300
James Almer  wrote:

> This reverts commit 7a02b364b68c0bf7f065f5c217fae458f0efdb8d.
> 
> The packet fetched by ff_bsf_get_packet() and ff_bsf_get_packet_ref()
> is now guaranteed to be reference counted.
> ---
>  libavcodec/vp9_superframe_bsf.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
> index 2ea49c672d..52569ab097 100644
> --- a/libavcodec/vp9_superframe_bsf.c
> +++ b/libavcodec/vp9_superframe_bsf.c
> @@ -147,9 +147,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
> AVPacket *out)
>  goto done;
>  }
>  
> -res = av_packet_ref(s->cache[s->n_cache++], in);
> -if (res < 0)
> -goto done;
> +av_packet_move_ref(s->cache[s->n_cache++], in);
>  
>  if (invisible) {
>  res = AVERROR(EAGAIN);

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


[FFmpeg-devel] [PATCH] avcodec: add a subcharenc mode that disables UTF-8 check

2018-03-24 Thread wm4
This is for applications which want to explicitly check for invalid
UTF-8 manually, and take actions that are better than dropping invalid
subtitles silently. (It's pretty much silent because sporadic avcodec
error messages are so common that you can't reasonably display them in a
prominent and meaningful way in a application GUI.)
---
 doc/APIchanges | 3 +++
 libavcodec/avcodec.h   | 1 +
 libavcodec/decode.c| 3 ++-
 libavcodec/options_table.h | 1 +
 libavcodec/version.h   | 2 +-
 5 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a099afd9bc..95b5cd772f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-03-xx - xxx - lavc 58.16.100 - avcodec.h
+  Add FF_SUB_CHARENC_MODE_IGNORE.
+
 2018-xx-xx - xxx - lavu 56.8.100 - encryption_info.h
   Add AVEncryptionInitInfo and AVEncryptionInfo structures to hold new 
side-data
   for encryption info.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 495242faf0..50c34dbff9 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3092,6 +3092,7 @@ typedef struct AVCodecContext {
 #define FF_SUB_CHARENC_MODE_DO_NOTHING  -1  ///< do nothing (demuxer outputs a 
stream supposed to be already in UTF-8, or the codec is bitmap for instance)
 #define FF_SUB_CHARENC_MODE_AUTOMATIC0  ///< libavcodec will select the 
mode itself
 #define FF_SUB_CHARENC_MODE_PRE_DECODER  1  ///< the AVPacket data needs to be 
recoded to UTF-8 before being fed to the decoder, requires iconv
+#define FF_SUB_CHARENC_MODE_IGNORE   2  ///< neither convert the 
subtitles, nor check them for valid UTF-8
 
 /**
  * Skip processing alpha if supported by codec.
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index ea2168ad0c..40c8a8855c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1057,7 +1057,8 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, 
AVSubtitle *sub,
 sub->format = 1;
 
 for (i = 0; i < sub->num_rects; i++) {
-if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
+if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
+sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
 av_log(avctx, AV_LOG_ERROR,
"Invalid UTF-8 in decoded subtitles text; "
"maybe missing -sub_charenc option\n");
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 5a5eae65fb..099261e168 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -447,6 +447,7 @@ static const AVOption avcodec_options[] = {
 {"do_nothing",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_DO_NOTHING},  INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 {"auto",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_AUTOMATIC},   INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 {"pre_decoder", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_PRE_DECODER}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
+{"ignore",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_IGNORE},  INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 #if FF_API_ASS_TIMING
 {"sub_text_format", "set decoded text subtitle format", 
OFFSET(sub_text_format), AV_OPT_TYPE_INT, {.i64 = 
FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS}, 0, 1, S|D, "sub_text_format"},
 #else
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a5b7f752d1..8ac4626da7 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  15
+#define LIBAVCODEC_VERSION_MINOR  16
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.16.1

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


Re: [FFmpeg-devel] Reimbursement request

2018-03-24 Thread Michael Niedermayer
On Sun, Mar 18, 2018 at 08:57:42PM +0100, Thilo Borgmann wrote:
> Hi,
> 
> > As already discussed, FFmpeg was present on Chemnitzer Linux Tage, in
> > addition, Thilo and I went to Brussels for FOSDEM where we attended
> > the talks in the multimedia room kindly (co-) organized by Kieran and
> > answered some questions. I would like to request reimbursement for the
> > travel costs, that's flights-only, Thilo payed the gasoline and the
> > hotel.
> 
> from my side there are hotel & gas for Chemnitz, and flight & hotel for 
> Brussels that I'd like to ask to reimburse for. For Chemnitz it is the usual 
> drive by car Carl Eugen and me do from Berlin, which are around 290 km one 
> way as well as a shared hotel room (they did not manage to put all of us into 
> one suite this time, so we had to stick to two rooms for all four of us):
> 
> > Chemnitz: 125,85
> 
> Hotel: 194.00 EUR
> Gas:   36.62 + 21.67 + 39.51 =  97.80 EUR
> -
> Total: 291,80 EUR
> 
> 
> > Brussels: 192,41
> 
> Flight:111.81 EUR
> Hotel: 186.69 EUR
> -
> Total: 298,50 EUR
> 

all LGTM

thx

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

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"


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/2] hlsenc: set target duration always exact or longer than max segment duration

2018-03-24 Thread Jan Ekström
On Sat, Mar 24, 2018 at 7:35 AM, Steven Liu  wrote:
> This is not correct, at the specification author said, the duration
> should set to 5, not 6, reference link
> :https://trac.ffmpeg.org/ticket/6915
>
> Thanks
>
> Steven

Right, somehow I missed that "when rounded to the nearest integer"
part when reading https://tools.ietf.org/html/rfc8216#page-22 .

Thus, this one can be considered not needed.

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


[FFmpeg-devel] [PATCH] avfilter: add declick audio filter

2018-03-24 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  35 +++
 libavfilter/Makefile |   1 +
 libavfilter/af_declick.c | 586 +++
 libavfilter/allfilters.c |   1 +
 4 files changed, 623 insertions(+)
 create mode 100644 libavfilter/af_declick.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 1620ae1cfa..9a067ba9ea 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2562,6 +2562,41 @@ Optional. It should have a value much less than 1 (e.g. 
0.05 or 0.02) and is
 used to prevent clipping.
 @end table
 
+@section declick
+Remove impulsive noise from input audio.
+
+Samples detected as impulsive noise are replaced by interpolated samples using
+autoregressive modeling.
+
+@table @option
+@item w
+Set window size, in milliseconds. Allowed range is from @code{10} to 
@code{100}.
+Default value is @code{54} milliseconds.
+This sets size of window which will be processed at once.
+
+@item o
+Set window overlap, in percentage of window size. Allowed range is from 
@code{50}
+to @code{95}. Default value is @code{75} percent.
+Setting this to very high value increases impulsive noise removal but makes 
whole
+processs much slower.
+
+@item a
+Set autoregression order, in percentage of window size. Allowed range is from
+@code{1} to @code{50}. Default value is @code{2} percent. This option also 
controls
+quality of interpolated samples using neighbour good samples.
+
+@item t
+Set threshold value. Allowed range is from @code{1} to @code{10}.
+Default value is @code{2}.
+This controls the strength of impulse noise which is going to be removed.
+
+@item b
+Set burst fusion, in percentage of window size. Allowed range is @code{0} to
+@code{40}. Default value is @code{10} percent.
+This controls between how much samples, which are detected as impulsive noise,
+any sample between 2 detected noise samples is considered also as noise sample.
+@end table
+
 @section drmeter
 Measure audio dynamic range.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1043b41d80..978751d2a0 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -87,6 +87,7 @@ OBJS-$(CONFIG_COMPENSATIONDELAY_FILTER)  += 
af_compensationdelay.o
 OBJS-$(CONFIG_CROSSFEED_FILTER)  += af_crossfeed.o
 OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o
 OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o
+OBJS-$(CONFIG_DECLICK_FILTER)+= af_declick.o
 OBJS-$(CONFIG_DRMETER_FILTER)+= af_drmeter.o
 OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o
 OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
diff --git a/libavfilter/af_declick.c b/libavfilter/af_declick.c
new file mode 100644
index 00..0de4c35c95
--- /dev/null
+++ b/libavfilter/af_declick.c
@@ -0,0 +1,586 @@
+/*
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * 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/audio_fifo.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "audio.h"
+#include "formats.h"
+
+typedef struct DeclickContext {
+const AVClass *class;
+double w;
+double overlap;
+double threshold;
+double ar;
+double burst;
+
+int ar_order;
+int nb_burst_samples;
+int window_size;
+int hop_size;
+
+AVFrame *in;
+AVFrame *out;
+AVFrame *buffer;
+AVFrame *is;
+double *auxiliary;
+double *detection;
+double *acoefficients;
+double *acorrelation;
+double *tmp;
+double *interpolated;
+double *matrix;
+int matrix_size;
+double *vector;
+int vector_size;
+uint8_t *click;
+int *index;
+
+double *ltriangular;
+int ltriangular_size;
+double *diagonal;
+int d_size;
+double *y;
+int y_size;
+
+int64_t pts;
+uint64_t nb_samples;
+uint64_t detected_clicks;
+int samples_left;
+
+AVAudioFifo *fifo;
+double *window_func_lut;
+} DeclickContext;
+
+#define OFFSET(x) offsetof(DeclickContext, x)
+#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption declick_options[] = {
+{ "w", "set window size",  OFFSET(w), AV_OPT_TYPE_DOUBLE, 
{.dbl=54}, 10,  100, AF },
+{ "o", "set window overlap",   

[FFmpeg-devel] Fwd: New Defects reported by Coverity Scan for FFmpeg/FFmpeg

2018-03-24 Thread Mark Thompson

Hi Dylan,

See below for a report from the Coverity static analysis tool - the variable 
err isn't initialised in all paths leading to the fail-and-return.  Would you 
like to fix this?

Also, following is a patch to your filter for you to review (try it, decide 
whether it's correct, make any appropriate comments).

Thanks,

- Mark


---

*** CID 1430382:  Uninitialized variables  (UNINIT)
/libavfilter/vf_avgblur_opencl.c: 254 in avgblur_opencl_filter_frame()
248 
249 fail:
250 clFinish(ctx->command_queue);
251 av_frame_free(&input);
252 av_frame_free(&output);
253 av_frame_free(&intermediate);
>>> CID 1430382:  Uninitialized variables  (UNINIT)
>>> Using uninitialized value "err".
254 return err;
255 }
256 
257 static av_cold void avgblur_opencl_uninit(AVFilterContext *avctx)
258 {
259 AverageBlurOpenCLContext *ctx = avctx->priv;

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


[FFmpeg-devel] [PATCH] vf_avgblur_opencl: Don't run kernel on pixels outside the image

2018-03-24 Thread Mark Thompson
The output frame size is larger than the image containing a subsampled
plane - use the actual size of the image being written rather than the
dimensions of the intended output frame.
---
 libavfilter/vf_avgblur_opencl.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c
index 5ee66c0ba2..3a5b4a28ca 100644
--- a/libavfilter/vf_avgblur_opencl.c
+++ b/libavfilter/vf_avgblur_opencl.c
@@ -170,8 +170,10 @@ static int avgblur_opencl_filter_frame(AVFilterLink 
*inlink, AVFrame *input)
 goto fail;
 }
 
-global_work[0] = output->width;
-global_work[1] = output->height;
+err = ff_opencl_filter_work_size_from_image(avctx, global_work,
+intermediate, p, 0);
+if (err < 0)
+goto fail;
 
 av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
"(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
@@ -206,8 +208,10 @@ static int avgblur_opencl_filter_frame(AVFilterLink 
*inlink, AVFrame *input)
 goto fail;
 }
 
-global_work[0] = output->width;
-global_work[1] = output->height;
+err = ff_opencl_filter_work_size_from_image(avctx, global_work,
+output, p, 0);
+if (err < 0)
+goto fail;
 
 av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
"(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
-- 
2.16.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Revert "avcodec/vp9_superframe_bsf: cache packets by creating new references rather than moving them"

2018-03-24 Thread James Almer
On 3/24/2018 9:19 AM, wm4 wrote:
> On Fri, 23 Mar 2018 22:26:08 -0300
> James Almer  wrote:
> 
>> This reverts commit 7a02b364b68c0bf7f065f5c217fae458f0efdb8d.
>>
>> The packet fetched by ff_bsf_get_packet() and ff_bsf_get_packet_ref()
>> is now guaranteed to be reference counted.
>> ---
>>  libavcodec/vp9_superframe_bsf.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/vp9_superframe_bsf.c 
>> b/libavcodec/vp9_superframe_bsf.c
>> index 2ea49c672d..52569ab097 100644
>> --- a/libavcodec/vp9_superframe_bsf.c
>> +++ b/libavcodec/vp9_superframe_bsf.c
>> @@ -147,9 +147,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, 
>> AVPacket *out)
>>  goto done;
>>  }
>>  
>> -res = av_packet_ref(s->cache[s->n_cache++], in);
>> -if (res < 0)
>> -goto done;
>> +av_packet_move_ref(s->cache[s->n_cache++], in);
>>  
>>  if (invisible) {
>>  res = AVERROR(EAGAIN);
> 
> LGTM

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


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) is retained during the encoding process

2018-03-24 Thread Mark Thompson
On 23/03/18 11:19, Kravchenko, Alexander wrote:
> Re: [FFmpeg-devel] [PATCH] lavc/amfenc: Reference to input AVFrame (hwaccel) 
> is retained during the encoding process

Say what the change is in the title.  Something like "amfenc: Retain a 
reference to D3D11 frames used as input during the encoding process", maybe?


> An additional reference to input AVFrame (hwaccel) is retained during the 
> encoding process.
> This postpone reusing frames by decoder while they are used by encoder and 
> prevents frame corruption
> Issue with frame corruption  was reproduced using:
> ffmpeg.exe -y -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.h264  
> -an -c:v h264_amf output.mkv

How many frames can end up queued inside the encoder here?

> 
> From: Alexander Kravchenko 
> ---
>  libavcodec/amfenc.c | 64 
> ++---
>  1 file changed, 61 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index 89a10ff253..9ffc52b0b0 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -443,6 +443,41 @@ int ff_amf_encode_init(AVCodecContext *avctx)
>  return ret;
>  }
> 
> +#define AV_AMF_QUERY_INTERFACE(res, from, InterfaceType, to ) \
> +{ \
> +AMFGuid guid_##InterfaceType = IID_##InterfaceType(); \
> +res = from->pVtbl->QueryInterface(from, &guid_##InterfaceType, 
> (void**)&to); \
> +}
> +
> +#define AV_AMF_ASSIGN_PROPERTY_INTERFACE(res, pThis, name, val ) \
> +{ \
> +AMFInterface *amf_interface; \
> +AV_AMF_QUERY_INTERFACE(res, val, AMFInterface, amf_interface)\
> +if(res == AMF_OK) { \

"if (", and in all places below too.

> +AMFVariantStruct var; \
> +AMFVariantInit(&var); \
> +AMFVariantAssignInterface(&var, amf_interface); \
> +amf_interface->pVtbl->Release(amf_interface); \
> +res = pThis->pVtbl->SetProperty(pThis, name, var); \
> +AMFVariantClear(&var); \

These AMFVariant functions all return an AMF_RESULT implying that they can fail 
(memory allocations?) - those should be checked.

> +} \
> +}
> +
> +#define AV_AMF_GET_PROPERTY_INTERFACE(res, pThis, name, target_type, val) \
> +{ \
> +AMFVariantStruct var; \
> +AMFVariantInit(&var); \
> +res = pThis->pVtbl->GetProperty(pThis, name, &var); \
> +if(res == AMF_OK) { \
> +if(var.type == AMF_VARIANT_INTERFACE && var.pInterface) { \
> +AMFGuid guid = IID_##target_type(); \
> +res = var.pInterface->pVtbl->QueryInterface(var.pInterface, 
> &guid, (void**)&val); \
> +} else { \
> +res = AMF_INVALID_DATA_TYPE; \
> +} \
> +AMFVariantClear(&var); \
> +} \
> +}

These should probably be functions rather than macros?  In any case, they 
shouldn't have the "AV_" prefix which is reserved for external symbols.

> 
>  int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame)
>  {
> @@ -484,6 +519,8 @@ int ff_amf_send_frame(AVCodecContext *avctx, const 
> AVFrame *frame)
>  (ctx->hw_device_ctx && 
> ((AVHWFramesContext*)frame->hw_frames_ctx->data)->device_ctx ==
>  (AVHWDeviceContext*)ctx->hw_device_ctx->data)
>  )) {
> +AVFrame* frame_ref = av_frame_clone(frame);

av_frame_clone() can fail.

> +AMFBuffer* frame_ref_storage_buffer;

Put the * in the right place - it's part of the declarator, not the 
declaration-specifiers.

>  #if CONFIG_D3D11VA
>  static const GUID AMFTextureArrayIndexGUID = { 0x28115527, 
> 0xe7c3, 0x4b66, { 0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf } };
>  ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // 
> actual texture
> @@ -496,6 +533,12 @@ int ff_amf_send_frame(AVCodecContext *avctx, const 
> AVFrame *frame)
>  // input HW surfaces can be vertically aligned by 16; tell AMF 
> the real size
>  surface->pVtbl->SetCrop(surface, 0, 0, frame->width, 
> frame->height);
>  #endif
> +res = ctx->context->pVtbl->AllocBuffer(ctx->context, 
> AMF_MEMORY_HOST, sizeof(frame_ref), &frame_ref_storage_buffer);
> +AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
> "AllocBuffer() failed  with error %d\n", res);
> +
> memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), 
> &frame_ref, sizeof(frame_ref));
> +
> +AV_AMF_ASSIGN_PROPERTY_INTERFACE(res, surface, L"av_frame_ref", 
> frame_ref_storage_buffer);
> +
> frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);

frame_ref is leaked if any of this buffer/property stuff fails.

>  } else {
>  res = ctx->context->pVtbl->AllocSurface(ctx->context, 
> AMF_MEMORY_HOST, ctx->format, avctx->width, avctx->height, &surface);
>  AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), 
> 

[FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread wm4
Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
ASCII characters) were not handled correctly. The spec mandates that
styling start/end ranges are in "characters". It's not quite clear what
a "character" is supposed to be, but maybe they mean unicode codepoints.

FFmpeg's decoder treated the style ranges as byte idexes, which could
lead to UTF-8 sequences being broken, and the common code dropping the
whole subtitle line.

Change this and count the codepoint instead. This also means that even
if this is somehow wrong, the decoder won't break UTF-8 sequences
anymore. The sample which led me to investigate this now appears to work
correctly.
---
https://github.com/mpv-player/mpv/issues/5675
---
 libavcodec/movtextdec.c | 50 -
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index bd19577724..89ac791602 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -326,9 +326,24 @@ static const Box box_types[] = {
 
 const static size_t box_count = FF_ARRAY_ELEMS(box_types);
 
+// Return byte length of the UTF-8 sequence starting at text[0]. 0 on error.
+static int get_utf8_length_at(const char *text, const char *text_end)
+{
+const char *start = text;
+int err = 0;
+uint32_t c;
+GET_UTF8(c, text < text_end ? (uint8_t)*text++ : (err = 1, 0), goto 
error;);
+if (err)
+goto error;
+return text - start;
+error:
+return 0;
+}
+
 static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
-MovTextContext *m)
+   AVCodecContext *avctx)
 {
+MovTextContext *m = avctx->priv_data;
 int i = 0;
 int j = 0;
 int text_pos = 0;
@@ -342,6 +357,8 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 
 while (text < text_end) {
+int len;
+
 if (m->box_flags & STYL_BOX) {
 for (i = 0; i < m->style_entries; i++) {
 if (m->s[i]->style_flag && text_pos == m->s[i]->style_end) {
@@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 }
 
-switch (*text) {
-case '\r':
-break;
-case '\n':
-av_bprintf(buf, "\\N");
-break;
-default:
-av_bprint_chars(buf, *text, 1);
-break;
+len = get_utf8_length_at(text, text_end);
+if (len < 1) {
+av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in subtitle\n");
+len = 1;
+}
+for (i = 0; i < len; i++) {
+switch (*text) {
+case '\r':
+break;
+case '\n':
+av_bprintf(buf, "\\N");
+break;
+default:
+av_bprint_chars(buf, *text, 1);
+break;
+}
+text++;
 }
-text++;
 text_pos++;
 }
 
@@ -507,10 +531,10 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
 }
 m->tracksize = m->tracksize + tsmb_size;
 }
-text_to_ass(&buf, ptr, end, m);
+text_to_ass(&buf, ptr, end, avctx);
 mov_text_cleanup(m);
 } else
-text_to_ass(&buf, ptr, end, m);
+text_to_ass(&buf, ptr, end, avctx);
 
 ret = ff_ass_add_rect(sub, buf.str, m->readorder++, 0, NULL, NULL);
 av_bprint_finalize(&buf, NULL);
-- 
2.16.1

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Jan Ekström
On Sat, Mar 24, 2018 at 4:48 PM, wm4  wrote:
> Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> ASCII characters) were not handled correctly. The spec mandates that
> styling start/end ranges are in "characters". It's not quite clear what
> a "character" is supposed to be, but maybe they mean unicode codepoints.
>
> FFmpeg's decoder treated the style ranges as byte idexes, which could
> lead to UTF-8 sequences being broken, and the common code dropping the
> whole subtitle line.
>
> Change this and count the codepoint instead. This also means that even
> if this is somehow wrong, the decoder won't break UTF-8 sequences
> anymore. The sample which led me to investigate this now appears to work
> correctly.
> ---
> https://github.com/mpv-player/mpv/issues/5675

For reference, the relevant specification for MOV/3GPP Timed Text
seems to be ETSI TS 126 245, which is currently at version 14
(2017-04), available at
http://www.etsi.org/deliver/etsi_ts/126200_126299/126245/14.00.00_60/ts_126245v14p.pdf
.

It is indeed rather ambiguous in 5.2 regarding what a "character" is
in the context of UTF-8 or UTF-16.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Philip Langdale
On Sat, 24 Mar 2018 15:48:36 +0100
wm4  wrote:

> Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> ASCII characters) were not handled correctly. The spec mandates that
> styling start/end ranges are in "characters". It's not quite clear
> what a "character" is supposed to be, but maybe they mean unicode
> codepoints.
> 
> FFmpeg's decoder treated the style ranges as byte idexes, which could
> lead to UTF-8 sequences being broken, and the common code dropping the
> whole subtitle line.
> 
> Change this and count the codepoint instead. This also means that even
> if this is somehow wrong, the decoder won't break UTF-8 sequences
> anymore. The sample which led me to investigate this now appears to
> work correctly.
> ---
> https://github.com/mpv-player/mpv/issues/5675
> ---
>  libavcodec/movtextdec.c | 50
> - 1 file changed, 37
> insertions(+), 13 deletions(-)
> 
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index bd19577724..89ac791602 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -326,9 +326,24 @@ static const Box box_types[] = {
>  
>  const static size_t box_count = FF_ARRAY_ELEMS(box_types);
>  
> +// Return byte length of the UTF-8 sequence starting at text[0]. 0
> on error. +static int get_utf8_length_at(const char *text, const char
> *text_end) +{
> +const char *start = text;
> +int err = 0;
> +uint32_t c;
> +GET_UTF8(c, text < text_end ? (uint8_t)*text++ : (err = 1, 0),
> goto error;);
> +if (err)
> +goto error;
> +return text - start;
> +error:
> +return 0;
> +}
> +
>  static int text_to_ass(AVBPrint *buf, const char *text, const char
> *text_end,
> -MovTextContext *m)
> +   AVCodecContext *avctx)
>  {
> +MovTextContext *m = avctx->priv_data;
>  int i = 0;
>  int j = 0;
>  int text_pos = 0;
> @@ -342,6 +357,8 @@ static int text_to_ass(AVBPrint *buf, const char
> *text, const char *text_end, }
>  
>  while (text < text_end) {
> +int len;
> +
>  if (m->box_flags & STYL_BOX) {
>  for (i = 0; i < m->style_entries; i++) {
>  if (m->s[i]->style_flag && text_pos ==
> m->s[i]->style_end) { @@ -388,17 +405,24 @@ static int
> text_to_ass(AVBPrint *buf, const char *text, const char *text_end, }
>  }
>  
> -switch (*text) {
> -case '\r':
> -break;
> -case '\n':
> -av_bprintf(buf, "\\N");
> -break;
> -default:
> -av_bprint_chars(buf, *text, 1);
> -break;
> +len = get_utf8_length_at(text, text_end);
> +if (len < 1) {
> +av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in
> subtitle\n");
> +len = 1;
> +}
> +for (i = 0; i < len; i++) {
> +switch (*text) {
> +case '\r':
> +break;
> +case '\n':
> +av_bprintf(buf, "\\N");
> +break;
> +default:
> +av_bprint_chars(buf, *text, 1);
> +break;
> +}
> +text++;
>  }
> -text++;
>  text_pos++;
>  }
>  
> @@ -507,10 +531,10 @@ static int mov_text_decode_frame(AVCodecContext
> *avctx, }
>  m->tracksize = m->tracksize + tsmb_size;
>  }
> -text_to_ass(&buf, ptr, end, m);
> +text_to_ass(&buf, ptr, end, avctx);
>  mov_text_cleanup(m);
>  } else
> -text_to_ass(&buf, ptr, end, m);
> +text_to_ass(&buf, ptr, end, avctx);
>  
>  ret = ff_ass_add_rect(sub, buf.str, m->readorder++, 0, NULL,
> NULL); av_bprint_finalize(&buf, NULL);

Ship it. Thanks!


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


Re: [FFmpeg-devel] Reimbursement request

2018-03-24 Thread Stefano Sabatini
On date Saturday 2018-03-24 13:51:38 +0100, Michael Niedermayer encoded:
> On Sun, Mar 18, 2018 at 08:57:42PM +0100, Thilo Borgmann wrote:
> > Hi,
> > 
> > > As already discussed, FFmpeg was present on Chemnitzer Linux Tage, in
> > > addition, Thilo and I went to Brussels for FOSDEM where we attended
> > > the talks in the multimedia room kindly (co-) organized by Kieran and
> > > answered some questions. I would like to request reimbursement for the
> > > travel costs, that's flights-only, Thilo payed the gasoline and the
> > > hotel.
> > 
> > from my side there are hotel & gas for Chemnitz, and flight & hotel for 
> > Brussels that I'd like to ask to reimburse for. For Chemnitz it is the 
> > usual drive by car Carl Eugen and me do from Berlin, which are around 290 
> > km one way as well as a shared hotel room (they did not manage to put all 
> > of us into one suite this time, so we had to stick to two rooms for all 
> > four of us):
> > 
> > > Chemnitz: 125,85
> > 
> > Hotel: 194.00 EUR
> > Gas:   36.62 + 21.67 + 39.51 =  97.80 EUR
> > -
> > Total: 291,80 EUR
> > 
> > 
> > > Brussels: 192,41
> > 
> > Flight:111.81 EUR
> > Hotel: 186.69 EUR
> > -
> > Total: 298,50 EUR
> > 
> 
> all LGTM

LGTM.

Will send the refund requests to SPI as usual.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 0/1] libavfilter: Add OpenCL convolution filter v0.2

2018-03-24 Thread Danil Iashchenko
Behaves like existing convolution filter.

Patch uses global kernel.

---
 configure   |   1 +
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/opencl/convolution.cl   |  42 
 libavfilter/opencl_source.h |   1 +
 libavfilter/vf_convolution_opencl.c | 368 
 6 files changed, 414 insertions(+)
 create mode 100644 libavfilter/opencl/convolution.cl
 create mode 100644 libavfilter/vf_convolution_opencl.c

diff --git a/configure b/configure
index cc3edeb..5ccf3ce 100755
--- a/configure
+++ b/configure
@@ -3235,6 +3235,7 @@ blackframe_filter_deps="gpl"
 boxblur_filter_deps="gpl"
 bs2b_filter_deps="libbs2b"
 colormatrix_filter_deps="gpl"
+convolution_opencl_filter_deps="opencl"
 convolve_filter_deps="avcodec"
 convolve_filter_select="fft"
 coreimage_filter_deps="coreimage appkit"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1043b41..c402670 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -159,6 +159,7 @@ OBJS-$(CONFIG_COLORLEVELS_FILTER)+= 
vf_colorlevels.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)+= vf_colormatrix.o
 OBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o colorspacedsp.o
 OBJS-$(CONFIG_CONVOLUTION_FILTER)+= vf_convolution.o
+OBJS-$(CONFIG_CONVOLUTION_OPENCL_FILTER) += vf_convolution_opencl.o 
opencl.o opencl/convolution.o
 OBJS-$(CONFIG_CONVOLVE_FILTER)   += vf_convolve.o framesync.o
 OBJS-$(CONFIG_COPY_FILTER)   += vf_copy.o
 OBJS-$(CONFIG_COREIMAGE_FILTER)  += vf_coreimage.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 3f67e32..1cf1340 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -168,6 +168,7 @@ static void register_all(void)
 REGISTER_FILTER(COLORMATRIX,colormatrix,vf);
 REGISTER_FILTER(COLORSPACE, colorspace, vf);
 REGISTER_FILTER(CONVOLUTION,convolution,vf);
+REGISTER_FILTER(CONVOLUTION_OPENCL, convolution_opencl, vf);
 REGISTER_FILTER(CONVOLVE,   convolve,   vf);
 REGISTER_FILTER(COPY,   copy,   vf);
 REGISTER_FILTER(COREIMAGE,  coreimage,  vf);
diff --git a/libavfilter/opencl/convolution.cl 
b/libavfilter/opencl/convolution.cl
new file mode 100644
index 000..c0748cc
--- /dev/null
+++ b/libavfilter/opencl/convolution.cl
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Danil Iashchenko
+ *
+ * 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
+ */
+
+__kernel void convolution_global(__write_only image2d_t dst,
+ __read_only  image2d_t src,
+ int coef_matrix_dim,
+ __constant float *coef_matrix,
+ float div,
+ float bias)
+{
+const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE | 
CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST);
+
+const int half_matrix_dim = (coef_matrix_dim / 2);
+int2 loc = (int2)(get_global_id(0), get_global_id(1));
+float4 convPix = (float4)(0.0f, 0.0f, 0.0f, 0.0f);
+
+for (int conv_i = -half_matrix_dim; conv_i <= half_matrix_dim; conv_i++) {
+for (int conv_j = -half_matrix_dim; conv_j <= half_matrix_dim; 
conv_j++) {
+float4 px = read_imagef(src, sampler, loc + (int2)(conv_j, 
conv_i));
+convPix += px * 
coef_matrix[(conv_i+half_matrix_dim)*coef_matrix_dim+(conv_j+half_matrix_dim)];
+}
+ }
+ float4 dstPix = convPix * div + bias;
+ write_imagef(dst, loc, dstPix);
+}
diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h
index 02bc172..4bb9969 100644
--- a/libavfilter/opencl_source.h
+++ b/libavfilter/opencl_source.h
@@ -20,6 +20,7 @@
 #define AVFILTER_OPENCL_SOURCE_H
 
 extern const char *ff_opencl_source_avgblur;
+extern const char *ff_opencl_source_convolution;
 extern const char *ff_opencl_source_overlay;
 extern const char *ff_opencl_source_unsharp;
 
diff --git a/libavfilter/vf_convolution_opencl.c 
b/libavfilter/vf_convolution_opencl.c
new file mode 100644
index 000..2df51e0
--- /dev/null
+++ b/libavfilter/vf_convolution_opencl.c
@@ -0,0 +1,36

Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Carl Eugen Hoyos
2018-03-24 15:48 GMT+01:00, wm4 :
> Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> ASCII characters) were not handled correctly. The spec mandates that
> styling start/end ranges are in "characters". It's not quite clear what
> a "character" is supposed to be, but maybe they mean unicode codepoints.
>
> FFmpeg's decoder treated the style ranges as byte idexes, which could
> lead to UTF-8 sequences being broken, and the common code dropping the
> whole subtitle line.
>
> Change this and count the codepoint instead. This also means that even
> if this is somehow wrong, the decoder won't break UTF-8 sequences
> anymore. The sample which led me to investigate this now appears to work
> correctly.

Could you confirm that this is also what QT does?

Or is it impossible that the patch breaks something?

[...]

> @@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char
> *text, const char *text_end,
>  }
>  }
>
> -switch (*text) {
> -case '\r':
> -break;
> -case '\n':
> -av_bprintf(buf, "\\N");
> -break;
> -default:
> -av_bprint_chars(buf, *text, 1);
> -break;
> +len = get_utf8_length_at(text, text_end);
> +if (len < 1) {
> +av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in
> subtitle\n");
> +len = 1;
> +}
> +for (i = 0; i < len; i++) {

> +switch (*text) {
> +case '\r':
> +break;
> +case '\n':
> +av_bprintf(buf, "\\N");
> +break;
> +default:
> +av_bprint_chars(buf, *text, 1);
> +break;

Imo, the reindentation is not ok but this isn't my code.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Hendrik Leppkes
On Sat, Mar 24, 2018 at 3:48 PM, wm4  wrote:
> Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> ASCII characters) were not handled correctly. The spec mandates that
> styling start/end ranges are in "characters". It's not quite clear what
> a "character" is supposed to be, but maybe they mean unicode codepoints.
>

Well a character certainly isn't a byte in a Unicode string, even if
the C type may be called that way.

So seems fine to me.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Jan Ekström
On Sat, Mar 24, 2018 at 6:05 PM, Carl Eugen Hoyos  wrote:
> Could you confirm that this is also what QT does?
>
> Or is it impossible that the patch breaks something?
>

Everything can in theory break something. Anyways, it was widely
understood that 3GPP timed text was a better defined MOV timed text,
but I did have a quick look at Apple's qtff.pdf, which happily enough
actually defined the start and end characters (yes, they are marked as
"characters") as follows from the "Subtitle Style Atom" definition
("styl"):

Start character
A 16-bit value that is the offset of the first character that is
to use the style specified in this record.
Zero (0) is the first character in the subtitle.
End character
A 16-bit value that is the offset of the character that follows
the last character to use this style.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread wm4
On Sat, 24 Mar 2018 17:05:41 +0100
Carl Eugen Hoyos  wrote:

> 2018-03-24 15:48 GMT+01:00, wm4 :
> > Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> > ASCII characters) were not handled correctly. The spec mandates that
> > styling start/end ranges are in "characters". It's not quite clear what
> > a "character" is supposed to be, but maybe they mean unicode codepoints.
> >
> > FFmpeg's decoder treated the style ranges as byte idexes, which could
> > lead to UTF-8 sequences being broken, and the common code dropping the
> > whole subtitle line.
> >
> > Change this and count the codepoint instead. This also means that even
> > if this is somehow wrong, the decoder won't break UTF-8 sequences
> > anymore. The sample which led me to investigate this now appears to work
> > correctly.  
> 
> Could you confirm that this is also what QT does?

I can't test with QT. VLC seems to behave like with this patch applied.

> Or is it impossible that the patch breaks something?

Could probably break movtext subtitles generated by ffmpeg (I didn't
fix the movtext encoder, and it seems to have the same bug). But these
will most likely be broken on other players too. Tough the worst case
is just that the styles get shifted.

> [...]
> 
> > @@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char
> > *text, const char *text_end,
> >  }
> >  }
> >
> > -switch (*text) {
> > -case '\r':
> > -break;
> > -case '\n':
> > -av_bprintf(buf, "\\N");
> > -break;
> > -default:
> > -av_bprint_chars(buf, *text, 1);
> > -break;
> > +len = get_utf8_length_at(text, text_end);
> > +if (len < 1) {
> > +av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in
> > subtitle\n");
> > +len = 1;
> > +}
> > +for (i = 0; i < len; i++) {  
> 
> > +switch (*text) {
> > +case '\r':
> > +break;
> > +case '\n':
> > +av_bprintf(buf, "\\N");
> > +break;
> > +default:
> > +av_bprint_chars(buf, *text, 1);
> > +break;  
> 
> Imo, the reindentation is not ok but this isn't my code.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread Carl Eugen Hoyos
2018-03-24 17:42 GMT+01:00, wm4 :
> On Sat, 24 Mar 2018 17:05:41 +0100
> Carl Eugen Hoyos  wrote:
>
>> 2018-03-24 15:48 GMT+01:00, wm4 :
>> > Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
>> > ASCII characters) were not handled correctly. The spec mandates that
>> > styling start/end ranges are in "characters". It's not quite clear what
>> > a "character" is supposed to be, but maybe they mean unicode codepoints.
>> >
>> > FFmpeg's decoder treated the style ranges as byte idexes, which could
>> > lead to UTF-8 sequences being broken, and the common code dropping the
>> > whole subtitle line.
>> >
>> > Change this and count the codepoint instead. This also means that even
>> > if this is somehow wrong, the decoder won't break UTF-8 sequences
>> > anymore. The sample which led me to investigate this now appears to work
>> > correctly.
>>
>> Could you confirm that this is also what QT does?
>
> I can't test with QT. VLC seems to behave like with this patch applied.
>
>> Or is it impossible that the patch breaks something?
>
> Could probably break movtext subtitles generated by ffmpeg (I didn't
> fix the movtext encoder, and it seems to have the same bug). But these
> will most likely be broken on other players too. Tough the worst case
> is just that the styles get shifted.

Thank you.

>> [...]
>>
>> > @@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char
>> > *text, const char *text_end,
>> >  }
>> >  }
>> >
>> > -switch (*text) {
>> > -case '\r':
>> > -break;
>> > -case '\n':
>> > -av_bprintf(buf, "\\N");
>> > -break;
>> > -default:
>> > -av_bprint_chars(buf, *text, 1);
>> > -break;
>> > +len = get_utf8_length_at(text, text_end);
>> > +if (len < 1) {
>> > +av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in
>> > subtitle\n");
>> > +len = 1;
>> > +}
>> > +for (i = 0; i < len; i++) {
>>
>> > +switch (*text) {
>> > +case '\r':
>> > +break;
>> > +case '\n':
>> > +av_bprintf(buf, "\\N");
>> > +break;
>> > +default:
>> > +av_bprint_chars(buf, *text, 1);
>> > +break;
>>
>> Imo, the reindentation is not ok but this isn't my code.
>
> Why not?

Because the patch is much easier to read without it.

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


Re: [FFmpeg-devel] [PATCH] movtextdec: fix handling of UTF-8 subtitles

2018-03-24 Thread wm4
On Sat, 24 Mar 2018 17:50:53 +0100
Carl Eugen Hoyos  wrote:

> 2018-03-24 17:42 GMT+01:00, wm4 :
> > On Sat, 24 Mar 2018 17:05:41 +0100
> > Carl Eugen Hoyos  wrote:
> >  
> >> 2018-03-24 15:48 GMT+01:00, wm4 :  
> >> > Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
> >> > ASCII characters) were not handled correctly. The spec mandates that
> >> > styling start/end ranges are in "characters". It's not quite clear what
> >> > a "character" is supposed to be, but maybe they mean unicode codepoints.
> >> >
> >> > FFmpeg's decoder treated the style ranges as byte idexes, which could
> >> > lead to UTF-8 sequences being broken, and the common code dropping the
> >> > whole subtitle line.
> >> >
> >> > Change this and count the codepoint instead. This also means that even
> >> > if this is somehow wrong, the decoder won't break UTF-8 sequences
> >> > anymore. The sample which led me to investigate this now appears to work
> >> > correctly.  
> >>
> >> Could you confirm that this is also what QT does?  
> >
> > I can't test with QT. VLC seems to behave like with this patch applied.
> >  
> >> Or is it impossible that the patch breaks something?  
> >
> > Could probably break movtext subtitles generated by ffmpeg (I didn't
> > fix the movtext encoder, and it seems to have the same bug). But these
> > will most likely be broken on other players too. Tough the worst case
> > is just that the styles get shifted.  
> 
> Thank you.
> 
> >> [...]
> >>  
> >> > @@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char
> >> > *text, const char *text_end,
> >> >  }
> >> >  }
> >> >
> >> > -switch (*text) {
> >> > -case '\r':
> >> > -break;
> >> > -case '\n':
> >> > -av_bprintf(buf, "\\N");
> >> > -break;
> >> > -default:
> >> > -av_bprint_chars(buf, *text, 1);
> >> > -break;
> >> > +len = get_utf8_length_at(text, text_end);
> >> > +if (len < 1) {
> >> > +av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in
> >> > subtitle\n");
> >> > +len = 1;
> >> > +}
> >> > +for (i = 0; i < len; i++) {  
> >>  
> >> > +switch (*text) {
> >> > +case '\r':
> >> > +break;
> >> > +case '\n':
> >> > +av_bprintf(buf, "\\N");
> >> > +break;
> >> > +default:
> >> > +av_bprint_chars(buf, *text, 1);
> >> > +break;  
> >>
> >> Imo, the reindentation is not ok but this isn't my code.  
> >
> > Why not?  
> 
> Because the patch is much easier to read without it.

git repo viewers can show commits without whitespaces, so I don't think
it matters anymore for this patch.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v2 2/5] lavfi: add new iteration API

2018-03-24 Thread Michael Niedermayer
On Sat, Mar 24, 2018 at 01:28:51AM +, Josh de Kock wrote:
> Signed-off-by: Josh de Kock 
> ---
>  configure|  24 +-
>  doc/APIchanges   |   4 +
>  doc/writing_filters.txt  |   6 +-
>  libavfilter/allfilters.c | 820 
> +--
>  libavfilter/avfilter.c   |  50 +--
>  libavfilter/avfilter.h   |  29 +-
>  libavfilter/version.h|   3 +
>  7 files changed, 481 insertions(+), 455 deletions(-)

This causes "ffplay -h" to infinite loop

[...]
-- 
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


Re: [FFmpeg-devel] avcodec/prores_ks : do not call estimate_alpha at each quantification step

2018-03-24 Thread Paul B Mahol
On 3/20/18, Martin Vignali  wrote:
> Hello,
>
> patch in attach move estimate_alpha outside the quantification loop
> no need to call it at each quantification step
>
> also remove "error" arg in estimate_alpha.
>
>
> Martin
>

probably ok, check that this does not break alpha encoding.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] swscale/rgb2rgb : add X86_64 SIMD (SSSE3 and AVX2) for shuffly_bytes func

2018-03-24 Thread Martin Vignali
>
> the code moving should be in a seperate patch idealy, no big issue here as
> this
> is not a very complex patch
>
> otherwise patches should be ok
>
> also tested on linux x86-32/64, mingw32/64, linux qemu mips
> thanks
>
>
>
patch split (code move/asm)

and pushed

Thanks for review and testing.

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


Re: [FFmpeg-devel] [PATCH] avdevice/decklink: fix leak when listing devices and there is no memory

2018-03-24 Thread Marton Balint



On Sat, 17 Mar 2018, Marton Balint wrote:


Fixes Coverity CID 1419523.

Signed-off-by: Marton Balint 
---
libavdevice/decklink_common.cpp | 17 +
1 file changed, 5 insertions(+), 12 deletions(-)


Applied.

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


[FFmpeg-devel] [PATCH] avcodec/avpacket: ensure the packet is writable in av_shrink_packet()

2018-03-24 Thread James Almer
Signed-off-by: James Almer 
---
This is a good time to deprecate this function and introduce a
replacement using the correct av_packet namespace and this time
returning an int.
What would be better

int av_packet_shrink(AVPacket *pkt, int size);

Or

int av_packet_resize(AVPacket *pkt, int size);

The latter would be a combination of both the current shrink and grow
functions.

 libavcodec/avpacket.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 0693ca6f62..7faa082395 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -100,9 +100,12 @@ int av_new_packet(AVPacket *pkt, int size)
 
 void av_shrink_packet(AVPacket *pkt, int size)
 {
+int packet_is_writable;
 if (pkt->size <= size)
 return;
 pkt->size = size;
+packet_is_writable = !av_packet_make_writable(pkt);
+av_assert0(packet_is_writable);
 memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 }
 
-- 
2.16.2

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


[FFmpeg-devel] [PATCHv2 1/2] ffmpeg: fallback to codecpar parameters on input filter eof

2018-03-24 Thread Marton Balint
Fixes ticket #6854 and the following simpler case:

ffmpeg -f lavfi -i testsrc=d=1 -f lavfi -i testsrc=d=0 -filter_complex overlay 
-f null none

Signed-off-by: Marton Balint 
---
 fftools/ffmpeg.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1b2e37b8d8..b72884673d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1829,6 +1829,19 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 print_final_stats(total_size);
 }
 
+static void ifilter_parameters_from_codecpar(InputFilter *ifilter, 
AVCodecParameters *par)
+{
+// We never got any input. Set a fake format, which will
+// come from libavformat.
+ifilter->format = par->format;
+ifilter->sample_rate= par->sample_rate;
+ifilter->channels   = par->channels;
+ifilter->channel_layout = par->channel_layout;
+ifilter->width  = par->width;
+ifilter->height = par->height;
+ifilter->sample_aspect_ratio= par->sample_aspect_ratio;
+}
+
 static void flush_encoders(void)
 {
 int i, ret;
@@ -1855,18 +1868,8 @@ static void flush_encoders(void)
 int x;
 for (x = 0; x < fg->nb_inputs; x++) {
 InputFilter *ifilter = fg->inputs[x];
-if (ifilter->format < 0) {
-AVCodecParameters *par = ifilter->ist->st->codecpar;
-// We never got any input. Set a fake format, which 
will
-// come from libavformat.
-ifilter->format = par->format;
-ifilter->sample_rate= par->sample_rate;
-ifilter->channels   = par->channels;
-ifilter->channel_layout = par->channel_layout;
-ifilter->width  = par->width;
-ifilter->height = par->height;
-ifilter->sample_aspect_ratio= 
par->sample_aspect_ratio;
-}
+if (ifilter->format < 0)
+ifilter_parameters_from_codecpar(ifilter, 
ifilter->ist->st->codecpar);
 }
 
 if (!ifilter_has_all_input_formats(fg))
@@ -2196,6 +2199,12 @@ static int ifilter_send_eof(InputFilter *ifilter, 
int64_t pts)
 } else {
 // the filtergraph was never configured
 FilterGraph *fg = ifilter->graph;
+if (ifilter->format < 0)
+ifilter_parameters_from_codecpar(ifilter, 
ifilter->ist->st->codecpar);
+if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || 
ifilter->type == AVMEDIA_TYPE_VIDEO)) {
+av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input 
stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index);
+return AVERROR_INVALIDDATA;
+}
 for (i = 0; i < fg->nb_inputs; i++)
 if (!fg->inputs[i]->eof)
 break;
-- 
2.13.6

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


[FFmpeg-devel] [PATCH v3] lavfi: add new iteration API

2018-03-24 Thread Josh de Kock
Signed-off-by: Josh de Kock 
---
 configure|  29 +-
 doc/APIchanges   |   4 +
 doc/writing_filters.txt  |   6 +-
 libavfilter/allfilters.c | 823 +--
 libavfilter/avfilter.c   |  50 +--
 libavfilter/avfilter.h   |  29 +-
 libavfilter/version.h|   3 +
 7 files changed, 489 insertions(+), 455 deletions(-)

diff --git a/configure b/configure
index cc3edeb80f..c1efefb61e 100755
--- a/configure
+++ b/configure
@@ -3561,15 +3561,6 @@ for v in "$@"; do
 FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
 done
 
-find_things(){
-thing=$1
-pattern=$2
-file=$source_path/$3
-sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" 
"$file"
-}
-
-FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
-
 find_things_extern(){
 thing=$1
 pattern=$2
@@ -3578,6 +3569,13 @@ find_things_extern(){
 sed -n "s/^[^#]*extern.*$pattern *ff_\([^ ]*\)_$thing;/\1_$out/p" "$file"
 }
 
+find_filters_extern(){
+file=$source_path/$1
+#sed -n "s/^extern AVFilter 
ff_\([avfsinkrc]\{2,5\}\)_\(\w\+\);/\2_filter/p" $file
+sed -E -n "s/^extern AVFilter 
ff_([avfsinkrc]{2,5})_([a-zA-Z0-9_]+);/\2_filter/p" $file
+}
+
+FILTER_LIST=$(find_filters_extern libavfilter/allfilters.c)
 OUTDEV_LIST=$(find_things_extern muxer AVOutputFormat libavdevice/alldevices.c 
outdev)
 INDEV_LIST=$(find_things_extern demuxer AVInputFormat libavdevice/alldevices.c 
indev)
 MUXER_LIST=$(find_things_extern muxer AVOutputFormat libavformat/allformats.c)
@@ -7088,6 +7086,10 @@ echo "#endif /* AVUTIL_AVCONFIG_H */" >> $TMPH
 
 cp_if_changed $TMPH libavutil/avconfig.h
 
+full_filter_name(){
+sed -n "s/^extern AVFilter ff_\([avfsinkrc]\{2,5\}\)_$1;/\1_$1/p" 
$source_path/libavfilter/allfilters.c
+}
+
 # generate the lists of enabled components
 print_enabled_components(){
 file=$1
@@ -7098,6 +7100,9 @@ print_enabled_components(){
 for c in $*; do
 if enabled $c; then
 case $name in
+filter_list)
+c=$(full_filter_name $(remove_suffix _filter $c))
+;;
 indev_list)
 c=$(add_suffix _demuxer $(remove_suffix _indev $c))
 ;;
@@ -7108,10 +7113,16 @@ print_enabled_components(){
 printf "&ff_%s,\n" $c >> $TMPH
 fi
 done
+if [ "$name" == "filter_list" ]; then
+for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+printf "&ff_%s,\n" $c >> $TMPH
+done
+fi
 echo "NULL };" >> $TMPH
 cp_if_changed $TMPH $file
 }
 
+print_enabled_components libavfilter/filter_list.c AVFilter filter_list 
$FILTER_LIST
 print_enabled_components libavcodec/codec_list.c AVCodec codec_list $CODEC_LIST
 print_enabled_components libavcodec/parser_list.c AVCodecParser parser_list 
$PARSER_LIST
 print_enabled_components libavcodec/bsf_list.c AVBitStreamFilter 
bitstream_filters $BSF_LIST
diff --git a/doc/APIchanges b/doc/APIchanges
index d410bcdd75..4052988f59 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-xx-xx - xxx - lavc 7.13.100 - avcodec.h
+  Deprecate use of avfilter_register(), avfilter_register_all(),
+  avfilter_next(). Add av_filter_iterate().
+
 2018-03-21 - xxx - lavc 58.15.100 - avcodec.h
   Add av_packet_make_writable().
 
diff --git a/doc/writing_filters.txt b/doc/writing_filters.txt
index 5cd4ecd6a4..98b9c6f3d2 100644
--- a/doc/writing_filters.txt
+++ b/doc/writing_filters.txt
@@ -31,10 +31,8 @@ If everything went right, you should get a foobar.png with 
Lena edge-detected.
 That's it, your new playground is ready.
 
 Some little details about what's going on:
-libavfilter/allfilters.c:avfilter_register_all() is called at runtime to create
-a list of the available filters, but it's important to know that this file is
-also parsed by the configure script, which in turn will define variables for
-the build system and the C:
+libavfilter/allfilters.c:this file is parsed by the configure script, which in 
turn
+will define variables for the build system and the C:
 
 --- after running configure ---
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 3f67e321bf..b6a193a8f0 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -23,410 +23,455 @@
 #include "avfilter.h"
 #include "config.h"
 
+extern AVFilter ff_af_abench;
+extern AVFilter ff_af_acompressor;
+extern AVFilter ff_af_acontrast;
+extern AVFilter ff_af_acopy;
+extern AVFilter ff_af_acrossfade;
+extern AVFilter ff_af_acrusher;
+extern AVFilter ff_af_adelay;
+extern AVFilter ff_af_aecho;
+extern AVFilter ff_af_aemphasis;
+extern AVFilter ff_af_aeval;
+extern AVFilter ff_af_afade;
+extern AVFilter ff_af_afftfilt;
+extern AVFilter ff_af_afir;
+extern AVFilter ff_af_aformat;
+extern AVFilter ff_af_agate;
+extern AVFilter ff_af_aiir;
+exter

Re: [FFmpeg-devel] [PATCH] avcodec/avpacket: ensure the packet is writable in av_shrink_packet()

2018-03-24 Thread wm4
On Sat, 24 Mar 2018 18:11:53 -0300
James Almer  wrote:

> Signed-off-by: James Almer 
> ---
> This is a good time to deprecate this function and introduce a
> replacement using the correct av_packet namespace and this time
> returning an int.
> What would be better
> 
> int av_packet_shrink(AVPacket *pkt, int size);
> 
> Or
> 

> int av_packet_resize(AVPacket *pkt, int size);

Seems better.

> 
> The latter would be a combination of both the current shrink and grow
> functions.
> 
>  libavcodec/avpacket.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 0693ca6f62..7faa082395 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -100,9 +100,12 @@ int av_new_packet(AVPacket *pkt, int size)
>  
>  void av_shrink_packet(AVPacket *pkt, int size)
>  {
> +int packet_is_writable;
>  if (pkt->size <= size)
>  return;
>  pkt->size = size;
> +packet_is_writable = !av_packet_make_writable(pkt);
> +av_assert0(packet_is_writable);
>  memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  }
>  

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


[FFmpeg-devel] [PATCH] avfilter/af_pan: parse properly expressions referencing the same channel multiple times

2018-03-24 Thread Marton Balint
Fixes parsing of expressions like c0=c0+c0. Previously no error was thrown and
only the last gain factor was used.

Signed-off-by: Marton Balint 
---
 libavfilter/af_pan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index d8a63a7952..148ac9f643 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -184,7 +184,7 @@ static av_cold int init(AVFilterContext *ctx)
 ret = AVERROR(EINVAL);
 goto fail;
 }
-pan->gain[out_ch_id][in_ch_id] = sign * gain;
+pan->gain[out_ch_id][in_ch_id] += sign * gain;
 skip_spaces(&arg);
 if (!*arg)
 break;
-- 
2.13.6

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


Re: [FFmpeg-devel] [PATCH 1/2] hlsenc: use stream's maximum bit rate as fall-back advertised rate

2018-03-24 Thread Jan Ekström
On Sat, Mar 24, 2018 at 7:26 AM, Steven Liu  wrote:
>
> LGTM
>
> Thanks
> Steven

Cheers,

Pushed with the prefix changed to avformat/hlsenc and made the
av_stream_get_side_data call fit into 80 columns.

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


[FFmpeg-devel] [PATCH] avcodec/wmalosslessdec: Fix null pointer dereference in decode_frame()

2018-03-24 Thread Michael Niedermayer
Fixes: 2018_03_23_poc.wav
Found-by: GwanYeong Kim 

Signed-off-by: Michael Niedermayer 
---
 libavcodec/wmalosslessdec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index 59e8929586..eb1db615ae 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -1256,7 +1256,9 @@ static int decode_packet(AVCodecContext *avctx, void 
*data, int *got_frame_ptr,
 (frame_size = show_bits(gb, s->log2_frame_size)) &&
 frame_size <= remaining_bits(s, gb)) {
 save_bits(s, gb, frame_size, 0);
-s->packet_done = !decode_frame(s);
+
+if (!s->packet_loss)
+s->packet_done = !decode_frame(s);
 } else if (!s->len_prefix
&& s->num_saved_bits > get_bits_count(&s->gb)) {
 /* when the frames do not have a length prefix, we don't know the
-- 
2.16.2

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


Re: [FFmpeg-devel] [PATCH] avcodec/avpacket: ensure the packet is writable in av_shrink_packet()

2018-03-24 Thread James Almer
On 3/24/2018 6:46 PM, wm4 wrote:
> On Sat, 24 Mar 2018 18:11:53 -0300
> James Almer  wrote:
> 
>> Signed-off-by: James Almer 
>> ---
>> This is a good time to deprecate this function and introduce a
>> replacement using the correct av_packet namespace and this time
>> returning an int.
>> What would be better
>>
>> int av_packet_shrink(AVPacket *pkt, int size);
>>
>> Or
>>
> 
>> int av_packet_resize(AVPacket *pkt, int size);
> 
> Seems better.
> 
>>
>> The latter would be a combination of both the current shrink and grow
>> functions.
>>
>>  libavcodec/avpacket.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
>> index 0693ca6f62..7faa082395 100644
>> --- a/libavcodec/avpacket.c
>> +++ b/libavcodec/avpacket.c
>> @@ -100,9 +100,12 @@ int av_new_packet(AVPacket *pkt, int size)
>>  
>>  void av_shrink_packet(AVPacket *pkt, int size)
>>  {
>> +int packet_is_writable;
>>  if (pkt->size <= size)
>>  return;
>>  pkt->size = size;
>> +packet_is_writable = !av_packet_make_writable(pkt);
>> +av_assert0(packet_is_writable);
>>  memset(pkt->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>>  }
>>  
> 
> LGTM

Ok, but i just realized that i can't apply this without first writing an
internal variant specifically for the encoders that makes sure pkt->data
!= avctx->internal->byte_buffer before trying to do anything, otherwise
the supposed benefits of that weird internal buffer code in
ff_alloc_packet2() would be lost.

Will look at that later.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/6] avcodec/frame_thread_encoder: remove usage of av_dup_packet()

2018-03-24 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/frame_thread_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/frame_thread_encoder.c 
b/libavcodec/frame_thread_encoder.c
index 215aee9fc0..2a56edce79 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -92,7 +92,7 @@ static void * attribute_align_arg worker(void *v){
 pthread_mutex_unlock(&c->buffer_mutex);
 av_frame_free(&frame);
 if(got_packet) {
-int ret2 = av_dup_packet(pkt);
+int ret2 = av_packet_make_ref(pkt);
 if (ret >= 0 && ret2 < 0)
 ret = ret2;
 } else {
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 3/6] avcodec/encode: use av_packet_make_ref to ensure packets are ref counted

2018-03-24 Thread James Almer
Simplifies code.

Signed-off-by: James Almer 
---
 libavcodec/encode.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 71b1b14afc..9dbdf4f5d9 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -223,12 +223,9 @@ int attribute_align_arg 
avcodec_encode_audio2(AVCodecContext *avctx,
 avpkt->buf  = user_pkt.buf;
 avpkt->data = user_pkt.data;
 } else if (!avpkt->buf) {
-AVPacket tmp = { 0 };
-ret = av_packet_ref(&tmp, avpkt);
-av_packet_unref(avpkt);
+ret = av_packet_make_ref(avpkt);
 if (ret < 0)
 goto end;
-*avpkt = tmp;
 }
 }
 
@@ -318,12 +315,9 @@ int attribute_align_arg 
avcodec_encode_video2(AVCodecContext *avctx,
 avpkt->buf  = user_pkt.buf;
 avpkt->data = user_pkt.data;
 } else if (!avpkt->buf) {
-AVPacket tmp = { 0 };
-ret = av_packet_ref(&tmp, avpkt);
-av_packet_unref(avpkt);
+ret = av_packet_make_ref(avpkt);
 if (ret < 0)
 return ret;
-*avpkt = tmp;
 }
 }
 
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 5/6] avcodec/bsf: use av_packet_make_ref to ensure packets are ref counted

2018-03-24 Thread James Almer
Simplifies code.

Signed-off-by: James Almer 
---
 libavcodec/bsf.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index 05a44e2e31..02550b01d7 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -174,6 +174,8 @@ int av_bsf_init(AVBSFContext *ctx)
 
 int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
 {
+int ret;
+
 if (!pkt || (!pkt->data && !pkt->side_data_elems)) {
 ctx->internal->eof = 1;
 return 0;
@@ -188,15 +190,10 @@ int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
 ctx->internal->buffer_pkt->side_data_elems)
 return AVERROR(EAGAIN);
 
-if (pkt->buf) {
-av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
-} else {
-int ret = av_packet_ref(ctx->internal->buffer_pkt, pkt);
-
-if (ret < 0)
-return ret;
-av_packet_unref(pkt);
-}
+ret = av_packet_make_ref(pkt);
+if (ret < 0)
+return ret;
+av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
 
 return 0;
 }
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 1/6] avcodec/avpacket: add av_packet_make_ref()

2018-03-24 Thread James Almer
It works as a drop in replacement for the deprecated av_dup_packet(),
to ensure a packet is reference counted.

Signed-off-by: James Almer 
---
Better name welcome.

 libavcodec/avcodec.h  | 18 +-
 libavcodec/avpacket.c | 18 ++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 495242faf0..eb3fe4e428 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4360,7 +4360,7 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int 
size);
  * @warning This is a hack - the packet memory allocation stuff is broken. The
  * packet is allocated if it was not really allocated.
  *
- * @deprecated Use av_packet_ref
+ * @deprecated Use av_packet_ref or av_packet_make_ref
  */
 attribute_deprecated
 int av_dup_packet(AVPacket *pkt);
@@ -4531,6 +4531,22 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src);
  */
 int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
 
+/**
+ * Ensure the data described by a given packet is reference counted.
+ *
+ * @note This function does no ensure that the reference will be writable.
+ *   Use av_packet_make_writable instead for that purpose.
+ *
+ * @see av_packet_ref
+ * @see av_packet_make_writable
+ *
+ * @param pkt packet whose data should be made reference counted.
+ *
+ * @return 0 on success, a negative AVERROR on error. On failure, the
+ * packet is unchanged.
+ */
+int av_packet_make_ref(AVPacket *pkt);
+
 /**
  * Create a writable reference for the data described by a given packet,
  * avoiding data copy if possible.
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 7faa082395..a6d2e6eb74 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -655,6 +655,24 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src)
 src->size = 0;
 }
 
+int av_packet_make_ref(AVPacket *pkt)
+{
+int ret;
+
+if (pkt->buf)
+return 0;
+
+ret = packet_alloc(&pkt->buf, pkt->size);
+if (ret < 0)
+return ret;
+if (pkt->size)
+memcpy(pkt->buf->data, pkt->data, pkt->size);
+
+pkt->data = pkt->buf->data;
+
+return 0;
+}
+
 int av_packet_make_writable(AVPacket *pkt)
 {
 AVBufferRef *buf = NULL;
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 4/6] avdevice/decklink_dec: use av_packet_make_ref to ensure packets are ref counted

2018-03-24 Thread James Almer
Partially reverts commit e91f0c4f8b, simplifying code.

Signed-off-by: James Almer 
---
 libavdevice/decklink_dec.cpp | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 28a748a28f..0ccf87f94f 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -464,24 +464,22 @@ static unsigned long long 
avpacket_queue_size(AVPacketQueue *q)
 static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
 {
 AVPacketList *pkt1;
-int ret;
 
 // Drop Packet if queue size is > maximum queue size
 if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) {
 av_log(q->avctx, AV_LOG_WARNING,  "Decklink input buffer overrun!\n");
 return -1;
 }
+/* ensure the packet is reference counted */
+if (av_packet_make_ref(pkt) < 0) {
+return -1;
+}
 
 pkt1 = (AVPacketList *)av_mallocz(sizeof(AVPacketList));
 if (!pkt1) {
 return -1;
 }
-ret = av_packet_ref(&pkt1->pkt, pkt);
-av_packet_unref(pkt);
-if (ret < 0) {
-av_free(pkt1);
-return -1;
-}
+av_packet_move_ref(&pkt1->pkt, pkt);
 pkt1->next = NULL;
 
 pthread_mutex_lock(&q->mutex);
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 6/6] avformat/utils: use av_packet_make_ref to ensure packets are ref counted

2018-03-24 Thread James Almer
Simplifies code, while also fixing a potential leak of side data in pkt.

Signed-off-by: James Almer 
---
 libavformat/utils.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index f13c8208b1..fbf681e490 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -867,13 +867,9 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 continue;
 }
 
-if (!pkt->buf) {
-AVPacket tmp = { 0 };
-err = av_packet_ref(&tmp, pkt);
-if (err < 0)
-return err;
-*pkt = tmp;
-}
+err = av_packet_make_ref(pkt);
+if (err < 0)
+return err;
 
 if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
 (pkt->flags & AV_PKT_FLAG_CORRUPT)) {
-- 
2.16.2

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