Re: [FFmpeg-devel] [PATCH v1 4/4] avcodec/proresenc_anatoliy: support for more color matrix for proresenc

2020-05-03 Thread Marton Balint



On Tue, 5 Nov 2019, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Please tested with below command:
./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries bt2020 
-colorspace bt2020_ncl -color_trc smpte2084 -an output.mov

mediainfo outout.mov
...
Color primaries  : BT.2020
Transfer characteristics : PQ
Matrix coefficients  : BT.2020 non-constant

./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries bt2020 
-colorspace bt2020_ncl -color_trc arib-std-b67 -an output.mov
mediainfo outout.mov
...
Color primaries  : BT.2020
Transfer characteristics : HLG
Matrix coefficients  : BT.2020 non-constant

Signed-off-by: Limin Wang 
---
libavcodec/proresenc_anatoliy.c | 9 +
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index 0fc79fc1de..81365c528c 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -55,7 +55,8 @@ static const int bitrate_table[6]  = { 1000, 2100, 3500, 
5400, 7000, 1};

static const int valid_primaries[9]  = { AVCOL_PRI_RESERVED0, AVCOL_PRI_BT709, 
AVCOL_PRI_UNSPECIFIED, AVCOL_PRI_BT470BG,
 AVCOL_PRI_SMPTE170M, AVCOL_PRI_BT2020, 
AVCOL_PRI_SMPTE431, AVCOL_PRI_SMPTE432,INT_MAX };
-static const int valid_trc[4]= { AVCOL_TRC_RESERVED0, AVCOL_TRC_BT709, 
AVCOL_TRC_UNSPECIFIED, INT_MAX };
+static const int valid_trc[6]= { AVCOL_TRC_RESERVED0, AVCOL_TRC_BT709, 
AVCOL_TRC_UNSPECIFIED, AVCOL_TRC_SMPTE2084,
+ AVCOL_TRC_ARIB_STD_B67, INT_MAX };
static const int valid_colorspace[5] = { AVCOL_SPC_BT709, 
AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_SMPTE170M,
 AVCOL_SPC_BT2020_NCL, INT_MAX };

@@ -757,9 +758,9 @@ static int prores_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
*buf++ = frame_flags;
*buf++ = 0; /* reserved */
/* only write color properties, if valid value. set to unspecified 
otherwise */
-*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
pict->color_primaries, valid_primaries, 0);
-*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
pict->color_trc, valid_trc, 0);
-*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
pict->colorspace, valid_colorspace, 0);
+*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
avctx->color_primaries, valid_primaries, 0);
+*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
avctx->color_trc, valid_trc, 0);
+*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
avctx->colorspace, valid_colorspace, 0);
if (avctx->profile >= FF_PROFILE_PRORES_) {
if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
*buf++ = 0xA0;/* src b64a and no alpha */


Please revert this, using codec context instead of frame does not seem 
right. Also have you pinged this before applying?


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 2/4] avcodec/prores_metadata_bsf: add smpte2084 format support

2020-05-03 Thread Marton Balint



On Fri, 15 Nov 2019, Limin Wang wrote:



ping, the patchset is for HDR/HLG color support for prores.

On Mon, Nov 04, 2019 at 07:10:00PM +0800, lance.lmw...@gmail.com wrote:

From: Limin Wang 

It's based on the following specs:
RDD 36:2015 - SMPTE Registered Disclosure Doc - Apple ProRes Bitstream Syntax 
and Decoding Process

Signed-off-by: Limin Wang 
---
 doc/bitstream_filters.texi   | 2 ++
 libavcodec/prores_metadata_bsf.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..e2de4fd4ed 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -589,6 +589,8 @@ Keep the same transfer characteristics property (default).
 @item unknown
 @item bt709
 BT 601, BT 709, BT 2020
+@item smpte2084
+SMPTE ST 2084
 @end table


diff --git a/libavcodec/prores_metadata_bsf.c b/libavcodec/prores_metadata_bsf.c
index 0510d3520a..24615e9305 100644
--- a/libavcodec/prores_metadata_bsf.c
+++ b/libavcodec/prores_metadata_bsf.c
@@ -140,10 +140,11 @@ static const AVOption options[] = {
 {"smpte431",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},
 {"smpte432",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},

-{"color_trc", "select color transfer", OFFSET(transfer_characteristics), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_BT709, FLAGS, "color_trc"},
+{"color_trc", "select color transfer", OFFSET(transfer_characteristics), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_NB, FLAGS, "color_trc"},


NB-1.


 {"auto", "keep the same color transfer",  0, AV_OPT_TYPE_CONST, {.i64=-1},   
INT_MIN, INT_MAX, FLAGS, "color_trc"},
 {"unknown",NULL,  0, AV_OPT_TYPE_CONST, {.i64=0},
INT_MIN, INT_MAX, FLAGS, "color_trc"},
 {"bt709",  NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_TRC_BT709},  INT_MIN, INT_MAX, FLAGS, "color_trc"},
+{"smpte2084",  NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_TRC_SMPTE2084},  INT_MIN, INT_MAX, FLAGS, "color_trc"},

 {"colorspace", "select colorspace", OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, 
{.i64=-1}, -1,  AVCOL_SPC_BT2020_NCL, FLAGS, "colorspace"},
 {"auto", "keep the same colorspace",  0, AV_OPT_TYPE_CONST, {.i64=-1},   
 INT_MIN, INT_MAX, FLAGS, "colorspace"},


Yet again, please, do not apply patches which have not been LGTM-ed and 
you have not pinged them recently.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] libswscale: add output support for AV_PIX_FMT_GBRAPF32

2020-05-03 Thread Mark Reid
On Thu., Apr. 30, 2020, 11:46 a.m. Mark Reid,  wrote:

>
>
> On Thu, Apr 30, 2020 at 7:59 AM Michael Niedermayer 
> wrote:
>
>> On Wed, Apr 29, 2020 at 02:49:35PM -0700, Mark Reid wrote:
>> > On Wed, Apr 29, 2020 at 2:22 PM Michael Niedermayer
>> 
>> > wrote:
>> >
>> > > On Wed, Apr 29, 2020 at 11:19:56PM +0200, Michael Niedermayer wrote:
>> > > > On Tue, Apr 28, 2020 at 08:02:34PM -0700, mindm...@gmail.com wrote:
>> > > > > From: Mark Reid 
>> > > > >
>> > > > > ---
>> > > > >  libswscale/output.c  | 82
>> 
>> > > > >  libswscale/slice.c   | 28 
>> > > > >  libswscale/swscale_unscaled.c| 33 ++
>> > > > >  libswscale/utils.c   |  8 +--
>> > > > >  tests/ref/fate/filter-pixdesc-gbrapf32be |  1 +
>> > > > >  tests/ref/fate/filter-pixdesc-gbrapf32le |  1 +
>> > > > >  tests/ref/fate/filter-pixdesc-gbrpf32be  |  1 +
>> > > > >  tests/ref/fate/filter-pixdesc-gbrpf32le  |  1 +
>> > > > >  tests/ref/fate/filter-pixfmts-copy   |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-crop   |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-field  |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-hflip  |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-il |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-null   |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-scale  |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-transpose  |  4 ++
>> > > > >  tests/ref/fate/filter-pixfmts-vflip  |  4 ++
>> > > > >  18 files changed, 180 insertions(+), 15 deletions(-)
>> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
>> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
>> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
>> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le
>> > > >
>> > > > Fails on qemu MIPS
>> > > >
>> > > > --- src/tests/ref/fate/filter-pixfmts-scale 2020-04-29
>> > > 22:18:07.326122866 +0200
>> > > > +++ tests/data/fate/filter-pixfmts-scale2020-04-29
>> > > 23:06:16.167950113 +0200
>> > > > @@ -25,8 +25,8 @@
>> > > >  gbrap12le   bb1ba1c157717db3dd612a76d38a018e
>> > > >  gbrap16be   c72b935a6e57a8e1c37bff08c2db55b1
>> > > >  gbrap16le   13eb0e62b1ac9c1c86c81521eaefab5f
>> > > > -gbrapf32be  e6abe67df7fdd5f5dc5db7d852e50954
>> > > > -gbrapf32le  4d3043b206f7053f7d8d5672f430d680
>> > > > +gbrapf32be  982d646dc5b2dc718c65fa2a439828f5
>> > > > +gbrapf32le  f1ffa56441e29aab5e1fd982337bb8ac
>> > > >  gbrpdc3387f925f972c61aae7eb23cdc19f0
>> > > >  gbrp10be0277d4c3a8498d75e2783fb81379e481
>> > > >  gbrp10lef3d70f8ab845c3c9b8f7452e4a6e285a
>> > > > Test filter-pixfmts-scale failed. Look at
>> > > tests/data/fate/filter-pixfmts-scale.err for details.
>> > > > src/tests/Makefile:254: recipe for target
>> 'fate-filter-pixfmts-scale'
>> > > failed
>> > > > make: *** [fate-filter-pixfmts-scale] Error 1
>> > > > TESTh264-conformance-frext-pph422i5_panasonic_a
>> > > > TESTh264-conformance-frext-pph422i6_panasonic_a
>> > > > TESTh264-conformance-frext-pph422i7_panasonic_a
>> > > > TESTh264-conformance-hcbp2_hhi_a
>> > > > TESTh264-conformance-hcmp1_hhi_a
>> > > >
>> > > > I also think for float, tests based on comparission instead of
>> checksums
>> > > > would allow more use of floats in the computations which would
>> > > > differ rounding wise between platforms
>> > >
>> > > and the 2 sws patches would otherwise be ok if they didnt break any
>> tests
>> > >
>> > >
>> > I was worried about the test with float, and tried to limiting the
>> number
>> > of float operations, but guess it's not enough.
>>
>> > I haven't looked yet, but is there anywhere you could point me to doing
>> > a comparison based test?
>>
>> anything float based needs a comparission or luck ...
>> audio tests using "oneoff/stddev" in fate for example
>> checkasm also checks some float code with comparissions
>>
>> not sure how to best integrate this here ...
>>
>> thx
>>
>
> Thanks! I'll check those out. I came up with some other ideas to try too
> that I think might work. Its a tricky problem for sure!
>

lt appears the mips test where only failing on the alpha channel formats.
it seems to because of a planefill function I missed implementing.  I've
fixed it and the same test results work both on mips and x86, so I don't
think this is hardware floating point rounding error.


>
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> If you drop bombs on a foreign country and kill a hundred thousand
>> innocent people, expect your government to call the consequence
>> "unprovoked inhuman terrorist attacks" and use it to justify dropping
>> more bombs and killing more people. The technology changed, the idea is

Re: [FFmpeg-devel] [PATCH 2/3] libswscale: add output support for AV_PIX_FMT_GBRAPF32

2020-05-03 Thread Carl Eugen Hoyos
Am So., 3. Mai 2020 um 11:08 Uhr schrieb Mark Reid :

> lt appears the mips test where only failing on the alpha channel formats.
> it seems to because of a planefill function I missed implementing.  I've
> fixed it and the same test results work both on mips and x86, so I don't
> think this is hardware floating point rounding error.

It sounds very unlikely that you can do a bitexact test to compare the
output of floating point operations.
This could only work if you are using soft-float algorithms but I assume
that there would be  a performance penalty.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/wmv2dsp: fix wrong macro for init_mips

2020-05-03 Thread Rosen Penev
ff_wmv2dsp_init_mips is a void function that only does anything for
HAVE_MMI, which is 64-bit specific.

Signed-off-by: Rosen Penev 
---
 libavcodec/wmv2dsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/wmv2dsp.c b/libavcodec/wmv2dsp.c
index 543f01b852..611bc04eeb 100644
--- a/libavcodec/wmv2dsp.c
+++ b/libavcodec/wmv2dsp.c
@@ -263,6 +263,6 @@ av_cold void ff_wmv2dsp_init(WMV2DSPContext *c)
 c->put_mspel_pixels_tab[6] = put_mspel8_mc22_c;
 c->put_mspel_pixels_tab[7] = put_mspel8_mc32_c;
 
-if (ARCH_MIPS)
+if (ARCH_MIPS64)
 ff_wmv2dsp_init_mips(c);
 }
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH]lavfi/signature: Fix a cast of a function pointer

2020-05-03 Thread Carl Eugen Hoyos
Am Fr., 1. Mai 2020 um 23:57 Uhr schrieb Carl Eugen Hoyos :

> Attached patch fixes an ugly warning when compiling with -Wpedantic.
> I am not in favour of adding casts to silence such warnings, but there
> already is an incorrect cast.

Will push if there are no comments.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/matroskadec: Free right buffer on error

2020-05-03 Thread Andreas Rheinhardt
Since commit 979b5b89594c7628bd846c63198cb64ef9d81d16, reverting the
Matroska ContentCompression is no longer done inside
matroska_parse_frame() (the function that creates AVPackets out of the
parsed data (unless we are dealing with certain codecs that need special
handling)), but instead in matroska_parse_block(). As a consequence,
the data that matroska_parse_frame() receives is no longer always owned
by an AVBuffer; it is owned by an AVBuffer iff no ContentCompression needed
to be reversed; otherwise the data is independently allocated and needs
to be freed on error.

Whether the data is owned by an AVBuffer or not is indicated by a variable
buf of type AVBufferRef *: If it is NULL, the data is independently
allocated, if not it is owned by the underlying AVBuffer (and is used to
avoid copying the data when creating the AVPackets).

Because the allocation of the buffer holding the uncompressed data happens
outside of matroska_parse_frame() (if a ContentCompression needs to be
reversed), the data is passed as uint8_t ** in order to not leave any
dangling pointers behind in matroska_parse_block() should the data need to
be freed: In case of errors, said uint8_t ** would be av_freep()'ed in
case buf indicated the data to be independently allocated.

Yet there is a problem with this: Some codecs (namely WavPack and
ProRes) need special handling: Their packets are only stored in
Matroska in a stripped form to save space and the demuxer reconstructs
full packets. This involved allocating a new, enlarged buffer. And if
an error happens when trying to wrap this new buffer into an AVBuffer,
this buffer needs to be freed; yet instead the given uint8_t ** (holding
the uncompressed, yet still stripped form of the data) would be freed
(av_freep()'ed) which certainly leads to a memleak of the new buffer;
even worse, in case the track does not use ContentCompression the given
uint8_t ** must not be freed as the actual data is owned by an AVBuffer
and the data given to matroska_parse_frame() is not the start of the
actual allocated buffer at all.

Both of these issues are fixed by always freeing the current data in
case it is independently allocated. Furthermore, while it would be
possible to track whether the pointer from matroska_parse_block() needs
to be reset or not, there is no gain in doing so, as the pointer is not
used at all afterwards and the sematics are clear: If the data passed
to matroska_parse_frame() is independently allocated, then ownership
of the data passes to matroska_parse_frame(). So don't pass the data
via uint8_t **.

Fixes Coverity ID 1462661 (the issue as described by Coverity is btw
a false positive: It thinks that this error can be triggered by ProRes
with a size of zero after reconstructing the original packets, but the
reconstructed packets can't have a size of zero).

Signed-off-by: Andreas Rheinhardt 
---
Sorry for this. Will push this soon if no one objects. I would really
appreciate another pair of eyes looking over this.

Coverity ID 610554 is btw a false positive stemming from Coverity not
knowing that the packet data is always owned by an AVBuffer when
ContentCompression is not in use.

 libavformat/matroskadec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 917c106258..24104837a5 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3414,13 +3414,13 @@ static int matroska_parse_webvtt(MatroskaDemuxContext 
*matroska,
 
 static int matroska_parse_frame(MatroskaDemuxContext *matroska,
 MatroskaTrack *track, AVStream *st,
-AVBufferRef *buf, uint8_t **data, int pkt_size,
+AVBufferRef *buf, uint8_t *data, int pkt_size,
 uint64_t timecode, uint64_t lace_duration,
 int64_t pos, int is_keyframe,
 uint8_t *additional, uint64_t additional_id, 
int additional_size,
 int64_t discard_padding)
 {
-uint8_t *pkt_data = *data;
+uint8_t *pkt_data = data;
 int res = 0;
 AVPacket pktl, *pkt = &pktl;
 
@@ -3432,7 +3432,7 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 goto fail;
 }
 if (!buf)
-av_freep(data);
+av_free(data);
 buf = NULL;
 }
 
@@ -3445,7 +3445,7 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 goto fail;
 }
 if (!buf)
-av_freep(data);
+av_free(data);
 buf = NULL;
 }
 
@@ -3525,7 +3525,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 no_output:
 fail:
 if (!buf)
-av_freep(data);
+av_free(pkt_data);
 return res;
 }
 
@@ -3659,7 +3659,7 @@ static int matroska_parse_block(MatroskaDemuxContext 
*matroska, AVBufferRef *buf
 if (res)
 ret

Re: [FFmpeg-devel] [PATCH v3] libavformat/flacdec: Workaround for truncated metadata picture size

2020-05-03 Thread Mattias Wadman
Sorry for nagging, something left to fix?

On Mon, Apr 27, 2020 at 10:10 AM Mattias Wadman
 wrote:
>
> Hi again, looks ok?
>
> On Fri, Apr 24, 2020 at 12:54 PM Mattias Wadman
>  wrote:
> >
> > lavf flacenc could previously write truncated metadata picture size if
> > the picture data did not fit in 24 bits. Detect this by truncting the
> > size found inside the picture block and if it matches the block size
> > use it and read rest of picture data.
> >
> > Also only enable this workaround flac files and not ogg files with flac
> > METADATA_BLOCK_PICTURE comment.
> >
> > flacenc was fixed in e447a4d112bcfee10126c54eb4481fa8712957c8
> > before the fix a broken flac for reproduction could be generated with:
> > ffmpeg -f lavfi -i sine -f lavfi -i color=red:size=2400x2400 -map 0:0 -map 
> > 1:0 -c:v:0 bmp -disposition:1 attached_pic -t 1 test.flac
> >
> > Fixes ticket 6333
> > ---
> >  libavformat/flac_picture.c   | 35 +++
> >  libavformat/flac_picture.h   |  2 +-
> >  libavformat/flacdec.c|  2 +-
> >  libavformat/oggparsevorbis.c |  2 +-
> >  4 files changed, 30 insertions(+), 11 deletions(-)
> >
> > diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
> > index 81ddf80465..61277e9dee 100644
> > --- a/libavformat/flac_picture.c
> > +++ b/libavformat/flac_picture.c
> > @@ -27,7 +27,7 @@
> >  #include "id3v2.h"
> >  #include "internal.h"
> >
> > -int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
> > +int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, 
> > int truncate_workaround)
> >  {
> >  const CodecMime *mime = ff_id3v2_mime_tags;
> >  enum AVCodecID id = AV_CODEC_ID_NONE;
> > @@ -36,7 +36,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
> > *buf, int buf_size)
> >  GetByteContext g;
> >  AVStream *st;
> >  int width, height, ret = 0;
> > -unsigned int len, type;
> > +unsigned int type;
> > +uint32_t len, left, trunclen = 0;
> >
> >  if (buf_size < 34) {
> >  av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > @@ -114,16 +115,34 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
> > *buf, int buf_size)
> >
> >  /* picture data */
> >  len = bytestream2_get_be32u(&g);
> > -if (len <= 0 || len > bytestream2_get_bytes_left(&g)) {
> > -av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > -if (s->error_recognition & AV_EF_EXPLODE)
> > -ret = AVERROR_INVALIDDATA;
> > -goto fail;
> > +
> > +left = bytestream2_get_bytes_left(&g);
> > +if (len <= 0 || len > left) {
> > +// Workaround lavf flacenc bug that allowed writing truncated 
> > metadata picture block size if
> > +// picture size did not fit in 24 bits
> > +if (truncate_workaround && len > left && (len & 0xff) == left) 
> > {
> > +av_log(s, AV_LOG_INFO, "Correcting truncated metadata picture 
> > size from %d to %d\n", left, len);
> > +trunclen = len - left;
> > +} else {
> > +av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > +if (s->error_recognition & AV_EF_EXPLODE)
> > +ret = AVERROR_INVALIDDATA;
> > +goto fail;
> > +}
> >  }
> >  if (!(data = av_buffer_alloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
> >  RETURN_ERROR(AVERROR(ENOMEM));
> >  }
> > -bytestream2_get_bufferu(&g, data->data, len);
> > +
> > +if (trunclen == 0) {
> > +bytestream2_get_bufferu(&g, data->data, len);
> > +} else {
> > +// If truncation was detect copy all data from block and read 
> > missing bytes
> > +// not included in the block size
> > +bytestream2_get_bufferu(&g, data->data, left);
> > +if (avio_read(s->pb, data->data + len - trunclen, trunclen) < 
> > trunclen)
> > +RETURN_ERROR(AVERROR_INVALIDDATA);
> > +}
> >  memset(data->data + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> >
> >  if (AV_RB64(data->data) == PNGSIG)
> > diff --git a/libavformat/flac_picture.h b/libavformat/flac_picture.h
> > index 4374b6f4f6..61fd0c8806 100644
> > --- a/libavformat/flac_picture.h
> > +++ b/libavformat/flac_picture.h
> > @@ -26,6 +26,6 @@
> >
> >  #define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
> >
> > -int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size);
> > +int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, 
> > int truncate_workaround);
> >
> >  #endif /* AVFORMAT_FLAC_PICTURE_H */
> > diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
> > index cb516fb1f3..79c05f14bf 100644
> > --- a/libavformat/flacdec.c
> > +++ b/libavformat/flacdec.c
> > @@ -146,7 +146,7 @@ static int flac_read_header(AVFormatContext *s)
> >  }
> >  av_freep(&buffer);
> >  } else if (metadata_type == FLAC

Re: [FFmpeg-devel] [PATCH] lavf/fps: add cmd to force write buf frame

2020-05-03 Thread Paul B Mahol
Missing documentation. Also it is lavfi not lavf.

On 5/3/20, Jai Luthra  wrote:
> Enables writing buffered frames to the outsink using send command api.
>
> This is useful when a lavf user wants to fetch buffered frames without
> closing/reopening the filtergraph again and again.
>
> Signed-off-by: Jai Luthra 
> ---
>  libavfilter/vf_fps.c | 36 +++-
>  1 file changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
> index cf1e36726a..fa856a8f45 100644
> --- a/libavfilter/vf_fps.c
> +++ b/libavfilter/vf_fps.c
> @@ -326,6 +326,23 @@ static int activate(AVFilterContext *ctx)
>  return FFERROR_NOT_READY;
>  }
>
> +static int process_command(AVFilterContext *ctx, const char *cmd, const
> char *args,
> +   char *res, int res_len, int flags)
> +{
> +FPSContext *s = ctx->priv;
> +int ret, again = 0;
> +
> +if (!strcmp(cmd, "force_write")) {
> +AVFilterLink *outlink = ctx->outputs[0];
> +ret = write_frame(ctx, s, outlink, &again);
> +if (again)
> +ff_filter_set_ready(ctx, 100);
> +} else
> +ret = AVERROR(ENOSYS);
> +
> +return ret;
> +}
> +
>  static const AVFilterPad avfilter_vf_fps_inputs[] = {
>  {
>  .name = "default",
> @@ -344,13 +361,14 @@ static const AVFilterPad avfilter_vf_fps_outputs[] = {
>  };
>
>  AVFilter ff_vf_fps = {
> -.name= "fps",
> -.description = NULL_IF_CONFIG_SMALL("Force constant framerate."),
> -.init= init,
> -.uninit  = uninit,
> -.priv_size   = sizeof(FPSContext),
> -.priv_class  = &fps_class,
> -.activate= activate,
> -.inputs  = avfilter_vf_fps_inputs,
> -.outputs = avfilter_vf_fps_outputs,
> +.name= "fps",
> +.description = NULL_IF_CONFIG_SMALL("Force constant framerate."),
> +.init= init,
> +.uninit  = uninit,
> +.priv_size   = sizeof(FPSContext),
> +.priv_class  = &fps_class,
> +.activate= activate,
> +.inputs  = avfilter_vf_fps_inputs,
> +.outputs = avfilter_vf_fps_outputs,
> +.process_command = process_command,
>  };
> --
> 2.26.2
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 2/4] avcodec/prores_metadata_bsf: add smpte2084 format support

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 10:01:31AM +0200, Marton Balint wrote:
> 
> 
> On Fri, 15 Nov 2019, Limin Wang wrote:
> 
> > 
> > ping, the patchset is for HDR/HLG color support for prores.
> > 
> > On Mon, Nov 04, 2019 at 07:10:00PM +0800, lance.lmw...@gmail.com wrote:
> > > From: Limin Wang 
> > > 
> > > It's based on the following specs:
> > > RDD 36:2015 - SMPTE Registered Disclosure Doc - Apple ProRes Bitstream 
> > > Syntax and Decoding Process
> > > 
> > > Signed-off-by: Limin Wang 
> > > ---
> > >  doc/bitstream_filters.texi   | 2 ++
> > >  libavcodec/prores_metadata_bsf.c | 3 ++-
> > >  2 files changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> > > index 8fe5b3ad75..e2de4fd4ed 100644
> > > --- a/doc/bitstream_filters.texi
> > > +++ b/doc/bitstream_filters.texi
> > > @@ -589,6 +589,8 @@ Keep the same transfer characteristics property 
> > > (default).
> > >  @item unknown
> > >  @item bt709
> > >  BT 601, BT 709, BT 2020
> > > +@item smpte2084
> > > +SMPTE ST 2084
> > >  @end table
> > > 
> > > 
> > > diff --git a/libavcodec/prores_metadata_bsf.c 
> > > b/libavcodec/prores_metadata_bsf.c
> > > index 0510d3520a..24615e9305 100644
> > > --- a/libavcodec/prores_metadata_bsf.c
> > > +++ b/libavcodec/prores_metadata_bsf.c
> > > @@ -140,10 +140,11 @@ static const AVOption options[] = {
> > >  {"smpte431",NULL,  0, AV_OPT_TYPE_CONST, 
> > > {.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, FLAGS, 
> > > "color_primaries"},
> > >  {"smpte432",NULL,  0, AV_OPT_TYPE_CONST, 
> > > {.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, FLAGS, 
> > > "color_primaries"},
> > > 
> > > -{"color_trc", "select color transfer", 
> > > OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, {.i64=-1}, -1, 
> > > AVCOL_TRC_BT709, FLAGS, "color_trc"},
> > > +{"color_trc", "select color transfer", 
> > > OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, {.i64=-1}, -1, 
> > > AVCOL_TRC_NB, FLAGS, "color_trc"},
> 
> NB-1.
> 
> > >  {"auto", "keep the same color transfer",  0, AV_OPT_TYPE_CONST, 
> > > {.i64=-1},   INT_MIN, INT_MAX, FLAGS, 
> > > "color_trc"},
> > >  {"unknown",NULL,  0, AV_OPT_TYPE_CONST, 
> > > {.i64=0},INT_MIN, INT_MAX, FLAGS, 
> > > "color_trc"},
> > >  {"bt709",  NULL,  0, AV_OPT_TYPE_CONST, 
> > > {.i64=AVCOL_TRC_BT709},  INT_MIN, INT_MAX, FLAGS, 
> > > "color_trc"},
> > > +{"smpte2084",  NULL,  0, AV_OPT_TYPE_CONST, 
> > > {.i64=AVCOL_TRC_SMPTE2084},  INT_MIN, INT_MAX, FLAGS, 
> > > "color_trc"},
> > > 
> > >  {"colorspace", "select colorspace", OFFSET(matrix_coefficients), 
> > > AV_OPT_TYPE_INT, {.i64=-1}, -1,  AVCOL_SPC_BT2020_NCL, FLAGS, 
> > > "colorspace"},
> > >  {"auto", "keep the same colorspace",  0, AV_OPT_TYPE_CONST, 
> > > {.i64=-1},INT_MIN, INT_MAX, FLAGS, 
> > > "colorspace"},
> 
> Yet again, please, do not apply patches which have not been LGTM-ed and you
> have not pinged them recently.
Sorry, I think I have ping before. Next time I'll try to ping again for the old 
patches
or resubmit.

> 
> Thanks,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avfilter/vf_subtitles: remove unneeded ifdef

2020-05-03 Thread lance . lmwang
On Mon, Mar 30, 2020 at 06:52:32PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavfilter/vf_subtitles.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> index a3b4029af4..2f312b0ba8 100644
> --- a/libavfilter/vf_subtitles.c
> +++ b/libavfilter/vf_subtitles.c
> @@ -30,10 +30,8 @@
>  #include 
>  
>  #include "config.h"
> -#if CONFIG_SUBTITLES_FILTER
> -# include "libavcodec/avcodec.h"
> -# include "libavformat/avformat.h"
> -#endif
> +#include "libavcodec/avcodec.h"
> +#include "libavformat/avformat.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/imgutils.h"
>  #include "libavutil/opt.h"
> -- 
> 2.21.0
> 

ping 

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avfilter/src_movie: Fix the loop function of dynamic logo

2020-05-03 Thread lance . lmwang
On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> The following command will attempt to create the input and overlay test 
> sequence for you.
> ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> 
> Please try with below command and compare the final output.
> ./ffmpeg -y -filter_complex 
> "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>  enable='between(t,0,25)" test.mkv
> 
>  Without the patch applied, the overlay will repeat the last frame in 
> overlay.mkv after the first loop.
> 
> Signed-off-by: Limin Wang 
> ---
>  libavfilter/src_movie.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> index 79423a8..2327046 100644
> --- a/libavfilter/src_movie.c
> +++ b/libavfilter/src_movie.c
> @@ -68,6 +68,8 @@ typedef struct MovieContext {
>  int loop_count;
>  int64_t discontinuity_threshold;
>  int64_t ts_offset;
> +int64_t last_pts;
> +int64_t last_loop_pts;
>  
>  AVFormatContext *format_ctx;
>  int eof;
> @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>  movie->st[i].done = 0;
>  }
>  movie->eof = 0;
> +movie->last_loop_pts = movie->last_pts;
>  return 0;
>  }
>  
> @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, 
> unsigned out_id)
>  if (frame->pts != AV_NOPTS_VALUE) {
>  if (movie->ts_offset)
>  frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, 
> outlink->time_base, AV_ROUND_UP);
> +if (movie->last_loop_pts)
> +frame->pts += movie->last_loop_pts;
>  if (st->discontinuity_threshold) {
>  if (st->last_pts != AV_NOPTS_VALUE) {
>  int64_t diff = frame->pts - st->last_pts;
> @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, 
> unsigned out_id)
>  }
>  }
>  }
> +movie->last_pts =
>  st->last_pts = frame->pts;
>  }
>  ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> -- 
> 2.9.5
> 

ping

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avcodec/utils: use av_rescale()

2020-05-03 Thread lance . lmwang
On Mon, Apr 20, 2020 at 07:00:55PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavcodec/utils.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 26c038dfd9..005d596dfd 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2229,8 +2229,8 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
>  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
>  bits_per_coded_sample = av_get_bits_per_pixel(desc);
>  }
> -bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
> -  framerate.num / framerate.den;
> +bitrate = av_rescale(avctx->width * avctx->height,
> +bits_per_coded_sample * framerate.num, framerate.den);
>  
>  return bitrate;
>  }
> -- 
> 2.21.0
> 

ping the patchset.

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avcodec/h264_metadata_bsf: add option to delete SEI user data

2020-05-03 Thread lance . lmwang
On Mon, Apr 20, 2020 at 07:01:09PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  doc/bitstream_filters.texi |  3 +++
>  libavcodec/h264_metadata_bsf.c | 19 +++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index 8fe5b3ad75..652eb4620f 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -273,6 +273,9 @@ possibly separated by hyphens, and the string can be 
> anything.
>  For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
>  insert the string ``hello'' associated with the given UUID.
>  
> +@item delete_user_data
> +Deletes all SEI user data messages.
> +
>  @item delete_filler
>  Deletes both filler NAL units and filler SEI messages.
>  
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index d96a50dbf7..8b42faff1b 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -76,6 +76,7 @@ typedef struct H264MetadataContext {
>  int crop_bottom;
>  
>  const char *sei_user_data;
> +int delete_user_data;
>  
>  int delete_filler;
>  
> @@ -361,6 +362,21 @@ static int h264_metadata_filter(AVBSFContext *bsf, 
> AVPacket *pkt)
>  }
>  }
>  
> +if (ctx->delete_user_data) {
> +for (i = au->nb_units - 1; i >= 0; i--) {
> +if (au->units[i].type == H264_NAL_SEI) {
> +H264RawSEI *sei = au->units[i].content;
> +
> +for (j = sei->payload_count - 1; j >= 0; j--) {
> +if (sei->payload[j].payload_type ==
> +H264_SEI_TYPE_USER_DATA_UNREGISTERED)
> +ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> +   &au->units[i], j);
> +}
> +}
> +}
> +}
> +
>  // Only insert the SEI in access units containing SPSs, and also
>  // unconditionally in the first access unit we ever see.
>  if (ctx->sei_user_data && (has_sps || !ctx->done_first_au)) {
> @@ -684,6 +700,9 @@ static const AVOption h264_metadata_options[] = {
>  { "sei_user_data", "Insert SEI user data (UUID+string)",
>  OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = 
> FLAGS },
>  
> +{ "delete_user_data", "Delete all SEI user data",
> +OFFSET(delete_user_data), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, 
> FLAGS},
> +
>  { "delete_filler", "Delete all filler (both NAL and SEI)",
>  OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS},
>  
> -- 
> 2.21.0

ping

> 

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avcodec/utils: use av_rescale()

2020-05-03 Thread Andreas Rheinhardt
lance.lmw...@gmail.com:
> On Mon, Apr 20, 2020 at 07:00:55PM +0800, lance.lmw...@gmail.com wrote:
>> From: Limin Wang 
>>
>> Signed-off-by: Limin Wang 
>> ---
>>  libavcodec/utils.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>> index 26c038dfd9..005d596dfd 100644
>> --- a/libavcodec/utils.c
>> +++ b/libavcodec/utils.c
>> @@ -2229,8 +2229,8 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
>>  const AVPixFmtDescriptor *desc = 
>> av_pix_fmt_desc_get(avctx->pix_fmt);
>>  bits_per_coded_sample = av_get_bits_per_pixel(desc);
>>  }
>> -bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height 
>> *
>> -  framerate.num / framerate.den;
>> +bitrate = av_rescale(avctx->width * avctx->height,
>> +bits_per_coded_sample * framerate.num, framerate.den);

Is this supposed to be a cosmetic patch or do you have a testcase where
it leads to better results? Anyway, bits_per_coded_sample *
framerate.num might overflow (the function parameter is 64bit, but the
calculation will nevertheless be performed as int * int).
(I am not saying that the overflow checks for the code as-is are
perfect, as I don't know what checks have already been performed to make
sure that the calculation doesn't overflow an int64_t; but you would add
a new possibility for overflow.)

And your indentation is off: the second line (i.e.
bits_per_coded_sample) should be aligned with the first function
parameter in the first line (i.e. avctx->width).

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 4/4] avcodec/proresenc_anatoliy: support for more color matrix for proresenc

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 09:53:09AM +0200, Marton Balint wrote:
> 
> 
> On Tue, 5 Nov 2019, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Please tested with below command:
> > ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries 
> > bt2020 -colorspace bt2020_ncl -color_trc smpte2084 -an output.mov
> > 
> > mediainfo outout.mov
> > ...
> > Color primaries  : BT.2020
> > Transfer characteristics : PQ
> > Matrix coefficients  : BT.2020 non-constant
> > 
> > ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries 
> > bt2020 -colorspace bt2020_ncl -color_trc arib-std-b67 -an output.mov
> > mediainfo outout.mov
> > ...
> > Color primaries  : BT.2020
> > Transfer characteristics : HLG
> > Matrix coefficients  : BT.2020 non-constant
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavcodec/proresenc_anatoliy.c | 9 +
> > 1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libavcodec/proresenc_anatoliy.c 
> > b/libavcodec/proresenc_anatoliy.c
> > index 0fc79fc1de..81365c528c 100644
> > --- a/libavcodec/proresenc_anatoliy.c
> > +++ b/libavcodec/proresenc_anatoliy.c
> > @@ -55,7 +55,8 @@ static const int bitrate_table[6]  = { 1000, 2100, 3500, 
> > 5400, 7000, 1};
> > 
> > static const int valid_primaries[9]  = { AVCOL_PRI_RESERVED0, 
> > AVCOL_PRI_BT709, AVCOL_PRI_UNSPECIFIED, AVCOL_PRI_BT470BG,
> >  AVCOL_PRI_SMPTE170M, 
> > AVCOL_PRI_BT2020, AVCOL_PRI_SMPTE431, AVCOL_PRI_SMPTE432,INT_MAX };
> > -static const int valid_trc[4]= { AVCOL_TRC_RESERVED0, 
> > AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, INT_MAX };
> > +static const int valid_trc[6]= { AVCOL_TRC_RESERVED0, 
> > AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, AVCOL_TRC_SMPTE2084,
> > + AVCOL_TRC_ARIB_STD_B67, INT_MAX };
> > static const int valid_colorspace[5] = { AVCOL_SPC_BT709, 
> > AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_SMPTE170M,
> >  AVCOL_SPC_BT2020_NCL, INT_MAX };
> > 
> > @@ -757,9 +758,9 @@ static int prores_encode_frame(AVCodecContext *avctx, 
> > AVPacket *pkt,
> > *buf++ = frame_flags;
> > *buf++ = 0; /* reserved */
> > /* only write color properties, if valid value. set to unspecified 
> > otherwise */
> > -*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
> > pict->color_primaries, valid_primaries, 0);
> > -*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
> > pict->color_trc, valid_trc, 0);
> > -*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
> > pict->colorspace, valid_colorspace, 0);
> > +*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
> > avctx->color_primaries, valid_primaries, 0);
> > +*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
> > avctx->color_trc, valid_trc, 0);
> > +*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
> > avctx->colorspace, valid_colorspace, 0);
> > if (avctx->profile >= FF_PROFILE_PRORES_) {
> > if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
> > *buf++ = 0xA0;/* src b64a and no alpha */
> 
> Please revert this, using codec context instead of frame does not seem
> right. Also have you pinged this before applying?

Before revert it, I'm glad to know why use frame instead of avctx, by my 
testing command, it'll failed to get expected result
without change to use avctx? also, most of encoder like mepg2, nvenc, vaapi, 
videotoolboxenc are using avctx context, what's
the rule for that?

> 
> Thanks,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avcodec/utils: use av_rescale()

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 03:10:09PM +0200, Andreas Rheinhardt wrote:
> lance.lmw...@gmail.com:
> > On Mon, Apr 20, 2020 at 07:00:55PM +0800, lance.lmw...@gmail.com wrote:
> >> From: Limin Wang 
> >>
> >> Signed-off-by: Limin Wang 
> >> ---
> >>  libavcodec/utils.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> >> index 26c038dfd9..005d596dfd 100644
> >> --- a/libavcodec/utils.c
> >> +++ b/libavcodec/utils.c
> >> @@ -2229,8 +2229,8 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
> >>  const AVPixFmtDescriptor *desc = 
> >> av_pix_fmt_desc_get(avctx->pix_fmt);
> >>  bits_per_coded_sample = av_get_bits_per_pixel(desc);
> >>  }
> >> -bitrate = (int64_t)bits_per_coded_sample * avctx->width * 
> >> avctx->height *
> >> -  framerate.num / framerate.den;
> >> +bitrate = av_rescale(avctx->width * avctx->height,
> >> +bits_per_coded_sample * framerate.num, framerate.den);
> 
> Is this supposed to be a cosmetic patch or do you have a testcase where
> it leads to better results? Anyway, bits_per_coded_sample *
> framerate.num might overflow (the function parameter is 64bit, but the
> calculation will nevertheless be performed as int * int).
> (I am not saying that the overflow checks for the code as-is are
> perfect, as I don't know what checks have already been performed to make
> sure that the calculation doesn't overflow an int64_t; but you would add
> a new possibility for overflow.)
> 
> And your indentation is off: the second line (i.e.
> bits_per_coded_sample) should be aligned with the first function
> parameter in the first line (i.e. avctx->width).

Sorry, my mistake, I ping another patch in fact. please ignore the patch.


> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/vividas: simplify, use av_rescale_q() instead

2020-05-03 Thread lance . lmwang
On Tue, Apr 28, 2020 at 11:49:16AM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> note it'll cause a small difference in accuracy for the pts, please see the 
> testing result below:
>  $ wget 
> http://samples.ffmpeg.org/archive/all/unknown+unknown+unknown+unknown+5029_paramount_en_1250.viv
>  $ ./ffmpeg -t 0.04 -i 
> ./unknown+unknown+unknown+unknown+5029_paramount_en_1250.viv -f null -
>  old:
>  pts: 522
>  pts: 1044
>  pts: 1567
>  pts: 3918
>  pts: 8097
>  pts: 12277
>  pts: 16457
>  ...
> 
>  new:
>  pts: 522
>  pts: 1045
>  pts: 1567
>  pts: 3918
>  pts: 8098
>  pts: 12278
>  pts: 16457
>  ...
> 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/vividas.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/vividas.c b/libavformat/vividas.c
> index 4f54a4302e..b0f9f35ac2 100644
> --- a/libavformat/vividas.c
> +++ b/libavformat/vividas.c
> @@ -646,7 +646,7 @@ static int viv_read_packet(AVFormatContext *s,
>  pkt->stream_index = 1;
>  astream = s->streams[pkt->stream_index];
>  
> -pkt->pts = av_rescale(viv->audio_sample, astream->time_base.den, 
> astream->time_base.num) / astream->codecpar->sample_rate;
> +pkt->pts = av_rescale_q(viv->audio_sample, av_make_q(1, 
> astream->codecpar->sample_rate), astream->time_base);
>  viv->audio_sample += 
> viv->audio_subpackets[viv->current_audio_subpacket].pcm_bytes / 2 / 
> astream->codecpar->channels;
>  pkt->flags |= AV_PKT_FLAG_KEY;
>  viv->current_audio_subpacket++;

ping the patchset.

> -- 
> 2.21.0
> 

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 2/3] avutil/avstring: add support for '\\' seperator for the path append

2020-05-03 Thread lance . lmwang
On Mon, Jan 13, 2020 at 09:44:50PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> I don't have a windows develoment system yet, so I had to test with modified
> avutil/tests/avstring.c like below,
> (change / to \\) and change HAVE_DOS_PATHS to 1 in config.h:
> -TEST_APPEND_PATH_COMPONENT("path", "/", "path");
> -TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
> -TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
> -TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
> -TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
> -TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", 
> "path/path2/comp/comp2");
> +TEST_APPEND_PATH_COMPONENT("path", "\\", "path");
> +TEST_APPEND_PATH_COMPONENT("path", "comp", "path\\comp");
> +TEST_APPEND_PATH_COMPONENT("path\\", "comp", "path\\comp");
> +TEST_APPEND_PATH_COMPONENT("path", "\\comp", "path\\comp");
> +TEST_APPEND_PATH_COMPONENT("path\\", "\\comp", "path\\comp");
> +TEST_APPEND_PATH_COMPONENT("path\\path2\\", "\\comp\\comp2", 
> "path\\path2\\comp\\comp2");
> 
> Then do test with fate-avstring for valid checking:
> 
> make fate-avstring SAMPLES=../fate-suite
> master:
> -path/comp = path/comp
> -path/comp = path/comp
> -path/comp = path/comp
> -path/comp = path/comp
> -path/path2/comp/comp2 = path/path2/comp/comp2
> +path/comp = path\comp
> +path\/comp = path\comp
> +path/\comp = path\comp
> +path\/\comp = path\comp
> +path\path2\/\comp\comp2 = path\path2\comp\comp2
> 
> Applied the patch:
> -path/comp = path/comp
> -path/comp = path/comp
> -path/comp = path/comp
> -path/comp = path/comp
> -path/path2/comp/comp2 = path/path2/comp/comp2
> +path\comp = path\comp
> +path\comp = path\comp
> +path\comp = path\comp
> +path\comp = path\comp
> +path\path2\comp\comp2 = path\path2\comp\comp2
> 
> Signed-off-by: Limin Wang 
> ---
>  libavutil/avstring.c | 30 +-
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index f4b8ed2..24bcc7d 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -299,14 +299,20 @@ const char *av_dirname(char *path)
>  return path;
>  }
>  
> +#if HAVE_DOS_PATHS
> +#define SEPARATOR '\\'
> +#else
> +#define SEPARATOR '/'
> +#endif
> +
>  char *av_append_path_component(const char *path, const char *component)
>  {
>  size_t p_len, c_len;
>  char *fullpath;
>  
> -if (!path)
> +if (!path || strlen(path) == 0 )
>  return av_strdup(component);
> -if (!component)
> +if (!component || strlen(component) == 0)
>  return av_strdup(path);
>  
>  p_len = strlen(path);
> @@ -315,18 +321,16 @@ char *av_append_path_component(const char *path, const 
> char *component)
>  return NULL;
>  fullpath = av_malloc(p_len + c_len + 2);
>  if (fullpath) {
> -if (p_len) {
> -av_strlcpy(fullpath, path, p_len + 1);
> -if (c_len) {
> -if (fullpath[p_len - 1] != '/' && component[0] != '/')
> -fullpath[p_len++] = '/';
> -else if (fullpath[p_len - 1] == '/' && component[0] == '/')
> -p_len--;
> -}
> -}
> -av_strlcpy(&fullpath[p_len], component, c_len + 1);
> -fullpath[p_len + c_len] = 0;
> +const char *component1 = component;
> +
> +av_strlcpy(fullpath, path, p_len + 1);
> +if (fullpath[p_len - 1] != SEPARATOR)
> +fullpath[p_len++] = SEPARATOR;
> +if (*component1 == SEPARATOR)
> +component1++;
> +av_strlcpy(fullpath + p_len, component1, strlen(component1) + 1);
>  }
> +
>  return fullpath;
>  }
>  
> -- 
> 2.9.5
> 

ping

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v11] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-05-03 Thread Michael Niedermayer
On Fri, May 01, 2020 at 12:55:18AM +, Zane van Iperen wrote:
> On Fri, 01 May 2020 00:36:57 +
> "Zane van Iperen"  wrote:
> 
> > On Fri, 1 May 2020 01:09:17 +0200
> > "Michael Niedermayer"  wrote:
> > 
> > > > +size = FFMIN(trk->data_size - ctx->bytes_read,
> > > > PP_BNK_MAX_READ_SIZE); +
> > > > +if ((ret = av_get_packet(s->pb, pkt, size)) < 0)
> > > > +return ret;
> > > > +
> > > > +ctx->bytes_read+= ret;
> > > > +pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
> > > > +pkt->stream_index   = ctx->current_track;
> > > > +pkt->duration   = ret * 2;  
> > >
> > > With this each stream would be returned completely before the next
> > > such non interleaved output is a bit odd.
> > >  
> > 
> > Yep, it's an odd format.  Some files are meant to be stereo, but I
> > can't present them as such. I have to present them as separate mono
> > streams and merge them with a filter.
> > 
> > > also where can i find such a file ?
> > >  
> > 
> > Here's a file I trimmed for FATE:
> > 
> > https://0x0.st/ie7O.11c
> > 
> Probably should have mentioned that first file is meant to be stereo
> music.
> 
> Here's one that's meant to be just a bunch of mono tracks:
> https://0x0.st/ie74.5C

just tried, and as expected this doesnt work

./ffmpeg -i pinball/ie74.5C -map 0 test.nut
...
Press [q] to stop, [?] for help
Too many packets buffered for output stream 0:1.
[libvorbis @ 0x557f49f3da40] 16 frames left in the queue on closing
[libvorbis @ 0x557f49f3f340] 14 frames left in the queue on closing
Conversion failed!


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

You can kill me, but you cannot change the truth.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 1/2] avfilter/vf_subtitles: remove unneeded ifdef

2020-05-03 Thread Andreas Rheinhardt
lance.lmw...@gmail.com:
> On Mon, Mar 30, 2020 at 06:52:32PM +0800, lance.lmw...@gmail.com wrote:
>> From: Limin Wang 
>>
>> Signed-off-by: Limin Wang 
>> ---
>>  libavfilter/vf_subtitles.c | 6 ++
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
>> index a3b4029af4..2f312b0ba8 100644
>> --- a/libavfilter/vf_subtitles.c
>> +++ b/libavfilter/vf_subtitles.c
>> @@ -30,10 +30,8 @@
>>  #include 
>>  
>>  #include "config.h"
>> -#if CONFIG_SUBTITLES_FILTER
>> -# include "libavcodec/avcodec.h"
>> -# include "libavformat/avformat.h"
>> -#endif
>> +#include "libavcodec/avcodec.h"
>> +#include "libavformat/avformat.h"
>>  #include "libavutil/avstring.h"
>>  #include "libavutil/imgutils.h"
>>  #include "libavutil/opt.h"
>> -- 
>> 2.21.0
>>
> 
> ping 
> 
Why is this supposed to be unneeded? This file contains two filters: The
subtitles and the ass filter, so it is possible for this file to be
compiled if the subtitles filter is disabled.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v11] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-05-03 Thread Zane van Iperen
On Sun, 3 May 2020 15:23:19 +0200
"Michael Niedermayer"  wrote:

> On Fri, May 01, 2020 at 12:55:18AM +, Zane van Iperen wrote:
> > On Fri, 01 May 2020 00:36:57 +
> > "Zane van Iperen"  wrote:
> >  
> > > On Fri, 1 May 2020 01:09:17 +0200
> > > "Michael Niedermayer"  wrote:
> > >  
> > > > > +size = FFMIN(trk->data_size - ctx->bytes_read,
> > > > > PP_BNK_MAX_READ_SIZE); +
> > > > > +if ((ret = av_get_packet(s->pb, pkt, size)) < 0)
> > > > > +return ret;
> > > > > +
> > > > > +ctx->bytes_read+= ret;
> > > > > +pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
> > > > > +pkt->stream_index   = ctx->current_track;
> > > > > +pkt->duration   = ret * 2;  
> > > >
> > > > With this each stream would be returned completely before the
> > > > next such non interleaved output is a bit odd.
> > > >  
> > >
> > > Yep, it's an odd format.  Some files are meant to be stereo, but I
> > > can't present them as such. I have to present them as separate
> > > mono streams and merge them with a filter.
> > >  
> > > > also where can i find such a file ?
> > > >  
> > >
> > > Here's a file I trimmed for FATE:
> > >
> > > https://0x0.st/ie7O.11c
> > >  
> > Probably should have mentioned that first file is meant to be stereo
> > music.
> >
> > Here's one that's meant to be just a bunch of mono tracks:
> > https://0x0.st/ie74.5C  
> 
> just tried, and as expected this doesnt work
> 
> ./ffmpeg -i pinball/ie74.5C -map 0 test.nut
> ...
> Press [q] to stop, [?] for help
> Too many packets buffered for output stream 0:1.
> [libvorbis @ 0x557f49f3da40] 16 frames left in the queue on closing
> [libvorbis @ 0x557f49f3f340] 14 frames left in the queue on closing
> Conversion failed!
> 

Interesting... that worked for me :/

./ffmpeg -y -i pp/ie74.5C -map 0 test.nut
...
[nut @ 0x55615988d700] Multiple keyframes with same PTS
Last message repeated 5 times
size= 632kB time=00:00:06.37 bitrate= 812.2kbits/s speed=59.8x
video:0kB audio:630kB subtitle:0kB other streams:0kB global headers:0kB muxing 
overhead: 0.366753%


This isn't a valid use case for this file format regardless, as they're 
soundbanks.
Each stream should be split into a separate file, and it's almost guaranteed 
that they're all different lengths.

If this is required, then I'm not sure of the best course of action is.
Unless I constantly seek back and forth in the file, but that seems messy...

Zane

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread James Almer
On 4/30/2020 6:50 PM, James Almer wrote:
> Fixes ticket #8622
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/cbs_h2645.c|  1 +
>  libavcodec/cbs_h265.h |  1 +
>  libavcodec/cbs_h265_syntax_template.c | 85 +--
>  3 files changed, 70 insertions(+), 17 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 095e449ddc..b432921ecc 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -553,6 +553,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload 
> *payload)
>  av_buffer_unref(&payload->payload.other.data_ref);
>  break;
>  }
> +av_buffer_unref(&payload->extension_data.data_ref);
>  }
>  
>  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
> diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
> index 2c1e153ad9..73897f77a4 100644
> --- a/libavcodec/cbs_h265.h
> +++ b/libavcodec/cbs_h265.h
> @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
>  AVBufferRef *data_ref;
>  } other;
>  } payload;
> +H265RawExtensionData extension_data;
>  } H265RawSEIPayload;
>  
>  typedef struct H265RawSEI {
> diff --git a/libavcodec/cbs_h265_syntax_template.c 
> b/libavcodec/cbs_h265_syntax_template.c
> index ed08b06e9c..d3ac618db6 100644
> --- a/libavcodec/cbs_h265_syntax_template.c
> +++ b/libavcodec/cbs_h265_syntax_template.c
> @@ -1564,7 +1564,8 @@ static int 
> FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
>  
>  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext 
> *rw,
>H265RawSEIBufferingPeriod *current,
> -  uint32_t *payload_size)
> +  uint32_t *payload_size,
> +  int *more_data)
>  {
>  CodedBitstreamH265Context *h265 = ctx->priv_data;
>  const H265RawSPS *sps;
> @@ -1658,8 +1659,15 @@ static int 
> FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
>  else
>  infer(use_alt_cpb_params_flag, 0);
>  #else
> -if (current->use_alt_cpb_params_flag)
> +// If unknown extension data exists, then use_alt_cpb_params_flag is
> +// coded in the bitstream and must be written even if it's 0.
> +if (current->use_alt_cpb_params_flag || *more_data) {
>  flag(use_alt_cpb_params_flag);
> +// Ensure this bit is not the last in the payload by making the
> +// more_data_in_payload() check evaluate to true, so it may not
> +// be mistaken as something else by decoders.
> +*more_data = 1;
> +}
>  #endif
>  
>  return 0;
> @@ -2057,11 +2065,48 @@ static int 
> FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
>  return 0;
>  }
>  
> +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext *rw,
> +   H265RawExtensionData *current, uint32_t 
> payload_size,
> +   int cur_pos)
> +{
> +int err;
> +size_t byte_length, k;
> +
> +#ifdef READ
> +GetBitContext tmp;
> +int bits_left, payload_zero_bits;
> +
> +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
> +return 0;
> +
> +bits_left = 8 * payload_size - cur_pos;
> +tmp = *rw;
> +if (bits_left > 8)
> +skip_bits_long(&tmp, bits_left - 8);
> +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
> +if (!payload_zero_bits)
> +return AVERROR_INVALIDDATA;
> +payload_zero_bits = ff_ctz(payload_zero_bits);
> +current->bit_length = bits_left - payload_zero_bits - 1;
> +allocate(current->data, (current->bit_length + 7) / 8);
> +#endif
> +
> +byte_length = (current->bit_length + 7) / 8;
> +for (k = 0; k < byte_length; k++) {
> +int length = FFMIN(current->bit_length - k * 8, 8);
> +xu(length, reserved_payload_extension_data, current->data[k],
> +   0, MAX_UINT_BITS(length), 0);
> +}
> +
> +return 0;
> +}
> +
>  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>   H265RawSEIPayload *current, int prefix)
>  {
>  int err, i;
> -int start_position, end_position;
> +int start_position, current_position;
> +int more_data = !!current->extension_data.bit_length;
>  
>  #ifdef READ
>  start_position = get_bits_count(rw);
> @@ -2093,8 +2138,15 @@ static int FUNC(sei_payload)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
>   ¤t->payload_size)); \
>  break
> +#define SEI_TYPE_E(type, prefix_valid, suffix_valid, name) \
> +case HEVC_SEI_TYPE_ ## type: \
> +SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid); \
> +CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
> + ¤t->payloa

Re: [FFmpeg-devel] [PATCH v1 1/2] avfilter/vf_subtitles: remove unneeded ifdef

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 03:35:19PM +0200, Andreas Rheinhardt wrote:
> lance.lmw...@gmail.com:
> > On Mon, Mar 30, 2020 at 06:52:32PM +0800, lance.lmw...@gmail.com wrote:
> >> From: Limin Wang 
> >>
> >> Signed-off-by: Limin Wang 
> >> ---
> >>  libavfilter/vf_subtitles.c | 6 ++
> >>  1 file changed, 2 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> >> index a3b4029af4..2f312b0ba8 100644
> >> --- a/libavfilter/vf_subtitles.c
> >> +++ b/libavfilter/vf_subtitles.c
> >> @@ -30,10 +30,8 @@
> >>  #include 
> >>  
> >>  #include "config.h"
> >> -#if CONFIG_SUBTITLES_FILTER
> >> -# include "libavcodec/avcodec.h"
> >> -# include "libavformat/avformat.h"
> >> -#endif
> >> +#include "libavcodec/avcodec.h"
> >> +#include "libavformat/avformat.h"
> >>  #include "libavutil/avstring.h"
> >>  #include "libavutil/imgutils.h"
> >>  #include "libavutil/opt.h"
> >> -- 
> >> 2.21.0
> >>
> > 
> > ping 
> > 
> Why is this supposed to be unneeded? This file contains two filters: The
> subtitles and the ass filter, so it is possible for this file to be
> compiled if the subtitles filter is disabled.

Oh, yes, ass don't need include the header, I haven't tested such condition.
please ignore the patch.

> 
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/3] avcodec/av1_metadata: filter parameter sets in packet side data

2020-05-03 Thread James Almer
On 4/22/2020 9:37 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Extradata included in packet side data is meant to replace the codec context
>> extradata. So when muxing for example to MP4 without this change and if
>> extradata is present in a packet side data, the result will be that the
>> parameter sets present in keyframes will be filtered, but the parameter sets
>> ultimately included in the av1C box will not.
>>
>> This is especially important for AV1 as both currently supported encoders 
>> don't
>> export the Sequence Header in the codec context extradata, but as packet side
>> data instead.
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/av1_metadata_bsf.c | 52 +++
>>  1 file changed, 52 insertions(+)
>>
>> diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
>> index dd0c9b6148..f3161cb286 100644
>> --- a/libavcodec/av1_metadata_bsf.c
>> +++ b/libavcodec/av1_metadata_bsf.c
>> @@ -111,6 +111,54 @@ static int 
>> av1_metadata_update_sequence_header(AVBSFContext *bsf,
>>  return 0;
>>  }
>>  
>> +static int av1_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
>> +{
>> +AV1MetadataContext *ctx = bsf->priv_data;
>> +CodedBitstreamFragment *frag = &ctx->access_unit;
>> +AV1RawOBU *obu;
>> +uint8_t *side_data;
>> +int side_data_size;
>> +int err, i;
>> +
>> +side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
>> +&side_data_size);
>> +if (!side_data_size)
>> +return 0;
>> +
>> +err = ff_cbs_read(ctx->cbc, frag, side_data, side_data_size);
>> +if (err < 0) {
>> +av_log(bsf, AV_LOG_ERROR, "Failed to read extradata from packet 
>> side data.\n");
>> +goto fail;
> 
> You can actually return immediately in this whole function: The fragment
> will be reset in the fail part of av1_metadata_filter().

Changed and pushed, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: Don't require a known device to pass a frames context to an encoder

2020-05-03 Thread Mark Thompson
On 29/04/2020 06:34, Fu, Linjie wrote:
>> From: ffmpeg-devel  On Behalf Of
>> Mark Thompson
>> Sent: Wednesday, April 29, 2020 06:57
>> To: FFmpeg development discussions and patches > de...@ffmpeg.org>
>> Subject: [FFmpeg-devel] [PATCH] ffmpeg: Don't require a known device to
>> pass a frames context to an encoder
>>
>> The previous version here did not handle passing a frames context when
>> ffmpeg itself did not know about the device it came from (for example,
>> because it was created by device derivation inside a filter graph), which
>> would break encoders requiring that input.  Fix that by checking for HW
>> frames and device context methods independently, and prefer to use a
>> frames context method if possible.  At the same time, revert the encoding
>> additions to the device matching function because the additional
>> complexity was not relevant to decoding.
>> ---
>>  fftools/ffmpeg_hw.c | 75 +
>>  1 file changed, 42 insertions(+), 33 deletions(-)
>> diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
>> index c5c8aa97ef..fc4a5d31d6 100644
>> --- a/fftools/ffmpeg_hw.c
>> +++ b/fftools/ffmpeg_hw.c
>> @@ -19,6 +19,7 @@
>>  #include 
>>
>>  #include "libavutil/avstring.h"
>> +#include "libavutil/pixdesc.h"
>>  #include "libavfilter/buffersink.h"
>>
>>  #include "ffmpeg.h"
>> @@ -282,10 +283,7 @@ void hw_device_free_all(void)
>>  nb_hw_devices = 0;
>>  }
>>
>> -static HWDevice *hw_device_match_by_codec(const AVCodec *codec,
>> -  enum AVPixelFormat format,
>> -  int possible_methods,
>> -  int *matched_methods)
>> +static HWDevice *hw_device_match_by_codec(const AVCodec *codec)
>>  {
>>  const AVCodecHWConfig *config;
>>  HWDevice *dev;
>> @@ -294,18 +292,11 @@ static HWDevice
>> *hw_device_match_by_codec(const AVCodec *codec,
>>  config = avcodec_get_hw_config(codec, i);
>>  if (!config)
>>  return NULL;
>> -if (format != AV_PIX_FMT_NONE &&
>> -config->pix_fmt != AV_PIX_FMT_NONE &&
>> -config->pix_fmt != format)
>> -continue;
>> -if (!(config->methods & possible_methods))
>> +if (!(config->methods &
>> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
>>  continue;
>>  dev = hw_device_get_by_type(config->device_type);
>> -if (dev) {
>> -if (matched_methods)
>> -*matched_methods = config->methods & possible_methods;
>> +if (dev)
>>  return dev;
>> -}
>>  }
>>  }
>>
>> @@ -351,9 +342,7 @@ int hw_device_setup_for_decode(InputStream *ist)
>>  if (!dev)
>>  err = hw_device_init_from_type(type, NULL, &dev);
>>  } else {
>> -dev = hw_device_match_by_codec(ist->dec, AV_PIX_FMT_NONE,
>> -   
>> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
>> -   NULL);
>> +dev = hw_device_match_by_codec(ist->dec);
>>  if (!dev) {
>>  // No device for this codec, but not using generic hwaccel
>>  // and therefore may well not need one - ignore.
>> @@ -429,37 +418,57 @@ int hw_device_setup_for_decode(InputStream
>> *ist)
>>
>>  int hw_device_setup_for_encode(OutputStream *ost)
>>  {
>> -HWDevice *dev;
>> -AVBufferRef *frames_ref;
>> -int methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX;
>> -int matched_methods;
>> +const AVCodecHWConfig *config;
>> +HWDevice *dev = NULL;
>> +AVBufferRef *frames_ref = NULL;
>> +int i;
>>
>>  if (ost->filter) {
>>  frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter);
>>  if (frames_ref &&
>>  ((AVHWFramesContext*)frames_ref->data)->format ==
>> -ost->enc_ctx->pix_fmt)
>> -methods |= AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX;
>> +ost->enc_ctx->pix_fmt) {
>> +// Matching format, will try to use hw_frames_ctx.
>> +} else {
>> +frames_ref = NULL;
>> +}
>>  }
>>
>> -dev = hw_device_match_by_codec(ost->enc, ost->enc_ctx->pix_fmt,
>> -   methods, &matched_methods);
>> -if (dev) {
>> -if (matched_methods &
>> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
>> -ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
>> -if (!ost->enc_ctx->hw_device_ctx)
>> -return AVERROR(ENOMEM);
>> -}
>> -if (matched_methods &
>> AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) {
>> +for (i = 0;; i++) {
>> +config = avcodec_get_hw_config(ost->enc, i);
>> +if (!config)
>> +break;
>> +
>> +if (frames_ref &&
>> +config->methods &
>> AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
>> +(config->pix_

[FFmpeg-devel] subtitles filter and -ss

2020-05-03 Thread Manolis Stamatogiannakis
Hello,

I've noticed what appears to be a bug/missing feature in the subtitles
filter: when "-ss" is used for the input, it is not applied to the
subtitles stream. E.g., for the following command line, the video playback
will start on 20:10, but the subtitles will start from 00:00.

ffmpeg -re -ss 20:10.00 -i input.mp4
-vf subtitles=subs.srt \
-c:v libx264 crf 25 -c:a aac -ab 160k \
-strict experimental \
-f flv $RTMP_URL

This should be fairly straightforward to fix and review, so I'd like to
directly submit a patch rather than opening a bug and having someone else
fix it. As I'm not an expert with the ffmpeg internals, I'd like some
guidance on implementing a proper fix.

What would be considered more appropriate:
(a) automatically skipping the subtitles for the time specified by -ss?
(b) adding a shift option to the subtitles filter that allows shifting
subtitles time by specific time?
(c) something else I can't think of?

Although (a) would probably be a bit more elegant to use, I'm not sure if
it always makes sense as ffmpeg may use several input files.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avcodec/h264_metadata_bsf: add option to delete SEI user data

2020-05-03 Thread Mark Thompson
On 20/04/2020 12:01, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  doc/bitstream_filters.texi |  3 +++
>  libavcodec/h264_metadata_bsf.c | 19 +++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index 8fe5b3ad75..652eb4620f 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -273,6 +273,9 @@ possibly separated by hyphens, and the string can be 
> anything.
>  For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
>  insert the string ``hello'' associated with the given UUID.
>  
> +@item delete_user_data
> +Deletes all SEI user data messages.
> +
>  @item delete_filler
>  Deletes both filler NAL units and filler SEI messages.
>  
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index d96a50dbf7..8b42faff1b 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -76,6 +76,7 @@ typedef struct H264MetadataContext {
>  int crop_bottom;
>  
>  const char *sei_user_data;
> +int delete_user_data;
>  
>  int delete_filler;
>  
> @@ -361,6 +362,21 @@ static int h264_metadata_filter(AVBSFContext *bsf, 
> AVPacket *pkt)
>  }
>  }
>  
> +if (ctx->delete_user_data) {
> +for (i = au->nb_units - 1; i >= 0; i--) {
> +if (au->units[i].type == H264_NAL_SEI) {
> +H264RawSEI *sei = au->units[i].content;
> +
> +for (j = sei->payload_count - 1; j >= 0; j--) {
> +if (sei->payload[j].payload_type ==
> +H264_SEI_TYPE_USER_DATA_UNREGISTERED)
> +ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> +   &au->units[i], j);
> +}
> +}
> +}
> +}
> +
>  // Only insert the SEI in access units containing SPSs, and also
>  // unconditionally in the first access unit we ever see.
>  if (ctx->sei_user_data && (has_sps || !ctx->done_first_au)) {
> @@ -684,6 +700,9 @@ static const AVOption h264_metadata_options[] = {
>  { "sei_user_data", "Insert SEI user data (UUID+string)",
>  OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = 
> FLAGS },
>  
> +{ "delete_user_data", "Delete all SEI user data",
> +OFFSET(delete_user_data), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, 
> FLAGS},
> +
>  { "delete_filler", "Delete all filler (both NAL and SEI)",
>  OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS},
>  
> 

This approach is too general, because stripping everything includes notes which 
may be required to correctly decode the stream.  An option like this was 
suggested a while ago and rejected because of the old nonstandard libx264 
streams which have decoding broken by it.

Can you explain your intended use-case?  Perhaps a delete option which takes a 
UUID argument and removes any SEI UDU matching it?

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] cbs_h265: Ensure that a predicted RPS doesn't contain too many pictures

2020-05-03 Thread Mark Thompson
If the RPS we are predicting from has maximum size then at least one of
the pictures in it must be discarded before adding the current one.

Also revert 588114cea4ee434c9c61353ed91ffc817d2965f5, which added
now-redundant checks for the special case of a too-large RPS with all
pictures being in the same direction from the current one.
---
It would be helpful to test this on the fuzzing samples from 
20446/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5707770718584832
 which prompted the original incomplete fix.  Is there somewhere I can find 
them?

 libavcodec/cbs_h265_syntax_template.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs_h265_syntax_template.c 
b/libavcodec/cbs_h265_syntax_template.c
index 5f5531944c..85ff5e5dc5 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -522,7 +522,7 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, 
RWContext *rw,
 infer(inter_ref_pic_set_prediction_flag, 0);
 
 if (current->inter_ref_pic_set_prediction_flag) {
-unsigned int ref_rps_idx, num_delta_pocs;
+unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
 const H265RawSTRefPicSet *ref;
 int delta_rps, d_poc;
 int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
@@ -538,18 +538,28 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext 
*ctx, RWContext *rw,
 ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
 ref = &sps->st_ref_pic_set[ref_rps_idx];
 num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
+av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
 
 flag(delta_rps_sign);
 ue(abs_delta_rps_minus1, 0, INT16_MAX);
 delta_rps = (1 - 2 * current->delta_rps_sign) *
 (current->abs_delta_rps_minus1 + 1);
 
+num_ref_pics = 0;
 for (j = 0; j <= num_delta_pocs; j++) {
 flags(used_by_curr_pic_flag[j], 1, j);
 if (!current->used_by_curr_pic_flag[j])
 flags(use_delta_flag[j], 1, j);
 else
 infer(use_delta_flag[j], 1);
+if (current->use_delta_flag[i])
+++num_ref_pics;
+}
+if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
+   "short-term ref pic set %d "
+   "contains too many pictures.\n", st_rps_idx);
+return AVERROR_INVALIDDATA;
 }
 
 // Since the stored form of an RPS here is actually the delta-step
@@ -601,8 +611,6 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, 
RWContext *rw,
 }
 }
 
-if (i > 15)
-return AVERROR_INVALIDDATA;
 infer(num_negative_pics, i);
 for (i = 0; i < current->num_negative_pics; i++) {
 infer(delta_poc_s0_minus1[i],
@@ -632,8 +640,6 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, 
RWContext *rw,
 }
 }
 
-if (i + current->num_negative_pics > 15)
-return AVERROR_INVALIDDATA;
 infer(num_positive_pics, i);
 for (i = 0; i < current->num_positive_pics; i++) {
 infer(delta_poc_s1_minus1[i],
-- 
2.26.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] subtitles filter and -ss

2020-05-03 Thread Gyan Doshi



On 03-05-2020 08:36 pm, Manolis Stamatogiannakis wrote:

Hello,

I've noticed what appears to be a bug/missing feature in the subtitles
filter: when "-ss" is used for the input, it is not applied to the
subtitles stream. E.g., for the following command line, the video playback
will start on 20:10, but the subtitles will start from 00:00.

ffmpeg -re -ss 20:10.00 -i input.mp4
 -vf subtitles=subs.srt \
 -c:v libx264 crf 25 -c:a aac -ab 160k \
 -strict experimental \
 -f flv $RTMP_URL

This should be fairly straightforward to fix and review, so I'd like to
directly submit a patch rather than opening a bug and having someone else
fix it. As I'm not an expert with the ffmpeg internals, I'd like some
guidance on implementing a proper fix.

What would be considered more appropriate:
(a) automatically skipping the subtitles for the time specified by -ss?
(b) adding a shift option to the subtitles filter that allows shifting
subtitles time by specific time?
(c) something else I can't think of?


-ss executes a seek for that input. The subtitles filter does not have 
access to that data. You can add an option to the subtitles filter that 
also carries out a seek. And make sure to adjust timestamps depending on 
the seek match.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] cbs_h265: Ensure that a predicted RPS doesn't contain too many pictures

2020-05-03 Thread James Almer
On 5/3/2020 12:30 PM, Mark Thompson wrote:
> If the RPS we are predicting from has maximum size then at least one of
> the pictures in it must be discarded before adding the current one.
> 
> Also revert 588114cea4ee434c9c61353ed91ffc817d2965f5, which added
> now-redundant checks for the special case of a too-large RPS with all
> pictures being in the same direction from the current one.

You could also revert it in a separate commit after this patch using git
revert, so this patch only contains the actual fix.

> ---
> It would be helpful to test this on the fuzzing samples from 
> 20446/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5707770718584832
>  which prompted the original incomplete fix.  Is there somewhere I can find 
> them?

Michael can send it to you. Poke him on IRC if he misses this patch.

> 
>  libavcodec/cbs_h265_syntax_template.c | 16 +++-
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/cbs_h265_syntax_template.c 
> b/libavcodec/cbs_h265_syntax_template.c
> index 5f5531944c..85ff5e5dc5 100644
> --- a/libavcodec/cbs_h265_syntax_template.c
> +++ b/libavcodec/cbs_h265_syntax_template.c
> @@ -522,7 +522,7 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  infer(inter_ref_pic_set_prediction_flag, 0);
>  
>  if (current->inter_ref_pic_set_prediction_flag) {
> -unsigned int ref_rps_idx, num_delta_pocs;
> +unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
>  const H265RawSTRefPicSet *ref;
>  int delta_rps, d_poc;
>  int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
> @@ -538,18 +538,28 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
>  ref = &sps->st_ref_pic_set[ref_rps_idx];
>  num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
> +av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
>  
>  flag(delta_rps_sign);
>  ue(abs_delta_rps_minus1, 0, INT16_MAX);
>  delta_rps = (1 - 2 * current->delta_rps_sign) *
>  (current->abs_delta_rps_minus1 + 1);
>  
> +num_ref_pics = 0;
>  for (j = 0; j <= num_delta_pocs; j++) {
>  flags(used_by_curr_pic_flag[j], 1, j);
>  if (!current->used_by_curr_pic_flag[j])
>  flags(use_delta_flag[j], 1, j);
>  else
>  infer(use_delta_flag[j], 1);
> +if (current->use_delta_flag[i])
> +++num_ref_pics;
> +}
> +if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
> +av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
> +   "short-term ref pic set %d "
> +   "contains too many pictures.\n", st_rps_idx);
> +return AVERROR_INVALIDDATA;
>  }
>  
>  // Since the stored form of an RPS here is actually the delta-step
> @@ -601,8 +611,6 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  }
>  }
>  
> -if (i > 15)
> -return AVERROR_INVALIDDATA;
>  infer(num_negative_pics, i);
>  for (i = 0; i < current->num_negative_pics; i++) {
>  infer(delta_poc_s0_minus1[i],
> @@ -632,8 +640,6 @@ static int FUNC(st_ref_pic_set)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  }
>  }
>  
> -if (i + current->num_negative_pics > 15)
> -return AVERROR_INVALIDDATA;
>  infer(num_positive_pics, i);
>  for (i = 0; i < current->num_positive_pics; i++) {
>  infer(delta_poc_s1_minus1[i],
> 

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments

2020-05-03 Thread John Stebbins
On Sat, 2020-05-02 at 22:30 +0200, Andreas Rheinhardt wrote:
> John Stebbins:
> > Required to remux m2ts to mkv
> > ---
> >  Changelog|   1 +
> >  doc/bitstream_filters.texi   |   8 ++
> >  libavcodec/Makefile  |   1 +
> >  libavcodec/bitstream_filters.c   |   1 +
> >  libavcodec/pgs_frame_merge_bsf.c | 168
> > +++
> >  5 files changed, 179 insertions(+)
> >  create mode 100644 libavcodec/pgs_frame_merge_bsf.c
> > 
> > diff --git a/Changelog b/Changelog
> > index d9fcd8bb0a..fec4867488 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -59,6 +59,7 @@ version :
> >  - mv30 decoder
> >  - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
> >  - WebP parser
> > +- PGS subtitle frame merge bitstream filter
> >  
> >  
> >  version 4.2:
> > diff --git a/doc/bitstream_filters.texi
> > b/doc/bitstream_filters.texi
> > index 8fe5b3ad75..21ed09986c 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1]
> > output.mkv
> >  @section null
> >  This bitstream filter passes the packets through unchanged.
> >  
> > +@section pgs_frame_merge
> > +
> > +Merge a sequence of PGS Subtitle segments ending with an "end of
> > display set"
> > +segment into a single packet.
> > +
> > +This is required by some containers that support PGS subtitles
> > +(muxer @code{matroska}).
> > +
> >  @section prores_metadata
> >  
> >  Modify color property metadata embedded in prores stream.
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index 88944d9a3a..b630de21bc 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  +=
> > mp3_header_decompress_bsf.o \
> >  OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
> >  OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
> >  OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
> > +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
> >  OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
> >  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   +=
> > remove_extradata_bsf.o
> >  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
> > diff --git a/libavcodec/bitstream_filters.c
> > b/libavcodec/bitstream_filters.c
> > index 6b5ffe4d70..92619225f0 100644
> > --- a/libavcodec/bitstream_filters.c
> > +++ b/libavcodec/bitstream_filters.c
> > @@ -49,6 +49,7 @@ extern const AVBitStreamFilter
> > ff_mpeg4_unpack_bframes_bsf;
> >  extern const AVBitStreamFilter ff_mov2textsub_bsf;
> >  extern const AVBitStreamFilter ff_noise_bsf;
> >  extern const AVBitStreamFilter ff_null_bsf;
> > +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf;
> >  extern const AVBitStreamFilter ff_prores_metadata_bsf;
> >  extern const AVBitStreamFilter ff_remove_extradata_bsf;
> >  extern const AVBitStreamFilter ff_text2movsub_bsf;
> > diff --git a/libavcodec/pgs_frame_merge_bsf.c
> > b/libavcodec/pgs_frame_merge_bsf.c
> > new file mode 100644
> > index 00..cae5c75655
> > --- /dev/null
> > +++ b/libavcodec/pgs_frame_merge_bsf.c
> > @@ -0,0 +1,168 @@
> > +/*
> > + * Copyright (c) 2020 John Stebbins 
> > + *
> > + * 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
> > + * This bitstream filter merges PGS subtitle packets containing
> > incomplete
> > + * set of segments into a single packet
> > + *
> > + * Packets already containing a complete set of segments will be
> > passed through
> > + * unchanged.
> > + */
> > +
> > +#include "avcodec.h"
> > +#include "bsf.h"
> > +#include "libavutil/intreadwrite.h"
> > +
> > +enum PGSSegmentType {
> > +PALETTE_SEGMENT  = 0x14,
> > +OBJECT_SEGMENT   = 0x15,
> > +PRESENTATION_SEGMENT = 0x16,
> > +WINDOW_SEGMENT   = 0x17,
> > +DISPLAY_SEGMENT  = 0x80,
> > +};
> > +
> > +typedef struct PGSMergeContext {
> > +AVPacket *buffer_pkt, *in;
> > +int presentation_found;
> > +} PGSMergeContext;
> > +
> > +static void frame_merge_flush(AVBSFContext *bsf)
> > +{
> > +PGSMergeContext *ctx = bsf->priv_data;
> > +
> > + 

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread Mark Thompson
On 30/04/2020 22:50, James Almer wrote:
> Fixes ticket #8622
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/cbs_h2645.c|  1 +
>  libavcodec/cbs_h265.h |  1 +
>  libavcodec/cbs_h265_syntax_template.c | 85 +--
>  3 files changed, 70 insertions(+), 17 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 095e449ddc..b432921ecc 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -553,6 +553,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload 
> *payload)
>  av_buffer_unref(&payload->payload.other.data_ref);
>  break;
>  }
> +av_buffer_unref(&payload->extension_data.data_ref);
>  }
>  
>  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
> diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
> index 2c1e153ad9..73897f77a4 100644
> --- a/libavcodec/cbs_h265.h
> +++ b/libavcodec/cbs_h265.h
> @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
>  AVBufferRef *data_ref;
>  } other;
>  } payload;
> +H265RawExtensionData extension_data;
>  } H265RawSEIPayload;
>  
>  typedef struct H265RawSEI {
> diff --git a/libavcodec/cbs_h265_syntax_template.c 
> b/libavcodec/cbs_h265_syntax_template.c
> index ed08b06e9c..d3ac618db6 100644
> --- a/libavcodec/cbs_h265_syntax_template.c
> +++ b/libavcodec/cbs_h265_syntax_template.c
> @@ -1564,7 +1564,8 @@ static int 
> FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
>  
>  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext 
> *rw,
>H265RawSEIBufferingPeriod *current,
> -  uint32_t *payload_size)
> +  uint32_t *payload_size,
> +  int *more_data)
>  {
>  CodedBitstreamH265Context *h265 = ctx->priv_data;
>  const H265RawSPS *sps;
> @@ -1658,8 +1659,15 @@ static int 
> FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
>  else
>  infer(use_alt_cpb_params_flag, 0);
>  #else
> -if (current->use_alt_cpb_params_flag)
> +// If unknown extension data exists, then use_alt_cpb_params_flag is
> +// coded in the bitstream and must be written even if it's 0.
> +if (current->use_alt_cpb_params_flag || *more_data) {
>  flag(use_alt_cpb_params_flag);
> +// Ensure this bit is not the last in the payload by making the
> +// more_data_in_payload() check evaluate to true, so it may not
> +// be mistaken as something else by decoders.
> +*more_data = 1;
> +}
>  #endif
>  
>  return 0;
> @@ -2057,11 +2065,48 @@ static int 
> FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
>  return 0;
>  }
>  
> +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext *rw,
> +   H265RawExtensionData *current, uint32_t 
> payload_size,
> +   int cur_pos)
> +{
> +int err;
> +size_t byte_length, k;
> +
> +#ifdef READ
> +GetBitContext tmp;
> +int bits_left, payload_zero_bits;
> +
> +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
> +return 0;
> +
> +bits_left = 8 * payload_size - cur_pos;
> +tmp = *rw;
> +if (bits_left > 8)
> +skip_bits_long(&tmp, bits_left - 8);
> +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
> +if (!payload_zero_bits)
> +return AVERROR_INVALIDDATA;
> +payload_zero_bits = ff_ctz(payload_zero_bits);
> +current->bit_length = bits_left - payload_zero_bits - 1;
> +allocate(current->data, (current->bit_length + 7) / 8);
> +#endif
> +
> +byte_length = (current->bit_length + 7) / 8;
> +for (k = 0; k < byte_length; k++) {
> +int length = FFMIN(current->bit_length - k * 8, 8);
> +xu(length, reserved_payload_extension_data, current->data[k],
> +   0, MAX_UINT_BITS(length), 0);
> +}
> +
> +return 0;
> +}
> +
>  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>   H265RawSEIPayload *current, int prefix)
>  {
>  int err, i;
> -int start_position, end_position;
> +int start_position, current_position;
> +int more_data = !!current->extension_data.bit_length;
>  
>  #ifdef READ
>  start_position = get_bits_count(rw);
> @@ -2093,8 +2138,15 @@ static int FUNC(sei_payload)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
>   ¤t->payload_size)); \
>  break
> +#define SEI_TYPE_E(type, prefix_valid, suffix_valid, name) \
> +case HEVC_SEI_TYPE_ ## type: \
> +SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid); \
> +CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
> + ¤t->payload

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread James Almer
On 5/3/2020 12:39 PM, Mark Thompson wrote:
> On 30/04/2020 22:50, James Almer wrote:
>> Fixes ticket #8622
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/cbs_h2645.c|  1 +
>>  libavcodec/cbs_h265.h |  1 +
>>  libavcodec/cbs_h265_syntax_template.c | 85 +--
>>  3 files changed, 70 insertions(+), 17 deletions(-)
>>
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 095e449ddc..b432921ecc 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -553,6 +553,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload 
>> *payload)
>>  av_buffer_unref(&payload->payload.other.data_ref);
>>  break;
>>  }
>> +av_buffer_unref(&payload->extension_data.data_ref);
>>  }
>>  
>>  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
>> diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
>> index 2c1e153ad9..73897f77a4 100644
>> --- a/libavcodec/cbs_h265.h
>> +++ b/libavcodec/cbs_h265.h
>> @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
>>  AVBufferRef *data_ref;
>>  } other;
>>  } payload;
>> +H265RawExtensionData extension_data;
>>  } H265RawSEIPayload;
>>  
>>  typedef struct H265RawSEI {
>> diff --git a/libavcodec/cbs_h265_syntax_template.c 
>> b/libavcodec/cbs_h265_syntax_template.c
>> index ed08b06e9c..d3ac618db6 100644
>> --- a/libavcodec/cbs_h265_syntax_template.c
>> +++ b/libavcodec/cbs_h265_syntax_template.c
>> @@ -1564,7 +1564,8 @@ static int 
>> FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
>>  
>>  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext 
>> *rw,
>>H265RawSEIBufferingPeriod *current,
>> -  uint32_t *payload_size)
>> +  uint32_t *payload_size,
>> +  int *more_data)
>>  {
>>  CodedBitstreamH265Context *h265 = ctx->priv_data;
>>  const H265RawSPS *sps;
>> @@ -1658,8 +1659,15 @@ static int 
>> FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
>>  else
>>  infer(use_alt_cpb_params_flag, 0);
>>  #else
>> -if (current->use_alt_cpb_params_flag)
>> +// If unknown extension data exists, then use_alt_cpb_params_flag is
>> +// coded in the bitstream and must be written even if it's 0.
>> +if (current->use_alt_cpb_params_flag || *more_data) {
>>  flag(use_alt_cpb_params_flag);
>> +// Ensure this bit is not the last in the payload by making the
>> +// more_data_in_payload() check evaluate to true, so it may not
>> +// be mistaken as something else by decoders.
>> +*more_data = 1;
>> +}
>>  #endif
>>  
>>  return 0;
>> @@ -2057,11 +2065,48 @@ static int 
>> FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
>>  return 0;
>>  }
>>  
>> +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext 
>> *rw,
>> +   H265RawExtensionData *current, uint32_t 
>> payload_size,
>> +   int cur_pos)
>> +{
>> +int err;
>> +size_t byte_length, k;
>> +
>> +#ifdef READ
>> +GetBitContext tmp;
>> +int bits_left, payload_zero_bits;
>> +
>> +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
>> +return 0;
>> +
>> +bits_left = 8 * payload_size - cur_pos;
>> +tmp = *rw;
>> +if (bits_left > 8)
>> +skip_bits_long(&tmp, bits_left - 8);
>> +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
>> +if (!payload_zero_bits)
>> +return AVERROR_INVALIDDATA;
>> +payload_zero_bits = ff_ctz(payload_zero_bits);
>> +current->bit_length = bits_left - payload_zero_bits - 1;
>> +allocate(current->data, (current->bit_length + 7) / 8);
>> +#endif
>> +
>> +byte_length = (current->bit_length + 7) / 8;
>> +for (k = 0; k < byte_length; k++) {
>> +int length = FFMIN(current->bit_length - k * 8, 8);
>> +xu(length, reserved_payload_extension_data, current->data[k],
>> +   0, MAX_UINT_BITS(length), 0);
>> +}
>> +
>> +return 0;
>> +}
>> +
>>  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>>   H265RawSEIPayload *current, int prefix)
>>  {
>>  int err, i;
>> -int start_position, end_position;
>> +int start_position, current_position;
>> +int more_data = !!current->extension_data.bit_length;
>>  
>>  #ifdef READ
>>  start_position = get_bits_count(rw);
>> @@ -2093,8 +2138,15 @@ static int FUNC(sei_payload)(CodedBitstreamContext 
>> *ctx, RWContext *rw,
>>  CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
>>   ¤t->payload_size)); \
>>  break
>> +#define SEI_TYPE_E(type, prefix_valid, suffix_valid, name) \
>> +case HEVC_SEI_TYPE_ ## type: \
>> +  

Re: [FFmpeg-devel] [PATCH 2/4] lavf/matroskaenc: add PGS merge to auto bsf list

2020-05-03 Thread John Stebbins
On Sat, 2020-05-02 at 22:40 +0200, Andreas Rheinhardt wrote:
> John Stebbins:
> > PGS segments must be merged to one packet for muxing to mkv
> > ---
> >  libavformat/matroskaenc.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> > index d3256d8f5d..bccf8b11d2 100644
> > --- a/libavformat/matroskaenc.c
> > +++ b/libavformat/matroskaenc.c
> > @@ -2655,6 +2655,8 @@ static int mkv_check_bitstream(struct
> > AVFormatContext *s, const AVPacket *pkt)
> >  ret = ff_stream_add_bitstream_filter(st,
> > "aac_adtstoasc", NULL);
> >  } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
> >  ret = ff_stream_add_bitstream_filter(st, "vp9_superframe",
> > NULL);
> > +} else if (st->codecpar->codec_id ==
> > AV_CODEC_ID_HDMV_PGS_SUBTITLE) {
> > +ret = ff_stream_add_bitstream_filter(st,
> > "pgs_frame_merge", NULL);
> >  }
> >  
> >  return ret;
> > 
> 1128aa875367f66ac11adc30364d5652919a2591 removed the auto bsf list
> (no
> muxer added more than one bsf for the same stream), so your commit
> message needs to be updated.
> 

Will do

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/librav1e: Require a bitrate to be set when using 2-pass mode

2020-05-03 Thread Derek Buitenhuis
On 02/05/2020 15:46, James Almer wrote:
>> +if ((avctx->flags & AV_CODEC_FLAG_PASS1 || avctx->flags & 
>> AV_CODEC_FLAG_PASS2) && !avctx->bit_rate) {
> 
> Maybe avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2) instead.

I thought about it, but I think the way I already have it is a little clearer,
and so prefer it.

>>  if (avctx->flags & AV_CODEC_FLAG_PASS2) {
>>  if (!avctx->stats_in) {
>>  av_log(avctx, AV_LOG_ERROR, "No stats file provided for second 
>> pass.\n");
>>
> 
> LGTM either way.

Pushed, thanks.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread Andreas Rheinhardt
Mark Thompson:
> On 30/04/2020 22:50, James Almer wrote:
>> Fixes ticket #8622
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/cbs_h2645.c|  1 +
>>  libavcodec/cbs_h265.h |  1 +
>>  libavcodec/cbs_h265_syntax_template.c | 85 +--
>>  3 files changed, 70 insertions(+), 17 deletions(-)
>>
>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>> index 095e449ddc..b432921ecc 100644
>> --- a/libavcodec/cbs_h2645.c
>> +++ b/libavcodec/cbs_h2645.c
>> @@ -553,6 +553,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload 
>> *payload)
>>  av_buffer_unref(&payload->payload.other.data_ref);
>>  break;
>>  }
>> +av_buffer_unref(&payload->extension_data.data_ref);
>>  }
>>  
>>  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
>> diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
>> index 2c1e153ad9..73897f77a4 100644
>> --- a/libavcodec/cbs_h265.h
>> +++ b/libavcodec/cbs_h265.h
>> @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
>>  AVBufferRef *data_ref;
>>  } other;
>>  } payload;
>> +H265RawExtensionData extension_data;
>>  } H265RawSEIPayload;
>>  
>>  typedef struct H265RawSEI {
>> diff --git a/libavcodec/cbs_h265_syntax_template.c 
>> b/libavcodec/cbs_h265_syntax_template.c
>> index ed08b06e9c..d3ac618db6 100644
>> --- a/libavcodec/cbs_h265_syntax_template.c
>> +++ b/libavcodec/cbs_h265_syntax_template.c
>> @@ -1564,7 +1564,8 @@ static int 
>> FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
>>  
>>  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext 
>> *rw,
>>H265RawSEIBufferingPeriod *current,
>> -  uint32_t *payload_size)
>> +  uint32_t *payload_size,
>> +  int *more_data)
>>  {
>>  CodedBitstreamH265Context *h265 = ctx->priv_data;
>>  const H265RawSPS *sps;
>> @@ -1658,8 +1659,15 @@ static int 
>> FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
>>  else
>>  infer(use_alt_cpb_params_flag, 0);
>>  #else
>> -if (current->use_alt_cpb_params_flag)
>> +// If unknown extension data exists, then use_alt_cpb_params_flag is
>> +// coded in the bitstream and must be written even if it's 0.
>> +if (current->use_alt_cpb_params_flag || *more_data) {
>>  flag(use_alt_cpb_params_flag);
>> +// Ensure this bit is not the last in the payload by making the
>> +// more_data_in_payload() check evaluate to true, so it may not
>> +// be mistaken as something else by decoders.
>> +*more_data = 1;
>> +}
>>  #endif
>>  
>>  return 0;
>> @@ -2057,11 +2065,48 @@ static int 
>> FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
>>  return 0;
>>  }
>>  
>> +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext 
>> *rw,
>> +   H265RawExtensionData *current, uint32_t 
>> payload_size,
>> +   int cur_pos)
>> +{
>> +int err;
>> +size_t byte_length, k;
>> +
>> +#ifdef READ
>> +GetBitContext tmp;
>> +int bits_left, payload_zero_bits;
>> +
>> +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
>> +return 0;
>> +
>> +bits_left = 8 * payload_size - cur_pos;
>> +tmp = *rw;
>> +if (bits_left > 8)
>> +skip_bits_long(&tmp, bits_left - 8);
>> +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
>> +if (!payload_zero_bits)
>> +return AVERROR_INVALIDDATA;
>> +payload_zero_bits = ff_ctz(payload_zero_bits);
>> +current->bit_length = bits_left - payload_zero_bits - 1;
>> +allocate(current->data, (current->bit_length + 7) / 8);
>> +#endif
>> +
>> +byte_length = (current->bit_length + 7) / 8;
>> +for (k = 0; k < byte_length; k++) {
>> +int length = FFMIN(current->bit_length - k * 8, 8);
>> +xu(length, reserved_payload_extension_data, current->data[k],
>> +   0, MAX_UINT_BITS(length), 0);
>> +}
>> +
>> +return 0;
>> +}
>> +
>>  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>>   H265RawSEIPayload *current, int prefix)
>>  {
>>  int err, i;
>> -int start_position, end_position;
>> +int start_position, current_position;
>> +int more_data = !!current->extension_data.bit_length;
>>  
>>  #ifdef READ
>>  start_position = get_bits_count(rw);
>> @@ -2093,8 +2138,15 @@ static int FUNC(sei_payload)(CodedBitstreamContext 
>> *ctx, RWContext *rw,
>>  CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
>>   ¤t->payload_size)); \
>>  break
>> +#define SEI_TYPE_E(type, prefix_valid, suffix_valid, name) \
>> +case HEVC_SEI_TYPE_ ## type: \
>> +SEI_TYPE_CHECK_VALID(n

Re: [FFmpeg-devel] [PATCH 3/4] lavc/pgs_frame_split_bsf: add bsf to split PGS segments

2020-05-03 Thread John Stebbins
On Sat, 2020-05-02 at 23:05 +0200, Andreas Rheinhardt wrote:
> John Stebbins:
> > Requried to remux mkv to m2ts
> > ---
> >  Changelog|   1 +
> >  doc/bitstream_filters.texi   |   8 ++
> >  libavcodec/Makefile  |   1 +
> >  libavcodec/bitstream_filters.c   |   1 +
> >  libavcodec/pgs_frame_split_bsf.c | 176
> > +++
> >  5 files changed, 187 insertions(+)
> >  create mode 100644 libavcodec/pgs_frame_split_bsf.c
> > 
> > diff --git a/Changelog b/Changelog
> > index fec4867488..372bb4694c 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -60,6 +60,7 @@ version :
> >  - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
> >  - WebP parser
> >  - PGS subtitle frame merge bitstream filter
> > +- PGS subtitle frame split bitstream filter
> >  
> >  
> >  version 4.2:
> > diff --git a/doc/bitstream_filters.texi
> > b/doc/bitstream_filters.texi
> > index 21ed09986c..643c419076 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -556,6 +556,14 @@ segment into a single packet.
> >  This is required by some containers that support PGS subtitles
> >  (muxer @code{matroska}).
> >  
> > +@section pgs_frame_split
> > +
> > +Split a packet containing a sequence of PGS Subtitle segments into
> > separate
> > +packets each containing a single segment.
> > +
> > +This is required by some streaming formats, typically the MPEG-2
> > +transport stream format (muxer @code{mpegts}).
> 
> Is there a reason you don't add this bsf automatically for ts?

Yes, it is dependent on:
http://ffmpeg.org/pipermail/ffmpeg-devel/2020-April/261598.html

I have a patch ready for when the above gets approved and committed

> 
> > +
> >  @section prores_metadata
> >  
> >  Modify color property metadata embedded in prores stream.
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index b630de21bc..0e5f2db192 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MPEG2_METADATA_BSF) +=
> > mpeg2_metadata_bsf.o
> >  OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
> >  OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
> >  OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
> > +OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o
> >  OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
> >  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   +=
> > remove_extradata_bsf.o
> >  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
> > diff --git a/libavcodec/bitstream_filters.c
> > b/libavcodec/bitstream_filters.c
> > index 92619225f0..02e72c9ca5 100644
> > --- a/libavcodec/bitstream_filters.c
> > +++ b/libavcodec/bitstream_filters.c
> > @@ -50,6 +50,7 @@ extern const AVBitStreamFilter
> > ff_mov2textsub_bsf;
> >  extern const AVBitStreamFilter ff_noise_bsf;
> >  extern const AVBitStreamFilter ff_null_bsf;
> >  extern const AVBitStreamFilter ff_pgs_frame_merge_bsf;
> > +extern const AVBitStreamFilter ff_pgs_frame_split_bsf;
> >  extern const AVBitStreamFilter ff_prores_metadata_bsf;
> >  extern const AVBitStreamFilter ff_remove_extradata_bsf;
> >  extern const AVBitStreamFilter ff_text2movsub_bsf;
> > diff --git a/libavcodec/pgs_frame_split_bsf.c
> > b/libavcodec/pgs_frame_split_bsf.c
> > new file mode 100644
> > index 00..c983f6acf5
> > --- /dev/null
> > +++ b/libavcodec/pgs_frame_split_bsf.c
> > @@ -0,0 +1,176 @@
> > +/*
> > + * Copyright (c) 2020 John Stebbins 
> > + *
> > + * 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
> > + * This bitstream filter splits PGS subtitle packets into packets
> > containing
> > + * just one segment.
> > + *
> > + * Packets already containing only one segment will be passed
> > through
> > + * unchanged.
> > + */
> > +
> > +#include "avcodec.h"
> > +#include "bsf.h"
> > +#include "libavutil/intreadwrite.h"
> > +
> > +enum PGSSegmentType {
> > +PALETTE_SEGMENT  = 0x14,
> > +OBJECT_SEGMENT   = 0x15,
> > +PRESENTATION_SEGMENT = 0x16,
> > +WINDOW_SEGMENT   = 0x17,
> > +DISPLAY_SEGMENT  = 0x80,
> > +};
> > +
> > +typedef s

Re: [FFmpeg-devel] [PATCH v1 4/4] avcodec/proresenc_anatoliy: support for more color matrix for proresenc

2020-05-03 Thread Marton Balint



On Sun, 3 May 2020, lance.lmw...@gmail.com wrote:


On Sun, May 03, 2020 at 09:53:09AM +0200, Marton Balint wrote:



On Tue, 5 Nov 2019, lance.lmw...@gmail.com wrote:

> From: Limin Wang 
> 
> Please tested with below command:

> ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries bt2020 
-colorspace bt2020_ncl -color_trc smpte2084 -an output.mov
> 
> mediainfo outout.mov

> ...
> Color primaries  : BT.2020
> Transfer characteristics : PQ
> Matrix coefficients  : BT.2020 non-constant
> 
> ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries bt2020 -colorspace bt2020_ncl -color_trc arib-std-b67 -an output.mov

> mediainfo outout.mov
> ...
> Color primaries  : BT.2020
> Transfer characteristics : HLG
> Matrix coefficients  : BT.2020 non-constant
> 
> Signed-off-by: Limin Wang 

> ---
> libavcodec/proresenc_anatoliy.c | 9 +
> 1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c

> index 0fc79fc1de..81365c528c 100644
> --- a/libavcodec/proresenc_anatoliy.c
> +++ b/libavcodec/proresenc_anatoliy.c
> @@ -55,7 +55,8 @@ static const int bitrate_table[6]  = { 1000, 2100, 3500, 
5400, 7000, 1};
> 
> static const int valid_primaries[9]  = { AVCOL_PRI_RESERVED0, AVCOL_PRI_BT709, AVCOL_PRI_UNSPECIFIED, AVCOL_PRI_BT470BG,

>  AVCOL_PRI_SMPTE170M, 
AVCOL_PRI_BT2020, AVCOL_PRI_SMPTE431, AVCOL_PRI_SMPTE432,INT_MAX };
> -static const int valid_trc[4]= { AVCOL_TRC_RESERVED0, 
AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, INT_MAX };
> +static const int valid_trc[6]= { AVCOL_TRC_RESERVED0, 
AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, AVCOL_TRC_SMPTE2084,
> + AVCOL_TRC_ARIB_STD_B67, INT_MAX };
> static const int valid_colorspace[5] = { AVCOL_SPC_BT709, 
AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_SMPTE170M,
>  AVCOL_SPC_BT2020_NCL, INT_MAX };
> 
> @@ -757,9 +758,9 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,

> *buf++ = frame_flags;
> *buf++ = 0; /* reserved */
> /* only write color properties, if valid value. set to unspecified 
otherwise */
> -*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
pict->color_primaries, valid_primaries, 0);
> -*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
pict->color_trc, valid_trc, 0);
> -*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
pict->colorspace, valid_colorspace, 0);
> +*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
avctx->color_primaries, valid_primaries, 0);
> +*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
avctx->color_trc, valid_trc, 0);
> +*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
avctx->colorspace, valid_colorspace, 0);
> if (avctx->profile >= FF_PROFILE_PRORES_) {
> if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
> *buf++ = 0xA0;/* src b64a and no alpha */

Please revert this, using codec context instead of frame does not seem
right. Also have you pinged this before applying?


Before revert it, I'm glad to know why use frame instead of avctx, by my 
testing command, it'll failed to get expected result
without change to use avctx? also, most of encoder like mepg2, nvenc, vaapi, 
videotoolboxenc are using avctx context, what's
the rule for that?


Prores writes the settings for each frame. Other encoders don't do this, 
on a per-frame basis, so it is not possible to signal the possibly 
different colorspace per frame. Anyway, this is not something that you 
should silently change in a patch which only claims to add a new color 
trc. Especially, if this changes behaviour you are experiencing.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1 2/4] avcodec/prores_metadata_bsf: add smpte2084 format support

2020-05-03 Thread Marton Balint



On Sun, 3 May 2020, lance.lmw...@gmail.com wrote:


On Sun, May 03, 2020 at 10:01:31AM +0200, Marton Balint wrote:



On Fri, 15 Nov 2019, Limin Wang wrote:

> 
> ping, the patchset is for HDR/HLG color support for prores.
> 
> On Mon, Nov 04, 2019 at 07:10:00PM +0800, lance.lmw...@gmail.com wrote:

> > From: Limin Wang 
> > 
> > It's based on the following specs:

> > RDD 36:2015 - SMPTE Registered Disclosure Doc - Apple ProRes Bitstream 
Syntax and Decoding Process
> > 
> > Signed-off-by: Limin Wang 

> > ---
> >  doc/bitstream_filters.texi   | 2 ++
> >  libavcodec/prores_metadata_bsf.c | 3 ++-
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi

> > index 8fe5b3ad75..e2de4fd4ed 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -589,6 +589,8 @@ Keep the same transfer characteristics property 
(default).
> >  @item unknown
> >  @item bt709
> >  BT 601, BT 709, BT 2020
> > +@item smpte2084
> > +SMPTE ST 2084
> >  @end table
> > 
> > 
> > diff --git a/libavcodec/prores_metadata_bsf.c b/libavcodec/prores_metadata_bsf.c

> > index 0510d3520a..24615e9305 100644
> > --- a/libavcodec/prores_metadata_bsf.c
> > +++ b/libavcodec/prores_metadata_bsf.c
> > @@ -140,10 +140,11 @@ static const AVOption options[] = {
> >  {"smpte431",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},
> >  {"smpte432",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},
> > 
> > -{"color_trc", "select color transfer", OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_BT709, FLAGS, "color_trc"},

> > +{"color_trc", "select color transfer", OFFSET(transfer_characteristics), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_NB, FLAGS, "color_trc"},

NB-1.

> >  {"auto", "keep the same color transfer",  0, AV_OPT_TYPE_CONST, {.i64=-1},   
INT_MIN, INT_MAX, FLAGS, "color_trc"},
> >  {"unknown",NULL,  0, AV_OPT_TYPE_CONST, {.i64=0},
INT_MIN, INT_MAX, FLAGS, "color_trc"},
> >  {"bt709",  NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_TRC_BT709},  INT_MIN, INT_MAX, FLAGS, "color_trc"},
> > +{"smpte2084",  NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_TRC_SMPTE2084},  INT_MIN, INT_MAX, FLAGS, "color_trc"},
> > 
> >  {"colorspace", "select colorspace", OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, {.i64=-1}, -1,  AVCOL_SPC_BT2020_NCL, FLAGS, "colorspace"},

> >  {"auto", "keep the same colorspace",  0, AV_OPT_TYPE_CONST, {.i64=-1},   
 INT_MIN, INT_MAX, FLAGS, "colorspace"},

Yet again, please, do not apply patches which have not been LGTM-ed and you
have not pinged them recently.

Sorry, I think I have ping before. Next time I'll try to ping again for the old 
patches
or resubmit.


Ok, but please fix the maximum value I commented above. NB is not a valid 
maximum, NB-1 is.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v1] avfilter/src_movie: Fix the loop function of dynamic logo

2020-05-03 Thread Marton Balint



On Sun, 3 May 2020, lance.lmw...@gmail.com wrote:


On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmw...@gmail.com wrote:

From: Limin Wang 

The following command will attempt to create the input and overlay test 
sequence for you.
./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv

Please try with below command and compare the final output.
./ffmpeg -y -filter_complex 
"movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
 enable='between(t,0,25)" test.mkv

 Without the patch applied, the overlay will repeat the last frame in 
overlay.mkv after the first loop.


Why?

Thanks,
Marton



Signed-off-by: Limin Wang 
---
 libavfilter/src_movie.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 79423a8..2327046 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -68,6 +68,8 @@ typedef struct MovieContext {
 int loop_count;
 int64_t discontinuity_threshold;
 int64_t ts_offset;
+int64_t last_pts;
+int64_t last_loop_pts;

 AVFormatContext *format_ctx;
 int eof;
@@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
 movie->st[i].done = 0;
 }
 movie->eof = 0;
+movie->last_loop_pts = movie->last_pts;
 return 0;
 }

@@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned 
out_id)
 if (frame->pts != AV_NOPTS_VALUE) {
 if (movie->ts_offset)
 frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, 
outlink->time_base, AV_ROUND_UP);
+if (movie->last_loop_pts)
+frame->pts += movie->last_loop_pts;
 if (st->discontinuity_threshold) {
 if (st->last_pts != AV_NOPTS_VALUE) {
 int64_t diff = frame->pts - st->last_pts;
@@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned 
out_id)
 }
 }
 }
+movie->last_pts =
 st->last_pts = frame->pts;
 }
 ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
--
2.9.5



ping

--
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v11] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-05-03 Thread Michael Niedermayer
On Sun, May 03, 2020 at 01:43:24PM +, Zane van Iperen wrote:
> On Sun, 3 May 2020 15:23:19 +0200
> "Michael Niedermayer"  wrote:
> 
> > On Fri, May 01, 2020 at 12:55:18AM +, Zane van Iperen wrote:
> > > On Fri, 01 May 2020 00:36:57 +
> > > "Zane van Iperen"  wrote:
> > >  
> > > > On Fri, 1 May 2020 01:09:17 +0200
> > > > "Michael Niedermayer"  wrote:
> > > >  
> > > > > > +size = FFMIN(trk->data_size - ctx->bytes_read,
> > > > > > PP_BNK_MAX_READ_SIZE); +
> > > > > > +if ((ret = av_get_packet(s->pb, pkt, size)) < 0)
> > > > > > +return ret;
> > > > > > +
> > > > > > +ctx->bytes_read+= ret;
> > > > > > +pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
> > > > > > +pkt->stream_index   = ctx->current_track;
> > > > > > +pkt->duration   = ret * 2;  
> > > > >
> > > > > With this each stream would be returned completely before the
> > > > > next such non interleaved output is a bit odd.
> > > > >  
> > > >
> > > > Yep, it's an odd format.  Some files are meant to be stereo, but I
> > > > can't present them as such. I have to present them as separate
> > > > mono streams and merge them with a filter.
> > > >  
> > > > > also where can i find such a file ?
> > > > >  
> > > >
> > > > Here's a file I trimmed for FATE:
> > > >
> > > > https://0x0.st/ie7O.11c
> > > >  
> > > Probably should have mentioned that first file is meant to be stereo
> > > music.
> > >
> > > Here's one that's meant to be just a bunch of mono tracks:
> > > https://0x0.st/ie74.5C  
> > 
> > just tried, and as expected this doesnt work
> > 
> > ./ffmpeg -i pinball/ie74.5C -map 0 test.nut
> > ...
> > Press [q] to stop, [?] for help
> > Too many packets buffered for output stream 0:1.
> > [libvorbis @ 0x557f49f3da40] 16 frames left in the queue on closing
> > [libvorbis @ 0x557f49f3f340] 14 frames left in the queue on closing
> > Conversion failed!
> > 
> 
> Interesting... that worked for me :/
> 
> ./ffmpeg -y -i pp/ie74.5C -map 0 test.nut
> ...
> [nut @ 0x55615988d700] Multiple keyframes with same PTS
> Last message repeated 5 times
> size= 632kB time=00:00:06.37 bitrate= 812.2kbits/s speed=59.8x
> video:0kB audio:630kB subtitle:0kB other streams:0kB global headers:0kB 
> muxing overhead: 0.366753%

Interresting, but the problem with 100% uninterleaved streams remains
applications will have issues with this, and the more the longer these are


> 
> 
> This isn't a valid use case for this file format regardless, as they're 
> soundbanks.

Well, if -map 0 is not a valid use case then how would you
convert such a pinball file to a new pinball file ?
(maybe with some audio filter adding echo or whatever)
Theres no muxer currently but if there was one that seems a valid use
case to me


> Each stream should be split into a separate file, and it's almost guaranteed 
> that they're all different lengths.
> 

> If this is required, then I'm not sure of the best course of action is.

iam also not sure but maybe looking at what exists could lead to some
inspiration
audio streams with concatenated songs, chapters, slide shows, mpeg ts which
stores several independant programms, ...


> Unless I constantly seek back and forth in the file, but that seems messy...

streams can be set to AVDISCARD_ALL when they are unneeded. So at least this
should not happen when parts are unused. Still not sure thats a solution

thx

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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/3] libswscale: add output support for AV_PIX_FMT_GBRAPF32

2020-05-03 Thread Michael Niedermayer
On Sun, May 03, 2020 at 02:01:21AM -0700, Mark Reid wrote:
> On Thu., Apr. 30, 2020, 11:46 a.m. Mark Reid,  wrote:
> 
> >
> >
> > On Thu, Apr 30, 2020 at 7:59 AM Michael Niedermayer 
> > wrote:
> >
> >> On Wed, Apr 29, 2020 at 02:49:35PM -0700, Mark Reid wrote:
> >> > On Wed, Apr 29, 2020 at 2:22 PM Michael Niedermayer
> >> 
> >> > wrote:
> >> >
> >> > > On Wed, Apr 29, 2020 at 11:19:56PM +0200, Michael Niedermayer wrote:
> >> > > > On Tue, Apr 28, 2020 at 08:02:34PM -0700, mindm...@gmail.com wrote:
> >> > > > > From: Mark Reid 
> >> > > > >
> >> > > > > ---
> >> > > > >  libswscale/output.c  | 82
> >> 
> >> > > > >  libswscale/slice.c   | 28 
> >> > > > >  libswscale/swscale_unscaled.c| 33 ++
> >> > > > >  libswscale/utils.c   |  8 +--
> >> > > > >  tests/ref/fate/filter-pixdesc-gbrapf32be |  1 +
> >> > > > >  tests/ref/fate/filter-pixdesc-gbrapf32le |  1 +
> >> > > > >  tests/ref/fate/filter-pixdesc-gbrpf32be  |  1 +
> >> > > > >  tests/ref/fate/filter-pixdesc-gbrpf32le  |  1 +
> >> > > > >  tests/ref/fate/filter-pixfmts-copy   |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-crop   |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-field  |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-hflip  |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-il |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-null   |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-scale  |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-transpose  |  4 ++
> >> > > > >  tests/ref/fate/filter-pixfmts-vflip  |  4 ++
> >> > > > >  18 files changed, 180 insertions(+), 15 deletions(-)
> >> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
> >> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
> >> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
> >> > > > >  create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le
> >> > > >
> >> > > > Fails on qemu MIPS
> >> > > >
> >> > > > --- src/tests/ref/fate/filter-pixfmts-scale 2020-04-29
> >> > > 22:18:07.326122866 +0200
> >> > > > +++ tests/data/fate/filter-pixfmts-scale2020-04-29
> >> > > 23:06:16.167950113 +0200
> >> > > > @@ -25,8 +25,8 @@
> >> > > >  gbrap12le   bb1ba1c157717db3dd612a76d38a018e
> >> > > >  gbrap16be   c72b935a6e57a8e1c37bff08c2db55b1
> >> > > >  gbrap16le   13eb0e62b1ac9c1c86c81521eaefab5f
> >> > > > -gbrapf32be  e6abe67df7fdd5f5dc5db7d852e50954
> >> > > > -gbrapf32le  4d3043b206f7053f7d8d5672f430d680
> >> > > > +gbrapf32be  982d646dc5b2dc718c65fa2a439828f5
> >> > > > +gbrapf32le  f1ffa56441e29aab5e1fd982337bb8ac
> >> > > >  gbrpdc3387f925f972c61aae7eb23cdc19f0
> >> > > >  gbrp10be0277d4c3a8498d75e2783fb81379e481
> >> > > >  gbrp10lef3d70f8ab845c3c9b8f7452e4a6e285a
> >> > > > Test filter-pixfmts-scale failed. Look at
> >> > > tests/data/fate/filter-pixfmts-scale.err for details.
> >> > > > src/tests/Makefile:254: recipe for target
> >> 'fate-filter-pixfmts-scale'
> >> > > failed
> >> > > > make: *** [fate-filter-pixfmts-scale] Error 1
> >> > > > TESTh264-conformance-frext-pph422i5_panasonic_a
> >> > > > TESTh264-conformance-frext-pph422i6_panasonic_a
> >> > > > TESTh264-conformance-frext-pph422i7_panasonic_a
> >> > > > TESTh264-conformance-hcbp2_hhi_a
> >> > > > TESTh264-conformance-hcmp1_hhi_a
> >> > > >
> >> > > > I also think for float, tests based on comparission instead of
> >> checksums
> >> > > > would allow more use of floats in the computations which would
> >> > > > differ rounding wise between platforms
> >> > >
> >> > > and the 2 sws patches would otherwise be ok if they didnt break any
> >> tests
> >> > >
> >> > >
> >> > I was worried about the test with float, and tried to limiting the
> >> number
> >> > of float operations, but guess it's not enough.
> >>
> >> > I haven't looked yet, but is there anywhere you could point me to doing
> >> > a comparison based test?
> >>
> >> anything float based needs a comparission or luck ...
> >> audio tests using "oneoff/stddev" in fate for example
> >> checkasm also checks some float code with comparissions
> >>
> >> not sure how to best integrate this here ...
> >>
> >> thx
> >>
> >
> > Thanks! I'll check those out. I came up with some other ideas to try too
> > that I think might work. Its a tricky problem for sure!
> >
> 
> lt appears the mips test where only failing on the alpha channel formats.
> it seems to because of a planefill function I missed implementing.  I've
> fixed it and the same test results work both on mips and x86, so I don't
> think this is hardware floating point rounding error.

well, if it works, we can try it, 
but what might happen is that once its used on real HW some platform might
not be 

[FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add shift options

2020-05-03 Thread Manolis Stamatogiannakis
Allows shifting of subtitle display times to align them with the video.
This avoids having to rewrite the subtitle file in order to display
subtitles correctly when input is seeked (-ss).
Also handy for minor subtitle timing corrections without rewriting the
subtitles file.

Signed-off-by: Manolis Stamatogiannakis 
---
 doc/filters.texi   |  8 
 libavfilter/vf_subtitles.c | 29 +++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d19fd346ae..94323495f0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -17851,6 +17851,9 @@ The filter accepts the following options:
 @item filename, f
 Set the filename of the subtitle file to read. It must be specified.
 
+@item shift
+Shift subtitles timings by the specified amount.
+
 @item original_size
 Specify the size of the original video, the video for which the ASS file
 was composed. For the syntax of this option, check the
@@ -17907,6 +17910,11 @@ To make the subtitles stream from @file{sub.srt} 
appear in 80% transparent blue
 subtitles=sub.srt:force_style='FontName=DejaVu Serif,PrimaryColour=&HCCFF'
 @end example
 
+To re-sync subtitles after seeking the input e.g. with @code{-ss 20:20}, use:
+@example
+subtitles=filename=sub.srt:shift=-20\:20
+@end example
+
 @section super2xsai
 
 Scale the input by 2x and smooth using the Super2xSaI (Scale and
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index a3b4029af4..74a902941a 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -52,6 +52,8 @@ typedef struct AssContext {
 char *filename;
 char *fontsdir;
 char *charenc;
+int64_t shift;
+char *shift_opt;
 char *force_style;
 int stream_index;
 int alpha;
@@ -68,6 +70,7 @@ typedef struct AssContext {
 #define COMMON_OPTIONS \
 {"filename",   "set the filename of file to read", 
OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, FLAGS }, \
 {"f",  "set the filename of file to read", 
OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, FLAGS }, \
+{"shift",  "set the tilename of file to read", 
OFFSET(shift_opt),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, FLAGS }, \
 {"original_size",  "set the size of the original video (used to scale 
fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  0, 0, 
FLAGS }, \
 {"fontsdir",   "set the directory containing the fonts to read",   
OFFSET(fontsdir),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, FLAGS }, \
 {"alpha",  "enable processing of alpha channel",   
OFFSET(alpha),  AV_OPT_TYPE_BOOL,   {.i64 = 0   }, 0,   
 1, FLAGS }, \
@@ -103,6 +106,16 @@ static av_cold int init(AVFilterContext *ctx)
 return AVERROR(EINVAL);
 }
 
+if (ass->shift_opt) {
+if (av_parse_time(&ass->shift, ass->shift_opt, 1) < 0) {
+av_log(ctx, AV_LOG_ERROR, "Invalid subtitles shift: %s\n",
+   ass->shift_opt);
+return AVERROR(EINVAL);
+}
+ass->shift = av_rescale_q(ass->shift, AV_TIME_BASE_Q, av_make_q(1, 
1000));
+av_log(ctx, AV_LOG_DEBUG, "Shifting subtitles by %0.3fsec.\n", 
ass->shift/1000.0);
+}
+
 ass->library = ass_library_init();
 if (!ass->library) {
 av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
@@ -297,7 +310,7 @@ AVFILTER_DEFINE_CLASS(subtitles);
 
 static av_cold int init_subtitles(AVFilterContext *ctx)
 {
-int j, ret, sid;
+int j, ret, sid, nskip;
 int k = 0;
 AVDictionary *codec_opts = NULL;
 AVFormatContext *fmt = NULL;
@@ -448,6 +461,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 av_init_packet(&pkt);
 pkt.data = NULL;
 pkt.size = 0;
+nskip = 0;
 while (av_read_frame(fmt, &pkt) >= 0) {
 int i, got_subtitle;
 AVSubtitle sub = {0};
@@ -458,8 +472,17 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
av_err2str(ret));
 } else if (got_subtitle) {
-const int64_t start_time = av_rescale_q(sub.pts, 
AV_TIME_BASE_Q, av_make_q(1, 1000));
+const int64_t start_time = av_rescale_q(sub.pts, 
AV_TIME_BASE_Q, av_make_q(1, 1000)) + ass->shift;
 const int64_t duration   = sub.end_display_time;
+
+if (start_time + duration < 0) {
+nskip++;
+goto pkt_end;
+} else if (nskip > 0) {
+av_log(ctx, AV_LOG_INFO, "Skipped %d subtitles out of time 
range.\n", nskip);
+nskip = 0;
+}
+
 for (i = 0; i < sub.num_rects; i++) {
 char *ass_line = sub

Re: [FFmpeg-devel] [PATCH] cbs_h265: Ensure that a predicted RPS doesn't contain too many pictures

2020-05-03 Thread Michael Niedermayer
On Sun, May 03, 2020 at 04:30:00PM +0100, Mark Thompson wrote:
> If the RPS we are predicting from has maximum size then at least one of
> the pictures in it must be discarded before adding the current one.
> 
> Also revert 588114cea4ee434c9c61353ed91ffc817d2965f5, which added
> now-redundant checks for the special case of a too-large RPS with all
> pictures being in the same direction from the current one.
> ---

> It would be helpful to test this on the fuzzing samples from 
> 20446/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5707770718584832
>  which prompted the original incomplete fix.  Is there somewhere I can find 
> them?

yes, the samples are automatically made public based on some rules
like timelimits and if they are fixed, if they are reproduceable, ...
this one should be public since 3 days and here:
https://oss-fuzz.com/download?testcase_id=5707770718584832

also your patch shows no regression with it here

thanks

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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] subtitles filter and -ss

2020-05-03 Thread Manolis Stamatogiannakis
Thanks for the prompt response. It did save me from wasting more time
trying to get the value of -ss starting from the AVFilterContext pointer.
I've submitted a patch that adds a "shift" option to the plugin.

I've opted for "shift" instead of "seek" as the name of the new option.
This should make it evident that the option can also be used for applying
minor timing corrections to the subtitles.

 Any feedback is welcome.

Best regards,
Manolis

On Sun, 3 May 2020 at 17:34, Gyan Doshi  wrote:

>
>
> On 03-05-2020 08:36 pm, Manolis Stamatogiannakis wrote:
> > Hello,
> >
> > I've noticed what appears to be a bug/missing feature in the subtitles
> > filter: when "-ss" is used for the input, it is not applied to the
> > subtitles stream. E.g., for the following command line, the video
> playback
> > will start on 20:10, but the subtitles will start from 00:00.
> >
> > ffmpeg -re -ss 20:10.00 -i input.mp4
> >  -vf subtitles=subs.srt \
> >  -c:v libx264 crf 25 -c:a aac -ab 160k \
> >  -strict experimental \
> >  -f flv $RTMP_URL
> >
> > This should be fairly straightforward to fix and review, so I'd like to
> > directly submit a patch rather than opening a bug and having someone else
> > fix it. As I'm not an expert with the ffmpeg internals, I'd like some
> > guidance on implementing a proper fix.
> >
> > What would be considered more appropriate:
> > (a) automatically skipping the subtitles for the time specified by -ss?
> > (b) adding a shift option to the subtitles filter that allows shifting
> > subtitles time by specific time?
> > (c) something else I can't think of?
>
> -ss executes a seek for that input. The subtitles filter does not have
> access to that data. You can add an option to the subtitles filter that
> also carries out a seek. And make sure to adjust timestamps depending on
> the seek match.
>
> Gyan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [RFC][PATCH] avfilter: add speechnorm filter

2020-05-03 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile|   1 +
 libavfilter/af_speechnorm.c | 381 
 libavfilter/allfilters.c|   1 +
 3 files changed, 383 insertions(+)
 create mode 100644 libavfilter/af_speechnorm.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f982afe15f..421a01753e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -134,6 +134,7 @@ OBJS-$(CONFIG_SIDECHAINGATE_FILTER)  += af_agate.o
 OBJS-$(CONFIG_SILENCEDETECT_FILTER)  += af_silencedetect.o
 OBJS-$(CONFIG_SILENCEREMOVE_FILTER)  += af_silenceremove.o
 OBJS-$(CONFIG_SOFALIZER_FILTER)  += af_sofalizer.o
+OBJS-$(CONFIG_SPEECHNORM_FILTER) += af_speechnorm.o
 OBJS-$(CONFIG_STEREOTOOLS_FILTER)+= af_stereotools.o
 OBJS-$(CONFIG_STEREOWIDEN_FILTER)+= af_stereowiden.o
 OBJS-$(CONFIG_SUPEREQUALIZER_FILTER) += af_superequalizer.o
diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c
new file mode 100644
index 00..52fc8e6e42
--- /dev/null
+++ b/libavfilter/af_speechnorm.c
@@ -0,0 +1,381 @@
+/*
+ * Speech Normalizer
+ * Copyright (c) 2020 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
+ */
+
+/**
+ * @file
+ * Speech Normalizer
+ */
+
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+
+#define FF_BUFQUEUE_SIZE (1024)
+#include "bufferqueue.h"
+
+#include "audio.h"
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+
+#define MAX_ITEMS  882000
+
+typedef struct PeriodItem {
+int size;
+int type;
+double max_peak;
+} PeriodItem;
+
+typedef struct SpeechNormalizerContext {
+const AVClass *class;
+
+double peak_value;
+double max_amplification;
+double threshold_value;
+double feedback;
+double decay;
+int channels;
+
+int max_period;
+int eof;
+int64_t pts;
+int state[12];
+
+PeriodItem pi[12][MAX_ITEMS];
+double gain_state[12];
+int pi_start[12];
+int pi_end[12];
+
+struct FFBufQueue queue;
+} SpeechNormalizerContext;
+
+#define OFFSET(x) offsetof(SpeechNormalizerContext, x)
+#define FLAGS 
AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
+
+static const AVOption speechnorm_options[] = {
+{ "peak","set the peak value",  OFFSET(peak_value),
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.95},  0.0, 1.0, FLAGS },
+{ "p",   "set the peak value",  OFFSET(peak_value),
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.95},  0.0, 1.0, FLAGS },
+{ "maxgain", "set the max amplification",   OFFSET(max_amplification), 
  AV_OPT_TYPE_DOUBLE, {.dbl = 2.0},   1.0,10.0, FLAGS },
+{ "m",   "set the max amplification",   OFFSET(max_amplification), 
  AV_OPT_TYPE_DOUBLE, {.dbl = 2.0},   1.0,10.0, FLAGS },
+{ "threshold",   "set the threshold value", OFFSET(threshold_value),   
  AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0.0, 1.0, FLAGS },
+{ "t",   "set the threshold value", OFFSET(threshold_value),   
  AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0.0, 1.0, FLAGS },
+{ "feedback","set the feedback value",  OFFSET(feedback),  
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.001}, 0.0, 1.0, FLAGS },
+{ "f",   "set the feedback value",  OFFSET(feedback),  
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.001}, 0.0, 1.0, FLAGS },
+{ "decay",   "set the decay value", OFFSET(decay), 
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.999}, 0.0, 1.0, FLAGS },
+{ "d",   "set the decay value", OFFSET(decay), 
  AV_OPT_TYPE_DOUBLE, {.dbl = 0.999}, 0.0, 1.0, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(speechnorm);
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats;
+AVFilterChannelLayouts *layouts;
+static const enum AVSampleFormat sample_fmts[] = {
+AV_SAMPLE_FMT_DBLP,
+AV_SAMPLE_FMT_NONE
+};
+int ret;
+
+layouts = ff_all_channel_counts();
+if (!layouts)
+return AVERROR(ENOMEM);
+ret = ff_set_common_channel_layouts(ctx, layouts);
+if (ret < 0)
+return ret;
+
+formats = ff_make_format

Re: [FFmpeg-devel] [PATCH v1 4/4] avcodec/proresenc_anatoliy: support for more color matrix for proresenc

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 07:01:36PM +0200, Marton Balint wrote:
> 
> 
> On Sun, 3 May 2020, lance.lmw...@gmail.com wrote:
> 
> > On Sun, May 03, 2020 at 09:53:09AM +0200, Marton Balint wrote:
> > > 
> > > 
> > > On Tue, 5 Nov 2019, lance.lmw...@gmail.com wrote:
> > > 
> > > > From: Limin Wang 
> > > > > Please tested with below command:
> > > > ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw -color_primaries 
> > > > bt2020 -colorspace bt2020_ncl -color_trc smpte2084 -an output.mov
> > > > > mediainfo outout.mov
> > > > ...
> > > > Color primaries  : BT.2020
> > > > Transfer characteristics : PQ
> > > > Matrix coefficients  : BT.2020 non-constant
> > > > > ./ffmpeg -i ../fate-suite/mpeg2/t.mpg  -c:v prores_aw
> > > -color_primaries bt2020 -colorspace bt2020_ncl -color_trc
> > > arib-std-b67 -an output.mov
> > > > mediainfo outout.mov
> > > > ...
> > > > Color primaries  : BT.2020
> > > > Transfer characteristics : HLG
> > > > Matrix coefficients  : BT.2020 non-constant
> > > > > Signed-off-by: Limin Wang 
> > > > ---
> > > > libavcodec/proresenc_anatoliy.c | 9 +
> > > > 1 file changed, 5 insertions(+), 4 deletions(-)
> > > > > diff --git a/libavcodec/proresenc_anatoliy.c
> > > b/libavcodec/proresenc_anatoliy.c
> > > > index 0fc79fc1de..81365c528c 100644
> > > > --- a/libavcodec/proresenc_anatoliy.c
> > > > +++ b/libavcodec/proresenc_anatoliy.c
> > > > @@ -55,7 +55,8 @@ static const int bitrate_table[6]  = { 1000, 2100, 
> > > > 3500, 5400, 7000, 1};
> > > > > static const int valid_primaries[9]  = { AVCOL_PRI_RESERVED0,
> > > AVCOL_PRI_BT709, AVCOL_PRI_UNSPECIFIED, AVCOL_PRI_BT470BG,
> > > >  AVCOL_PRI_SMPTE170M, 
> > > > AVCOL_PRI_BT2020, AVCOL_PRI_SMPTE431, AVCOL_PRI_SMPTE432,INT_MAX };
> > > > -static const int valid_trc[4]= { AVCOL_TRC_RESERVED0, 
> > > > AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, INT_MAX };
> > > > +static const int valid_trc[6]= { AVCOL_TRC_RESERVED0, 
> > > > AVCOL_TRC_BT709, AVCOL_TRC_UNSPECIFIED, AVCOL_TRC_SMPTE2084,
> > > > + AVCOL_TRC_ARIB_STD_B67, 
> > > > INT_MAX };
> > > > static const int valid_colorspace[5] = { AVCOL_SPC_BT709, 
> > > > AVCOL_SPC_UNSPECIFIED, AVCOL_SPC_SMPTE170M,
> > > >  AVCOL_SPC_BT2020_NCL, INT_MAX 
> > > > };
> > > > > @@ -757,9 +758,9 @@ static int
> > > prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> > > > *buf++ = frame_flags;
> > > > *buf++ = 0; /* reserved */
> > > > /* only write color properties, if valid value. set to unspecified 
> > > > otherwise */
> > > > -*buf++ = ff_int_from_list_or_default(avctx, "frame color 
> > > > primaries", pict->color_primaries, valid_primaries, 0);
> > > > -*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
> > > > pict->color_trc, valid_trc, 0);
> > > > -*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
> > > > pict->colorspace, valid_colorspace, 0);
> > > > +*buf++ = ff_int_from_list_or_default(avctx, "frame color 
> > > > primaries", avctx->color_primaries, valid_primaries, 0);
> > > > +*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
> > > > avctx->color_trc, valid_trc, 0);
> > > > +*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
> > > > avctx->colorspace, valid_colorspace, 0);
> > > > if (avctx->profile >= FF_PROFILE_PRORES_) {
> > > > if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
> > > > *buf++ = 0xA0;/* src b64a and no alpha */
> > > 
> > > Please revert this, using codec context instead of frame does not seem
> > > right. Also have you pinged this before applying?
> > 
> > Before revert it, I'm glad to know why use frame instead of avctx, by my 
> > testing command, it'll failed to get expected result
> > without change to use avctx? also, most of encoder like mepg2, nvenc, 
> > vaapi, videotoolboxenc are using avctx context, what's
> > the rule for that?
> 
> Prores writes the settings for each frame. Other encoders don't do this, on
> a per-frame basis, so it is not possible to signal the possibly different
> colorspace per frame. Anyway, this is not something that you should silently
> change in a patch which only claims to add a new color trc. Especially, if
> this changes behaviour you are experiencing.

thanks, revert it anyway.

> 
> Regards,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit

Re: [FFmpeg-devel] [PATCH v1 2/4] avcodec/prores_metadata_bsf: add smpte2084 format support

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 07:05:14PM +0200, Marton Balint wrote:
> 
> 
> On Sun, 3 May 2020, lance.lmw...@gmail.com wrote:
> 
> > On Sun, May 03, 2020 at 10:01:31AM +0200, Marton Balint wrote:
> > > 
> > > 
> > > On Fri, 15 Nov 2019, Limin Wang wrote:
> > > 
> > > > > ping, the patchset is for HDR/HLG color support for prores.
> > > > > On Mon, Nov 04, 2019 at 07:10:00PM +0800, lance.lmw...@gmail.com
> > > wrote:
> > > > > From: Limin Wang 
> > > > > > > It's based on the following specs:
> > > > > RDD 36:2015 - SMPTE Registered Disclosure Doc - Apple ProRes 
> > > > > Bitstream Syntax and Decoding Process
> > > > > > > Signed-off-by: Limin Wang 
> > > > > ---
> > > > >  doc/bitstream_filters.texi   | 2 ++
> > > > >  libavcodec/prores_metadata_bsf.c | 3 ++-
> > > > >  2 files changed, 4 insertions(+), 1 deletion(-)
> > > > > > > diff --git a/doc/bitstream_filters.texi
> > > b/doc/bitstream_filters.texi
> > > > > index 8fe5b3ad75..e2de4fd4ed 100644
> > > > > --- a/doc/bitstream_filters.texi
> > > > > +++ b/doc/bitstream_filters.texi
> > > > > @@ -589,6 +589,8 @@ Keep the same transfer characteristics property 
> > > > > (default).
> > > > >  @item unknown
> > > > >  @item bt709
> > > > >  BT 601, BT 709, BT 2020
> > > > > +@item smpte2084
> > > > > +SMPTE ST 2084
> > > > >  @end table
> > > > > > > > > diff --git a/libavcodec/prores_metadata_bsf.c
> > > b/libavcodec/prores_metadata_bsf.c
> > > > > index 0510d3520a..24615e9305 100644
> > > > > --- a/libavcodec/prores_metadata_bsf.c
> > > > > +++ b/libavcodec/prores_metadata_bsf.c
> > > > > @@ -140,10 +140,11 @@ static const AVOption options[] = {
> > > > >  {"smpte431",NULL,  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_primaries"},
> > > > >  {"smpte432",NULL,  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_primaries"},
> > > > > > > -{"color_trc", "select color transfer",
> > > OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, {.i64=-1}, -1,
> > > AVCOL_TRC_BT709, FLAGS, "color_trc"},
> > > > > +{"color_trc", "select color transfer", 
> > > > > OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, {.i64=-1}, -1, 
> > > > > AVCOL_TRC_NB, FLAGS, "color_trc"},
> > > 
> > > NB-1.
> > > 
> > > > >  {"auto", "keep the same color transfer",  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=-1},   INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_trc"},
> > > > >  {"unknown",NULL,  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=0},INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_trc"},
> > > > >  {"bt709",  NULL,  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=AVCOL_TRC_BT709},  INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_trc"},
> > > > > +{"smpte2084",  NULL,  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=AVCOL_TRC_SMPTE2084},  INT_MIN, INT_MAX, FLAGS, 
> > > > > "color_trc"},
> > > > > > >  {"colorspace", "select colorspace",
> > > OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, {.i64=-1}, -1,
> > > AVCOL_SPC_BT2020_NCL, FLAGS, "colorspace"},
> > > > >  {"auto", "keep the same colorspace",  0, AV_OPT_TYPE_CONST, 
> > > > > {.i64=-1},INT_MIN, INT_MAX, FLAGS, 
> > > > > "colorspace"},
> > > 
> > > Yet again, please, do not apply patches which have not been LGTM-ed and 
> > > you
> > > have not pinged them recently.
> > Sorry, I think I have ping before. Next time I'll try to ping again for the 
> > old patches
> > or resubmit.
> 
> Ok, but please fix the maximum value I commented above. NB is not a valid
> maximum, NB-1 is.

Of course, Will submit a patch to fix it. 

> 
> Regards,
> Marton
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/prores_metadata_bsf: Use AVCOL_TRC_NB - 1 for the valid max range

2020-05-03 Thread lance . lmwang
From: Limin Wang 

Report by Marton after commit.

Reviewed-by: Marton Balint 
Signed-off-by: Limin Wang 
---
 libavcodec/prores_metadata_bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/prores_metadata_bsf.c b/libavcodec/prores_metadata_bsf.c
index 8bfcb50..7cc2320 100644
--- a/libavcodec/prores_metadata_bsf.c
+++ b/libavcodec/prores_metadata_bsf.c
@@ -140,7 +140,7 @@ static const AVOption options[] = {
 {"smpte431",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},
 {"smpte432",NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, FLAGS, "color_primaries"},
 
-{"color_trc", "select color transfer", OFFSET(transfer_characteristics), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_NB, FLAGS, "color_trc"},
+{"color_trc", "select color transfer", OFFSET(transfer_characteristics), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_NB - 1, FLAGS, "color_trc"},
 {"auto", "keep the same color transfer",  0, AV_OPT_TYPE_CONST, {.i64=-1}, 
  INT_MIN, INT_MAX, FLAGS, "color_trc"},
 {"unknown",NULL,  0, AV_OPT_TYPE_CONST, {.i64=0},  
  INT_MIN, INT_MAX, FLAGS, "color_trc"},
 {"bt709",  NULL,  0, AV_OPT_TYPE_CONST, 
{.i64=AVCOL_TRC_BT709},  INT_MIN, INT_MAX, FLAGS, "color_trc"},
-- 
1.8.3.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 01/22] cbs: Mention all codecs in unit type comment

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 9ca1fbd609..cb3081e2c6 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -45,8 +45,10 @@ struct CodedBitstreamType;
 /**
  * The codec-specific type of a bitstream unit.
  *
+ * AV1: obu_type
  * H.264 / AVC: nal_unit_type
  * H.265 / HEVC: nal_unit_type
+ * JPEG: marker value (without 0xff prefix)
  * MPEG-2: start code value (without prefix)
  * VP9: unused, set to zero (every unit is a frame)
  */
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 02/22] cbs: Ensure that reference fields always follow the associated pointer

2020-05-03 Thread Mark Thompson
Having these together allows us to find both pointers given the address
of only one of them.
---
 libavcodec/cbs_av1.h   |  6 +++---
 libavcodec/cbs_h264.h  | 18 +-
 libavcodec/cbs_h265.h  | 16 
 libavcodec/cbs_jpeg.h  |  2 +-
 libavcodec/cbs_mpeg2.h | 10 +-
 libavcodec/cbs_vp9.h   |  2 +-
 6 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index fdc629b00c..8925c45772 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -284,8 +284,8 @@ typedef struct AV1RawFrameHeader {
 
 typedef struct AV1RawTileData {
 uint8_t *data;
-size_t   data_size;
 AVBufferRef *data_ref;
+size_t   data_size;
 } AV1RawTileData;
 
 typedef struct AV1RawTileGroup {
@@ -346,8 +346,8 @@ typedef struct AV1RawMetadataITUTT35 {
 uint8_t itu_t_t35_country_code_extension_byte;
 
 uint8_t *payload;
-size_t   payload_size;
 AVBufferRef *payload_ref;
+size_t   payload_size;
 } AV1RawMetadataITUTT35;
 
 typedef struct AV1RawMetadataTimecode {
@@ -379,8 +379,8 @@ typedef struct AV1RawMetadata {
 
 typedef struct AV1RawPadding {
 uint8_t *payload;
-size_t   payload_size;
 AVBufferRef *payload_ref;
+size_t   payload_size;
 } AV1RawPadding;
 
 
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 9f7c2a0d30..65659ae52c 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -277,16 +277,16 @@ typedef struct H264RawSEIPanScanRect {
 typedef struct H264RawSEIUserDataRegistered {
 uint8_t itu_t_t35_country_code;
 uint8_t itu_t_t35_country_code_extension_byte;
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H264RawSEIUserDataRegistered;
 
 typedef struct H264RawSEIUserDataUnregistered {
 uint8_t uuid_iso_iec_11578[16];
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H264RawSEIUserDataUnregistered;
 
 typedef struct H264RawSEIRecoveryPoint {
@@ -334,9 +334,9 @@ typedef struct H264RawSEIPayload {
 H264RawSEIAlternativeTransferCharacteristics
 alternative_transfer_characteristics;
 struct {
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } other;
 } payload;
 } H264RawSEIPayload;
@@ -429,10 +429,10 @@ typedef struct H264RawSliceHeader {
 typedef struct H264RawSlice {
 H264RawSliceHeader header;
 
-uint8_t *data;
-size_t   data_size;
-int  data_bit_start;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_size;
+int  data_bit_start;
 } H264RawSlice;
 
 typedef struct H264RawFiller {
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index ad746bf35f..f5eb5af5b2 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -184,8 +184,8 @@ typedef struct H265RawVUI {
 
 typedef struct H265RawPSExtensionData {
 uint8_t *data;
-size_t bit_length;
 AVBufferRef *data_ref;
+size_t bit_length;
 } H265RawPSExtensionData;
 
 typedef struct H265RawVPS {
@@ -541,10 +541,10 @@ typedef struct  H265RawSliceHeader {
 typedef struct H265RawSlice {
 H265RawSliceHeader header;
 
-uint8_t *data;
-size_t   data_size;
-int  data_bit_start;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_size;
+int  data_bit_start;
 } H265RawSlice;
 
 
@@ -600,15 +600,15 @@ typedef struct H265RawSEIUserDataRegistered {
 uint8_t itu_t_t35_country_code;
 uint8_t itu_t_t35_country_code_extension_byte;
 uint8_t *data;
-size_t   data_length;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H265RawSEIUserDataRegistered;
 
 typedef struct H265RawSEIUserDataUnregistered {
 uint8_t uuid_iso_iec_11578[16];
 uint8_t *data;
-size_t   data_length;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H265RawSEIUserDataUnregistered;
 
 typedef struct H265RawSEIRecoveryPoint {
@@ -710,9 +710,9 @@ typedef struct H265RawSEIPayload {
 alternative_transfer_characteristics;
 H265RawSEIAlphaChannelInfo alpha_channel_info;
 struct {
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } other;
 } payload;
 } H265RawSEIPayload;
diff --git a/libavcodec/cbs_jpeg.h b/libavcodec/cbs_jpeg.h
index ff1961106f..6305f0ee86 100644
--- a/libavcodec/cbs_jpeg.h
+++ b/libavcodec/cbs_jpeg.h
@@ -80,8 +80,8 @@ typedef struct JPEGRawScanHeader {
 typedef struct JPEGRawScan {
 JPEGRawScanHeader header;
 uint8_t  *data;
-size_tdata_size;
 AVBufferRef  *data_ref;
+size_tdata_

[FFmpeg-devel] [PATCH v5 03/22] cbs: Describe allocate/free methods in tabular form

2020-05-03 Thread Mark Thompson
Unit types are split into three categories, depending on how their
content is managed:
* POD structure - these require no special treatment.
* Structure containing references to refcounted buffers - these can use
  a common free function when the offsets of all the internal references
  are known.
* More complex structures - these still require ad-hoc treatment.

For each codec we can then maintain a table of descriptors for each set of
equivalent unit types, defining the mechanism needed to allocate/free that
unit content.  This is not required to be used immediately - a new alloc
function supports this, but does not replace the old one which works without
referring to these tables.
---
 libavcodec/cbs.c  | 69 +++
 libavcodec/cbs.h  |  9 +
 libavcodec/cbs_internal.h | 61 ++
 3 files changed, 139 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 0bd5e1ac5d..6cc559e545 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -812,3 +812,72 @@ void ff_cbs_delete_unit(CodedBitstreamContext *ctx,
 frag->units + position + 1,
 (frag->nb_units - position) * sizeof(*frag->units));
 }
+
+static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
+{
+const CodedBitstreamUnitTypeDescriptor *desc = opaque;
+if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
+int i;
+for (i = 0; i < desc->nb_ref_offsets; i++) {
+void **ptr = (void**)(data + desc->ref_offsets[i]);
+av_buffer_unref((AVBufferRef**)(ptr + 1));
+}
+}
+av_free(data);
+}
+
+static const CodedBitstreamUnitTypeDescriptor
+*cbs_find_unit_type_desc(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+int i, j;
+
+if (!ctx->codec->unit_types)
+return NULL;
+
+for (i = 0;; i++) {
+desc = &ctx->codec->unit_types[i];
+if (desc->nb_unit_types == 0)
+break;
+if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
+if (unit->type >= desc->unit_type_range_start &&
+unit->type <= desc->unit_type_range_end)
+return desc;
+} else {
+for (j = 0; j < desc->nb_unit_types; j++) {
+if (desc->unit_types[j] == unit->type)
+return desc;
+}
+}
+}
+return NULL;
+}
+
+int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
+   CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+
+av_assert0(!unit->content && !unit->content_ref);
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+unit->content = av_mallocz(desc->content_size);
+if (!unit->content)
+return AVERROR(ENOMEM);
+
+unit->content_ref =
+av_buffer_create(unit->content, desc->content_size,
+ desc->content_free ? desc->content_free
+: cbs_default_free_unit_content,
+ (void*)desc, 0);
+if (!unit->content_ref) {
+av_freep(&unit->content);
+return AVERROR(ENOMEM);
+}
+
+return 0;
+}
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index cb3081e2c6..2a5959a2b0 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -352,6 +352,15 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
   size_t size,
   void (*free)(void *opaque, uint8_t *content));
 
+/**
+ * Allocate a new internal content buffer matching the type of the unit.
+ *
+ * The content will be zeroed.
+ */
+int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
+   CodedBitstreamUnit *unit);
+
+
 /**
  * Allocate a new internal data buffer of the given size in the unit.
  *
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 4c5a535ca6..282492bc88 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -25,11 +25,72 @@
 #include "put_bits.h"
 
 
+enum CBSContentType {
+// Unit content is a simple structure.
+CBS_CONTENT_TYPE_POD,
+// Unit content contains some references to other structures, but all
+// managed via buffer reference counting.  The descriptor defines the
+// structure offsets of every buffer reference.
+CBS_CONTENT_TYPE_INTERNAL_REFS,
+// Unit content is something more complex.  The descriptor defines
+// special functions to manage the content.
+CBS_CONTENT_TYPE_COMPLEX,
+};
+
+enum {
+  // Maximum number of unit types described by the same unit type
+  // descriptor.
+  CBS_MAX_UNIT_TYPES  = 3,
+  // Maximum number of reference buffer offsets in any one unit.
+  CBS_MAX_REF_OFFSETS = 2,
+  // Special value used in a unit typ

[FFmpeg-devel] [PATCH v5 07/22] cbs_h2645: Ensure that non-refcounted parameter sets are fully copied

2020-05-03 Thread Mark Thompson
Only copying the main structure is not necessarily sufficient - there
could be references to substructures.
---
 libavcodec/cbs_h2645.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index b5a033dcbd..e4fbd8e633 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -708,18 +708,20 @@ static int cbs_h26 ## h26n ## _replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
 CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
 H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
 unsigned int id = ps_var->id_element; \
+int err; \
 if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
" id : %d.\n", id); \
 return AVERROR_INVALIDDATA; \
 } \
+err = ff_cbs_make_unit_refcounted(ctx, unit); \
+if (err < 0) \
+return err; \
 if (priv->ps_var[id] == priv->active_ ## ps_var) \
 priv->active_ ## ps_var = NULL ; \
 av_buffer_unref(&priv->ps_var ## _ref[id]); \
-if (unit->content_ref) \
-priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
-else \
-priv->ps_var ## _ref[id] = av_buffer_alloc(sizeof(*ps_var)); \
+av_assert0(unit->content_ref); \
+priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
 if (!priv->ps_var ## _ref[id]) \
 return AVERROR(ENOMEM); \
 priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## 
_ref[id]->data; \
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 12/22] cbs_mpeg2: Use table-based alloc/free

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_mpeg2.c | 70 +-
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 97f7889cbb..94e02945f3 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -140,28 +140,6 @@
 #undef infer
 
 
-static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content)
-{
-MPEG2RawPictureHeader *picture = (MPEG2RawPictureHeader*)content;
-av_buffer_unref(&picture->extra_information_picture.extra_information_ref);
-av_freep(&content);
-}
-
-static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content)
-{
-MPEG2RawUserData *user = (MPEG2RawUserData*)content;
-av_buffer_unref(&user->user_data_ref);
-av_freep(&content);
-}
-
-static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content)
-{
-MPEG2RawSlice *slice = (MPEG2RawSlice*)content;
-
av_buffer_unref(&slice->header.extra_information_slice.extra_information_ref);
-av_buffer_unref(&slice->data_ref);
-av_freep(&content);
-}
-
 static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
 CodedBitstreamFragment *frag,
 int header)
@@ -231,16 +209,14 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 if (MPEG2_START_IS_SLICE(unit->type)) {
-MPEG2RawSlice *slice;
+MPEG2RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*slice),
-&cbs_mpeg2_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->header);
 if (err < 0)
 return err;
@@ -264,12 +240,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
 #define START(start_code, type, read_func, free_func) \
 case start_code: \
 { \
-type *header; \
-err = ff_cbs_alloc_unit_content(ctx, unit, \
-sizeof(*header), free_func); \
-if (err < 0) \
-return err; \
-header = unit->content; \
+type *header = unit->content; \
 err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \
 if (err < 0) \
 return err; \
@@ -420,11 +391,40 @@ static int 
cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
 return 0;
 }
 
+static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = {
+CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_PICTURE, MPEG2RawPictureHeader,
+   extra_information_picture.extra_information),
+
+{
+.nb_unit_types = CBS_UNIT_TYPE_RANGE,
+.unit_type_range_start = 0x01,
+.unit_type_range_end   = 0xaf,
+
+.content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS,
+.content_size   = sizeof(MPEG2RawSlice),
+.nb_ref_offsets = 2,
+.ref_offsets= { offsetof(MPEG2RawSlice, 
header.extra_information_slice.extra_information),
+offsetof(MPEG2RawSlice, data) },
+},
+
+CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData,
+   user_data),
+
+CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader),
+CBS_UNIT_TYPE_POD(MPEG2_START_EXTENSION,   MPEG2RawExtensionData),
+CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_END,MPEG2RawSequenceEnd),
+CBS_UNIT_TYPE_POD(MPEG2_START_GROUP,   
MPEG2RawGroupOfPicturesHeader),
+
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_mpeg2 = {
 .codec_id  = AV_CODEC_ID_MPEG2VIDEO,
 
 .priv_data_size= sizeof(CodedBitstreamMPEG2Context),
 
+.unit_types= cbs_mpeg2_unit_types,
+
 .split_fragment= &cbs_mpeg2_split_fragment,
 .read_unit = &cbs_mpeg2_read_unit,
 .write_unit= &cbs_mpeg2_write_unit,
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 06/22] cbs: Add support functions for handling unit content references

2020-05-03 Thread Mark Thompson
Use the unit type table to determine what we need to do to clone the
internals of the unit content when making copies for refcounting or
writeability.  (This will still fail for units with complex content
if they do not have a defined clone function.)

Setup and naming from a patch by Andreas Rheinhardt
, but with the implementation changed
to use the unit type information if possible rather than requiring a
codec-specific function.
---
 libavcodec/cbs.c  | 163 ++
 libavcodec/cbs.h  |  29 +++
 libavcodec/cbs_internal.h |   1 +
 3 files changed, 193 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 6cc559e545..2f39ddbfb4 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -881,3 +881,166 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
 
 return 0;
 }
+
+static int cbs_clone_unit_content(AVBufferRef **clone_ref,
+  CodedBitstreamUnit *unit,
+  const CodedBitstreamUnitTypeDescriptor *desc)
+{
+uint8_t *src, *copy;
+uint8_t **src_ptr, **copy_ptr;
+AVBufferRef **src_buf, **copy_buf;
+int err, i;
+
+av_assert0(unit->content);
+src = unit->content;
+
+copy = av_memdup(src, desc->content_size);
+if (!copy)
+return AVERROR(ENOMEM);
+
+for (i = 0; i < desc->nb_ref_offsets; i++) {
+src_ptr  = (uint8_t**)(src + desc->ref_offsets[i]);
+src_buf  = (AVBufferRef**)(src_ptr + 1);
+copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
+copy_buf = (AVBufferRef**)(copy_ptr + 1);
+
+if (!*src_ptr) {
+av_assert0(!*src_buf);
+continue;
+}
+if (!*src_buf) {
+// We can't handle a non-refcounted pointer here - we don't
+// have enough information to handle whatever structure lies
+// at the other end of it.
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+// src_ptr is required to point somewhere inside src_buf.  If it
+// doesn't, there is a bug somewhere.
+av_assert0(*src_ptr >= (*src_buf)->data &&
+   *src_ptr <  (*src_buf)->data + (*src_buf)->size);
+
+*copy_buf = av_buffer_ref(*src_buf);
+if (!*copy_buf) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+*copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
+}
+
+*clone_ref = av_buffer_create(copy, desc->content_size,
+  desc->content_free ? desc->content_free :
+  cbs_default_free_unit_content,
+  (void*)desc, 0);
+if (!*clone_ref) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+
+return 0;
+
+fail:
+for (--i; i >= 0; i--)
+av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i]));
+av_freep(©);
+*clone_ref = NULL;
+return err;
+}
+
+int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
+CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+AVBufferRef *ref;
+int err;
+
+av_assert0(unit->content);
+if (unit->content_ref) {
+// Already refcounted, nothing to do.
+return 0;
+}
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+switch (desc->content_type) {
+case CBS_CONTENT_TYPE_POD:
+ref = av_buffer_alloc(desc->content_size);
+if (!ref)
+return AVERROR(ENOMEM);
+memcpy(ref->data, unit->content, desc->content_size);
+err = 0;
+break;
+
+case CBS_CONTENT_TYPE_INTERNAL_REFS:
+err = cbs_clone_unit_content(&ref, unit, desc);
+break;
+
+case CBS_CONTENT_TYPE_COMPLEX:
+if (!desc->content_clone)
+return AVERROR_PATCHWELCOME;
+err = desc->content_clone(&ref, unit);
+break;
+
+default:
+av_assert0(0 && "Invalid content type.");
+}
+
+if (err < 0)
+return err;
+
+unit->content_ref = ref;
+unit->content = ref->data;
+return 0;
+}
+
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+  CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+AVBufferRef *ref;
+int err;
+
+// This can only be applied to refcounted units.
+err = ff_cbs_make_unit_refcounted(ctx, unit);
+if (err < 0)
+return err;
+av_assert0(unit->content && unit->content_ref);
+
+if (av_buffer_is_writable(unit->content_ref))
+return 0;
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+switch (desc->content_type) {
+case CBS_CONTENT_TYPE_POD:
+err = av_buffer_make_writable(&unit->content_ref);
+break;
+
+case CBS_CONTENT_TYPE_INTERNAL_REFS:
+er

[FFmpeg-devel] [PATCH v5 13/22] cbs: Expose the function to insert a new empty unit into a fragment

2020-05-03 Thread Mark Thompson
This will be helpful when adding new SEI to an existing access unit.
---
 libavcodec/cbs.c | 10 +-
 libavcodec/cbs.h |  7 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 2f39ddbfb4..2346b1621b 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -680,9 +680,9 @@ int ff_cbs_alloc_unit_data(CodedBitstreamContext *ctx,
 return 0;
 }
 
-static int cbs_insert_unit(CodedBitstreamContext *ctx,
-   CodedBitstreamFragment *frag,
-   int position)
+int ff_cbs_insert_unit(CodedBitstreamContext *ctx,
+   CodedBitstreamFragment *frag,
+   int position)
 {
 CodedBitstreamUnit *units;
 
@@ -742,7 +742,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
 content_ref = NULL;
 }
 
-err = cbs_insert_unit(ctx, frag, position);
+err = ff_cbs_insert_unit(ctx, frag, position);
 if (err < 0) {
 av_buffer_unref(&content_ref);
 return err;
@@ -781,7 +781,7 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
 return AVERROR(ENOMEM);
 }
 
-err = cbs_insert_unit(ctx, frag, position);
+err = ff_cbs_insert_unit(ctx, frag, position);
 if (err < 0) {
 av_buffer_unref(&data_ref);
 return err;
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index eb7f4b878b..09b06a047d 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -370,6 +370,13 @@ int ff_cbs_alloc_unit_data(CodedBitstreamContext *ctx,
CodedBitstreamUnit *unit,
size_t size);
 
+/**
+ * Insert a new empty unit into a fragment.
+ */
+int ff_cbs_insert_unit(CodedBitstreamContext *ctx,
+   CodedBitstreamFragment *frag,
+   int position);
+
 /**
  * Insert a new unit into a fragment with the given content.
  *
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 05/22] cbs_h264: Use table-based alloc/free

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_h2645.c | 163 ++---
 1 file changed, 70 insertions(+), 93 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index d42073cc5a..b5a033dcbd 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -443,52 +443,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #undef allocate
 
 
-static void cbs_h264_free_pps(void *opaque, uint8_t *content)
-{
-H264RawPPS *pps = (H264RawPPS*)content;
-av_buffer_unref(&pps->slice_group_id_ref);
-av_freep(&content);
-}
-
-static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload)
-{
-switch (payload->payload_type) {
-case H264_SEI_TYPE_BUFFERING_PERIOD:
-case H264_SEI_TYPE_PIC_TIMING:
-case H264_SEI_TYPE_PAN_SCAN_RECT:
-case H264_SEI_TYPE_RECOVERY_POINT:
-case H264_SEI_TYPE_DISPLAY_ORIENTATION:
-case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
-case H264_SEI_TYPE_ALTERNATIVE_TRANSFER:
-break;
-case H264_SEI_TYPE_USER_DATA_REGISTERED:
-av_buffer_unref(&payload->payload.user_data_registered.data_ref);
-break;
-case H264_SEI_TYPE_USER_DATA_UNREGISTERED:
-av_buffer_unref(&payload->payload.user_data_unregistered.data_ref);
-break;
-default:
-av_buffer_unref(&payload->payload.other.data_ref);
-break;
-}
-}
-
-static void cbs_h264_free_sei(void *opaque, uint8_t *content)
-{
-H264RawSEI *sei = (H264RawSEI*)content;
-int i;
-for (i = 0; i < sei->payload_count; i++)
-cbs_h264_free_sei_payload(&sei->payload[i]);
-av_freep(&content);
-}
-
-static void cbs_h264_free_slice(void *opaque, uint8_t *content)
-{
-H264RawSlice *slice = (H264RawSlice*)content;
-av_buffer_unref(&slice->data_ref);
-av_freep(&content);
-}
-
 static void cbs_h265_free_vps(void *opaque, uint8_t *content)
 {
 H265RawVPS *vps = (H265RawVPS*)content;
@@ -790,15 +744,14 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 switch (unit->type) {
 case H264_NAL_SPS:
 {
-H264RawSPS *sps;
-
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*sps), NULL);
-if (err < 0)
-return err;
-sps = unit->content;
+H264RawSPS *sps = unit->content;
 
 err = cbs_h264_read_sps(ctx, &gbc, sps);
 if (err < 0)
@@ -812,12 +765,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_SPS_EXT:
 {
-err = ff_cbs_alloc_unit_content(ctx, unit,
-sizeof(H264RawSPSExtension),
-NULL);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content);
 if (err < 0)
 return err;
@@ -826,13 +773,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_PPS:
 {
-H264RawPPS *pps;
-
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*pps),
-&cbs_h264_free_pps);
-if (err < 0)
-return err;
-pps = unit->content;
+H264RawPPS *pps = unit->content;
 
 err = cbs_h264_read_pps(ctx, &gbc, pps);
 if (err < 0)
@@ -848,15 +789,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 case H264_NAL_IDR_SLICE:
 case H264_NAL_AUXILIARY_SLICE:
 {
-H264RawSlice *slice;
+H264RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*slice),
-&cbs_h264_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header);
 if (err < 0)
 return err;
@@ -878,11 +813,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_AUD:
 {
-err = ff_cbs_alloc_unit_content(ctx, unit,
-sizeof(H264RawAUD), NULL);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_aud(ctx, &gbc, unit->content);
 if (err < 0)
 return err;
@@ -891,11 +821,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_SEI:
 {
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(H264RawSEI),
-&cbs_h264_free_sei);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_sei(ctx, &gbc, unit->content);

[FFmpeg-devel] [PATCH v5 04/22] cbs: Add macros to support defining unit type tables

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_internal.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 282492bc88..35159f9c5f 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -167,6 +167,30 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
 
 
+#define CBS_UNIT_TYPE_POD(type, structure) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_POD, \
+.content_size   = sizeof(structure), \
+}
+#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS, \
+.content_size   = sizeof(structure), \
+.nb_ref_offsets = 1, \
+.ref_offsets= { offsetof(structure, ref_field) }, \
+}
+#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_COMPLEX, \
+.content_size   = sizeof(structure), \
+.content_free   = free_func, \
+}
+#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
+
+
 extern const CodedBitstreamType ff_cbs_type_av1;
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 15/22] cbs_h264: Add support for frame packing arrangement SEI messages

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_h264.h | 24 
 libavcodec/cbs_h2645.c|  1 +
 libavcodec/cbs_h264_syntax_template.c | 40 +++
 3 files changed, 65 insertions(+)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index abc0c1b732..512674ec07 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -296,6 +296,29 @@ typedef struct H264RawSEIRecoveryPoint {
 uint8_t changing_slice_group_idc;
 } H264RawSEIRecoveryPoint;
 
+typedef struct H264RawSEIFramePackingArrangement {
+uint32_t frame_packing_arrangement_id;
+uint8_t  frame_packing_arrangement_cancel_flag;
+
+uint8_t  frame_packing_arrangement_type;
+uint8_t  quincunx_sampling_flag;
+uint8_t  content_interpretation_type;
+uint8_t  spatial_flipping_flag;
+uint8_t  frame0_flipped_flag;
+uint8_t  field_views_flag;
+uint8_t  current_frame_is_frame0_flag;
+uint8_t  frame0_self_contained_flag;
+uint8_t  frame1_self_contained_flag;
+uint8_t  frame0_grid_position_x;
+uint8_t  frame0_grid_position_y;
+uint8_t  frame1_grid_position_x;
+uint8_t  frame1_grid_position_y;
+uint8_t  frame_packing_arrangement_reserved_byte;
+uint16_t frame_packing_arrangement_repetition_period;
+
+uint8_t  frame_packing_arrangement_extension_flag;
+} H264RawSEIFramePackingArrangement;
+
 typedef struct H264RawSEIDisplayOrientation {
 uint8_t display_orientation_cancel_flag;
 uint8_t hor_flip;
@@ -329,6 +352,7 @@ typedef struct H264RawSEIPayload {
 H264RawSEIUserDataRegistered user_data_registered;
 H264RawSEIUserDataUnregistered user_data_unregistered;
 H264RawSEIRecoveryPoint recovery_point;
+H264RawSEIFramePackingArrangement frame_packing_arrangement;
 H264RawSEIDisplayOrientation display_orientation;
 H264RawSEIMasteringDisplayColourVolume mastering_display_colour_volume;
 H264RawSEIAlternativeTransferCharacteristics
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 3911cfa100..a48b07057d 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1320,6 +1320,7 @@ void ff_cbs_h264_free_sei_payload(H264RawSEIPayload 
*payload)
 case H264_SEI_TYPE_PIC_TIMING:
 case H264_SEI_TYPE_PAN_SCAN_RECT:
 case H264_SEI_TYPE_RECOVERY_POINT:
+case H264_SEI_TYPE_FRAME_PACKING:
 case H264_SEI_TYPE_DISPLAY_ORIENTATION:
 case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
 case H264_SEI_TYPE_ALTERNATIVE_TRANSFER:
diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index b65460996b..7880b1472c 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -779,6 +779,42 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext 
*ctx, RWContext *rw,
 return 0;
 }
 
+static int FUNC(sei_frame_packing_arrangement)(CodedBitstreamContext *ctx, 
RWContext *rw,
+   
H264RawSEIFramePackingArrangement *current)
+{
+int err;
+
+HEADER("Frame Packing Arrangement");
+
+ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
+flag(frame_packing_arrangement_cancel_flag);
+
+if (!current->frame_packing_arrangement_cancel_flag) {
+u(7, frame_packing_arrangement_type, 0, 7);
+flag(quincunx_sampling_flag);
+u(6, content_interpretation_type, 0, 2);
+flag(spatial_flipping_flag);
+flag(frame0_flipped_flag);
+flag(field_views_flag);
+flag(current_frame_is_frame0_flag);
+flag(frame0_self_contained_flag);
+flag(frame1_self_contained_flag);
+if (!current->quincunx_sampling_flag &&
+current->frame_packing_arrangement_type != 5) {
+ub(4, frame0_grid_position_x);
+ub(4, frame0_grid_position_y);
+ub(4, frame1_grid_position_x);
+ub(4, frame1_grid_position_y);
+}
+u(8, frame_packing_arrangement_reserved_byte, 0, 0);
+ue(frame_packing_arrangement_repetition_period, 0, 16384);
+}
+
+flag(frame_packing_arrangement_extension_flag);
+
+return 0;
+}
+
 static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext 
*rw,
  H264RawSEIDisplayOrientation *current)
 {
@@ -879,6 +915,10 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, 
RWContext *rw,
 CHECK(FUNC(sei_display_orientation)
   (ctx, rw, ¤t->payload.display_orientation));
 break;
+case H264_SEI_TYPE_FRAME_PACKING:
+CHECK(FUNC(sei_frame_packing_arrangement)
+  (ctx, rw, ¤t->payload.frame_packing_arrangement));
+break;
 case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
 CHECK(FUNC(sei_mastering_display_colour_volume)
   (ctx, rw, ¤t->payload.mastering_display_colour_volume));
-- 
2.26.2

___
ffmpeg-devel mailing list

[FFmpeg-devel] [PATCH v5 10/22] cbs_vp9: Use table-based alloc/free

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_vp9.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index eef603bfb2..37b817cfde 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -479,13 +479,6 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext 
*ctx,
 return 0;
 }
 
-static void cbs_vp9_free_frame(void *opaque, uint8_t *content)
-{
-VP9RawFrame *frame = (VP9RawFrame*)content;
-av_buffer_unref(&frame->data_ref);
-av_freep(&frame);
-}
-
 static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
  CodedBitstreamUnit *unit)
 {
@@ -497,8 +490,7 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*frame),
-&cbs_vp9_free_frame);
+err = ff_cbs_alloc_unit_content2(ctx, unit);
 if (err < 0)
 return err;
 frame = unit->content;
@@ -642,11 +634,18 @@ static int 
cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx,
 return 0;
 }
 
+static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = {
+CBS_UNIT_TYPE_INTERNAL_REF(0, VP9RawFrame, data),
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_vp9 = {
 .codec_id  = AV_CODEC_ID_VP9,
 
 .priv_data_size= sizeof(CodedBitstreamVP9Context),
 
+.unit_types= cbs_vp9_unit_types,
+
 .split_fragment= &cbs_vp9_split_fragment,
 .read_unit = &cbs_vp9_read_unit,
 .write_unit= &cbs_vp9_write_unit,
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 14/22] cbs_h264: Simplify SEI addition

2020-05-03 Thread Mark Thompson
At the same time, move the H.264 SEI functions to a new file - the combined
H.26[45] CBS file is already very large, and these functions do not require
any of the common read/write elements.
---
 libavcodec/Makefile|   2 +-
 libavcodec/cbs_h264.c  | 106 +
 libavcodec/cbs_h264.h  |  11 +
 libavcodec/cbs_h2645.c |  96 +
 4 files changed, 120 insertions(+), 95 deletions(-)
 create mode 100644 libavcodec/cbs_h264.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 28076c2c83..076f2fd953 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -67,7 +67,7 @@ OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
-OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_h264.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c
new file mode 100644
index 00..75759c7f25
--- /dev/null
+++ b/libavcodec/cbs_h264.c
@@ -0,0 +1,106 @@
+/*
+ * 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 "cbs_h264.h"
+
+int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
+CodedBitstreamFragment *au,
+H264RawSEIPayload *payload)
+{
+H264RawSEI *sei = NULL;
+int err, i;
+
+// Find an existing SEI NAL unit to add to.
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SEI) {
+sei = au->units[i].content;
+if (sei->payload_count < H264_MAX_SEI_PAYLOADS)
+break;
+
+sei = NULL;
+}
+}
+
+if (!sei) {
+// Need to make a new SEI NAL unit.  Insert it before the first
+// slice data NAL unit; if no slice data, add at the end.
+CodedBitstreamUnit *unit;
+
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SLICE ||
+au->units[i].type == H264_NAL_IDR_SLICE)
+break;
+}
+
+err = ff_cbs_insert_unit(ctx, au, i);
+if (err < 0)
+goto fail;
+unit = &au->units[i];
+
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0) {
+ff_cbs_delete_unit(ctx, au, i);
+goto fail;
+}
+sei = unit->content;
+
+*sei = (H264RawSEI) {
+.nal_unit_header = {
+.nal_unit_type = H264_NAL_SEI,
+},
+};
+}
+
+memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload));
+++sei->payload_count;
+
+return 0;
+fail:
+ff_cbs_h264_free_sei_payload(payload);
+return err;
+}
+
+void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
+CodedBitstreamFragment *au,
+CodedBitstreamUnit *nal,
+int position)
+{
+H264RawSEI *sei = nal->content;
+
+av_assert0(nal->type == H264_NAL_SEI);
+av_assert0(position >= 0 && position < sei->payload_count);
+
+if (position == 0 && sei->payload_count == 1) {
+// Deleting NAL unit entirely.
+int i;
+
+for (i = 0; i < au->nb_units; i++) {
+if (&au->units[i] == nal)
+break;
+}
+
+ff_cbs_delete_unit(ctx, au, i);
+} else {
+ff_cbs_h264_free_sei_payload(&sei->payload[position]);
+
+--sei->payload_count;
+memmove(sei->payload + position,
+sei->payload + position + 1,
+(sei->payload_count - position) * sizeof(*sei->payload));
+}
+}
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 65659ae52c..abc0c1b732 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -466,11 +466,22 @@ typedef struct CodedBitstreamH264Context {
 } CodedBitstreamH264Context;
 
 
+/**
+ * Free an SEI payload

[FFmpeg-devel] [PATCH v5 09/22] cbs_h265: Use table-based alloc/free

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_h2645.c | 196 +++--
 1 file changed, 92 insertions(+), 104 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e4fbd8e633..b70aa3c39d 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -443,71 +443,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #undef allocate
 
 
-static void cbs_h265_free_vps(void *opaque, uint8_t *content)
-{
-H265RawVPS *vps = (H265RawVPS*)content;
-av_buffer_unref(&vps->extension_data.data_ref);
-av_freep(&content);
-}
-
-static void cbs_h265_free_sps(void *opaque, uint8_t *content)
-{
-H265RawSPS *sps = (H265RawSPS*)content;
-av_buffer_unref(&sps->extension_data.data_ref);
-av_freep(&content);
-}
-
-static void cbs_h265_free_pps(void *opaque, uint8_t *content)
-{
-H265RawPPS *pps = (H265RawPPS*)content;
-av_buffer_unref(&pps->extension_data.data_ref);
-av_freep(&content);
-}
-
-static void cbs_h265_free_slice(void *opaque, uint8_t *content)
-{
-H265RawSlice *slice = (H265RawSlice*)content;
-av_buffer_unref(&slice->data_ref);
-av_freep(&content);
-}
-
-static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
-{
-switch (payload->payload_type) {
-case HEVC_SEI_TYPE_BUFFERING_PERIOD:
-case HEVC_SEI_TYPE_PICTURE_TIMING:
-case HEVC_SEI_TYPE_PAN_SCAN_RECT:
-case HEVC_SEI_TYPE_RECOVERY_POINT:
-case HEVC_SEI_TYPE_DISPLAY_ORIENTATION:
-case HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS:
-case HEVC_SEI_TYPE_DECODED_PICTURE_HASH:
-case HEVC_SEI_TYPE_TIME_CODE:
-case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
-case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
-case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
-case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO:
-break;
-case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
-av_buffer_unref(&payload->payload.user_data_registered.data_ref);
-break;
-case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
-av_buffer_unref(&payload->payload.user_data_unregistered.data_ref);
-break;
-default:
-av_buffer_unref(&payload->payload.other.data_ref);
-break;
-}
-}
-
-static void cbs_h265_free_sei(void *opaque, uint8_t *content)
-{
-H265RawSEI *sei = (H265RawSEI*)content;
-int i;
-for (i = 0; i < sei->payload_count; i++)
-cbs_h265_free_sei_payload(&sei->payload[i]);
-av_freep(&content);
-}
-
 static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
const H2645Packet *packet)
@@ -865,16 +800,14 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 switch (unit->type) {
 case HEVC_NAL_VPS:
 {
-H265RawVPS *vps;
-
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*vps),
-&cbs_h265_free_vps);
-if (err < 0)
-return err;
-vps = unit->content;
+H265RawVPS *vps = unit->content;
 
 err = cbs_h265_read_vps(ctx, &gbc, vps);
 if (err < 0)
@@ -887,13 +820,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 break;
 case HEVC_NAL_SPS:
 {
-H265RawSPS *sps;
-
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*sps),
-&cbs_h265_free_sps);
-if (err < 0)
-return err;
-sps = unit->content;
+H265RawSPS *sps = unit->content;
 
 err = cbs_h265_read_sps(ctx, &gbc, sps);
 if (err < 0)
@@ -907,13 +834,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case HEVC_NAL_PPS:
 {
-H265RawPPS *pps;
-
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*pps),
-&cbs_h265_free_pps);
-if (err < 0)
-return err;
-pps = unit->content;
+H265RawPPS *pps = unit->content;
 
 err = cbs_h265_read_pps(ctx, &gbc, pps);
 if (err < 0)
@@ -942,15 +863,9 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 case HEVC_NAL_IDR_N_LP:
 case HEVC_NAL_CRA_NUT:
 {
-H265RawSlice *slice;
+H265RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*slice),
-&cbs_h265_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_h265_read_slice_segment_header(ctx, &gbc, 
&slice->header);
 if (err < 0)
 return err;
@@ -

[FFmpeg-devel] [PATCH v5 08/22] h264_redundant_pps: Make it reference-compatible

2020-05-03 Thread Mark Thompson
From: Andreas Rheinhardt 

Since c6a63e11092c975b89d824f08682fe31948d3686, the parameter sets
modified as content of PPS units were references shared with the
CodedBitstreamH264Context, so modifying them alters the parsing process
of future access units which meant that frames often got discarded
because invalid values were parsed. This patch makes h264_redundant_pps
compatible with the reality of reference-counted parameter sets.

Fixes #7807.

Signed-off-by: Andreas Rheinhardt 
Signed-off-by: Mark Thompson 
---
 libavcodec/h264_redundant_pps_bsf.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264_redundant_pps_bsf.c 
b/libavcodec/h264_redundant_pps_bsf.c
index 8405738c4b..4d5dd9a90f 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -40,8 +40,19 @@ typedef struct H264RedundantPPSContext {
 
 
 static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
-H264RawPPS *pps)
+CodedBitstreamUnit *unit)
 {
+H264RawPPS *pps;
+int err;
+
+// The changes we are about to perform affect the parsing process,
+// so we must make sure that the PPS is writable, otherwise the
+// parsing of future slices will be incorrect and even raise errors.
+err = ff_cbs_make_unit_writable(ctx->input, unit);
+if (err < 0)
+return err;
+pps = unit->content;
+
 // Record the current value of pic_init_qp in order to fix up
 // following slices, then overwrite with the global value.
 ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26;
@@ -88,7 +99,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, 
AVPacket *pkt)
 if (nal->type == H264_NAL_SPS)
 au_has_sps = 1;
 if (nal->type == H264_NAL_PPS) {
-err = h264_redundant_pps_fixup_pps(ctx, nal->content);
+err = h264_redundant_pps_fixup_pps(ctx, nal);
 if (err < 0)
 goto fail;
 if (!au_has_sps) {
@@ -144,7 +155,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf)
 
 for (i = 0; i < au->nb_units; i++) {
 if (au->units[i].type == H264_NAL_PPS) {
-err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content);
+err = h264_redundant_pps_fixup_pps(ctx, &au->units[i]);
 if (err < 0)
 goto fail;
 }
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 11/22] cbs_av1: Use table-based alloc/free

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_av1.c | 85 
 1 file changed, 39 insertions(+), 46 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index fc228086c2..7b1f6c8a44 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -812,50 +812,6 @@ fail:
 return err;
 }
 
-static void cbs_av1_free_tile_data(AV1RawTileData *td)
-{
-av_buffer_unref(&td->data_ref);
-}
-
-static void cbs_av1_free_padding(AV1RawPadding *pd)
-{
-av_buffer_unref(&pd->payload_ref);
-}
-
-static void cbs_av1_free_metadata(AV1RawMetadata *md)
-{
-switch (md->metadata_type) {
-case AV1_METADATA_TYPE_ITUT_T35:
-av_buffer_unref(&md->metadata.itut_t35.payload_ref);
-break;
-}
-}
-
-static void cbs_av1_free_obu(void *opaque, uint8_t *content)
-{
-AV1RawOBU *obu = (AV1RawOBU*)content;
-
-switch (obu->header.obu_type) {
-case AV1_OBU_TILE_GROUP:
-cbs_av1_free_tile_data(&obu->obu.tile_group.tile_data);
-break;
-case AV1_OBU_FRAME:
-cbs_av1_free_tile_data(&obu->obu.frame.tile_group.tile_data);
-break;
-case AV1_OBU_TILE_LIST:
-cbs_av1_free_tile_data(&obu->obu.tile_list.tile_data);
-break;
-case AV1_OBU_METADATA:
-cbs_av1_free_metadata(&obu->obu.metadata);
-break;
-case AV1_OBU_PADDING:
-cbs_av1_free_padding(&obu->obu.padding);
-break;
-}
-
-av_freep(&obu);
-}
-
 static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
  CodedBitstreamUnit *unit,
  GetBitContext *gbc,
@@ -890,8 +846,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
 GetBitContext gbc;
 int err, start_pos, end_pos;
 
-err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*obu),
-&cbs_av1_free_obu);
+err = ff_cbs_alloc_unit_content2(ctx, unit);
 if (err < 0)
 return err;
 obu = unit->content;
@@ -1260,11 +1215,49 @@ static void cbs_av1_close(CodedBitstreamContext *ctx)
 av_buffer_unref(&priv->frame_header_ref);
 }
 
+static void cbs_av1_free_metadata(void *unit, uint8_t *content)
+{
+AV1RawOBU *obu = (AV1RawOBU*)content;
+AV1RawMetadata *md;
+
+av_assert0(obu->header.obu_type == AV1_OBU_METADATA);
+md = &obu->obu.metadata;
+
+switch (md->metadata_type) {
+case AV1_METADATA_TYPE_ITUT_T35:
+av_buffer_unref(&md->metadata.itut_t35.payload_ref);
+break;
+}
+}
+
+static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
+CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER,AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_TEMPORAL_DELIMITER, AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_FRAME_HEADER,   AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_REDUNDANT_FRAME_HEADER, AV1RawOBU),
+
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_GROUP, AV1RawOBU,
+   obu.tile_group.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_FRAME,  AV1RawOBU,
+   obu.frame.tile_group.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST,  AV1RawOBU,
+   obu.tile_list.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING,AV1RawOBU,
+   obu.padding.payload),
+
+CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
+  &cbs_av1_free_metadata),
+
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_av1 = {
 .codec_id  = AV_CODEC_ID_AV1,
 
 .priv_data_size= sizeof(CodedBitstreamAV1Context),
 
+.unit_types= cbs_av1_unit_types,
+
 .split_fragment= &cbs_av1_split_fragment,
 .read_unit = &cbs_av1_read_unit,
 .write_unit= &cbs_av1_write_obu,
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 16/22] cbs_h264: Add a function to turn stereo 3D metadata into SEI

2020-05-03 Thread Mark Thompson
---
 libavcodec/cbs_h264.c | 47 +++
 libavcodec/cbs_h264.h |  8 
 2 files changed, 55 insertions(+)

diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c
index 75759c7f25..096949e67b 100644
--- a/libavcodec/cbs_h264.c
+++ b/libavcodec/cbs_h264.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/stereo3d.h"
+
 #include "cbs_h264.h"
 
 int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
@@ -104,3 +106,48 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamContext 
*ctx,
 (sei->payload_count - position) * sizeof(*sei->payload));
 }
 }
+
+void 
ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement
 *fp,
+const AVStereo3D *st)
+{
+static const uint8_t type_map[] = {
+[AV_STEREO3D_2D]  = 6,
+[AV_STEREO3D_SIDEBYSIDE]  = 3,
+[AV_STEREO3D_TOPBOTTOM]   = 4,
+[AV_STEREO3D_FRAMESEQUENCE]   = 5,
+[AV_STEREO3D_CHECKERBOARD]= 0,
+[AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = 3,
+[AV_STEREO3D_LINES]   = 2,
+[AV_STEREO3D_COLUMNS] = 1,
+};
+
+memset(fp, 0, sizeof(*fp));
+
+if (st->type >= FF_ARRAY_ELEMS(type_map))
+return;
+
+fp->frame_packing_arrangement_type = type_map[st->type];
+
+fp->quincunx_sampling_flag =
+st->type == AV_STEREO3D_CHECKERBOARD ||
+st->type == AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+
+if (st->type == AV_STEREO3D_2D)
+fp->content_interpretation_type = 0;
+else if (st->flags & AV_STEREO3D_FLAG_INVERT)
+fp->content_interpretation_type = 2;
+else
+fp->content_interpretation_type = 1;
+
+if (st->type == AV_STEREO3D_FRAMESEQUENCE) {
+if (st->flags & AV_STEREO3D_FLAG_INVERT)
+fp->current_frame_is_frame0_flag =
+st->view == AV_STEREO3D_VIEW_RIGHT;
+else
+fp->current_frame_is_frame0_flag =
+st->view == AV_STEREO3D_VIEW_LEFT;
+}
+
+fp->frame_packing_arrangement_repetition_period =
+st->type != AV_STEREO3D_FRAMESEQUENCE;
+}
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 512674ec07..76211c976b 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -525,4 +525,12 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamContext 
*ctx,
 CodedBitstreamUnit *nal_unit,
 int position);
 
+struct AVStereo3D;
+/**
+ * Fill an SEI Frame Packing Arrangement structure with values derived from
+ * the AVStereo3D side-data structure.
+ */
+void 
ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement
 *fp,
+const struct AVStereo3D 
*st);
+
 #endif /* AVCODEC_CBS_H264_H */
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 17/22] vaapi_encode: Unify SEI types enum

2020-05-03 Thread Mark Thompson
This was in two disjoint parts in the H.264 and H.265 files.  Unify them in
the header to avoid any confusion, because they are really the same enum.
---
 libavcodec/vaapi_encode.h  | 10 ++
 libavcodec/vaapi_encode_h264.c |  6 --
 libavcodec/vaapi_encode_h265.c |  5 -
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 1329f6428f..3a095231fe 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -459,4 +459,14 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
 VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
 
 
+// SEI types used in options for both H.264 and H.265.
+enum {
+SEI_TIMING  = 0x01,
+SEI_IDENTIFIER  = 0x02,
+SEI_RECOVERY_POINT  = 0x04,
+SEI_MASTERING_DISPLAY   = 0x08,
+SEI_CONTENT_LIGHT_LEVEL = 0x10,
+};
+
+
 #endif /* AVCODEC_VAAPI_ENCODE_H */
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 67b1ecae1b..34a6a8993d 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -35,12 +35,6 @@
 #include "internal.h"
 #include "vaapi_encode.h"
 
-enum {
-SEI_TIMING = 0x01,
-SEI_IDENTIFIER = 0x02,
-SEI_RECOVERY_POINT = 0x04,
-};
-
 // Random (version 4) ISO 11578 UUID.
 static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = {
 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index e20e8cbdd0..ee44d7c442 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -37,11 +37,6 @@
 #include "put_bits.h"
 #include "vaapi_encode.h"
 
-enum {
-SEI_MASTERING_DISPLAY   = 0x08,
-SEI_CONTENT_LIGHT_LEVEL = 0x10,
-};
-
 typedef struct VAAPIEncodeH265Picture {
 int pic_order_cnt;
 
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 21/22] h264_metadata_bsf: Refactor the filter function into smaller parts

2020-05-03 Thread Mark Thompson
---
 libavcodec/h264_metadata_bsf.c | 447 ++---
 1 file changed, 244 insertions(+), 203 deletions(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 451eaa0b67..bfb5b7d7e4 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -54,6 +54,7 @@ typedef struct H264MetadataContext {
 int done_first_au;
 
 int aud;
+H264RawAUD aud_nal;
 
 AVRational sample_aspect_ratio;
 
@@ -76,6 +77,7 @@ typedef struct H264MetadataContext {
 int crop_bottom;
 
 const char *sei_user_data;
+H264RawSEIPayload sei_user_data_payload;
 
 int delete_filler;
 
@@ -87,6 +89,59 @@ typedef struct H264MetadataContext {
 } H264MetadataContext;
 
 
+static int h264_metadata_insert_aud(AVBSFContext *bsf,
+CodedBitstreamFragment *au)
+{
+H264MetadataContext *ctx = bsf->priv_data;
+int primary_pic_type_mask = 0xff;
+int err, i, j;
+
+static const int primary_pic_type_table[] = {
+0x084, // 2, 7
+0x0a5, // 0, 2, 5, 7
+0x0e7, // 0, 1, 2, 5, 6, 7
+0x210, // 4, 9
+0x318, // 3, 4, 8, 9
+0x294, // 2, 4, 7, 9
+0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
+0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+};
+
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SLICE ||
+au->units[i].type == H264_NAL_IDR_SLICE) {
+H264RawSlice *slice = au->units[i].content;
+for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) {
+if (!(primary_pic_type_table[j] &
+  (1 << slice->header.slice_type)))
+primary_pic_type_mask &= ~(1 << j);
+}
+}
+}
+for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++)
+if (primary_pic_type_mask & (1 << j))
+break;
+if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) {
+av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: "
+   "invalid slice types?\n");
+return AVERROR_INVALIDDATA;
+}
+
+ctx->aud_nal = (H264RawAUD) {
+.nal_unit_header.nal_unit_type = H264_NAL_AUD,
+.primary_pic_type = j,
+};
+
+err = ff_cbs_insert_unit_content(ctx->cbc, au,
+ 0, H264_NAL_AUD, &ctx->aud_nal, NULL);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
+return err;
+}
+
+return 0;
+}
+
 static int h264_metadata_update_sps(AVBSFContext *bsf,
 H264RawSPS *sps)
 {
@@ -318,221 +373,60 @@ static int h264_metadata_update_side_data(AVBSFContext 
*bsf, AVPacket *pkt)
 return 0;
 }
 
-static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
+static int h264_metadata_handle_display_orientation(AVBSFContext *bsf,
+AVPacket *pkt,
+CodedBitstreamFragment *au,
+int seek_point)
 {
 H264MetadataContext *ctx = bsf->priv_data;
-CodedBitstreamFragment *au = &ctx->access_unit;
-int err, i, j, has_sps;
-H264RawAUD aud;
-
-err = ff_bsf_get_packet_ref(bsf, pkt);
-if (err < 0)
-return err;
-
-err = h264_metadata_update_side_data(bsf, pkt);
-if (err < 0)
-goto fail;
-
-err = ff_cbs_read_packet(ctx->cbc, au, pkt);
-if (err < 0) {
-av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
-goto fail;
-}
-
-if (au->nb_units == 0) {
-av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n");
-err = AVERROR_INVALIDDATA;
-goto fail;
-}
-
-// If an AUD is present, it must be the first NAL unit.
-if (au->units[0].type == H264_NAL_AUD) {
-if (ctx->aud == REMOVE)
-ff_cbs_delete_unit(ctx->cbc, au, 0);
-} else {
-if (ctx->aud == INSERT) {
-static const int primary_pic_type_table[] = {
-0x084, // 2, 7
-0x0a5, // 0, 2, 5, 7
-0x0e7, // 0, 1, 2, 5, 6, 7
-0x210, // 4, 9
-0x318, // 3, 4, 8, 9
-0x294, // 2, 4, 7, 9
-0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
-0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
-};
-int primary_pic_type_mask = 0xff;
-
-for (i = 0; i < au->nb_units; i++) {
-if (au->units[i].type == H264_NAL_SLICE ||
-au->units[i].type == H264_NAL_IDR_SLICE) {
-H264RawSlice *slice = au->units[i].content;
-for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); 
j++) {
- if (!(primary_pic_type_table[j] &
-   (1 << slice->header.slice_type)))
- primary_pic_type_mask &= ~(1 << j);
-   

[FFmpeg-devel] [PATCH v5 18/22] vaapi_encode_h264: Support stereo 3D metadata

2020-05-03 Thread Mark Thompson
Insert frame packing arrangement messages into the stream when input
frames have associated stereo 3D side-data.
---
 doc/encoders.texi  |  3 +++
 libavcodec/vaapi_encode.h  |  1 +
 libavcodec/vaapi_encode_h264.c | 24 +++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 18bfe8f2eb..4da8c701a2 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3074,6 +3074,9 @@ Include picture timing parameters 
(@emph{buffering_period} and
 @emph{pic_timing} messages).
 @item recovery_point
 Include recovery points where appropriate (@emph{recovery_point} messages).
+@item frame_packing
+Include stereo 3D metadata if the input frames have it
+(@emph{frame_packing_arrangement} messages).
 @end table
 
 @end table
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 3a095231fe..5ba1679b92 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -466,6 +466,7 @@ enum {
 SEI_RECOVERY_POINT  = 0x04,
 SEI_MASTERING_DISPLAY   = 0x08,
 SEI_CONTENT_LIGHT_LEVEL = 0x10,
+SEI_FRAME_PACKING   = 0x20,
 };
 
 
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 34a6a8993d..d6a9321e5d 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -25,6 +25,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/stereo3d.h"
 
 #include "avcodec.h"
 #include "cbs.h"
@@ -90,6 +91,7 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIBufferingPeriod  sei_buffering_period;
 H264RawSEIPicTimingsei_pic_timing;
 H264RawSEIRecoveryPointsei_recovery_point;
+H264RawSEIFramePackingArrangement sei_frame_packing;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
 
@@ -245,6 +247,12 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_FRAME_PACKING) {
+sei->payload[i].payload_type = H264_SEI_TYPE_FRAME_PACKING;
+sei->payload[i].payload.frame_packing_arrangement =
+priv->sei_frame_packing;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -694,6 +702,17 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+if (priv->sei & SEI_FRAME_PACKING) {
+AVFrameSideData *sd = av_frame_get_side_data(pic->input_image,
+ AV_FRAME_DATA_STEREO3D);
+if (sd) {
+ff_cbs_h264_fill_sei_frame_packing_arrangement(
+&priv->sei_frame_packing, (const AVStereo3D*)sd->data);
+
+priv->sei_needed |= SEI_FRAME_PACKING;
+}
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1265,7 +1284,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
-  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | 
SEI_FRAME_PACKING },
   0, INT_MAX, FLAGS, "sei" },
 { "identifier", "Include encoder version identifier",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1276,6 +1295,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "recovery_point", "Include recovery points where appropriate",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
   INT_MIN, INT_MAX, FLAGS, "sei" },
+{ "frame_packing", "Include frame packing arrangement for stereo 3D",
+  0, AV_OPT_TYPE_CONST, { .i64 = SEI_FRAME_PACKING },
+  INT_MIN, INT_MAX, FLAGS, "sei" },
 
 { "profile", "Set profile (profile_idc and constraint_set*_flag)",
   OFFSET(profile), AV_OPT_TYPE_INT,
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 22/22] h264_metadata_bsf: Improve interpretation of input display matrices

2020-05-03 Thread Mark Thompson
The previous code here only worked in more limited cases.
---
 libavcodec/h264_metadata_bsf.c | 42 +++---
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index bfb5b7d7e4..10f4c3c56d 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -440,23 +440,39 @@ static int 
h264_metadata_handle_display_orientation(AVBSFContext *bsf,
 data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
 if (data && size >= 9 * sizeof(int32_t)) {
 int32_t matrix[9];
+double dmatrix[9];
 int hflip, vflip;
-double angle;
+double scale_x, scale_y, angle;
 
 memcpy(matrix, data, sizeof(matrix));
 
-hflip = vflip = 0;
-if (matrix[0] < 0 && matrix[4] > 0)
-hflip = 1;
-else if (matrix[0] > 0 && matrix[4] < 0)
-vflip = 1;
-av_display_matrix_flip(matrix, hflip, vflip);
+for (i = 0; i < 9; i++)
+dmatrix[i] = matrix[i] / 65536.0;
+
+// Extract scale factors.
+scale_x = hypot(dmatrix[0], dmatrix[3]);
+scale_y = hypot(dmatrix[1], dmatrix[4]);
+
+// Select flips to make the main diagonal positive.
+hflip = dmatrix[0] < 0.0;
+vflip = dmatrix[4] < 0.0;
+if (hflip)
+scale_x = -scale_x;
+if (vflip)
+scale_y = -scale_y;
+
+// Rescale.
+for (i = 0; i < 9; i += 3) {
+dmatrix[i] /= scale_x;
+dmatrix[i + 1] /= scale_y;
+}
 
-angle = av_display_rotation_get(matrix);
+// Extract rotation.
+angle = atan2(dmatrix[3], dmatrix[0]);
 
-if (!(angle >= -180.0 && angle <= 180.0 /* also excludes NaN */) ||
-matrix[2] != 0 || matrix[5] != 0 ||
-matrix[6] != 0 || matrix[7] != 0) {
+if (!(angle >= -M_PI && angle <= M_PI) ||
+matrix[2] != 0.0 || matrix[5] != 0.0 ||
+matrix[6] != 0.0 || matrix[7] != 0.0) {
 av_log(bsf, AV_LOG_WARNING, "Input display matrix is not "
"representable in H.264 parameters.\n");
 } else {
@@ -464,8 +480,8 @@ static int 
h264_metadata_handle_display_orientation(AVBSFContext *bsf,
 disp->ver_flip = vflip;
 disp->anticlockwise_rotation =
 (uint16_t)rint((angle >= 0.0 ? angle
- : angle + 360.0) *
-   65536.0 / 360.0);
+ : angle + 2 * M_PI) *
+   32768.0 / M_PI);
 write = 1;
 }
 }
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v5 19/22] cbs_h265: Add functions to turn HDR metadata into SEI

2020-05-03 Thread Mark Thompson
---
 libavcodec/Makefile   |   2 +-
 libavcodec/cbs_h265.c | 100 ++
 libavcodec/cbs_h265.h |  18 
 3 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/cbs_h265.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 076f2fd953..844e971d42 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -68,7 +68,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_h264.o h2645_parse.o
-OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o cbs_h265.o h2645_parse.o
 OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
diff --git a/libavcodec/cbs_h265.c b/libavcodec/cbs_h265.c
new file mode 100644
index 00..afbdd37896
--- /dev/null
+++ b/libavcodec/cbs_h265.c
@@ -0,0 +1,100 @@
+/*
+ * 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/mathematics.h"
+#include "libavutil/mastering_display_metadata.h"
+
+#include "cbs_h265.h"
+
+
+static uint32_t rescale_clip(AVRational value, uint32_t scale, uint32_t max)
+{
+int64_t scaled = av_rescale(scale, value.num, value.den);
+return av_clip64(scaled, 0, max);
+}
+
+static uint32_t rescale_fraction(AVRational value, uint32_t max)
+{
+return rescale_clip(value, max, max);
+}
+
+void 
ff_cbs_h265_fill_sei_mastering_display(H265RawSEIMasteringDisplayColourVolume 
*mdcv,
+const AVMasteringDisplayMetadata 
*mdm)
+{
+memset(mdcv, 0, sizeof(*mdcv));
+
+if (mdm->has_primaries) {
+// The values in the metadata structure are fractions between 0 and 1,
+// while the SEI message contains fixed-point values with an increment
+// of 0.2.  So, scale up by 5 to convert between them.
+
+for (int a = 0; a < 3; a++) {
+// The metadata structure stores this in RGB order, but the SEI
+// wants it in GBR order.
+static const uint8_t mapping[] = { 1, 2, 0 };
+int b = mapping[a];
+mdcv->display_primaries_x[a] =
+rescale_fraction(mdm->display_primaries[b][0], 5);
+mdcv->display_primaries_y[a] =
+rescale_fraction(mdm->display_primaries[b][1], 5);
+}
+
+mdcv->white_point_x = rescale_fraction(mdm->white_point[0], 5);
+mdcv->white_point_y = rescale_fraction(mdm->white_point[1], 5);
+}
+
+if (mdm->has_luminance) {
+// Metadata are rational values in candelas per square metre, SEI
+// contains fixed point in units of 0.0001 candelas per square
+// metre.  So scale up by 1 to convert between them, and clip to
+// ensure that we don't overflow.
+
+mdcv->max_display_mastering_luminance =
+rescale_clip(mdm->max_luminance, 1, UINT32_MAX);
+mdcv->min_display_mastering_luminance =
+rescale_clip(mdm->min_luminance, 1, UINT32_MAX);
+
+// The spec has a hard requirement that min is less than the max,
+// and the SEI-writing code enforces that.
+if (!(mdcv->min_display_mastering_luminance <
+  mdcv->max_display_mastering_luminance)) {
+if (mdcv->max_display_mastering_luminance == UINT32_MAX)
+mdcv->min_display_mastering_luminance =
+mdcv->max_display_mastering_luminance - 1;
+else
+mdcv->max_display_mastering_luminance =
+mdcv->min_display_mastering_luminance + 1;
+}
+} else {
+mdcv->max_display_mastering_luminance = 1;
+mdcv->min_display_mastering_luminance = 0;
+}
+}
+
+void ff_cbs_h265_fill_sei_content_light_level(H265RawSEIContentLightLevelInfo 
*cll,
+  const AVContentLightMetadata 
*clm)
+{
+memset(cll, 0, sizeof(*cll));
+
+// Both the metadata and the SEI are in units of candelas per square
+// metre, so

[FFmpeg-devel] [PATCH v5 20/22] vaapi_encode_h265: Use common handling for HDR metadata

2020-05-03 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h265.c | 45 +-
 1 file changed, 6 insertions(+), 39 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index ee44d7c442..4307da7bb1 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -745,39 +745,10 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 AVMasteringDisplayMetadata *mdm =
 (AVMasteringDisplayMetadata *)sd->data;
 
-// SEI is needed when both the primaries and luminance are set
+// Only needed when both primaries and luminance are set.
 if (mdm->has_primaries && mdm->has_luminance) {
-H265RawSEIMasteringDisplayColourVolume *mdcv =
-&priv->sei_mastering_display;
-const int mapping[3] = {1, 2, 0};
-const int chroma_den = 5;
-const int luma_den   = 1;
-
-for (i = 0; i < 3; i++) {
-const int j = mapping[i];
-mdcv->display_primaries_x[i] =
-FFMIN(lrint(chroma_den *
-av_q2d(mdm->display_primaries[j][0])),
-  chroma_den);
-mdcv->display_primaries_y[i] =
-FFMIN(lrint(chroma_den *
-av_q2d(mdm->display_primaries[j][1])),
-  chroma_den);
-}
-
-mdcv->white_point_x =
-FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
-  chroma_den);
-mdcv->white_point_y =
-FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
-  chroma_den);
-
-mdcv->max_display_mastering_luminance =
-lrint(luma_den * av_q2d(mdm->max_luminance));
-mdcv->min_display_mastering_luminance =
-FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
-  mdcv->max_display_mastering_luminance);
-
+ff_cbs_h265_fill_sei_mastering_display(
+&priv->sei_mastering_display, mdm);
 priv->sei_needed |= SEI_MASTERING_DISPLAY;
 }
 }
@@ -790,13 +761,9 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
 
 if (sd) {
-AVContentLightMetadata *clm =
-(AVContentLightMetadata *)sd->data;
-H265RawSEIContentLightLevelInfo *clli =
-&priv->sei_content_light_level;
-
-clli->max_content_light_level = FFMIN(clm->MaxCLL,  65535);
-clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
+ff_cbs_h265_fill_sei_content_light_level(
+&priv->sei_content_light_level,
+(const AVContentLightMetadata*)sd->data);
 
 priv->sei_needed |= SEI_CONTENT_LIGHT_LEVEL;
 }
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] avdevice/v4l2enc: Allow writing non-rawvideos to v4l2

2020-05-03 Thread Mark Thompson
On 26/04/2020 21:26, David Manouchehri wrote:
> Resubmit of a previous patch, not sure why the diff didn't come through.
> 
> From d125fea410dea1c2d4bd791a7472a72822de54a3 Mon Sep 17 00:00:00 2001
> From: David Manouchehri 
> Date: Sat, 4 Nov 2017 16:32:41 -0400
> Subject: [PATCH] avdevice/v4l2enc: Allow writing non-rawvideos to v4l2.
> 
> Signed-off-by: David Manouchehri 
> ---
>  libavdevice/v4l2enc.c | 11 ---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/libavdevice/v4l2enc.c b/libavdevice/v4l2enc.c
> index 1c36f81f90..f89ff50dbb 100644
> --- a/libavdevice/v4l2enc.c
> +++ b/libavdevice/v4l2enc.c
> @@ -47,8 +47,7 @@ static av_cold int write_header(AVFormatContext *s1)
>  }
>  
>  if (s1->nb_streams != 1 ||
> -s1->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ||
> -s1->streams[0]->codecpar->codec_id   != AV_CODEC_ID_RAWVIDEO) {
> +s1->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
>  av_log(s1, AV_LOG_ERROR,
> "V4L2 output device supports only a single raw video 
> stream\n");
>  return AVERROR(EINVAL);
> @@ -56,7 +55,13 @@ static av_cold int write_header(AVFormatContext *s1)
>  
>  par = s1->streams[0]->codecpar;
>  
> -v4l2_pixfmt = ff_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO);
> +if(s1->streams[0]->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {
> +v4l2_pixfmt = ff_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO);
> +}
> +else {
> +v4l2_pixfmt = ff_fmt_ff2v4l(AV_PIX_FMT_NONE, 
> s1->streams[0]->codecpar->codec_id);
> +}
> +
>  if (!v4l2_pixfmt) { // XXX: try to force them one by one?
>  av_log(s1, AV_LOG_ERROR, "Unknown V4L2 pixel format equivalent for 
> %s\n",
> av_get_pix_fmt_name(par->format));
> -- 
> 2.17.1

LGTM.  If noone else has any comments I'll apply this in two days.

Thanks,

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread Mark Thompson
On 03/05/2020 16:55, James Almer wrote:
> On 5/3/2020 12:39 PM, Mark Thompson wrote:
>> On 30/04/2020 22:50, James Almer wrote:
>>> Fixes ticket #8622
>>>
>>> Signed-off-by: James Almer 
>>> ---
>>>  libavcodec/cbs_h2645.c|  1 +
>>>  libavcodec/cbs_h265.h |  1 +
>>>  libavcodec/cbs_h265_syntax_template.c | 85 +--
>>>  3 files changed, 70 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>>> index 095e449ddc..b432921ecc 100644
>>> --- a/libavcodec/cbs_h2645.c
>>> +++ b/libavcodec/cbs_h2645.c
>>> @@ -553,6 +553,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload 
>>> *payload)
>>>  av_buffer_unref(&payload->payload.other.data_ref);
>>>  break;
>>>  }
>>> +av_buffer_unref(&payload->extension_data.data_ref);
>>>  }
>>>  
>>>  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
>>> diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
>>> index 2c1e153ad9..73897f77a4 100644
>>> --- a/libavcodec/cbs_h265.h
>>> +++ b/libavcodec/cbs_h265.h
>>> @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
>>>  AVBufferRef *data_ref;
>>>  } other;
>>>  } payload;
>>> +H265RawExtensionData extension_data;
>>>  } H265RawSEIPayload;
>>>  
>>>  typedef struct H265RawSEI {
>>> diff --git a/libavcodec/cbs_h265_syntax_template.c 
>>> b/libavcodec/cbs_h265_syntax_template.c
>>> index ed08b06e9c..d3ac618db6 100644
>>> --- a/libavcodec/cbs_h265_syntax_template.c
>>> +++ b/libavcodec/cbs_h265_syntax_template.c
>>> @@ -1564,7 +1564,8 @@ static int 
>>> FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
>>>  
>>>  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, 
>>> RWContext *rw,
>>>H265RawSEIBufferingPeriod *current,
>>> -  uint32_t *payload_size)
>>> +  uint32_t *payload_size,
>>> +  int *more_data)
>>>  {
>>>  CodedBitstreamH265Context *h265 = ctx->priv_data;
>>>  const H265RawSPS *sps;
>>> @@ -1658,8 +1659,15 @@ static int 
>>> FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
>>>  else
>>>  infer(use_alt_cpb_params_flag, 0);
>>>  #else
>>> -if (current->use_alt_cpb_params_flag)
>>> +// If unknown extension data exists, then use_alt_cpb_params_flag is
>>> +// coded in the bitstream and must be written even if it's 0.
>>> +if (current->use_alt_cpb_params_flag || *more_data) {
>>>  flag(use_alt_cpb_params_flag);
>>> +// Ensure this bit is not the last in the payload by making the
>>> +// more_data_in_payload() check evaluate to true, so it may not
>>> +// be mistaken as something else by decoders.
>>> +*more_data = 1;
>>> +}
>>>  #endif
>>>  
>>>  return 0;
>>> @@ -2057,11 +2065,48 @@ static int 
>>> FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
>>>  return 0;
>>>  }
>>>  
>>> +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext 
>>> *rw,
>>> +   H265RawExtensionData *current, uint32_t 
>>> payload_size,
>>> +   int cur_pos)
>>> +{
>>> +int err;
>>> +size_t byte_length, k;
>>> +
>>> +#ifdef READ
>>> +GetBitContext tmp;
>>> +int bits_left, payload_zero_bits;
>>> +
>>> +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
>>> +return 0;
>>> +
>>> +bits_left = 8 * payload_size - cur_pos;
>>> +tmp = *rw;
>>> +if (bits_left > 8)
>>> +skip_bits_long(&tmp, bits_left - 8);
>>> +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
>>> +if (!payload_zero_bits)
>>> +return AVERROR_INVALIDDATA;
>>> +payload_zero_bits = ff_ctz(payload_zero_bits);
>>> +current->bit_length = bits_left - payload_zero_bits - 1;
>>> +allocate(current->data, (current->bit_length + 7) / 8);
>>> +#endif
>>> +
>>> +byte_length = (current->bit_length + 7) / 8;
>>> +for (k = 0; k < byte_length; k++) {
>>> +int length = FFMIN(current->bit_length - k * 8, 8);
>>> +xu(length, reserved_payload_extension_data, current->data[k],
>>> +   0, MAX_UINT_BITS(length), 0);
>>> +}
>>> +
>>> +return 0;
>>> +}
>>> +
>>>  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
>>>   H265RawSEIPayload *current, int prefix)
>>>  {
>>>  int err, i;
>>> -int start_position, end_position;
>>> +int start_position, current_position;
>>> +int more_data = !!current->extension_data.bit_length;
>>>  
>>>  #ifdef READ
>>>  start_position = get_bits_count(rw);
>>> @@ -2093,8 +2138,15 @@ static int FUNC(sei_payload)(CodedBitstreamContext 
>>> *ctx, RWContext *rw,
>>>  CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
>>>

Re: [FFmpeg-devel] [PATCH] cbs_h265: Ensure that a predicted RPS doesn't contain too many pictures

2020-05-03 Thread Mark Thompson
On 03/05/2020 19:14, Michael Niedermayer wrote:
> On Sun, May 03, 2020 at 04:30:00PM +0100, Mark Thompson wrote:
>> If the RPS we are predicting from has maximum size then at least one of
>> the pictures in it must be discarded before adding the current one.
>>
>> Also revert 588114cea4ee434c9c61353ed91ffc817d2965f5, which added
>> now-redundant checks for the special case of a too-large RPS with all
>> pictures being in the same direction from the current one.
>> ---
> 
>> It would be helpful to test this on the fuzzing samples from 
>> 20446/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-5707770718584832
>>  which prompted the original incomplete fix.  Is there somewhere I can find 
>> them?
> 
> yes, the samples are automatically made public based on some rules
> like timelimits and if they are fixed, if they are reproduceable, ...
> this one should be public since 3 days and here:
> https://oss-fuzz.com/download?testcase_id=5707770718584832

Ha, cute.  A stream with enough RPS entries hits this by overwriting with 
all-ones in the SPS, because an all-ones RPS reads as inter predicted from the 
previous RPS with all pictures used.

> also your patch shows no regression with it here

Confirmed here as well.

Will apply tomorrow if there are no other comments.

Thanks,

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavf/fps: add cmd to force write buf frame

2020-05-03 Thread Jim DeLaHunt

On 2020-05-02 15:35, Jai Luthra wrote:


Enables writing buffered frames to the outsink using send command api.

This is useful when a lavf user wants to fetch buffered frames without
closing/reopening the filtergraph again and again.

Signed-off-by: Jai Luthra 
---
  libavfilter/vf_fps.c | 36 +++-
  1 file changed, 27 insertions(+), 9 deletions(-)


…[snip]…

Jai:

I'm not an official reviewer or anything, but I have looked at the 
libavfilter/vf_fps.c code recently.


This looks like a useful extension. I can imagine it being useful to 
flush frames through the *fps* filter while FFmpeg is running. I could 
imagine this patch pointing the way for further improvements later.


However, I don't see any change to the *fps* filter documentation in 
this patch. If a patch changes the way a user can control a filter, but 
doesn't document that change, then doesn't the patch cause the code to 
diverge further from the documentation? And long-term, doesn't that lead 
to problems?


Best regards,
   —Jim DeLaHunt, software engineer, Vancouver, Canada


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 0/2] initial input/output support for AV_PIX_FMT_GBRAPF32

2020-05-03 Thread mindmark
From: Mark Reid 

changes since v1
- added missing fillPlane32 function
- tests should pass now for qemu-mips
- removed exr patch for now

Mark Reid (2):
  libswscale: add input support AV_PIX_FMT_GBRAPF32
  libswscale: add output support for AV_PIX_FMT_GBRAPF32

 libswscale/input.c   | 91 
 libswscale/output.c  | 82 +
 libswscale/slice.c   | 28 +---
 libswscale/swscale.c |  5 ++
 libswscale/swscale_internal.h| 36 ++
 libswscale/swscale_unscaled.c| 33 +
 libswscale/utils.c   |  4 ++
 tests/ref/fate/filter-pixdesc-gbrapf32be |  1 +
 tests/ref/fate/filter-pixdesc-gbrapf32le |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32be  |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32le  |  1 +
 tests/ref/fate/filter-pixfmts-copy   |  4 ++
 tests/ref/fate/filter-pixfmts-crop   |  4 ++
 tests/ref/fate/filter-pixfmts-field  |  4 ++
 tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
 tests/ref/fate/filter-pixfmts-hflip  |  4 ++
 tests/ref/fate/filter-pixfmts-il |  4 ++
 tests/ref/fate/filter-pixfmts-null   |  4 ++
 tests/ref/fate/filter-pixfmts-scale  |  4 ++
 tests/ref/fate/filter-pixfmts-transpose  |  4 ++
 tests/ref/fate/filter-pixfmts-vflip  |  4 ++
 21 files changed, 312 insertions(+), 11 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] libswscale: add input support AV_PIX_FMT_GBRAPF32

2020-05-03 Thread mindmark
From: Mark Reid 

---
 libswscale/input.c | 91 ++
 libswscale/utils.c |  4 ++
 2 files changed, 95 insertions(+)

diff --git a/libswscale/input.c b/libswscale/input.c
index 099661cb6d..e74cf04133 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -960,6 +960,59 @@ static av_always_inline void planar_rgb16_to_uv(uint8_t 
*_dstU, uint8_t *_dstV,
 }
 #undef rdpx
 
+#define rdpx(src) (is_be ? av_int2float(AV_RB32(src)): 
av_int2float(AV_RL32(src)))
+
+static av_always_inline void planar_rgbf32_to_a(uint8_t *_dst, const uint8_t 
*_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dst= (uint16_t *)_dst;
+
+for (i = 0; i < width; i++) {
+dst[i] = av_clip_uint16(lrintf(65535.0f * rdpx(src[3] + i)));
+}
+}
+
+static av_always_inline void planar_rgbf32_to_uv(uint8_t *_dstU, uint8_t 
*_dstV, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dstU   = (uint16_t *)_dstU;
+uint16_t *dstV   = (uint16_t *)_dstV;
+int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+int bpc = 16;
+int shift = 14;
+for (i = 0; i < width; i++) {
+int g = av_clip_uint16(lrintf(65535.0f * rdpx(src[0] + i)));
+int b = av_clip_uint16(lrintf(65535.0f * rdpx(src[1] + i)));
+int r = av_clip_uint16(lrintf(65535.0f * rdpx(src[2] + i)));
+
+dstU[i] = (ru*r + gu*g + bu*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14);
+dstV[i] = (rv*r + gv*g + bv*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14);
+}
+}
+
+static av_always_inline void planar_rgbf32_to_y(uint8_t *_dst, const uint8_t 
*_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dst= (uint16_t *)_dst;
+
+int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
+int bpc = 16;
+int shift = 14;
+for (i = 0; i < width; i++) {
+int g = av_clip_uint16(lrintf(65535.0f * rdpx(src[0] + i)));
+int b = av_clip_uint16(lrintf(65535.0f * rdpx(src[1] + i)));
+int r = av_clip_uint16(lrintf(65535.0f * rdpx(src[2] + i)));
+
+dst[i] = ((ry*r + gy*g + by*b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14));
+}
+}
+
+#undef rdpx
+
 static av_always_inline void grayf32ToY16_c(uint8_t *_dst, const uint8_t 
*_src, const uint8_t *unused1,
 const uint8_t *unused2, int width, 
uint32_t *unused)
 {
@@ -1022,6 +1075,26 @@ rgb9plus_planar_transparency_funcs(10)
 rgb9plus_planar_transparency_funcs(12)
 rgb9plus_planar_transparency_funcs(16)
 
+#define rgbf32_planar_funcs_endian(endian_name, endian)
 \
+static void planar_rgbf32##endian_name##_to_y(uint8_t *dst, const uint8_t 
*src[4],  \
+  int w, int32_t *rgb2yuv) 
 \
+{  
 \
+planar_rgbf32_to_y(dst, src, w, endian, rgb2yuv);  
 \
+}  
 \
+static void planar_rgbf32##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV,   
 \
+   const uint8_t *src[4], int 
w, int32_t *rgb2yuv)  \
+{  
 \
+planar_rgbf32_to_uv(dstU, dstV, src, w, endian, rgb2yuv);  
 \
+}  
 \
+static void planar_rgbf32##endian_name##_to_a(uint8_t *dst, const uint8_t 
*src[4],  \
+  int w, int32_t *rgb2yuv) 
 \
+{  
 \
+planar_rgbf32_to_a(dst, src, w, endian, rgb2yuv);  
 \
+}
+
+rgbf32_planar_funcs_endian(le, 0)
+rgbf32_planar_funcs_endian(be, 1)
+
 av_cold void ff_sws_init_input_funcs(SwsContext *c)
 {
 enum AVPixelFormat srcFormat = c->srcFormat;
@@ -1070,6 +1143,10 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
 case AV_PIX_FMT_GBRP16LE:
 c->readChrPlanar = planar_rgb16le_to_uv;
 break;
+case AV_PIX_FMT_GBRAPF32LE:
+case AV_PIX_FMT_GBRPF32LE:
+c->readChrPlanar = planar_rgbf32le_to_uv;
+break;
 case AV_PIX_F

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/wavpack: Check rate_x and sample rate for overflow

2020-05-03 Thread David Bryant
On 5/2/20 2:08 PM, Michael Niedermayer wrote:
> Fixes: shift exponent 32 is too large for 32-bit type 'int'
> Fixes: 
> 21647/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WAVPACK_fuzzer-5686168323883008
>
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/wavpack.c | 13 ++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
> index 58ab561a15..ead57063c8 100644
> --- a/libavcodec/wavpack.c
> +++ b/libavcodec/wavpack.c
> @@ -1359,7 +1359,10 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
> int block_no,
>  bytestream2_skip(&gb, ssize);
>  continue;
>  }
> -rate_x = 1 << bytestream2_get_byte(&gb);
> +rate_x = bytestream2_get_byte(&gb);
> +if (rate_x > 30)
> +return AVERROR_INVALIDDATA;
> +rate_x = 1 << rate_x;
>  dsd_mode = bytestream2_get_byte(&gb);
>  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
>  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: 
> %d\n",
> @@ -1498,9 +1501,13 @@ static int wavpack_decode_block(AVCodecContext *avctx, 
> int block_no,
>  av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
>  return AVERROR_INVALIDDATA;
>  }
> -new_samplerate = sample_rate * rate_x;
> +new_samplerate = sample_rate;
>  } else
> -new_samplerate = wv_rates[sr] * rate_x;
> +new_samplerate = wv_rates[sr];
> +
> +if (new_samplerate * (uint64_t)rate_x > INT_MAX)
> +return AVERROR_INVALIDDATA;
> +new_samplerate *= rate_x;
>  
>  if (multiblock) {
>  if (chan)

Looks correct to me. Thanks.


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/2] libswscale: add output support for AV_PIX_FMT_GBRAPF32

2020-05-03 Thread mindmark
From: Mark Reid 

---
 libswscale/output.c  | 82 
 libswscale/slice.c   | 28 
 libswscale/swscale.c |  5 ++
 libswscale/swscale_internal.h| 36 +++
 libswscale/swscale_unscaled.c| 33 ++
 libswscale/utils.c   |  8 +--
 tests/ref/fate/filter-pixdesc-gbrapf32be |  1 +
 tests/ref/fate/filter-pixdesc-gbrapf32le |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32be  |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32le  |  1 +
 tests/ref/fate/filter-pixfmts-copy   |  4 ++
 tests/ref/fate/filter-pixfmts-crop   |  4 ++
 tests/ref/fate/filter-pixfmts-field  |  4 ++
 tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
 tests/ref/fate/filter-pixfmts-hflip  |  4 ++
 tests/ref/fate/filter-pixfmts-il |  4 ++
 tests/ref/fate/filter-pixfmts-null   |  4 ++
 tests/ref/fate/filter-pixfmts-scale  |  4 ++
 tests/ref/fate/filter-pixfmts-transpose  |  4 ++
 tests/ref/fate/filter-pixfmts-vflip  |  4 ++
 20 files changed, 221 insertions(+), 15 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le

diff --git a/libswscale/output.c b/libswscale/output.c
index 68f43ffba3..e864e515d0 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2312,6 +2312,82 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 }
 }
 
+static void
+yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
+const int16_t **lumSrcx, int lumFilterSize,
+const int16_t *chrFilter, const int16_t **chrUSrcx,
+const int16_t **chrVSrcx, int chrFilterSize,
+const int16_t **alpSrcx, uint8_t **dest,
+int dstW, int y)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
+int i;
+int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
+uint32_t **dest32 = (uint32_t**)dest;
+const int32_t **lumSrc  = (const int32_t**)lumSrcx;
+const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
+const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
+const int32_t **alpSrc  = (const int32_t**)alpSrcx;
+static const float float_mult = 1.0f / 65535.0f;
+
+for (i = 0; i < dstW; i++) {
+int j;
+int Y = -0x4000;
+int U = -(128 << 23);
+int V = -(128 << 23);
+int R, G, B, A;
+
+for (j = 0; j < lumFilterSize; j++)
+Y += lumSrc[j][i] * (unsigned)lumFilter[j];
+
+for (j = 0; j < chrFilterSize; j++) {
+U += chrUSrc[j][i] * (unsigned)chrFilter[j];
+V += chrVSrc[j][i] * (unsigned)chrFilter[j];
+}
+
+Y >>= 14;
+Y += 0x1;
+U >>= 14;
+V >>= 14;
+
+if (hasAlpha) {
+A = -0x4000;
+
+for (j = 0; j < lumFilterSize; j++)
+A += alpSrc[j][i] * (unsigned)lumFilter[j];
+
+A >>= 1;
+A += 0x20002000;
+}
+
+Y -= c->yuv2rgb_y_offset;
+Y *= c->yuv2rgb_y_coeff;
+Y += 1 << 13;
+R = V * c->yuv2rgb_v2r_coeff;
+G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
+B =U * c->yuv2rgb_u2b_coeff;
+
+R = av_clip_uintp2(Y + R, 30);
+G = av_clip_uintp2(Y + G, 30);
+B = av_clip_uintp2(Y + B, 30);
+
+dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
+dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
+dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
+if (hasAlpha)
+dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 
30) >> 14));
+}
+if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
+for (i = 0; i < dstW; i++) {
+dest32[0][i] = av_bswap32(dest32[0][i]);
+dest32[1][i] = av_bswap32(dest32[1][i]);
+dest32[2][i] = av_bswap32(dest32[2][i]);
+if (hasAlpha)
+dest32[3][i] = av_bswap32(dest32[3][i]);
+}
+}
+}
+
 static void
 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
 const int16_t *ubuf[2], const int16_t *vbuf[2],
@@ -2716,6 +2792,12 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
 case AV_PIX_FMT_GBRAP16LE:
 *yuv2anyX = yuv2gbrp16_full_X_c;
 break;
+case AV_PIX_FMT_GBRPF32BE:
+case AV_PIX_FMT_GBRPF32LE:
+case AV_PIX_FMT_GBRAPF32BE:
+case AV_PIX_FMT_GBRAPF32LE:
+*yuv2anyX = yuv2gbrpf32_full_X_c;
+break;
 }
 if (!*yuv2packedX && !*yuv2anyX)
 goto YUV_PACKED;
diff --git a/libswscale/slice.c b/libswscale/slice.c
index db4fa874ff..7849b70f4d 100644

Re: [FFmpeg-devel] [PATCH 3/3 v4] avcodec/cbs_h265: add missing support for reserved_payload_extension_data SEI bits

2020-05-03 Thread James Almer
On 5/3/2020 7:22 PM, Mark Thompson wrote:
> On 03/05/2020 16:55, James Almer wrote:
>> On 5/3/2020 12:39 PM, Mark Thompson wrote:
>>> On 30/04/2020 22:50, James Almer wrote:
 Fixes ticket #8622

 Signed-off-by: James Almer 
 ---
  libavcodec/cbs_h2645.c|  1 +
  libavcodec/cbs_h265.h |  1 +
  libavcodec/cbs_h265_syntax_template.c | 85 +--
  3 files changed, 70 insertions(+), 17 deletions(-)

 diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
 index 095e449ddc..b432921ecc 100644
 --- a/libavcodec/cbs_h2645.c
 +++ b/libavcodec/cbs_h2645.c
 @@ -553,6 +553,7 @@ static void 
 cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
  av_buffer_unref(&payload->payload.other.data_ref);
  break;
  }
 +av_buffer_unref(&payload->extension_data.data_ref);
  }
  
  static void cbs_h265_free_sei(void *opaque, uint8_t *content)
 diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
 index 2c1e153ad9..73897f77a4 100644
 --- a/libavcodec/cbs_h265.h
 +++ b/libavcodec/cbs_h265.h
 @@ -715,6 +715,7 @@ typedef struct H265RawSEIPayload {
  AVBufferRef *data_ref;
  } other;
  } payload;
 +H265RawExtensionData extension_data;
  } H265RawSEIPayload;
  
  typedef struct H265RawSEI {
 diff --git a/libavcodec/cbs_h265_syntax_template.c 
 b/libavcodec/cbs_h265_syntax_template.c
 index ed08b06e9c..d3ac618db6 100644
 --- a/libavcodec/cbs_h265_syntax_template.c
 +++ b/libavcodec/cbs_h265_syntax_template.c
 @@ -1564,7 +1564,8 @@ static int 
 FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
  
  static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, 
 RWContext *rw,
H265RawSEIBufferingPeriod *current,
 -  uint32_t *payload_size)
 +  uint32_t *payload_size,
 +  int *more_data)
  {
  CodedBitstreamH265Context *h265 = ctx->priv_data;
  const H265RawSPS *sps;
 @@ -1658,8 +1659,15 @@ static int 
 FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
  else
  infer(use_alt_cpb_params_flag, 0);
  #else
 -if (current->use_alt_cpb_params_flag)
 +// If unknown extension data exists, then use_alt_cpb_params_flag is
 +// coded in the bitstream and must be written even if it's 0.
 +if (current->use_alt_cpb_params_flag || *more_data) {
  flag(use_alt_cpb_params_flag);
 +// Ensure this bit is not the last in the payload by making the
 +// more_data_in_payload() check evaluate to true, so it may not
 +// be mistaken as something else by decoders.
 +*more_data = 1;
 +}
  #endif
  
  return 0;
 @@ -2057,11 +2065,48 @@ static int 
 FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
  return 0;
  }
  
 +static int FUNC(payload_extension)(CodedBitstreamContext *ctx, RWContext 
 *rw,
 +   H265RawExtensionData *current, 
 uint32_t payload_size,
 +   int cur_pos)
 +{
 +int err;
 +size_t byte_length, k;
 +
 +#ifdef READ
 +GetBitContext tmp;
 +int bits_left, payload_zero_bits;
 +
 +if (!cbs_h265_payload_extension_present(rw, payload_size, cur_pos))
 +return 0;
 +
 +bits_left = 8 * payload_size - cur_pos;
 +tmp = *rw;
 +if (bits_left > 8)
 +skip_bits_long(&tmp, bits_left - 8);
 +payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
 +if (!payload_zero_bits)
 +return AVERROR_INVALIDDATA;
 +payload_zero_bits = ff_ctz(payload_zero_bits);
 +current->bit_length = bits_left - payload_zero_bits - 1;
 +allocate(current->data, (current->bit_length + 7) / 8);
 +#endif
 +
 +byte_length = (current->bit_length + 7) / 8;
 +for (k = 0; k < byte_length; k++) {
 +int length = FFMIN(current->bit_length - k * 8, 8);
 +xu(length, reserved_payload_extension_data, current->data[k],
 +   0, MAX_UINT_BITS(length), 0);
 +}
 +
 +return 0;
 +}
 +
  static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
   H265RawSEIPayload *current, int prefix)
  {
  int err, i;
 -int start_position, end_position;
 +int start_position, current_position;
 +int more_data = !!current->extension_data.bit_length;
  
  #ifdef READ
  start_position = get_bits_count(rw);
 @@ -2093,8 +2138,

[FFmpeg-devel] [PATCH] lavc/bsf: add an Opus metadata bitstream filter

2020-05-03 Thread Lynne
The only adjustable field is the gain. Some ripping/transcoding programs 
have started to use it for replaygain adjustments.

Patch attached.

>From 44f83786e057d468efee986ee865ba8c776ebe9b Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Sun, 3 May 2020 21:17:33 +0100
Subject: [PATCH] lavc/bsf: add an Opus metadata bitstream filter

The only adjustable field is the gain. Some ripping/transcoding programs
have started to use it.
---
 libavcodec/Makefile|  1 +
 libavcodec/bitstream_filters.c |  1 +
 libavcodec/opus_metadata_bsf.c | 72 ++
 3 files changed, 74 insertions(+)
 create mode 100644 libavcodec/opus_metadata_bsf.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 28076c2c83..cf72f55aff 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_OPUS_METADATA_BSF)  += opus_metadata_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..f1b24baa53 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_opus_metadata_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/opus_metadata_bsf.c b/libavcodec/opus_metadata_bsf.c
new file mode 100644
index 00..f0d794c1b3
--- /dev/null
+++ b/libavcodec/opus_metadata_bsf.c
@@ -0,0 +1,72 @@
+/*
+ * 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 "bsf.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+typedef struct OpusBSFContext {
+const AVClass *class;
+int64_t gain;
+} OpusBSFContext;
+
+static int opus_metadata_filter(AVBSFContext *bsfc, AVPacket *pkt)
+{
+return ff_bsf_get_packet_ref(bsfc, pkt);
+}
+
+static int opus_metadata_init(AVBSFContext *bsfc)
+{
+OpusBSFContext *s = bsfc->priv_data;
+
+if (bsfc->par_out->extradata_size < 19)
+return AVERROR_INVALIDDATA;
+
+AV_WL16(bsfc->par_out->extradata + 16, s->gain);
+
+return 0;
+}
+
+#define OFFSET(x) offsetof(OpusBSFContext, x)
+#define FLAGS (AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_BSF_PARAM)
+static const AVOption opus_metadata_options[] = {
+{ "gain", "Gain, actual amplification is pow(10, gain/(20.0*256))", OFFSET(gain),
+  AV_OPT_TYPE_INT, { .i64 = 0 }, -(INT16_MAX + 1), INT16_MAX, .flags = FLAGS },
+
+{ NULL },
+};
+
+static const AVClass opus_metadata_class = {
+.class_name = "opus_metadata_bsf",
+.item_name  = av_default_item_name,
+.option = opus_metadata_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+static const enum AVCodecID codec_ids[] = {
+AV_CODEC_ID_OPUS, AV_CODEC_ID_NONE,
+};
+
+const AVBitStreamFilter ff_opus_metadata_bsf = {
+.name   = "opus_metadata",
+.priv_data_size = sizeof(OpusBSFContext),
+.priv_class = &opus_metadata_class,
+.init   = &opus_metadata_init,
+.filter = &opus_metadata_filter,
+.codec_ids  = codec_ids,
+};
-- 
2.26.2

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: add FF_CODEC_CAP_INIT_CLEANUP caps for encoders

2020-05-03 Thread Fu, Linjie
> From: ffmpeg-devel  On Behalf Of Fu,
> Linjie
> Sent: Thursday, April 23, 2020 22:59
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: add
> FF_CODEC_CAP_INIT_CLEANUP caps for encoders
> 
> > From: Fu, Linjie 
> > Sent: Tuesday, March 31, 2020 23:34
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Fu, Linjie 
> > Subject: [PATCH] lavc/vaapi_encode: add FF_CODEC_CAP_INIT_CLEANUP
> > caps for encoders
> >
> > ff_vaapi_encode_close() is not enough to free the resources like cbs
> > if initialization failure happens after codec->configure (except for
> > vp8/vp9).
> >
> > We need to call avctx->codec->close() to deallocate, otherwise memory
> > leak happens.
> >
> > Add FF_CODEC_CAP_INIT_CLEANUP for vaapi encoders and deallocate the
> > resources at free_and_end inside avcodec_open2().
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  libavcodec/vaapi_encode.c   | 1 -
> >  libavcodec/vaapi_encode_h264.c  | 1 +
> >  libavcodec/vaapi_encode_h265.c  | 1 +
> >  libavcodec/vaapi_encode_mjpeg.c | 1 +
> >  libavcodec/vaapi_encode_mpeg2.c | 1 +
> >  libavcodec/vaapi_encode_vp8.c   | 1 +
> >  libavcodec/vaapi_encode_vp9.c   | 1 +
> >  7 files changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > index 8ff720e..d371033 100644
> > --- a/libavcodec/vaapi_encode.c
> > +++ b/libavcodec/vaapi_encode.c
> > @@ -2361,7 +2361,6 @@ av_cold int
> ff_vaapi_encode_init(AVCodecContext
> > *avctx)
> >  return 0;
> >
> >  fail:
> > -ff_vaapi_encode_close(avctx);
> >  return err;
> >  }
> >
> > diff --git a/libavcodec/vaapi_encode_h264.c
> > b/libavcodec/vaapi_encode_h264.c
> > index f4965d8..6a86905 100644
> > --- a/libavcodec/vaapi_encode_h264.c
> > +++ b/libavcodec/vaapi_encode_h264.c
> > @@ -1356,6 +1356,7 @@ AVCodec ff_h264_vaapi_encoder = {
> >  .close  = &vaapi_encode_h264_close,
> >  .priv_class = &vaapi_encode_h264_class,
> >  .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
> > +.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> >  .defaults   = vaapi_encode_h264_defaults,
> >  .pix_fmts = (const enum AVPixelFormat[]) {
> >  AV_PIX_FMT_VAAPI,
> > diff --git a/libavcodec/vaapi_encode_h265.c
> > b/libavcodec/vaapi_encode_h265.c
> > index 97dc5a7..4c24f7c 100644
> > --- a/libavcodec/vaapi_encode_h265.c
> > +++ b/libavcodec/vaapi_encode_h265.c
> > @@ -1292,6 +1292,7 @@ AVCodec ff_hevc_vaapi_encoder = {
> >  .close  = &vaapi_encode_h265_close,
> >  .priv_class = &vaapi_encode_h265_class,
> >  .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
> > +.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> >  .defaults   = vaapi_encode_h265_defaults,
> >  .pix_fmts = (const enum AVPixelFormat[]) {
> >  AV_PIX_FMT_VAAPI,
> > diff --git a/libavcodec/vaapi_encode_mjpeg.c
> > b/libavcodec/vaapi_encode_mjpeg.c
> > index bd029cc..c469e70 100644
> > --- a/libavcodec/vaapi_encode_mjpeg.c
> > +++ b/libavcodec/vaapi_encode_mjpeg.c
> > @@ -565,6 +565,7 @@ AVCodec ff_mjpeg_vaapi_encoder = {
> >  .priv_class = &vaapi_encode_mjpeg_class,
> >  .capabilities   = AV_CODEC_CAP_HARDWARE |
> >AV_CODEC_CAP_INTRA_ONLY,
> > +.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> >  .defaults   = vaapi_encode_mjpeg_defaults,
> >  .pix_fmts = (const enum AVPixelFormat[]) {
> >  AV_PIX_FMT_VAAPI,
> > diff --git a/libavcodec/vaapi_encode_mpeg2.c
> > b/libavcodec/vaapi_encode_mpeg2.c
> > index bac9ea1..55f9289 100644
> > --- a/libavcodec/vaapi_encode_mpeg2.c
> > +++ b/libavcodec/vaapi_encode_mpeg2.c
> > @@ -702,6 +702,7 @@ AVCodec ff_mpeg2_vaapi_encoder = {
> >  .close  = &vaapi_encode_mpeg2_close,
> >  .priv_class = &vaapi_encode_mpeg2_class,
> >  .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
> > +.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> >  .defaults   = vaapi_encode_mpeg2_defaults,
> >  .pix_fmts = (const enum AVPixelFormat[]) {
> >  AV_PIX_FMT_VAAPI,
> > diff --git a/libavcodec/vaapi_encode_vp8.c
> > b/libavcodec/vaapi_encode_vp8.c
> > index 6e7bf9d..d8fb031 100644
> > --- a/libavcodec/vaapi_encode_vp8.c
> > +++ b/libavcodec/vaapi_encode_vp8.c
> > @@ -257,6 +257,7 @@ AVCodec ff_vp8_vaapi_encoder = {
> >  .close  = &ff_vaapi_encode_close,
> >  .priv_class = &vaapi_encode_vp8_class,
> >  .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
> > +.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> >  .defaults   = vaapi_encode_vp8_defaults,
> >  .pix_fmts = (const enum AVPixelFormat[]) {
> >  AV_PIX_FMT_VAAPI,
> > diff --git a/libavcodec/vaapi_encode_vp9.c
> > b/libavcodec/vaapi_encode_vp9.c
> > index d7f415d..ea19470 100644
> > --- a/libavcodec/vaapi_encode_vp9.c
> > +++ b/libavcodec/vaapi_encode_vp9.c
> > @@ -291,6 +291,7 @@ AVCodec ff_vp9_vaapi_encoder = {
> >  .close

Re: [FFmpeg-devel] [PATCH v1] avcodec/h264_metadata_bsf: add option to delete SEI user data

2020-05-03 Thread lance . lmwang
On Sun, May 03, 2020 at 03:56:58PM +0100, Mark Thompson wrote:
> On 20/04/2020 12:01, lance.lmw...@gmail.com wrote:
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> >  doc/bitstream_filters.texi |  3 +++
> >  libavcodec/h264_metadata_bsf.c | 19 +++
> >  2 files changed, 22 insertions(+)
> > 
> > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> > index 8fe5b3ad75..652eb4620f 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -273,6 +273,9 @@ possibly separated by hyphens, and the string can be 
> > anything.
> >  For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
> >  insert the string ``hello'' associated with the given UUID.
> >  
> > +@item delete_user_data
> > +Deletes all SEI user data messages.
> > +
> >  @item delete_filler
> >  Deletes both filler NAL units and filler SEI messages.
> >  
> > diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> > index d96a50dbf7..8b42faff1b 100644
> > --- a/libavcodec/h264_metadata_bsf.c
> > +++ b/libavcodec/h264_metadata_bsf.c
> > @@ -76,6 +76,7 @@ typedef struct H264MetadataContext {
> >  int crop_bottom;
> >  
> >  const char *sei_user_data;
> > +int delete_user_data;
> >  
> >  int delete_filler;
> >  
> > @@ -361,6 +362,21 @@ static int h264_metadata_filter(AVBSFContext *bsf, 
> > AVPacket *pkt)
> >  }
> >  }
> >  
> > +if (ctx->delete_user_data) {
> > +for (i = au->nb_units - 1; i >= 0; i--) {
> > +if (au->units[i].type == H264_NAL_SEI) {
> > +H264RawSEI *sei = au->units[i].content;
> > +
> > +for (j = sei->payload_count - 1; j >= 0; j--) {
> > +if (sei->payload[j].payload_type ==
> > +H264_SEI_TYPE_USER_DATA_UNREGISTERED)
> > +ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> > +   &au->units[i], j);
> > +}
> > +}
> > +}
> > +}
> > +
> >  // Only insert the SEI in access units containing SPSs, and also
> >  // unconditionally in the first access unit we ever see.
> >  if (ctx->sei_user_data && (has_sps || !ctx->done_first_au)) {
> > @@ -684,6 +700,9 @@ static const AVOption h264_metadata_options[] = {
> >  { "sei_user_data", "Insert SEI user data (UUID+string)",
> >  OFFSET(sei_user_data), AV_OPT_TYPE_STRING, { .str = NULL }, .flags 
> > = FLAGS },
> >  
> > +{ "delete_user_data", "Delete all SEI user data",
> > +OFFSET(delete_user_data), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, 
> > FLAGS},
> > +
> >  { "delete_filler", "Delete all filler (both NAL and SEI)",
> >  OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS},
> >  
> > 
> 
> This approach is too general, because stripping everything includes notes 
> which may be required to correctly decode the stream.  An option like this 
> was suggested a while ago and rejected because of the old nonstandard libx264 
> streams which have decoding broken by it.

I haven't notice other alike patch have submit and reject. I'll try to search 
the thread to check.

> 
> Can you explain your intended use-case?  Perhaps a delete option which takes 
> a UUID argument and removes any SEI UDU matching it?

We may do stream copy for some h264 stream, so we don't want to keep all of the 
old SEI
user data. If delete one of the UUID matching SEI, it's better to take a UUID
options, also user had to know the UUID first.  

> 
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v4] avcodec/options_table: Support mpeg2 encoder profile with const options

2020-05-03 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavcodec/options_table.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 5436674..044a8a2 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -280,6 +280,10 @@ static const AVOption avcodec_options[] = {
 {"mpeg4_core", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_CORE }, 
INT_MIN, INT_MAX, V|E, "profile"},
 {"mpeg4_main", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_MAIN }, 
INT_MIN, INT_MAX, V|E, "profile"},
 {"mpeg4_asp",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_PROFILE_MPEG4_ADVANCED_SIMPLE }, INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg2_422",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG2_422 }, 
INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg2_high", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG2_HIGH }, 
INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg2_main", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG2_MAIN }, 
INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg2_simple", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG2_SIMPLE 
}, INT_MIN, INT_MAX, V|E, "profile"},
 {"main10",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_HEVC_MAIN_10 }, 
INT_MIN, INT_MAX, V|E, "profile"},
 {"msbc",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_SBC_MSBC }, INT_MIN, 
INT_MAX, A|E, "profile"},
 {"level", NULL, OFFSET(level), AV_OPT_TYPE_INT, {.i64 = FF_LEVEL_UNKNOWN }, 
INT_MIN, INT_MAX, V|A|E, "level"},
-- 
2.6.4

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/hlsenc: resend full url of the init fragment mp4

2020-05-03 Thread Steven Liu
fix ticket: 8651
because the init fragment mp4 file name is without base url name,
so just modify it use the full url which splice after init function.

Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 4a83db04e9..4c3c643773 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2258,7 +2258,7 @@ static int hls_init_file_resend(AVFormatContext *s, 
VariantStream *vs)
 int ret = 0;
 
 set_http_options(s, &options, hls);
-ret = hlsenc_io_open(s, &vs->out, hls->fmp4_init_filename, &options);
+ret = hlsenc_io_open(s, &vs->out, vs->base_output_dirname, &options);
 av_dict_free(&options);
 if (ret < 0)
 return ret;
-- 
2.25.0




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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: add FF_CODEC_CAP_INIT_CLEANUP caps for encoders

2020-05-03 Thread Timo Rothenpieler

On 31.03.2020 17:34, Linjie Fu wrote:

ff_vaapi_encode_close() is not enough to free the resources like cbs
if initialization failure happens after codec->configure (except for
vp8/vp9).

We need to call avctx->codec->close() to deallocate, otherwise memory
leak happens.

Add FF_CODEC_CAP_INIT_CLEANUP for vaapi encoders and deallocate the
resources at free_and_end inside avcodec_open2().

Signed-off-by: Linjie Fu 


Not my area of code, but the patch looks straight forward enough to my eyes.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments

2020-05-03 Thread Andreas Rheinhardt
John Stebbins:
> On Sat, 2020-05-02 at 22:30 +0200, Andreas Rheinhardt wrote:
>> John Stebbins:
>>> Required to remux m2ts to mkv
>>> ---
>>>  Changelog|   1 +
>>>  doc/bitstream_filters.texi   |   8 ++
>>>  libavcodec/Makefile  |   1 +
>>>  libavcodec/bitstream_filters.c   |   1 +
>>>  libavcodec/pgs_frame_merge_bsf.c | 168
>>> +++
>>>  5 files changed, 179 insertions(+)
>>>  create mode 100644 libavcodec/pgs_frame_merge_bsf.c
>>>
>>> diff --git a/Changelog b/Changelog
>>> index d9fcd8bb0a..fec4867488 100644
>>> --- a/Changelog
>>> +++ b/Changelog
>>> @@ -59,6 +59,7 @@ version :
>>>  - mv30 decoder
>>>  - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
>>>  - WebP parser
>>> +- PGS subtitle frame merge bitstream filter
>>>  
>>>  
>>>  version 4.2:
>>> diff --git a/doc/bitstream_filters.texi
>>> b/doc/bitstream_filters.texi
>>> index 8fe5b3ad75..21ed09986c 100644
>>> --- a/doc/bitstream_filters.texi
>>> +++ b/doc/bitstream_filters.texi
>>> @@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1]
>>> output.mkv
>>>  @section null
>>>  This bitstream filter passes the packets through unchanged.
>>>  
>>> +@section pgs_frame_merge
>>> +
>>> +Merge a sequence of PGS Subtitle segments ending with an "end of
>>> display set"
>>> +segment into a single packet.
>>> +
>>> +This is required by some containers that support PGS subtitles
>>> +(muxer @code{matroska}).
>>> +
>>>  @section prores_metadata
>>>  
>>>  Modify color property metadata embedded in prores stream.
>>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>>> index 88944d9a3a..b630de21bc 100644
>>> --- a/libavcodec/Makefile
>>> +++ b/libavcodec/Makefile
>>> @@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  +=
>>> mp3_header_decompress_bsf.o \
>>>  OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
>>>  OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
>>>  OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
>>> +OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
>>>  OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
>>>  OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   +=
>>> remove_extradata_bsf.o
>>>  OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
>>> diff --git a/libavcodec/bitstream_filters.c
>>> b/libavcodec/bitstream_filters.c
>>> index 6b5ffe4d70..92619225f0 100644
>>> --- a/libavcodec/bitstream_filters.c
>>> +++ b/libavcodec/bitstream_filters.c
>>> @@ -49,6 +49,7 @@ extern const AVBitStreamFilter
>>> ff_mpeg4_unpack_bframes_bsf;
>>>  extern const AVBitStreamFilter ff_mov2textsub_bsf;
>>>  extern const AVBitStreamFilter ff_noise_bsf;
>>>  extern const AVBitStreamFilter ff_null_bsf;
>>> +extern const AVBitStreamFilter ff_pgs_frame_merge_bsf;
>>>  extern const AVBitStreamFilter ff_prores_metadata_bsf;
>>>  extern const AVBitStreamFilter ff_remove_extradata_bsf;
>>>  extern const AVBitStreamFilter ff_text2movsub_bsf;
>>> diff --git a/libavcodec/pgs_frame_merge_bsf.c
>>> b/libavcodec/pgs_frame_merge_bsf.c
>>> new file mode 100644
>>> index 00..cae5c75655
>>> --- /dev/null
>>> +++ b/libavcodec/pgs_frame_merge_bsf.c
>>> @@ -0,0 +1,168 @@
>>> +/*
>>> + * Copyright (c) 2020 John Stebbins 
>>> + *
>>> + * 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
>>> + * This bitstream filter merges PGS subtitle packets containing
>>> incomplete
>>> + * set of segments into a single packet
>>> + *
>>> + * Packets already containing a complete set of segments will be
>>> passed through
>>> + * unchanged.
>>> + */
>>> +
>>> +#include "avcodec.h"
>>> +#include "bsf.h"
>>> +#include "libavutil/intreadwrite.h"
>>> +
>>> +enum PGSSegmentType {
>>> +PALETTE_SEGMENT  = 0x14,
>>> +OBJECT_SEGMENT   = 0x15,
>>> +PRESENTATION_SEGMENT = 0x16,
>>> +WINDOW_SEGMENT   = 0x17,
>>> +DISPLAY_SEGMENT  = 0x80,
>>> +};
>>> +
>>> +typedef struct PGSMergeContext {
>>> +AVPacket *buffer_pkt, *in;
>>> +int presentation_found;
>>> +} PGSMergeContext;
>>> +
>>> +static void frame_merge_flush(AVBSFContext *bsf)
>>> +{
>>> +PGSMergeContext *ctx = bsf->priv_d

Re: [FFmpeg-devel] [RFC][PATCH] avfilter: add speechnorm filter

2020-05-03 Thread Andreas Rheinhardt
Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/Makefile|   1 +
>  libavfilter/af_speechnorm.c | 381 
>  libavfilter/allfilters.c|   1 +
>  3 files changed, 383 insertions(+)
>  create mode 100644 libavfilter/af_speechnorm.c
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index f982afe15f..421a01753e 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -134,6 +134,7 @@ OBJS-$(CONFIG_SIDECHAINGATE_FILTER)  += af_agate.o
>  OBJS-$(CONFIG_SILENCEDETECT_FILTER)  += af_silencedetect.o
>  OBJS-$(CONFIG_SILENCEREMOVE_FILTER)  += af_silenceremove.o
>  OBJS-$(CONFIG_SOFALIZER_FILTER)  += af_sofalizer.o
> +OBJS-$(CONFIG_SPEECHNORM_FILTER) += af_speechnorm.o
>  OBJS-$(CONFIG_STEREOTOOLS_FILTER)+= af_stereotools.o
>  OBJS-$(CONFIG_STEREOWIDEN_FILTER)+= af_stereowiden.o
>  OBJS-$(CONFIG_SUPEREQUALIZER_FILTER) += af_superequalizer.o
> diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c
> new file mode 100644
> index 00..52fc8e6e42
> --- /dev/null
> +++ b/libavfilter/af_speechnorm.c
> @@ -0,0 +1,381 @@
> +/*
> + * Speech Normalizer
> + * Copyright (c) 2020 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
> + */
> +
> +/**
> + * @file
> + * Speech Normalizer
> + */
> +
> +#include 
> +
> +#include "libavutil/avassert.h"
> +#include "libavutil/opt.h"
> +
> +#define FF_BUFQUEUE_SIZE (1024)
> +#include "bufferqueue.h"
> +
> +#include "audio.h"
> +#include "avfilter.h"
> +#include "filters.h"
> +#include "internal.h"
> +
> +#define MAX_ITEMS  882000
> +
> +typedef struct PeriodItem {
> +int size;
> +int type;
> +double max_peak;
> +} PeriodItem;
> +
> +typedef struct SpeechNormalizerContext {
> +const AVClass *class;
> +
> +double peak_value;
> +double max_amplification;
> +double threshold_value;
> +double feedback;
> +double decay;
> +int channels;
> +
> +int max_period;
> +int eof;
> +int64_t pts;
> +int state[12];
> +
> +PeriodItem pi[12][MAX_ITEMS];
> +double gain_state[12];
> +int pi_start[12];
> +int pi_end[12];
> +
> +struct FFBufQueue queue;
> +} SpeechNormalizerContext;
> +
> +#define OFFSET(x) offsetof(SpeechNormalizerContext, x)
> +#define FLAGS 
> AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
> +
> +static const AVOption speechnorm_options[] = {
> +{ "peak","set the peak value",  OFFSET(peak_value),  
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.95},  0.0, 1.0, FLAGS },
> +{ "p",   "set the peak value",  OFFSET(peak_value),  
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.95},  0.0, 1.0, FLAGS },
> +{ "maxgain", "set the max amplification",   
> OFFSET(max_amplification),   AV_OPT_TYPE_DOUBLE, {.dbl = 2.0},   1.0,
> 10.0, FLAGS },
> +{ "m",   "set the max amplification",   
> OFFSET(max_amplification),   AV_OPT_TYPE_DOUBLE, {.dbl = 2.0},   1.0,
> 10.0, FLAGS },
> +{ "threshold",   "set the threshold value", OFFSET(threshold_value), 
> AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0.0, 1.0, FLAGS },
> +{ "t",   "set the threshold value", OFFSET(threshold_value), 
> AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0.0, 1.0, FLAGS },
> +{ "feedback","set the feedback value",  OFFSET(feedback),
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.001}, 0.0, 1.0, FLAGS },
> +{ "f",   "set the feedback value",  OFFSET(feedback),
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.001}, 0.0, 1.0, FLAGS },
> +{ "decay",   "set the decay value", OFFSET(decay),   
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.999}, 0.0, 1.0, FLAGS },
> +{ "d",   "set the decay value", OFFSET(decay),   
> AV_OPT_TYPE_DOUBLE, {.dbl = 0.999}, 0.0, 1.0, FLAGS },
> +{ NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(speechnorm);
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +AVFilterFormats *formats;
> +AVFilterChannelLayouts *layouts;
> +static const enum AVSampleFormat sample_fmts[] = {
> +AV_