Re: [FFmpeg-devel] [PATCH v7 3/3] lavc, doc, configure: add avs2 video decoder wrapper

2018-07-04 Thread Gyan Doshi



On 05-07-2018 10:42 AM, hwren wrote:


+
+libdavs2 uses GPLv2, so you may also need to add @code{--enable-gpl} while 
configuring.


Is it permissible to link against GPLv3 ffmpeg build? If yes, please 
change above line to what x264 section currently has.


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


Re: [FFmpeg-devel] [PATCH v6 4/4] lavc, doc, configure: add avs2 video decoder

2018-07-04 Thread hwren
Almost another one.


hwrenx.











At 2018-07-04 04:28:16, "Carl Eugen Hoyos"  wrote:
>2018-07-03 6:22 GMT+02:00, hwren :
>
>> +- AVS2 video decoder via libdavs2
>
>Is this related to ticket #6948 or is this another codec?
>
>Carl Eugen
>___
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v7 2/3] lavf: add avs2 fourcc

2018-07-04 Thread hwren
Signed-off-by: hwren 
---
 libavformat/riff.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/riff.c b/libavformat/riff.c
index 8911725..4153372 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -369,6 +369,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
 { AV_CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
 { AV_CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
 { AV_CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
+{ AV_CODEC_ID_AVS2, MKTAG('A', 'V', 'S', '2') },
 { AV_CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') },
 { AV_CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
 { AV_CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') },
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v7 1/3] lavc: add avs2 parser

2018-07-04 Thread hwren
Signed-off-by: hwren 
---
 libavcodec/Makefile  |  1 +
 libavcodec/avcodec.h |  1 +
 libavcodec/avs2_parser.c | 95 
 libavcodec/codec_desc.c  |  7 
 libavcodec/parser.c  |  1 +
 libavcodec/version.h |  4 +-
 6 files changed, 107 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/avs2_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3ab071a..6b6d6de 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -994,6 +994,7 @@ OBJS-$(CONFIG_AAC_PARSER)  += aac_parser.o 
aac_ac3_parser.o \
   mpeg4audio.o
 OBJS-$(CONFIG_AC3_PARSER)  += ac3tab.o aac_ac3_parser.o
 OBJS-$(CONFIG_ADX_PARSER)  += adx_parser.o adx.o
+OBJS-$(CONFIG_AVS2_PARSER) += avs2_parser.o
 OBJS-$(CONFIG_BMP_PARSER)  += bmp_parser.o
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)+= cavs_parser.o
 OBJS-$(CONFIG_COOK_PARSER) += cook_parser.o
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c90166d..1ac9092 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -409,6 +409,7 @@ enum AVCodecID {
 AV_CODEC_ID_DXV,
 AV_CODEC_ID_SCREENPRESSO,
 AV_CODEC_ID_RSCC,
+AV_CODEC_ID_AVS2,
 
 AV_CODEC_ID_Y41P = 0x8000,
 AV_CODEC_ID_AVRP,
diff --git a/libavcodec/avs2_parser.c b/libavcodec/avs2_parser.c
new file mode 100644
index 000..163b297
--- /dev/null
+++ b/libavcodec/avs2_parser.c
@@ -0,0 +1,95 @@
+/*
+ * AVS2/IEEE 1857.4 video parser.
+ * Copyright (c) 2018  Huiwen Ren 
+ *
+ * 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 "parser.h"
+
+#define SLICE_MAX_START_CODE0x01af
+
+#define ISPIC(x)  ((x) == 0xB3 || (x) == 0xB6)
+#define ISUNIT(x) ((x) == 0xB0 || (x) == 0xB1 || (x) == 0xB2 || ISPIC(x))
+
+static int avs2_find_frame_end(ParseContext *pc, const uint8_t *buf, int 
buf_size) 
+{
+int pic_found  = pc->frame_start_found;
+uint32_t state = pc->state;
+int cur = 0;
+
+if (!pic_found) {
+for (; cur < buf_size; ++cur) {
+state = (state<<8) | buf[cur];
+if (ISUNIT(buf[cur])){
+++cur;
+pic_found = 1;
+break;
+}
+}
+}
+
+if (pic_found) {
+if (!buf_size)
+return END_NOT_FOUND;
+for (; cur < buf_size; ++cur) {
+state = (state << 8) | buf[cur];
+if ((state & 0xFF00) == 0x100 && state > SLICE_MAX_START_CODE) 
{
+pc->frame_start_found = 0;
+pc->state = -1;
+return cur - 3;
+}
+}
+}
+
+pc->frame_start_found = pic_found;
+pc->state = state;
+
+return END_NOT_FOUND;
+}
+
+static int avs2_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+  const uint8_t **poutbuf, int *poutbuf_size,
+  const uint8_t *buf, int buf_size)
+{
+ParseContext *pc = s->priv_data;
+int next;
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES)  {
+next = buf_size;
+} else {
+next = avs2_find_frame_end(pc, buf, buf_size);
+if (ff_combine_frame(pc, next, , _size) < 0) {
+*poutbuf = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}
+}
+
+*poutbuf = buf;
+*poutbuf_size = buf_size;
+
+return next;
+}
+
+AVCodecParser ff_avs2_parser = {
+.codec_ids  = { AV_CODEC_ID_AVS2 },
+.priv_data_size = sizeof(ParseContext),
+.parser_parse   = avs2_parse,
+.parser_close   = ff_parse_close,
+.split  = ff_mpeg4video_split,
+};
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 36e9a9b..c0ed4d4 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1395,6 +1395,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .props = AV_CODEC_PROP_LOSSLESS,
 },
 {
+.id= AV_CODEC_ID_AVS2,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "avs2",
+.long_name = NULL_IF_CONFIG_SMALL("AVS2/IEEE 1857.4"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
 .id= AV_CODEC_ID_Y41P,
 .type  = 

[FFmpeg-devel] [PATCH v7 3/3] lavc, doc, configure: add avs2 video decoder wrapper

2018-07-04 Thread hwren
Signed-off-by: hwren 
---
 Changelog  |   1 +
 configure  |   4 ++
 doc/decoders.texi  |  10 +++
 doc/general.texi   |   8 +++
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libdavs2.c  | 177 +
 7 files changed, 202 insertions(+)
 create mode 100644 libavcodec/libdavs2.c

diff --git a/Changelog b/Changelog
index d8e2811..ec65f43 100644
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@ version :
 - adeclip filter
 - libtensorflow backend for DNN based filters like srcnn
 - vc1 decoder is now bit-exact
+- AVS2 video decoder via libdavs2
 
 
 version 4.0:
diff --git a/configure b/configure
index 0e8e8a6..059812f 100755
--- a/configure
+++ b/configure
@@ -226,6 +226,7 @@ External library support:
   --enable-libcelt enable CELT decoding via libcelt [no]
   --enable-libcdio enable audio CD grabbing with libcdio [no]
   --enable-libcodec2   enable codec2 en/decoding using libcodec2 [no]
+  --enable-libdavs2enable AVS2 decoding via libdavs2 [no]
   --enable-libdc1394   enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
   --enable-libfdk-aac  enable AAC de/encoding via libfdk-aac [no]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_GPL_LIST="
 avisynth
 frei0r
 libcdio
+libdavs2
 librubberband
 libvidstab
 libx264
@@ -3048,6 +3050,7 @@ libaom_av1_encoder_deps="libaom"
 libcelt_decoder_deps="libcelt"
 libcodec2_decoder_deps="libcodec2"
 libcodec2_encoder_deps="libcodec2"
+libdavs2_decoder_deps="libdavs2"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
 libfdk_aac_encoder_select="audio_frame_queue"
@@ -6001,6 +6004,7 @@ enabled libcelt   && require libcelt celt/celt.h 
celt_decode -lcelt0 &&
die "ERROR: libcelt must be installed and 
version must be >= 0.11.0."; }
 enabled libcaca   && require_pkg_config libcaca caca caca.h 
caca_create_canvas
 enabled libcodec2 && require libcodec2 codec2/codec2.h codec2_create 
-lcodec2
+enabled libdavs2  && require_pkg_config libdavs2 "davs2 >= 1.4.95" 
davs2.h davs2_decoder_open
 enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 
dc1394/dc1394.h dc1394_new
 enabled libdrm&& require_pkg_config libdrm libdrm xf86drm.h 
drmGetVersion
 enabled libfdk_aac&& { check_pkg_config libfdk_aac fdk-aac 
"fdk-aac/aacenc_lib.h" aacEncOpen ||
diff --git a/doc/decoders.texi b/doc/decoders.texi
index 8f07bc1..f119917 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -47,6 +47,16 @@ top-field-first is assumed
 
 @end table
 
+@section libdavs2
+
+AVS2/IEEE 1857.4 video decoder wrapper.
+
+This decoder allows libavcodec to decode AVS2 streams with libdavs2 library.
+Using it requires the presence of the libdavs2 headers and library during
+configuration. You need to explicitly configure the build with 
@code{--enable-libdavs2}.
+
+libdavs2 uses GPLv2, so you may also need to add @code{--enable-gpl} while 
configuring.
+
 @c man end VIDEO DECODERS
 
 @chapter Audio Decoders
diff --git a/doc/general.texi b/doc/general.texi
index 8c3a04b..7e89e95 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -17,6 +17,14 @@ for more formats. None of them are used by default, their 
use has to be
 explicitly requested by passing the appropriate flags to
 @command{./configure}.
 
+@section libdavs2
+
+FFmpeg can make use of the libdavs2 library for AVS2 decoding.
+
+Go to @url{https://github.com/pkuvcl/davs2} and follow the instructions for
+installing the library. Then pass @code{--enable-libdavs2} to configure to
+enable it.
+
 @section Alliance for Open Media libaom
 
 FFmpeg can make use of the libaom library for AV1 decoding.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6b6d6de..5135b97 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -944,6 +944,7 @@ OBJS-$(CONFIG_LIBAOM_AV1_ENCODER) += libaomenc.o
 OBJS-$(CONFIG_LIBCELT_DECODER)+= libcelt_dec.o
 OBJS-$(CONFIG_LIBCODEC2_DECODER)  += libcodec2.o codec2utils.o
 OBJS-$(CONFIG_LIBCODEC2_ENCODER)  += libcodec2.o codec2utils.o
+OBJS-$(CONFIG_LIBDAVS2_DECODER)   += libdavs2.o
 OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
 OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
 OBJS-$(CONFIG_LIBGSM_DECODER) += libgsmdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 90d170b..a59b601 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -667,6 +667,7 @@ extern AVCodec ff_libaom_av1_encoder;
 extern AVCodec ff_libcelt_decoder;
 extern AVCodec ff_libcodec2_encoder;
 extern AVCodec ff_libcodec2_decoder;
+extern AVCodec ff_libdavs2_decoder;
 extern AVCodec ff_libfdk_aac_encoder;
 extern AVCodec ff_libfdk_aac_decoder;
 extern AVCodec ff_libgsm_encoder;
diff --git a/libavcodec/libdavs2.c 

Re: [FFmpeg-devel] [PATCH v6 1/4] lavc,doc: add avs2 codec

2018-07-04 Thread hwren
The decoder could not work well without its parser,
so I merged the parser-patch into the codec-patch.


Thanks for advice, hwrenx.









At 2018-07-04 04:24:39, "Carl Eugen Hoyos"  wrote:
>2018-07-03 6:22 GMT+02:00, hwren :
>> Signed-off-by: hwren 
>> ---
>>  doc/APIchanges  | 3 +++
>>  libavcodec/avcodec.h| 1 +
>>  libavcodec/codec_desc.c | 7 +++
>>  libavcodec/version.h| 4 ++--
>>  4 files changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index efe15ba..3372118 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>>
>>  API changes, most recent first:
>>
>> +2018-07-xx - xx - lavc 58.21.100 - avcodec.h
>> +  Add AV_CODEC_ID_AVS2.
>
>Looking at the file, this seems unneeded to me.
>
>And if nobody requested something else, please merge
>the actual external decoder into this patch (not the
>libavformat changes), together with the configure and
>the doc change.
>
>Wait for another review, Carl Eugen
>___
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/12] avformat/mxfenc: automatically update descriptors klv size

2018-07-04 Thread Michael Niedermayer
On Wed, Jul 04, 2018 at 11:35:03AM -0700, Baptiste Coudurier wrote:
> ---
>  libavformat/mxfenc.c | 80 +---
>  1 file changed, 39 insertions(+), 41 deletions(-)
> 
> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> index 77f60f5874..b98d234f03 100644
> --- a/libavformat/mxfenc.c
> +++ b/libavformat/mxfenc.c
> @@ -1104,14 +1104,16 @@ static void 
> mxf_write_multi_descriptor(AVFormatContext *s)
>  mxf_write_uuid(pb, SubDescriptor, i);
>  }
>  
> -static void mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const 
> UID key, unsigned size)
> +static int64_t mxf_write_generic_desc(AVFormatContext *s, AVStream *st, 
> const UID key)
>  {
>  MXFContext *mxf = s->priv_data;
>  MXFStreamContext *sc = st->priv_data;
>  AVIOContext *pb = s->pb;
> +int64_t pos;
>  
>  avio_write(pb, key, 16);
> -klv_encode_ber4_length(pb, size+20+8+12+20);
> +klv_encode_ber4_length(pb, 0);
> +pos = avio_tell(pb);
>  
>  mxf_write_local_tag(pb, 16, 0x3C0A);
>  mxf_write_uuid(pb, SubDescriptor, st->index);
> @@ -1136,6 +1138,8 @@ static void mxf_write_generic_desc(AVFormatContext *s, 
> AVStream *st, const UID k
>  
>  mxf_write_local_tag(pb, 16, 0x3004);
>  avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
> +
> +return pos;
>  }
>  
>  static const UID mxf_mpegvideo_descriptor_key = { 
> 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00
>  };
> @@ -1172,7 +1176,7 @@ static int get_trc(UID ul, enum 
> AVColorTransferCharacteristic trc)
>  }
>  }
>  
> -static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const 
> UID key, unsigned size)
> +static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const 
> UID key)
>  {
>  MXFStreamContext *sc = st->priv_data;
>  AVIOContext *pb = s->pb;
> @@ -1180,25 +1184,10 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
> AVStream *st, const UID ke
>  int stored_height = (st->codecpar->height+15)/16*16;
>  int display_height;
>  int f1, f2;
> -unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5 + 5*8 + 6;
>  UID transfer_ul = {0};
> +int64_t pos = mxf_write_generic_desc(s, st, key);
>  
> -if (sc->interlaced && sc->field_dominance)
> -desc_size += 5;
> -if (sc->signal_standard)
> -desc_size += 5;
> -if (sc->interlaced)
> -desc_size += 8;
> -if (sc->v_chroma_sub_sample)
> -desc_size += 8;
> -if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED)
> -desc_size += 8 * 3;
> -if (s->oformat == _mxf_d10_muxer)
> -desc_size += 8 + 8 + 8;
> -if (get_trc(transfer_ul, st->codecpar->color_trc) >= 0)
> -desc_size += 20;
> -
> -mxf_write_generic_desc(s, st, key, desc_size);
> +get_trc(transfer_ul, st->codecpar->color_trc);

nice simplification!

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

Those who are best at talking, realize last or never when they are wrong.


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


Re: [FFmpeg-devel] [PATCH v2] lavf/mxfenc: support creating s436m data tracks

2018-07-04 Thread Marton Balint


On Wed, 4 Jul 2018, Baptiste Coudurier wrote:


---
libavformat/mxf.c|  1 +
libavformat/mxfdec.c |  2 ++
libavformat/mxfenc.c | 41 +
libavformat/utils.c  |  6 +-
4 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 8376a2b9bf..451cbcfb2c 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -28,6 +28,7 @@
const MXFCodecUL ff_mxf_data_definition_uls[] = {
{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_VIDEO },
{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_AUDIO },
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x03,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_DATA },
{ { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x6F,0x3C,0x8C,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_VIDEO }, /* LegacyPicture Avid Media Composer MXF */
{ { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x78,0xE1,0xEB,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_AUDIO }, /* LegacySound Avid Media Composer MXF */
{ { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  AVMEDIA_TYPE_DATA },
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index b76beb962f..575126d639 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3299,6 +3299,8 @@ static int mxf_set_pts(MXFContext *mxf, AVStream *st, 
AVPacket *pkt)
return ret;
} else if (track) {
track->sample_count++;
+pkt->dts = pkt->pts = track->sample_count;
+pkt->duration = 1;


You probably need to set pts before increasing sample_count.

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


Re: [FFmpeg-devel] [PATCH v2] lavf/mxfdec: demux s436m as eia608 subtitle track

2018-07-04 Thread Derek Buitenhuis
On 04/07/2018 23:05, Baptiste Coudurier wrote:
> +if (length < 0)
> +return AVERROR_INVALIDDATA;
> +
> +int array_count = avio_rb32(s->pb);
> +int array_elem_size = avio_rb32(s->pb);

Mixed declarations aren't allowed in FFmpeg.

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


[FFmpeg-devel] [PATCH v2] lavf/mxfenc: support creating s436m data tracks

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxf.c|  1 +
 libavformat/mxfdec.c |  2 ++
 libavformat/mxfenc.c | 41 +
 libavformat/utils.c  |  6 +-
 4 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 8376a2b9bf..451cbcfb2c 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -28,6 +28,7 @@
 const MXFCodecUL ff_mxf_data_definition_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_VIDEO },
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_AUDIO },
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x03,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_DATA },
 { { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x6F,0x3C,0x8C,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_VIDEO }, /* LegacyPicture Avid Media Composer MXF */
 { { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x78,0xE1,0xEB,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_AUDIO }, /* LegacySound Avid Media Composer MXF */
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  AVMEDIA_TYPE_DATA },
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index b76beb962f..575126d639 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3299,6 +3299,8 @@ static int mxf_set_pts(MXFContext *mxf, AVStream *st, 
AVPacket *pkt)
 return ret;
 } else if (track) {
 track->sample_count++;
+pkt->dts = pkt->pts = track->sample_count;
+pkt->duration = 1;
 }
 return 0;
 }
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 036adce011..6da27bf4f5 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -175,6 +175,7 @@ static void mxf_write_aes3_desc(AVFormatContext *s, 
AVStream *st);
 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st);
 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st);
 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st);
+static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st);
 
 static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 
},
@@ -361,6 +362,11 @@ static const MXFContainerEssenceEntry 
mxf_essence_container_uls[] = {
   { 
0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 
},
   { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 
},
   mxf_write_mpegvideo_desc },
+// S436M ANC
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 
},
+  { 
0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x17,0x01,0x02,0x00 
},
+  { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x01,0x5C,0x00 
},
+  mxf_write_s436m_anc_desc },
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
   { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
   { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
@@ -695,9 +701,14 @@ static void 
mxf_write_essence_container_refs(AVFormatContext *s)
 
 mxf_write_refs_count(pb, DESCRIPTOR_COUNT(c->essence_container_count));
 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", 
c->essence_container_count);
-for (i = 0; i < c->essence_container_count; i++) {
+for (i = 0; i < s->nb_streams; i++) {
 MXFStreamContext *sc = s->streams[i]->priv_data;
+// check first track of essence container type and only write it once
+if (sc->track_essence_element_key[15] != 0)
+continue;
 avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
+if (c->essence_container_count == 1)
+break;
 }
 
 if (c->essence_container_count > 1)
@@ -1154,6 +1165,7 @@ static int64_t mxf_write_generic_desc(AVFormatContext *s, 
AVStream *st, const UI
 return pos;
 }
 
+static const UID mxf_s436m_anc_descriptor_key = { 
0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 
};
 static const UID mxf_mpegvideo_descriptor_key = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 
};
 static const UID mxf_wav_descriptor_key   = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 
};
 static const UID mxf_aes3_descriptor_key  = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 
};
@@ -1369,6 +1381,12 @@ static void mxf_write_cdci_desc(AVFormatContext *s, 
AVStream *st)
 mxf_update_klv_size(s->pb, pos);
 }
 
+static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st)
+{
+int64_t pos = mxf_write_generic_desc(s, st, 

[FFmpeg-devel] [PATCH v2] lavf/mxfdec: demux s436m as eia608 subtitle track

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfdec.c | 103 +++
 1 file changed, 103 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 575126d639..13226333cc 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -52,6 +52,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timecode.h"
+#include "libavutil/opt.h"
 #include "avformat.h"
 #include "internal.h"
 #include "mxf.h"
@@ -265,6 +266,7 @@ typedef struct MXFIndexTable {
 } MXFIndexTable;
 
 typedef struct MXFContext {
+const AVClass *class; /**< Class for private options. */
 MXFPartition *partitions;
 unsigned partitions_count;
 MXFOP op;
@@ -287,6 +289,7 @@ typedef struct MXFContext {
 int last_forward_partition;
 int nb_index_tables;
 MXFIndexTable *index_tables;
+int eia608_extract;
 } MXFContext;
 
 /* NOTE: klv_offset is not set (-1) for local keys */
@@ -449,6 +452,78 @@ static int find_body_sid_by_offset(MXFContext *mxf, 
int64_t offset)
 return mxf->partitions[a].body_sid;
 }
 
+static int mxf_get_eia608_packet(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int64_t length)
+{
+int count = avio_rb16(s->pb);
+int i, ret;
+
+for (i = 0; i < count; i++) {
+if (length < 6) {
+av_log(s, AV_LOG_ERROR, "error reading s436m packet %"PRId64"\n", 
length);
+return AVERROR_INVALIDDATA;
+}
+int line_num = avio_rb16(s->pb);
+int wrapping_type = avio_r8(s->pb);
+int sample_coding = avio_r8(s->pb);
+int sample_count = avio_rb16(s->pb);
+av_log(s, AV_LOG_DEBUG, "len %"PRId64" line %d wrap type %d coding %d 
count %d\n",
+   length, line_num, wrapping_type, sample_coding, sample_count);
+length -= 6 + 8 + sample_count;
+if (line_num != 9 && line_num != 11)
+break;
+if (sample_coding == 7 || sample_coding == 8 || sample_coding == 9) {
+av_log(s, AV_LOG_ERROR, "unsupported s436m 10 bit sample 
coding\n");
+return 0;
+}
+if (length < 0)
+return AVERROR_INVALIDDATA;
+
+int array_count = avio_rb32(s->pb);
+int array_elem_size = avio_rb32(s->pb);
+av_log(s, AV_LOG_DEBUG, "array count %d elem size %d\n", array_count, 
array_elem_size);
+int did = avio_r8(s->pb);
+int sdid = avio_r8(s->pb);
+int data_count = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "did %x sdid %x count %d\n", did, sdid, 
data_count);
+if (did != 0x61)
+break;
+int cdp_id = avio_rb16(s->pb);
+int cdp_data_count = avio_r8(s->pb);
+int cdp_framing_rate = avio_r8(s->pb) >> 4;
+int cdp_flags = avio_r8(s->pb);
+int cdp_counter = avio_rb16(s->pb);
+int cdp_data_section = avio_r8(s->pb);
+if (cdp_data_section != 0x72) {
+av_log(s, AV_LOG_ERROR, "wrong cdp data section %x\n", 
cdp_data_section);
+return AVERROR_INVALIDDATA;
+}
+int flags = avio_r8(s->pb);
+int cc_count = flags & 0x1f;
+av_log(s, AV_LOG_DEBUG, "cdp id %x dcount %d frame rate %d cdp flags 
%x flags %x "
+   "cc count %d counter %d section %x\n", cdp_id, cdp_data_count, 
cdp_framing_rate,
+   cdp_flags, flags, cc_count, cdp_counter, cdp_data_section);
+ret = av_get_packet(s->pb, pkt, cc_count * 3);
+if (ret < 0)
+return ret;
+if (cdp_data_count - 9 - 4 <  cc_count * 3) {
+av_log(s, AV_LOG_ERROR, "wrong cdp size %d cc count %d\n", 
data_count, cc_count);
+return AVERROR_INVALIDDATA;
+}
+avio_skip(s->pb, data_count - 9 - 4 - cc_count * 3);
+int cdp_footer_section = avio_r8(s->pb);
+if (cdp_footer_section != 0x74) {
+av_log(s, AV_LOG_ERROR, "wrong cdp footer section %x\n", 
cdp_footer_section);
+return AVERROR_INVALIDDATA;
+}
+int cdp_counter2 = avio_rb16(s->pb);
+int cdp_checksum = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "cdp counter %d checksum %x\n", cdp_counter2, 
cdp_checksum);
+break;
+}
+
+return 0;
+}
+
 /* XXX: use AVBitStreamFilter */
 static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket 
*pkt, int64_t length)
 {
@@ -2424,6 +2499,11 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 st->codecpar->codec_type = type;
 if (container_ul->desc)
 av_dict_set(>metadata, "data_type", container_ul->desc, 0);
+if (mxf->eia608_extract &&
+!strcmp(container_ul->desc, "vbi_vanc_smpte_436M")) {
+st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+st->codecpar->codec_id = AV_CODEC_ID_EIA_608;
+}
 }
 if (descriptor->extradata) {
 if (!ff_alloc_extradata(st->codecpar, 

Re: [FFmpeg-devel] [PATCH 09/12] lavf/mxfenc: support creating s436m data tracks

2018-07-04 Thread Baptiste Coudurier
Hi Marton,

On Wed, Jul 4, 2018 at 1:38 PM, Marton Balint  wrote:

>
>
> On Wed, 4 Jul 2018, Baptiste Coudurier wrote:
>
> ---
>> libavformat/mxf.c|  1 +
>> libavformat/mxfdec.c |  3 +++
>> libavformat/mxfenc.c | 41 +
>> libavformat/utils.c  |  6 +-
>> 4 files changed, 46 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavformat/mxf.c b/libavformat/mxf.c
>> index 8376a2b9bf..451cbcfb2c 100644
>> --- a/libavformat/mxf.c
>> +++ b/libavformat/mxf.c
>> @@ -28,6 +28,7 @@
>> const MXFCodecUL ff_mxf_data_definition_uls[] = {
>> { { 
>> 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00
>> }, 13, AVMEDIA_TYPE_VIDEO },
>> { { 
>> 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00
>> }, 13, AVMEDIA_TYPE_AUDIO },
>> +{ { 
>> 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x03,0x00,0x00,0x00
>> }, 13, AVMEDIA_TYPE_DATA },
>> { { 
>> 0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x6F,0x3C,0x8C,0xE1,0x6C,0xEF,0x11,0xD2
>> }, 16, AVMEDIA_TYPE_VIDEO }, /* LegacyPicture Avid Media Composer MXF */
>> { { 
>> 0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x78,0xE1,0xEB,0xE1,0x6C,0xEF,0x11,0xD2
>> }, 16, AVMEDIA_TYPE_AUDIO }, /* LegacySound Avid Media Composer MXF */
>> { { 
>> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
>> },  0,  AVMEDIA_TYPE_DATA },
>> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
>> index 8c417aea26..3f443bbbc9 100644
>> --- a/libavformat/mxfdec.c
>> +++ b/libavformat/mxfdec.c
>> @@ -3291,6 +3291,9 @@ static int mxf_set_pts(MXFContext *mxf, AVStream
>> *st, AVPacket *pkt, int64_t nex
>> int ret = mxf_set_audio_pts(mxf, par, pkt);
>> if (ret < 0)
>> return ret;
>> +} else {
>> +pkt->dts = pkt->pts = mxf->current_edit_unit;
>> +pkt->duration = 1;
>> }
>> return 0;
>> }
>>
>
> Sorry, my clip wrapping patches I just committed conflicted with your work
> here, you should use something like this for this hunk:
>
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -3298,6 +3298,8 @@ static int mxf_set_pts(MXFContext *mxf, AVStream
> *st, AVPacket *pkt)
>  if (ret < 0)
>  return ret;
>  } else if (track) {
> +pkt->dts = pkt->pts = track->sample_count;
> +pkt->duration = 1;
>  track->sample_count++;
>  }
>  return 0;
>
> Thanks,
> Marton
>

No worries, I'll just rebase.

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


Re: [FFmpeg-devel] [PATCH v3 3/3] aadec: fix seeking in mp3 content

2018-07-04 Thread Michael Niedermayer
On Wed, Jul 04, 2018 at 09:32:32AM +0200, Karsten Otto wrote:
> 
> > Am 04.07.2018 um 03:26 schrieb Michael Niedermayer :
> > 
> > Signierter PGP-Teil
> > On Tue, Jul 03, 2018 at 10:25:36PM +0200, Karsten Otto wrote:
> >> TL;DR: I will drop patch 3/3, may rather spend some time investigating why
> >> "ff ee 47 9d“ passes the mp3 header parser. Also, the aa file "index" 
> >> cannot
> >> be used for frame or chapter detection, unfortunately.
> >> 
> >> More details inline below.
> >> 
> >>> Am 03.07.2018 um 02:32 schrieb Michael Niedermayer 
> >>> :
> >>> 
> >>> Signierter PGP-Teil
> >>> On Mon, Jul 02, 2018 at 07:21:43PM +0200, Karsten Otto wrote:
>  
> > Am 02.07.2018 um 10:59 schrieb Michael Niedermayer 
> > :
> > 
> > Signierter PGP-Teil
> > On Thu, Jun 21, 2018 at 06:58:26PM +0200, Karsten Otto wrote:
> >> MP3 frames may not be aligned to aa chunk boundaries. After seeking,
> >> scan for the next valid frame header. Then truncate the packet, and
> >> also adjust timestamp information accordingly.
> >> ---
> >> libavformat/aadec.c | 33 -
> >> 1 file changed, 28 insertions(+), 5 deletions(-)
> > 
> > Please see AVSTREAM_PARSE_TIMESTAMPS
> > 
> > This codec specific code in demuxers should not be needed
> > 
>  I tried that before, and you are right that it takes care of timestamp 
>  adjustments.
>  
>  However, after a seek the parsed packet still contains a partial frame 
>  before the
>  next full one. I had expected libavformat/mpegaudio_parser.c to detect 
>  this
>  situation and discard the fragment, but unfortunately it does not. 
>  Instead it passes
>  it unchanged to the codec, which plays it as a pop or even a very ugly 
>  BLEEEP -
>  painful while wearing headphones!
> >>> 
> >>> I think you mis-diagnose this at least somewhat
> >>> your code searches for a specific mp3 header, the parser and decoder would
> >>> accept a wider range of mp3 variants.
> >>> But both can choose points that are not mp3 frame starts. (if that is the
> >>> problem you are seeing, iam not completely sure it is)
> >>> 
> >> It took a closer look at what happens when I hear a BLEEP: The packet 
> >> begins
> >> with a partial frame, starting with the byte sequence "ff ee 47 9d“. 
> >> Unfortunately,
> >> the mp3 parser indeed accepts this as a valid mp3 header, causing the 
> >> noise.
> >> By looking for the more restricted header, my patch finds the real next 
> >> frame at
> >> offset 78.
> >> 
> >> BTW: Should this sequence actually pass? AFAIK 01 is not a valid MPEG audio
> >> version ID?
> >> 
> >>> Also is the more restricted header you search for always used or could
> >>> this be failing with some files ?
> >>> 
> >> Good question. So far, all mp3 aa files I tested with matched the format 
> >> (MPEG 2
> >> Layer III at 32 kbps and 22kHz). I doubt there are other variants, but 
> >> can’t be sure.
> >> 
> >>> Either way, looking at the demuxer a bit deeper, theres a TOC list in the
> >>> main header which points to chunks. The one file i found has 12 such 
> >>> chunks
> >>> the first represents the whole file i suspect, the next largest the audio
> >>> data, another one the metadata.
> >>> I guess the remaining 2 large ones could be a cover image and an index.
> >> Correct, seems like all aa files have the TOC, but its entries can be in a 
> >> different
> >> order in each file. I guess thats why the original aadec.c implementation 
> >> just
> >> looks for the largest chunk to play.
> >> 
> >>> I didnt really look at it, but theres a table in there with pairs of 32bit
> >>> values. the first in the file i have goes from 0 to 3 the second starts
> >>> multiple times from 0 and seems monotonly increasing and staying within
> >>> the filesize.
> >>> The sample i have does not store mp3 but it looks like this is a index
> >>> maybe offsets for packets in each of the 3 chapters.
> >>> 
> >>> Please look at the data, if it can be used. It would be much better than
> >>> scaning the file linearly and searching for some byte sequence to find
> >>> packet starts.
> >>> 
> >> Short answer: Sorry, it is not possible to derive frame offsets nor chapter
> >> offsets from the index.
> >> 
> > 
> >> Long answer:
> >> All offsets in the index are the same, and matching the "codec_second_size"
> >> = crypto chunk size, roughly one second of audio:
> >> - 1045 for format 2 (SIPR 8kbps)
> >> - 2000 for format 3 (SIPR 16kbps)
> >> - 3982 for format 4 (MP3 32kbps)
> >> This is different from the respective frame size, which is 19, 20, and 
> >> 104/105
> > 
> > The first 2 are exact multiples of the frame size.
> > 
> > I dont have a sample for the mp3 case so i cannot check but are you sure
> > the actually writen numbers dont match up multiples of mp3 frames ?
> > 
> Yes, I have tested both with some old aa books I still had on disk, and some I
> bought more recently. Using 

Re: [FFmpeg-devel] [PATCH 10/12] lavf/mxfdec: demux s436m as eia608 subtitle track

2018-07-04 Thread Marton Balint



On Wed, 4 Jul 2018, Baptiste Coudurier wrote:


---
libavformat/mxfdec.c | 102 +++
1 file changed, 102 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 3f443bbbc9..54e4be7934 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -52,6 +52,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/parseutils.h"
#include "libavutil/timecode.h"
+#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
#include "mxf.h"
@@ -263,6 +264,7 @@ typedef struct MXFIndexTable {
} MXFIndexTable;

typedef struct MXFContext {
+const AVClass *class; /**< Class for private options. */
MXFPartition *partitions;
unsigned partitions_count;
MXFOP op;
@@ -287,6 +289,8 @@ typedef struct MXFContext {
int64_t current_edit_unit;
int nb_index_tables;
MXFIndexTable *index_tables;
+int edit_units_per_packet;  ///< how many edit units to read at a time 
(PCM, OPAtom)


This seems unused, probably remained after a merge. (edit_units_per_packet 
is now an MXFTrack property).



+int eia608_extract;
} MXFContext;

/* NOTE: klv_offset is not set (-1) for local keys */
@@ -449,6 +453,78 @@ static int find_body_sid_by_offset(MXFContext *mxf, 
int64_t offset)
return mxf->partitions[a].body_sid;
}

+static int mxf_get_eia608_packet(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int64_t length)
+{
+int count = avio_rb16(s->pb);
+int i, ret;
+
+for (i = 0; i < count; i++) {
+if (length < 6) {
+av_log(s, AV_LOG_ERROR, "error reading s436m packet %"PRId64"\n", 
length);
+return AVERROR_INVALIDDATA;
+}
+int line_num = avio_rb16(s->pb);
+int wrapping_type = avio_r8(s->pb);
+int sample_coding = avio_r8(s->pb);
+int sample_count = avio_rb16(s->pb);
+av_log(s, AV_LOG_DEBUG, "len %"PRId64" line %d wrap type %d coding %d count 
%d\n",
+   length, line_num, wrapping_type, sample_coding, sample_count);
+length -= 6 + 8 + sample_count;
+if (line_num != 9 && line_num != 11)
+break;
+if (sample_coding == 7 || sample_coding == 8 || sample_coding == 9) {
+av_log(s, AV_LOG_ERROR, "unsupported s436m 10 bit sample 
coding\n");
+return 0;
+}
+if (length < 0)
+return AVERROR_INVALIDDATA;
+
+int array_count = avio_rb32(s->pb);
+int array_elem_size = avio_rb32(s->pb);
+av_log(s, AV_LOG_DEBUG, "array count %d elem size %d\n", array_count, 
array_elem_size);
+int did = avio_r8(s->pb);
+int sdid = avio_r8(s->pb);
+int data_count = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "did %x sdid %x count %d\n", did, sdid, 
data_count);
+if (did != 0x61)
+break;
+int cdp_id = avio_rb16(s->pb);
+int cdp_data_count = avio_r8(s->pb);
+int cdp_framing_rate = avio_r8(s->pb) >> 4;
+int cdp_flags = avio_r8(s->pb);
+int cdp_counter = avio_rb16(s->pb);
+int cdp_data_section = avio_r8(s->pb);
+if (cdp_data_section != 0x72) {
+av_log(s, AV_LOG_ERROR, "wrong cdp data section %x\n", 
cdp_data_section);
+return AVERROR_INVALIDDATA;
+}
+int flags = avio_r8(s->pb);
+int cc_count = flags & 0x1f;
+av_log(s, AV_LOG_DEBUG, "cdp id %x dcount %d frame rate %d cdp flags %x 
flags %x "
+   "cc count %d counter %d section %x\n", cdp_id, cdp_data_count, 
cdp_framing_rate,
+   cdp_flags, flags, cc_count, cdp_counter, cdp_data_section);
+ret = av_get_packet(s->pb, pkt, cc_count * 3);
+if (ret < 0)
+return ret;
+if (cdp_data_count - 9 - 4 <  cc_count * 3) {
+av_log(s, AV_LOG_ERROR, "wrong cdp size %d cc count %d\n", 
data_count, cc_count);
+return AVERROR_INVALIDDATA;
+}
+avio_skip(s->pb, data_count - 9 - 4 - cc_count * 3);
+int cdp_footer_section = avio_r8(s->pb);
+if (cdp_footer_section != 0x74) {
+av_log(s, AV_LOG_ERROR, "wrong cdp footer section %x\n", 
cdp_footer_section);
+return AVERROR_INVALIDDATA;
+}
+int cdp_counter2 = avio_rb16(s->pb);
+int cdp_checksum = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "cdp counter %d checksum %x\n", cdp_counter2, 
cdp_checksum);
+break;
+}
+
+return 0;
+}
+
/* XXX: use AVBitStreamFilter */
static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket 
*pkt, int64_t length)
{
@@ -2415,6 +2491,11 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
st->codecpar->codec_type = type;
if (container_ul->desc)
av_dict_set(>metadata, "data_type", container_ul->desc, 0);
+if (mxf->eia608_extract &&
+!strcmp(container_ul->desc, "vbi_vanc_smpte_436M")) {
+

Re: [FFmpeg-devel] [PATCH 09/12] lavf/mxfenc: support creating s436m data tracks

2018-07-04 Thread Marton Balint



On Wed, 4 Jul 2018, Baptiste Coudurier wrote:


---
libavformat/mxf.c|  1 +
libavformat/mxfdec.c |  3 +++
libavformat/mxfenc.c | 41 +
libavformat/utils.c  |  6 +-
4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 8376a2b9bf..451cbcfb2c 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -28,6 +28,7 @@
const MXFCodecUL ff_mxf_data_definition_uls[] = {
{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_VIDEO },
{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_AUDIO },
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x03,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_DATA },
{ { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x6F,0x3C,0x8C,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_VIDEO }, /* LegacyPicture Avid Media Composer MXF */
{ { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x78,0xE1,0xEB,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_AUDIO }, /* LegacySound Avid Media Composer MXF */
{ { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  AVMEDIA_TYPE_DATA },
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 8c417aea26..3f443bbbc9 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3291,6 +3291,9 @@ static int mxf_set_pts(MXFContext *mxf, AVStream *st, 
AVPacket *pkt, int64_t nex
int ret = mxf_set_audio_pts(mxf, par, pkt);
if (ret < 0)
return ret;
+} else {
+pkt->dts = pkt->pts = mxf->current_edit_unit;
+pkt->duration = 1;
}
return 0;
}


Sorry, my clip wrapping patches I just committed conflicted with your work 
here, you should use something like this for this hunk:


--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3298,6 +3298,8 @@ static int mxf_set_pts(MXFContext *mxf, AVStream *st, 
AVPacket *pkt)
 if (ret < 0)
 return ret;
 } else if (track) {
+pkt->dts = pkt->pts = track->sample_count;
+pkt->duration = 1;
 track->sample_count++;
 }
 return 0;

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


Re: [FFmpeg-devel] [PATCH 6/6] avcodec/mpeg4videodec: Check for bitstream end in read_quant_matrix_ext()

2018-07-04 Thread Michael Niedermayer
On Wed, Jul 04, 2018 at 03:03:03AM +0200, Michael Niedermayer wrote:
> On Tue, Jul 03, 2018 at 11:52:59PM +0200, Carl Eugen Hoyos wrote:
> > 2018-07-03 23:05 GMT+02:00, Michael Niedermayer :
> > > Fixes: out of array read
> > > Fixes: asff-crash-0e53d0dc491dfdd507530b66562812fbd4c36678
> > >
> > > Found-by: Paul Ch 
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavcodec/mpeg4videodec.c | 11 ++-
> > >  1 file changed, 10 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> > > index 2df525e03a..24c280df46 100644
> > > --- a/libavcodec/mpeg4videodec.c
> > > +++ b/libavcodec/mpeg4videodec.c
> > > @@ -2867,11 +2867,13 @@ static int decode_vop_header(Mpeg4DecContext *ctx,
> > > GetBitContext *gb)
> > >  return 0;
> > >  }
> > >
> > > -static void read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
> > > +static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
> > 
> > Why is changing the return type of this function useful (in the context
> > of the actual patch)?
> 
> Its just more in line with how the code should be.
> Full error checking, reporting and handling such errors.
> The patch does only the hunks needed to fix this (easy backportable i assume)
> if i leave the return type and just return, i will need a future patch that
> changes the very same lines to return an error

will apply as this issue was reported by a 2nd researcher it seems already

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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


[FFmpeg-devel] [PATCH] avformat/mxfdec: only return stream indexes which have a corresponding track

2018-07-04 Thread Marton Balint
Without this check some crafted files might crash because a packet might be
demuxed which have no corresponding mxf track.

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

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index b76beb962f..c52ece9655 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -423,7 +423,7 @@ static int mxf_get_stream_index(AVFormatContext *s, 
KLVPacket *klv, int body_sid
 return i;
 }
 /* return 0 if only one stream, for OP Atom files with 0 as track number */
-return s->nb_streams == 1 ? 0 : -1;
+return s->nb_streams == 1 && s->streams[0]->priv_data ? 0 : -1;
 }
 
 static int find_body_sid_by_offset(MXFContext *mxf, int64_t offset)
-- 
2.16.4

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


Re: [FFmpeg-devel] [PATCH 1/5] avformat/mxfdec: add support for clip wrapped essences

2018-07-04 Thread Marton Balint



On Tue, 3 Jul 2018, Tomas Härdin wrote:


tis 2018-07-03 klockan 22:36 +0200 skrev Marton Balint:


On Mon, 25 Jun 2018, Marton Balint wrote:

> Also use common code with opAtom.
> 
> Fixes ticket #2776.

> Partially fixes ticket #5671.
> Fixes ticket #5866.

Will push the series soon.


Sorry, should have looked at this earlier. I only really have two
comments:

* patch 1/5 is still hard to digest, so I'm just going to trust you on
it
* I see my suggestion made it into patch 4/5 :)


Thanks, pushed.

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


[FFmpeg-devel] [PATCH] Optimize libavformat/metadata.c

2018-07-04 Thread Shlomi Fish


-- 
-
Shlomi Fish   http://www.shlomifish.org/
What does “Zionism” mean? - http://shlom.in/def-zionism

It is impossible to make anything foolproof because fools are so ingenious.
— Source Unknown

Please reply to list if it's a mailing list post - http://shlom.in/reply .
>From 98e0629d28394f8683abd98f80645ee63b295d24 Mon Sep 17 00:00:00 2001
From: Shlomi Fish 
Date: Wed, 4 Jul 2018 22:53:08 +0300
Subject: [PATCH] Short-circuit several calls on a condition.

This is an optimization - more details in the comment in the changeset.
---
 libavformat/metadata.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index b9b6de7972..4b720efd38 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -60,6 +60,10 @@ void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
 const AVMetadataConv *s_conv)
 {
 int i;
+/* We pass those to all ff_metadata_conv calls below and it returns
+ * immediately if they are equal, so we can short-circuit. */
+if (d_conv == s_conv)
+return;
 ff_metadata_conv(>metadata, d_conv, s_conv);
 for (i=0; inb_streams ; i++)
 ff_metadata_conv(>streams [i]->metadata, d_conv, s_conv);
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 09/12] lavf/mxfenc: support creating s436m data tracks

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxf.c|  1 +
 libavformat/mxfdec.c |  3 +++
 libavformat/mxfenc.c | 41 +
 libavformat/utils.c  |  6 +-
 4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 8376a2b9bf..451cbcfb2c 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -28,6 +28,7 @@
 const MXFCodecUL ff_mxf_data_definition_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_VIDEO },
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_AUDIO },
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x03,0x00,0x00,0x00 
}, 13, AVMEDIA_TYPE_DATA },
 { { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x6F,0x3C,0x8C,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_VIDEO }, /* LegacyPicture Avid Media Composer MXF */
 { { 
0x80,0x7D,0x00,0x60,0x08,0x14,0x3E,0x6F,0x78,0xE1,0xEB,0xE1,0x6C,0xEF,0x11,0xD2 
}, 16, AVMEDIA_TYPE_AUDIO }, /* LegacySound Avid Media Composer MXF */
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  AVMEDIA_TYPE_DATA },
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 8c417aea26..3f443bbbc9 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -3291,6 +3291,9 @@ static int mxf_set_pts(MXFContext *mxf, AVStream *st, 
AVPacket *pkt, int64_t nex
 int ret = mxf_set_audio_pts(mxf, par, pkt);
 if (ret < 0)
 return ret;
+} else {
+pkt->dts = pkt->pts = mxf->current_edit_unit;
+pkt->duration = 1;
 }
 return 0;
 }
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 036adce011..6da27bf4f5 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -175,6 +175,7 @@ static void mxf_write_aes3_desc(AVFormatContext *s, 
AVStream *st);
 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st);
 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st);
 static void mxf_write_generic_sound_desc(AVFormatContext *s, AVStream *st);
+static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st);
 
 static const MXFContainerEssenceEntry mxf_essence_container_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 
},
@@ -361,6 +362,11 @@ static const MXFContainerEssenceEntry 
mxf_essence_container_uls[] = {
   { 
0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x15,0x01,0x05,0x00 
},
   { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x00,0x00,0x00 
},
   mxf_write_mpegvideo_desc },
+// S436M ANC
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x0D,0x01,0x03,0x01,0x02,0x0e,0x00,0x00 
},
+  { 
0x06,0x0E,0x2B,0x34,0x01,0x02,0x01,0x01,0x0D,0x01,0x03,0x01,0x17,0x01,0x02,0x00 
},
+  { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x01,0x5C,0x00 
},
+  mxf_write_s436m_anc_desc },
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
   { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
   { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},
@@ -695,9 +701,14 @@ static void 
mxf_write_essence_container_refs(AVFormatContext *s)
 
 mxf_write_refs_count(pb, DESCRIPTOR_COUNT(c->essence_container_count));
 av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", 
c->essence_container_count);
-for (i = 0; i < c->essence_container_count; i++) {
+for (i = 0; i < s->nb_streams; i++) {
 MXFStreamContext *sc = s->streams[i]->priv_data;
+// check first track of essence container type and only write it once
+if (sc->track_essence_element_key[15] != 0)
+continue;
 avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
+if (c->essence_container_count == 1)
+break;
 }
 
 if (c->essence_container_count > 1)
@@ -1154,6 +1165,7 @@ static int64_t mxf_write_generic_desc(AVFormatContext *s, 
AVStream *st, const UI
 return pos;
 }
 
+static const UID mxf_s436m_anc_descriptor_key = { 
0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 
};
 static const UID mxf_mpegvideo_descriptor_key = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 
};
 static const UID mxf_wav_descriptor_key   = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 
};
 static const UID mxf_aes3_descriptor_key  = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 
};
@@ -1369,6 +1381,12 @@ static void mxf_write_cdci_desc(AVFormatContext *s, 
AVStream *st)
 mxf_update_klv_size(s->pb, pos);
 }
 
+static void mxf_write_s436m_anc_desc(AVFormatContext *s, AVStream *st)
+{
+int64_t pos = 

[FFmpeg-devel] [PATCH 12/12] lavf/sccenc: write proper timecode, use proper stream timebase and split lines properly

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/sccenc.c | 90 ++--
 1 file changed, 54 insertions(+), 36 deletions(-)

diff --git a/libavformat/sccenc.c b/libavformat/sccenc.c
index f3cf3d599c..dd6a4b36d8 100644
--- a/libavformat/sccenc.c
+++ b/libavformat/sccenc.c
@@ -23,16 +23,22 @@
 #include "internal.h"
 #include "libavutil/log.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/timecode.h"
+#include "libavutil/opt.h"
 
 typedef struct SCCContext {
-int prev_h, prev_m, prev_s, prev_f;
+AVClass *av_class;
+int64_t expected_pts;
 int inside;
 int n;
+AVTimecode tc;
+char *timecode_start;
 } SCCContext;
 
 static int scc_write_header(AVFormatContext *avf)
 {
 SCCContext *scc = avf->priv_data;
+AVStream *st = avf->streams[0];
 
 if (avf->nb_streams != 1 ||
 avf->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
@@ -46,11 +52,19 @@ static int scc_write_header(AVFormatContext *avf)
avcodec_get_name(avf->streams[0]->codecpar->codec_id));
 return AVERROR(EINVAL);
 }
-avpriv_set_pts_info(avf->streams[0], 64, 1, 1000);
-avio_printf(avf->pb, "Scenarist_SCC V1.0\n");
 
-scc->prev_h = scc->prev_m = scc->prev_s = scc->prev_f = -1;
-scc->inside = 0;
+if (!(st->time_base.den == 3 && st->time_base.num == 1001)) {
+av_log(avf, AV_LOG_ERROR, "Unsupported frame rate: %d/%d\n",
+   st->time_base.den, st->time_base.num);
+return AVERROR(EINVAL);
+}
+
+if (av_timecode_init_from_string(>tc, (AVRational){3, 1001}, 
scc->timecode_start, avf) < 0)
+return -1;
+
+avio_printf(avf->pb, "Scenarist_SCC V1.0");
+
+scc->expected_pts = -2;
 
 return 0;
 }
@@ -59,58 +73,60 @@ static int scc_write_packet(AVFormatContext *avf, AVPacket 
*pkt)
 {
 SCCContext *scc = avf->priv_data;
 int64_t pts = pkt->pts;
-int i, h, m, s, f;
+char tcbuf[AV_TIMECODE_STR_SIZE];
+int i;
 
 if (pts == AV_NOPTS_VALUE) {
-av_log(avf, AV_LOG_WARNING,
-   "Insufficient timestamps.\n");
-return 0;
+av_log(avf, AV_LOG_WARNING, "Insufficient timestamps\n");
+return -1;
 }
 
-h = (int)(pts / (360));
-m = (int)(pts / (6)) % 60;
-s = (int)(pts /  1000) % 60;
-f = (int)(pts %  1000) / 33;
+if (!av_timecode_make_string(>tc, tcbuf, pts))
+return -1;
 
-for (i = 0; i < pkt->size; i+=3) {
-if (pkt->data[i] == 0xfc && ((pkt->data[i + 1] != 0x80 || pkt->data[i 
+ 2] != 0x80)))
-break;
-}
-if (i >= pkt->size)
-return 0;
-
-if (!scc->inside && (scc->prev_h != h || scc->prev_m != m || scc->prev_s 
!= s || scc->prev_f != f)) {
-avio_printf(avf->pb, "\n%02d:%02d:%02d:%02d\t", h, m, s, f);
-scc->inside = 1;
-}
 for (i = 0; i < pkt->size; i+=3) {
 if (i + 3 > pkt->size)
 break;
 
 if (pkt->data[i] != 0xfc || (pkt->data[i + 1] == 0x80 && pkt->data[i + 
2] == 0x80))
 continue;
-if (!scc->inside) {
-avio_printf(avf->pb, "\n%02d:%02d:%02d:%02d\t", h, m, s, f);
-scc->inside = 1;
+
+if (pts > scc->expected_pts+1 || AV_RB16(>data[i + 1]) == 0x942c) 
{
+avio_printf(avf->pb, "\r\n\n%s\t", tcbuf);
+scc->expected_pts = pts;
+scc->n = 0;
 }
+
 if (scc->n > 0)
 avio_printf(avf->pb, " ");
+
 avio_printf(avf->pb, "%02x%02x", pkt->data[i + 1], pkt->data[i + 2]);
+scc->expected_pts += 1;
 scc->n++;
 }
-if (scc->inside && (scc->prev_h != h || scc->prev_m != m || scc->prev_s != 
s || scc->prev_f != f)) {
-avio_printf(avf->pb, "\n");
-scc->n = 0;
-scc->inside = 0;
-}
 
-scc->prev_h = h;
-scc->prev_m = m;
-scc->prev_s = s;
-scc->prev_f = f;
 return 0;
 }
 
+static int scc_write_trailer(AVFormatContext *avf)
+{
+avio_printf(avf->pb, "\n\n");
+return 0;
+}
+
+static const AVOption scc_options[] = {
+{ "timecode_start", "Set the SCC file initial timecode",
+  offsetof(SCCContext, timecode_start), AV_OPT_TYPE_STRING, {.str = 
"00:00:00;00"}, CHAR_MIN, CHAR_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+{ NULL },
+};
+
+static const AVClass scc_muxer_class = {
+.class_name = "scc muxer",
+.item_name  = av_default_item_name,
+.option = scc_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 AVOutputFormat ff_scc_muxer = {
 .name   = "scc",
 .long_name  = NULL_IF_CONFIG_SMALL("Scenarist Closed Captions"),
@@ -118,6 +134,8 @@ AVOutputFormat ff_scc_muxer = {
 .priv_data_size = sizeof(SCCContext),
 .write_header   = scc_write_header,
 .write_packet   = scc_write_packet,
+.write_trailer  = scc_write_trailer,
 .flags  = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS | 
AVFMT_TS_NONSTRICT,
 .subtitle_codec = AV_CODEC_ID_EIA_608,
+.priv_class 

[FFmpeg-devel] [PATCH 08/12] avformat/mxfenc: fix muxing when audio tracks are longer than video track

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 1f272ce6e5..036adce011 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2935,6 +2935,9 @@ static int mxf_interleave_get_packet(AVFormatContext *s, 
AVPacket *out, AVPacket
 while (pktl) {
 if (!stream_count || pktl->pkt.stream_index == 0)
 break;
+// update last packet in packet buffer
+if (s->streams[pktl->pkt.stream_index]->last_in_packet_buffer 
!= pktl)
+s->streams[pktl->pkt.stream_index]->last_in_packet_buffer 
= pktl;
 last = pktl;
 pktl = pktl->next;
 stream_count--;
@@ -2942,9 +2945,6 @@ static int mxf_interleave_get_packet(AVFormatContext *s, 
AVPacket *out, AVPacket
 // purge packet queue
 while (pktl) {
 AVPacketList *next = pktl->next;
-
-if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer 
== pktl)
-s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= 
NULL;
 av_packet_unref(>pkt);
 av_freep();
 pktl = next;
-- 
2.17.0 (Apple Git-106)

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


[FFmpeg-devel] [PATCH 05/12] avformat/mxfenc: correctly set content package rate in system element

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxf.c| 17 +
 libavformat/mxf.h|  2 ++
 libavformat/mxfenc.c |  4 +++-
 tests/ref/lavf/mxf   |  2 +-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index c8b57f7f0b..8376a2b9bf 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -171,3 +171,20 @@ const MXFSamplesPerFrame 
*ff_mxf_get_samples_per_frame(AVFormatContext *s,
 
 return _spf[idx];
 }
+
+static const int mxf_content_package_rates[] = {
+3, 2, 7, 13, 4, 10, 12,
+};
+
+int ff_mxf_get_content_package_rate(AVRational time_base)
+{
+int idx = av_find_nearest_q_idx(time_base, mxf_time_base);
+AVRational diff = av_sub_q(time_base, mxf_time_base[idx]);
+
+diff.num = FFABS(diff.num);
+
+if (av_cmp_q(diff, (AVRational){1, 1000}) >= 0)
+return -1;
+
+return mxf_content_package_rates[idx];
+}
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index f6e75919c5..4394450dea 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -93,6 +93,8 @@ extern const MXFCodecUL ff_mxf_codec_tag_uls[];
 
 int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat 
*pix_fmt);
 const MXFSamplesPerFrame *ff_mxf_get_samples_per_frame(AVFormatContext *s, 
AVRational time_base);
+int ff_mxf_get_content_package_rate(AVRational time_base);
+
 
 #define PRIxUID \
 "%02x.%02x.%02x.%02x."  \
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index d13ddaff6d..1f272ce6e5 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -386,6 +386,7 @@ typedef struct MXFContext {
 AVStream *timecode_track;
 int timecode_base;   ///< rounded time code base (25 or 30)
 int edit_unit_byte_count; ///< fixed edit unit byte count
+int content_package_rate; ///< content package rate in system element, see 
SMPTE 326M
 uint64_t body_offset;
 uint32_t instance_number;
 uint8_t umid[16];///< unique material identifier
@@ -2411,6 +2412,7 @@ static int mxf_write_header(AVFormatContext *s)
tbc.den, tbc.num);
 return AVERROR(EINVAL);
 }
+mxf->content_package_rate = ff_mxf_get_content_package_rate(tbc);
 mxf->time_base = spf->time_base;
 rate = av_inv_q(mxf->time_base);
 avpriv_set_pts_info(st, 64, mxf->time_base.num, 
mxf->time_base.den);
@@ -2579,7 +2581,7 @@ static void mxf_write_system_item(AVFormatContext *s)
 avio_write(pb, system_metadata_pack_key, 16);
 klv_encode_ber4_length(pb, 57);
 avio_w8(pb, 0x5c); // UL, user date/time stamp, picture and sound item 
present
-avio_w8(pb, 0x04); // content package rate
+avio_w8(pb, mxf->content_package_rate); // content package rate
 avio_w8(pb, 0x00); // content package type
 avio_wb16(pb, 0x00); // channel handle
 avio_wb16(pb, (mxf->tc.start + frame) & 0x); // continuity count, 
supposed to overflow
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index 1971e25fdf..81d21704d9 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,7 +1,7 @@
 649009e3d3d62eb3b6c56334d057cc4d *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
-1ab46fe6d07dc9eeb457772096f3a7db *./tests/data/lavf/lavf.mxf
+5756c5f9bdb9718b91bfbf588afec189 *./tests/data/lavf/lavf.mxf
 561721 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0xf21b1b48
 02bf8f0cd8951a49e277306691cb1538 *./tests/data/lavf/lavf.mxf
-- 
2.17.0 (Apple Git-106)

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


[FFmpeg-devel] [PATCH 10/12] lavf/mxfdec: demux s436m as eia608 subtitle track

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfdec.c | 102 +++
 1 file changed, 102 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 3f443bbbc9..54e4be7934 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -52,6 +52,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timecode.h"
+#include "libavutil/opt.h"
 #include "avformat.h"
 #include "internal.h"
 #include "mxf.h"
@@ -263,6 +264,7 @@ typedef struct MXFIndexTable {
 } MXFIndexTable;
 
 typedef struct MXFContext {
+const AVClass *class; /**< Class for private options. */
 MXFPartition *partitions;
 unsigned partitions_count;
 MXFOP op;
@@ -287,6 +289,8 @@ typedef struct MXFContext {
 int64_t current_edit_unit;
 int nb_index_tables;
 MXFIndexTable *index_tables;
+int edit_units_per_packet;  ///< how many edit units to read at a time 
(PCM, OPAtom)
+int eia608_extract;
 } MXFContext;
 
 /* NOTE: klv_offset is not set (-1) for local keys */
@@ -449,6 +453,78 @@ static int find_body_sid_by_offset(MXFContext *mxf, 
int64_t offset)
 return mxf->partitions[a].body_sid;
 }
 
+static int mxf_get_eia608_packet(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int64_t length)
+{
+int count = avio_rb16(s->pb);
+int i, ret;
+
+for (i = 0; i < count; i++) {
+if (length < 6) {
+av_log(s, AV_LOG_ERROR, "error reading s436m packet %"PRId64"\n", 
length);
+return AVERROR_INVALIDDATA;
+}
+int line_num = avio_rb16(s->pb);
+int wrapping_type = avio_r8(s->pb);
+int sample_coding = avio_r8(s->pb);
+int sample_count = avio_rb16(s->pb);
+av_log(s, AV_LOG_DEBUG, "len %"PRId64" line %d wrap type %d coding %d 
count %d\n",
+   length, line_num, wrapping_type, sample_coding, sample_count);
+length -= 6 + 8 + sample_count;
+if (line_num != 9 && line_num != 11)
+break;
+if (sample_coding == 7 || sample_coding == 8 || sample_coding == 9) {
+av_log(s, AV_LOG_ERROR, "unsupported s436m 10 bit sample 
coding\n");
+return 0;
+}
+if (length < 0)
+return AVERROR_INVALIDDATA;
+
+int array_count = avio_rb32(s->pb);
+int array_elem_size = avio_rb32(s->pb);
+av_log(s, AV_LOG_DEBUG, "array count %d elem size %d\n", array_count, 
array_elem_size);
+int did = avio_r8(s->pb);
+int sdid = avio_r8(s->pb);
+int data_count = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "did %x sdid %x count %d\n", did, sdid, 
data_count);
+if (did != 0x61)
+break;
+int cdp_id = avio_rb16(s->pb);
+int cdp_data_count = avio_r8(s->pb);
+int cdp_framing_rate = avio_r8(s->pb) >> 4;
+int cdp_flags = avio_r8(s->pb);
+int cdp_counter = avio_rb16(s->pb);
+int cdp_data_section = avio_r8(s->pb);
+if (cdp_data_section != 0x72) {
+av_log(s, AV_LOG_ERROR, "wrong cdp data section %x\n", 
cdp_data_section);
+return AVERROR_INVALIDDATA;
+}
+int flags = avio_r8(s->pb);
+int cc_count = flags & 0x1f;
+av_log(s, AV_LOG_DEBUG, "cdp id %x dcount %d frame rate %d cdp flags 
%x flags %x "
+   "cc count %d counter %d section %x\n", cdp_id, cdp_data_count, 
cdp_framing_rate,
+   cdp_flags, flags, cc_count, cdp_counter, cdp_data_section);
+ret = av_get_packet(s->pb, pkt, cc_count * 3);
+if (ret < 0)
+return ret;
+if (cdp_data_count - 9 - 4 <  cc_count * 3) {
+av_log(s, AV_LOG_ERROR, "wrong cdp size %d cc count %d\n", 
data_count, cc_count);
+return AVERROR_INVALIDDATA;
+}
+avio_skip(s->pb, data_count - 9 - 4 - cc_count * 3);
+int cdp_footer_section = avio_r8(s->pb);
+if (cdp_footer_section != 0x74) {
+av_log(s, AV_LOG_ERROR, "wrong cdp footer section %x\n", 
cdp_footer_section);
+return AVERROR_INVALIDDATA;
+}
+int cdp_counter2 = avio_rb16(s->pb);
+int cdp_checksum = avio_r8(s->pb);
+av_log(s, AV_LOG_DEBUG, "cdp counter %d checksum %x\n", cdp_counter2, 
cdp_checksum);
+break;
+}
+
+return 0;
+}
+
 /* XXX: use AVBitStreamFilter */
 static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket 
*pkt, int64_t length)
 {
@@ -2415,6 +2491,11 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 st->codecpar->codec_type = type;
 if (container_ul->desc)
 av_dict_set(>metadata, "data_type", container_ul->desc, 0);
+if (mxf->eia608_extract &&
+!strcmp(container_ul->desc, "vbi_vanc_smpte_436M")) {
+st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+st->codecpar->codec_id = AV_CODEC_ID_EIA_608;
+}
 }
 if 

[FFmpeg-devel] [PATCH 11/12] lavf/sccdec: fix timestamps and demux one eai608 frame at a time

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/sccdec.c | 100 ---
 1 file changed, 56 insertions(+), 44 deletions(-)

diff --git a/libavformat/sccdec.c b/libavformat/sccdec.c
index 89d21b9c1f..0472b4e031 100644
--- a/libavformat/sccdec.c
+++ b/libavformat/sccdec.c
@@ -24,9 +24,14 @@
 #include "subtitles.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/timecode.h"
+#include "libavutil/opt.h"
 
 typedef struct SCCContext {
+AVClass *av_class;
 FFDemuxSubtitlesQueue q;
+AVTimecode initial_tc;
+char *timecode_start;
 } SCCContext;
 
 static int scc_probe(AVProbeData *p)
@@ -62,57 +67,53 @@ static int scc_read_header(AVFormatContext *s)
 {
 SCCContext *scc = s->priv_data;
 AVStream *st = avformat_new_stream(s, NULL);
-char line[4096], line2[4096];
-int count = 0, ret = 0;
-ptrdiff_t len2, len;
-uint8_t out[4096];
+char line[4096];
+int ret = 0;
+ptrdiff_t len;
 FFTextReader tr;
+const AVRational frame_rate = {3,1001};
 
 ff_text_init_avio(s, , s->pb);
 
 if (!st)
 return AVERROR(ENOMEM);
-avpriv_set_pts_info(st, 64, 1, 1000);
+avpriv_set_pts_info(st, 64, 1001, 3);
 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
 st->codecpar->codec_id   = AV_CODEC_ID_EIA_608;
 
+if (av_timecode_init_from_string(>initial_tc,
+ (AVRational){3, 1001},
+ scc->timecode_start, s) < 0)
+return -1;
+
+while (!ff_text_eof()) {
+len = ff_subtitles_read_line(, line, sizeof(line));
+if (!strncmp(line, "Scenarist_SCC V1.0", 18))
+break;
+}
+
 while (!ff_text_eof()) {
 const int64_t pos = ff_text_pos();
 char *saveptr = NULL, *lline;
-int hh1, mm1, ss1, fs1, i;
-int hh2, mm2, ss2, fs2;
-int64_t ts_start, ts_end;
+AVTimecode tc_start;
+int i;
 AVPacket *sub;
-
-if (count == 0) {
-while (!ff_text_eof()) {
-len = ff_subtitles_read_line(, line, sizeof(line));
-if (len > 13)
-break;
-}
-}
-
-if (!strncmp(line, "Scenarist_SCC V1.0", 18))
-continue;
-if (sscanf(line, "%d:%d:%d%*[:;]%d", , , , ) != 4)
-continue;
-
-ts_start = (hh1 * 3600LL + mm1 * 60LL + ss1) * 1000LL + fs1 * 33;
+char out[4];
 
 while (!ff_text_eof()) {
-len2 = ff_subtitles_read_line(, line2, sizeof(line2));
-if (len2 > 13)
+len = ff_subtitles_read_line(, line, sizeof(line));
+if (len > 13)
 break;
 }
-if (sscanf(line2, "%d:%d:%d%*[:;]%d", , , , ) != 4)
-continue;
 
-ts_end = (hh2 * 3600LL + mm2 * 60LL + ss2) * 1000LL + fs2 * 33;
-count++;
+if (av_timecode_init_from_string(_start, frame_rate, line, s) < 0)
+continue;
 
 lline = (char *)
 lline += 12;
 
+out[3] = 0;
+
 for (i = 0; i < 4095; i += 3) {
 char *ptr = av_strtok(lline, " ", );
 char c1, c2, c3, c4;
@@ -124,21 +125,17 @@ static int scc_read_header(AVFormatContext *s)
 break;
 
 lline = NULL;
-out[i+0] = 0xfc;
-out[i+1] = convert(c2) | (convert(c1) << 4);
-out[i+2] = convert(c4) | (convert(c3) << 4);
+out[0] = 0xfc;
+out[1] = convert(c2) | (convert(c1) << 4);
+out[2] = convert(c4) | (convert(c3) << 4);
+
+sub = ff_subtitles_queue_insert(>q, out, 3, 0);
+if (!sub)
+return AVERROR(ENOMEM);
+sub->pos = pos + i * 3;
+sub->pts = tc_start.start + i / 3;
+sub->duration = 1;
 }
-out[i] = 0;
-
-sub = ff_subtitles_queue_insert(>q, out, i, 0);
-if (!sub)
-return AVERROR(ENOMEM);
-
-sub->pos = pos;
-sub->pts = ts_start;
-sub->duration = FFMAX(1200, ts_end - ts_start);
-memmove(line, line2, sizeof(line));
-FFSWAP(ptrdiff_t, len, len2);
 }
 
 ff_subtitles_queue_finalize(s, >q);
@@ -149,7 +146,8 @@ static int scc_read_header(AVFormatContext *s)
 static int scc_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 SCCContext *scc = s->priv_data;
-return ff_subtitles_queue_read_packet(>q, pkt);
+int ret = ff_subtitles_queue_read_packet(>q, pkt);
+return ret;
 }
 
 static int scc_read_seek(AVFormatContext *s, int stream_index,
@@ -167,6 +165,19 @@ static int scc_read_close(AVFormatContext *s)
 return 0;
 }
 
+static const AVOption scc_options[] = {
+{ "timecode_start", "Set the SCC file initial timecode, to adjust 
timestamps",
+  offsetof(SCCContext, timecode_start), AV_OPT_TYPE_STRING, {.str = 
"00:00:00;00"}, CHAR_MIN, CHAR_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+{ NULL },
+};

[FFmpeg-devel] [PATCH 07/12] ratecontrol: fix stuffing bits for 30000/1001 fps one frame vbv

2018-07-04 Thread Baptiste Coudurier
---
 libavcodec/ratecontrol.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 49d169ba25..28bdddbad1 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -705,16 +705,16 @@ int ff_vbv_update(MpegEncContext *s, int frame_size)
 rcc->buffer_index += av_clip(left, min_rate, max_rate);
 
 if (rcc->buffer_index > buffer_size) {
-int stuffing = ceil((rcc->buffer_index - buffer_size) / 8);
+int stuffing = rcc->buffer_index - buffer_size;
 
-if (stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4)
-stuffing = 4;
-rcc->buffer_index -= 8 * stuffing;
+if (stuffing < 32 && s->codec_id == AV_CODEC_ID_MPEG4)
+stuffing = 32;
+rcc->buffer_index -= stuffing;
 
 if (s->avctx->debug & FF_DEBUG_RC)
-av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", 
stuffing);
+av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", 
stuffing>>3);
 
-return stuffing;
+return stuffing>>3;
 }
 }
 return 0;
-- 
2.17.0 (Apple Git-106)

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


[FFmpeg-devel] [PATCH 06/12] avformat/audiointerleave: pad last audio frame

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/audiointerleave.c | 10 +++---
 tests/ref/lavf/mxf|  4 ++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 6d4954befe..dea5d99821 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -81,15 +81,19 @@ static int interleave_new_audio_packet(AVFormatContext *s, 
AVPacket *pkt,
 AVStream *st = s->streams[stream_index];
 AudioInterleaveContext *aic = st->priv_data;
 int ret;
-int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * 
aic->sample_size);
+int frame_size = *aic->samples * aic->sample_size;
+int size = FFMIN(av_fifo_size(aic->fifo), frame_size);
 if (!size || (!flush && size == av_fifo_size(aic->fifo)))
 return 0;
 
-ret = av_new_packet(pkt, size);
+ret = av_new_packet(pkt, frame_size);
 if (ret < 0)
 return ret;
 av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);
 
+if (size < pkt->size)
+memset(pkt->data + size, 0, pkt->size - size);
+
 pkt->dts = pkt->pts = aic->dts;
 pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
 pkt->stream_index = stream_index;
@@ -99,7 +103,7 @@ static int interleave_new_audio_packet(AVFormatContext *s, 
AVPacket *pkt,
 if (!*aic->samples)
 aic->samples = aic->samples_per_frame;
 
-return size;
+return pkt->size;
 }
 
 int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket 
*pkt, int flush,
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index 81d21704d9..4466685a2d 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,9 +1,9 @@
 649009e3d3d62eb3b6c56334d057cc4d *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
-5756c5f9bdb9718b91bfbf588afec189 *./tests/data/lavf/lavf.mxf
+9076b7015cffe8aa72883e900a2041a5 *./tests/data/lavf/lavf.mxf
 561721 ./tests/data/lavf/lavf.mxf
-./tests/data/lavf/lavf.mxf CRC=0xf21b1b48
+./tests/data/lavf/lavf.mxf CRC=0x96ff1b48
 02bf8f0cd8951a49e277306691cb1538 *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
-- 
2.17.0 (Apple Git-106)

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


[FFmpeg-devel] [PATCH 04/12] avformat/mxfenc: update body partition with footer offset

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfenc.c| 9 +++--
 tests/ref/lavf/mxf  | 6 +++---
 tests/ref/lavf/mxf_d10  | 2 +-
 tests/ref/lavf/mxf_dv25 | 2 +-
 tests/ref/lavf/mxf_dvcpro50 | 2 +-
 tests/ref/lavf/mxf_opatom   | 2 +-
 tests/ref/lavf/mxf_opatom_audio | 2 +-
 7 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index b54a94b62e..d13ddaff6d 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1908,7 +1908,7 @@ static int mxf_write_partition(AVFormatContext *s, int 
bodysid,
 else
 avio_write(pb, body_partition_key, 16);
 
-klv_encode_ber_length(pb, 88 + 16LL * 
DESCRIPTOR_COUNT(mxf->essence_container_count));
+klv_encode_ber4_length(pb, 88 + 16LL * 
DESCRIPTOR_COUNT(mxf->essence_container_count));
 
 // write partition value
 avio_wb16(pb, 1); // majorVersion
@@ -2854,7 +2854,7 @@ static int mxf_write_footer(AVFormatContext *s)
 {
 MXFContext *mxf = s->priv_data;
 AVIOContext *pb = s->pb;
-int err = 0;
+int i, err = 0;
 
 if (!mxf->header_written ||
 (s->oformat == _mxf_opatom_muxer && !mxf->body_partition_offset)) {
@@ -2898,6 +2898,11 @@ static int mxf_write_footer(AVFormatContext *s)
 if ((err = mxf_write_partition(s, 0, 0, 
header_closed_partition_key, 1)) < 0)
 goto end;
 }
+// update footer partition offset
+for (i = 0; i < mxf->body_partitions_count; i++) {
+avio_seek(pb, mxf->body_partition_offset[i]+44, SEEK_SET);
+avio_wb64(pb, mxf->footer_partition_offset);
+}
 }
 
 end:
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index 7f6d698855..1971e25fdf 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,9 +1,9 @@
-eea31259441d909fedb9a0e0eb9bbdb2 *./tests/data/lavf/lavf.mxf
+649009e3d3d62eb3b6c56334d057cc4d *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
-2c4a6634f646f7ab76bf2b7e71c8c893 *./tests/data/lavf/lavf.mxf
+1ab46fe6d07dc9eeb457772096f3a7db *./tests/data/lavf/lavf.mxf
 561721 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0xf21b1b48
-e547b44d71cd5871582522a31511ae9c *./tests/data/lavf/lavf.mxf
+02bf8f0cd8951a49e277306691cb1538 *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
diff --git a/tests/ref/lavf/mxf_d10 b/tests/ref/lavf/mxf_d10
index 0b9f49bb09..856fe9c3e9 100644
--- a/tests/ref/lavf/mxf_d10
+++ b/tests/ref/lavf/mxf_d10
@@ -1,3 +1,3 @@
-9f299fd4da6a20ef93adad7fe6a9f481 *./tests/data/lavf/lavf.mxf_d10
+e597f73ef9c9819710d2f815813eb91f *./tests/data/lavf/lavf.mxf_d10
 5332013 ./tests/data/lavf/lavf.mxf_d10
 ./tests/data/lavf/lavf.mxf_d10 CRC=0x6c74d488
diff --git a/tests/ref/lavf/mxf_dv25 b/tests/ref/lavf/mxf_dv25
index 200511e164..e94b3ca1ca 100644
--- a/tests/ref/lavf/mxf_dv25
+++ b/tests/ref/lavf/mxf_dv25
@@ -1,3 +1,3 @@
-358791c5468c39673239e038fb64a734 *./tests/data/lavf/lavf.mxf_dv25
+0fc964fa22bc8b3a389b81b9a2efccb3 *./tests/data/lavf/lavf.mxf_dv25
 3834413 ./tests/data/lavf/lavf.mxf_dv25
 ./tests/data/lavf/lavf.mxf_dv25 CRC=0xbdaf7f52
diff --git a/tests/ref/lavf/mxf_dvcpro50 b/tests/ref/lavf/mxf_dvcpro50
index f212c0321d..514a0475c9 100644
--- a/tests/ref/lavf/mxf_dvcpro50
+++ b/tests/ref/lavf/mxf_dvcpro50
@@ -1,3 +1,3 @@
-fac7c59ea81c752d769335ddaa818f90 *./tests/data/lavf/lavf.mxf_dvcpro50
+aa81ea83af44a69e73849e327cc4bd12 *./tests/data/lavf/lavf.mxf_dvcpro50
 7431213 ./tests/data/lavf/lavf.mxf_dvcpro50
 ./tests/data/lavf/lavf.mxf_dvcpro50 CRC=0xe3bbe4b4
diff --git a/tests/ref/lavf/mxf_opatom b/tests/ref/lavf/mxf_opatom
index 5ea47f4df6..cc4eb519ea 100644
--- a/tests/ref/lavf/mxf_opatom
+++ b/tests/ref/lavf/mxf_opatom
@@ -1,3 +1,3 @@
-49b0b3dfeb6a9ec024b047fc627b66fd *./tests/data/lavf/lavf.mxf_opatom
+06a1816aa91c733e1ef7e45d82e4f1d3 *./tests/data/lavf/lavf.mxf_opatom
 4717625 ./tests/data/lavf/lavf.mxf_opatom
 ./tests/data/lavf/lavf.mxf_opatom CRC=0xf55aa22a
diff --git a/tests/ref/lavf/mxf_opatom_audio b/tests/ref/lavf/mxf_opatom_audio
index 540f430cda..485964529f 100644
--- a/tests/ref/lavf/mxf_opatom_audio
+++ b/tests/ref/lavf/mxf_opatom_audio
@@ -1,3 +1,3 @@
-862dc5c9f2c94bd2c545ca64f923d1a1 *./tests/data/lavf/lavf.mxf_opatom_audio
+c45bb140605339556a77e751fda2c449 *./tests/data/lavf/lavf.mxf_opatom_audio
 102969 ./tests/data/lavf/lavf.mxf_opatom_audio
 ./tests/data/lavf/lavf.mxf_opatom_audio CRC=0xd155c6ff
-- 
2.17.0 (Apple Git-106)

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


[FFmpeg-devel] [PATCH 02/12] avformat/mxfenc: write index delta entry array needed by sony vegas pro 11

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfenc.c| 208 ++--
 tests/ref/lavf/mxf  |   6 +-
 tests/ref/lavf/mxf_d10  |   2 +-
 tests/ref/lavf/mxf_dv25 |   2 +-
 tests/ref/lavf/mxf_dvcpro50 |   2 +-
 tests/ref/lavf/mxf_opatom   |   2 +-
 tests/ref/lavf/mxf_opatom_audio |   2 +-
 7 files changed, 101 insertions(+), 123 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index b98d234f03..8c1e38353c 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -93,6 +93,8 @@ typedef struct MXFStreamContext {
 AVRational aspect_ratio; ///< display aspect ratio
 int closed_gop;  ///< gop is closed, used in mpeg-2 frame parsing
 int video_bit_rate;
+int slice_offset;
+int frame_size;  ///< frame size in bytes
 } MXFStreamContext;
 
 typedef struct MXFContainerEssenceEntry {
@@ -389,6 +391,7 @@ typedef struct MXFContext {
 AVRational audio_edit_rate;
 int store_user_comments;
 int track_instance_count; // used to generate MXFTrack uuids
+int cbr_index;   ///< use a constant bitrate index
 } MXFContext;
 
 static const uint8_t uuid_base[]= { 
0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd };
@@ -1696,6 +1699,7 @@ static void mxf_write_index_table_segment(AVFormatContext 
*s)
 AVIOContext *pb = s->pb;
 int i, j, temporal_reordering = 0;
 int key_index = mxf->last_key_index;
+int64_t pos;
 
 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
 
@@ -1704,12 +1708,8 @@ static void 
mxf_write_index_table_segment(AVFormatContext *s)
 
 avio_write(pb, index_table_segment_key, 16);
 
-if (mxf->edit_unit_byte_count) {
-klv_encode_ber_length(pb, 80);
-} else {
-klv_encode_ber_length(pb, 85 + 12+(s->nb_streams+1LL)*6 +
-  
12+mxf->edit_units_count*(11+mxf->slice_count*4LL));
-}
+klv_encode_ber4_length(pb, 0);
+pos = avio_tell(pb);
 
 // instance id
 mxf_write_local_tag(pb, 16, 0x3C0A);
@@ -1743,39 +1743,43 @@ static void 
mxf_write_index_table_segment(AVFormatContext *s)
 mxf_write_local_tag(pb, 4, 0x3F07);
 avio_wb32(pb, 1);
 
-if (!mxf->edit_unit_byte_count) {
-// real slice count - 1
-mxf_write_local_tag(pb, 1, 0x3F08);
-avio_w8(pb, mxf->slice_count);
-
-// delta entry array
-mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09);
-avio_wb32(pb, s->nb_streams+1); // num of entries
-avio_wb32(pb, 6);   // size of one entry
-// write system item delta entry
-avio_w8(pb, 0);
-avio_w8(pb, 0); // slice entry
-avio_wb32(pb, 0); // element delta
-for (i = 0; i < s->nb_streams; i++) {
-AVStream *st = s->streams[i];
-MXFStreamContext *sc = st->priv_data;
-avio_w8(pb, sc->temporal_reordering);
-if (sc->temporal_reordering)
-temporal_reordering = 1;
-if (i == 0) { // video track
-avio_w8(pb, 0); // slice number
-avio_wb32(pb, KAG_SIZE); // system item size including klv fill
-} else { // audio track
-unsigned audio_frame_size = 
sc->aic.samples[0]*sc->aic.sample_size;
-audio_frame_size += klv_fill_size(audio_frame_size);
-avio_w8(pb, 1);
-avio_wb32(pb, (i-1)*audio_frame_size); // element delta
-}
+// real slice count - 1
+mxf_write_local_tag(pb, 1, 0x3F08);
+avio_w8(pb, !mxf->edit_unit_byte_count); // only one slice for CBR
+
+// delta entry array
+mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09);
+avio_wb32(pb, s->nb_streams+1); // num of entries
+avio_wb32(pb, 6);   // size of one entry
+// write system item delta entry
+avio_w8(pb, 0);
+avio_w8(pb, 0); // slice entry
+avio_wb32(pb, 0); // element delta
+// write each stream delta entry
+for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = s->streams[i];
+MXFStreamContext *sc = st->priv_data;
+avio_w8(pb, sc->temporal_reordering);
+if (sc->temporal_reordering)
+temporal_reordering = 1;
+if (mxf->edit_unit_byte_count) {
+avio_w8(pb, 0); // slice number
+avio_wb32(pb, sc->slice_offset);
+} else if (i == 0) { // video track
+avio_w8(pb, 0); // slice number
+avio_wb32(pb, KAG_SIZE); // system item size including klv fill
+} else { // audio track
+unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size;
+audio_frame_size += klv_fill_size(audio_frame_size);
+avio_w8(pb, 1);
+avio_wb32(pb, (i-1)*audio_frame_size); // element delta
 }
+}
 
-mxf_write_local_tag(pb, 8 + 
mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A);
+if 

[FFmpeg-devel] [PATCH 03/12] avformat/mxfenc: add mpeg-2 specific metadata, fix compatibility with sony content browser

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfenc.c| 46 ++---
 tests/ref/lavf/mxf  |  6 ++---
 tests/ref/lavf/mxf_d10  |  2 +-
 tests/ref/lavf/mxf_dv25 |  2 +-
 tests/ref/lavf/mxf_dvcpro50 |  2 +-
 tests/ref/lavf/mxf_opatom   |  2 +-
 tests/ref/lavf/mxf_opatom_audio |  2 +-
 7 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 8c1e38353c..b54a94b62e 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -95,6 +95,10 @@ typedef struct MXFStreamContext {
 int video_bit_rate;
 int slice_offset;
 int frame_size;  ///< frame size in bytes
+int seq_closed_gop;  ///< all gops in sequence are closed, used in 
mpeg-2 descriptor
+int max_gop; ///< maximum gop size, used by mpeg-2 descriptor
+int b_picture_count; ///< maximum number of consecutive b pictures, 
used in mpeg-2 descriptor
+int low_delay;   ///< low delay, used in mpeg-2 descriptor
 } MXFStreamContext;
 
 typedef struct MXFContainerEssenceEntry {
@@ -528,7 +532,11 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
 { 0x3F0A, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x04,0x04,0x02,0x05,0x00,0x00,0x00}},
 /* Index Entry Array */
 // MPEG video Descriptor
 { 0x8000, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}},
 /* BitRate */
+{ 0x8003, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}},
 /* LowDelay */
+{ 0x8004, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}},
 /* ClosedGOP */
+{ 0x8006, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}},
 /* MaxGOP */
 { 0x8007, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}},
 /* ProfileAndLevel */
+{ 0x8008, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}},
 /* BPictureCount */
 // Wave Audio Essence Descriptor
 { 0x3D09, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}},
 /* Average Bytes Per Second */
 { 0x3D0A, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}},
 /* Block Align */
@@ -1264,10 +1272,8 @@ static int64_t mxf_write_cdci_common(AVFormatContext *s, 
AVStream *st, const UID
 avio_wb32(pb, sc->h_chroma_sub_sample);
 
 // vertical subsampling
-if (sc->v_chroma_sub_sample) {
-mxf_write_local_tag(pb, 4, 0x3308);
-avio_wb32(pb, sc->v_chroma_sub_sample);
-}
+mxf_write_local_tag(pb, 4, 0x3308);
+avio_wb32(pb, sc->v_chroma_sub_sample);
 
 // color siting
 mxf_write_local_tag(pb, 1, 0x3303);
@@ -1379,6 +1385,22 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, 
AVStream *st)
 if (!st->codecpar->profile)
 profile_and_level |= 0x80; // escape bit
 avio_w8(pb, profile_and_level);
+
+// low delay
+mxf_write_local_tag(pb, 1, 0x8003);
+avio_w8(pb, sc->low_delay);
+
+// closed gop
+mxf_write_local_tag(pb, 1, 0x8004);
+avio_w8(pb, sc->seq_closed_gop);
+
+// max gop
+mxf_write_local_tag(pb, 2, 0x8006);
+avio_wb16(pb, sc->max_gop);
+
+// b picture count
+mxf_write_local_tag(pb, 2, 0x8008);
+avio_wb16(pb, sc->b_picture_count);
 }
 
 mxf_update_klv_size(pb, pos);
@@ -1699,6 +1721,7 @@ static void mxf_write_index_table_segment(AVFormatContext 
*s)
 AVIOContext *pb = s->pb;
 int i, j, temporal_reordering = 0;
 int key_index = mxf->last_key_index;
+int prev_non_b_picture = 0;
 int64_t pos;
 
 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
@@ -1777,6 +1800,7 @@ static void mxf_write_index_table_segment(AVFormatContext 
*s)
 }
 
 if (!mxf->edit_unit_byte_count) {
+MXFStreamContext *sc = s->streams[0]->priv_data;
 mxf_write_local_tag(pb, 8 + mxf->edit_units_count*15, 0x3F0A);
 avio_wb32(pb, mxf->edit_units_count);  // num of entries
 avio_wb32(pb, 15);  // size of one entry
@@ -1785,6 +1809,7 @@ static void mxf_write_index_table_segment(AVFormatContext 
*s)
 int temporal_offset = 0;
 
 if (!(mxf->index_entries[i].flags & 0x33)) { // I-frame
+sc->max_gop = FFMAX(sc->max_gop, i - mxf->last_key_index);
 mxf->last_key_index = key_index;
 key_index = i;
 }
@@ -1804,11 +1829,13 @@ static void 
mxf_write_index_table_segment(AVFormatContext *s)
 avio_w8(pb, temporal_offset);
 
 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and 
forward prediction
+sc->b_picture_count = FFMAX(sc->b_picture_count, i - 
prev_non_b_picture);
 avio_w8(pb, mxf->last_key_index - i);
 } else {
 

[FFmpeg-devel] [PATCH 01/12] avformat/mxfenc: automatically update descriptors klv size

2018-07-04 Thread Baptiste Coudurier
---
 libavformat/mxfenc.c | 80 +---
 1 file changed, 39 insertions(+), 41 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 77f60f5874..b98d234f03 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1104,14 +1104,16 @@ static void mxf_write_multi_descriptor(AVFormatContext 
*s)
 mxf_write_uuid(pb, SubDescriptor, i);
 }
 
-static void mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const UID 
key, unsigned size)
+static int64_t mxf_write_generic_desc(AVFormatContext *s, AVStream *st, const 
UID key)
 {
 MXFContext *mxf = s->priv_data;
 MXFStreamContext *sc = st->priv_data;
 AVIOContext *pb = s->pb;
+int64_t pos;
 
 avio_write(pb, key, 16);
-klv_encode_ber4_length(pb, size+20+8+12+20);
+klv_encode_ber4_length(pb, 0);
+pos = avio_tell(pb);
 
 mxf_write_local_tag(pb, 16, 0x3C0A);
 mxf_write_uuid(pb, SubDescriptor, st->index);
@@ -1136,6 +1138,8 @@ static void mxf_write_generic_desc(AVFormatContext *s, 
AVStream *st, const UID k
 
 mxf_write_local_tag(pb, 16, 0x3004);
 avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16);
+
+return pos;
 }
 
 static const UID mxf_mpegvideo_descriptor_key = { 
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 
};
@@ -1172,7 +1176,7 @@ static int get_trc(UID ul, enum 
AVColorTransferCharacteristic trc)
 }
 }
 
-static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID 
key, unsigned size)
+static int64_t mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const 
UID key)
 {
 MXFStreamContext *sc = st->priv_data;
 AVIOContext *pb = s->pb;
@@ -1180,25 +1184,10 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
AVStream *st, const UID ke
 int stored_height = (st->codecpar->height+15)/16*16;
 int display_height;
 int f1, f2;
-unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5 + 5*8 + 6;
 UID transfer_ul = {0};
+int64_t pos = mxf_write_generic_desc(s, st, key);
 
-if (sc->interlaced && sc->field_dominance)
-desc_size += 5;
-if (sc->signal_standard)
-desc_size += 5;
-if (sc->interlaced)
-desc_size += 8;
-if (sc->v_chroma_sub_sample)
-desc_size += 8;
-if (st->codecpar->color_range != AVCOL_RANGE_UNSPECIFIED)
-desc_size += 8 * 3;
-if (s->oformat == _mxf_d10_muxer)
-desc_size += 8 + 8 + 8;
-if (get_trc(transfer_ul, st->codecpar->color_trc) >= 0)
-desc_size += 20;
-
-mxf_write_generic_desc(s, st, key, desc_size);
+get_trc(transfer_ul, st->codecpar->color_trc);
 
 mxf_write_local_tag(pb, 4, 0x3203);
 avio_wb32(pb, stored_width);
@@ -1352,11 +1341,22 @@ static void mxf_write_cdci_common(AVFormatContext *s, 
AVStream *st, const UID ke
 avio_w8(pb, sc->field_dominance);
 }
 
+return pos;
+}
+
+static void mxf_update_klv_size(AVIOContext *pb, int64_t pos)
+{
+int64_t cur_pos = avio_tell(pb);
+int size = cur_pos - pos;
+avio_seek(pb, pos - 4, SEEK_SET);
+klv_encode_ber4_length(pb, size);
+avio_seek(pb, cur_pos, SEEK_SET);
 }
 
 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)
 {
-mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key, 0);
+int64_t pos = mxf_write_cdci_common(s, st, mxf_cdci_descriptor_key);
+mxf_update_klv_size(s->pb, pos);
 }
 
 static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
@@ -1364,10 +1364,9 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, 
AVStream *st)
 AVIOContext *pb = s->pb;
 MXFStreamContext *sc = st->priv_data;
 int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
+int64_t pos = mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key);
 
 if (st->codecpar->codec_id != AV_CODEC_ID_H264) {
-mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
-
 // bit rate
 mxf_write_local_tag(pb, 4, 0x8000);
 avio_wb32(pb, sc->video_bit_rate);
@@ -1377,26 +1376,19 @@ static void mxf_write_mpegvideo_desc(AVFormatContext 
*s, AVStream *st)
 if (!st->codecpar->profile)
 profile_and_level |= 0x80; // escape bit
 avio_w8(pb, profile_and_level);
-} else {
-mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 0);
 }
+
+mxf_update_klv_size(pb, pos);
 }
 
-static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, 
const UID key, unsigned size)
+static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream 
*st, const UID key)
 {
 AVIOContext *pb = s->pb;
 MXFContext *mxf = s->priv_data;
 int show_warnings = !mxf->footer_partition_offset;
-int duration_size = 0;
+int64_t pos = mxf_write_generic_desc(s, st, key);
 
-if (s->oformat == _mxf_opatom_muxer)
-duration_size = 12;
-if (s->oformat == _mxf_d10_muxer)
-size += 5;
-
-

Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Shlomi Fish
On Wed, 4 Jul 2018 18:55:42 +0200
Carl Eugen Hoyos  wrote:

> 2018-06-28 10:52 GMT+02:00, Shlomi Fish :
> 
> > Attached is the 2nd take of the patch for vf_weave.c. Please review.  
> 
> Patch applied.
> 

Thanks!

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



-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/Summerschool-at-the-NSA/

He who reinvents the wheel, will understand much better how a wheel works.
— http://www.shlomifish.org/humour.html

Please reply to list if it's a mailing list post - http://shlom.in/reply .
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Shlomi Fish
Hi,

On Wed, 4 Jul 2018 18:45:09 +0200
Carl Eugen Hoyos  wrote:

> 2018-06-28 10:52 GMT+02:00, Shlomi Fish :
> 
> > Attached is the 2nd take of the patch for vf_weave.c. Please review.  
> 
> For future patches:
> 
> > The changes contained in this patch are hereby placed under the Expat
> > licence.  
> 
> If you add a new file (like a new filter or decoder) please feel free
> to use the MIT license if you prefer it over the LGPL.
> If you change a small number of lines in an existing file, please avoid
> this, two developers already spent time on this unneeded line.
> 

my intention in that was to avoid licensing my changes under the LGPL, so
future maintainers will be able to change the licence of the file to a
different one, should it be desirable. Next time, I will provide a better
phrasing, however.

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



-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://is.gd/KNvczZ - The FSF Announces New Versions of the GPL

He who has more is not happier than he who wants less.
— Source unknown, via Nadav Har’El.

Please reply to list if it's a mailing list post - http://shlom.in/reply .
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [RFC] New build system

2018-07-04 Thread Mathieu Duponchelle
On 07/04/2018 07:01 PM, Carl Eugen Hoyos wrote:
> I don't understand: If everything is enabled and there are
> no options to disable features, how did you (and other
> people in favour of this change) measure performance?


Everything is automatically enabled indeed, but most of the system checks are
however implemented, and the internal dependency check loop has been ported,
making for a pretty fair comparison, if anything the amount of checks is 
probably
higher with the meson port.

Regarding build time (which as I stated is similar), the amount of object files 
being
compiled is also roughly the same.

Given the nature of FFmpeg's build system, a pure apples to apples comparison
is probably be going to be difficult to make, but I think the measurements I 
made
show differences significant enough to be worth mentioning.

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


Re: [FFmpeg-devel] [RFC] New build system

2018-07-04 Thread Carl Eugen Hoyos
2018-06-14 18:03 GMT+02:00, Josh de Kock :

> - Exposing options, for now everything is automatically enabled

I don't understand: If everything is enabled and there are
no options to disable features, how did you (and other
people in favour of this change) measure performance?

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


Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Carl Eugen Hoyos
2018-06-28 10:52 GMT+02:00, Shlomi Fish :

> Attached is the 2nd take of the patch for vf_weave.c. Please review.

Patch applied.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Jean-Baptiste Kempf
Hello,

On Wed, 4 Jul 2018, at 16:19, Pedro Arthur wrote:
> 2018-07-04 4:03 GMT-03:00 Jean-Baptiste Kempf :
> > On Wed, 4 Jul 2018, at 01:22, Carl Eugen Hoyos wrote:
> >> 2018-07-04 0:14 GMT+02:00, Jean-Baptiste Kempf :
> >> > On Tue, 3 Jul 2018, at 20:59, Carl Eugen Hoyos wrote:
> >> >> How is this case different from many arrays in libavcodec/*data*?
> >> >
> >> > It is very different: the arrays in *data* come either from a
> >> > mathematical computation or a spec.
> >>
> >> (Apart from: Free and open specs?)
> >> This is probably true for some of the arrays, I think it is
> >> very unlikely that it's true for all of them.
> >
> > The point is: you can recreate all of those arrays.
> > If OP dies, you can still take over.
> >
> >> > Else, as some Debian Developer said: "It looks like code
> >> > hidden in an unsigned char array"
> >>
> >> Is it "code" or data that was computed with a copyrighted
> >> algorithm?
> It is only data, namely the weights used in the filters.

Sure, but how can we recreate this data, if you are not around?
How can we check your findings?

> > How can you know, if it is not explained, and you cannot reproduce it?
> > How is it different from a binary blob?
> >
> > Anything related to NN is very annoying, if you don't share the dataset and 
> > the methodology.
> 
> The paper cited in the code contains all relevant information for
> anyone with basic CNN knowledge to understand the model and maintain
> the code.
> The whole point of training a NN is that you do it once, takes a lot
> of time, and never do it again.
> If you look at the publications in this area, the concept of
> reproducibility is not the usually expected "bit exact" ,as other
> mathematical fields.
> It is more like achieving similar results, given the model and dataset.

I completely understand, having done some of that myself.

> For anyone interested in the training process, Sergey provided the
> repo [1] with scripts for downloading the dataset and training.

That's great!
What is the licensing of this?

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Jean-Baptiste Kempf
Hello,

On Wed, 4 Jul 2018, at 18:42, Carl Eugen Hoyos wrote:
> > The point is: you can recreate all of those arrays.
> 
> I believe the only way to recreate (some of) the
> arrays in libavcodec/*data* is to look into old
> FFmpeg sources but I apparently misunderstand
> you, sorry.
> 
> I always thought we can use these arrays of numbers
> because arrays of numbers are in general not
> copyrightable but you seem to disagree?

It's not at all a problem of copyright, but a question of being free software 
or not.
And yes, array of numbers are not copyrightable.

> > If OP dies, you can still take over.
> 
> In the case of this filter, you can always recreate
> the numbers using the github repository, no?

Sure, but the numbers are not meaningfull at all.
How can you be sure that the dataset is sane?


> >> > Else, as some Debian Developer said: "It looks like code
> >> > hidden in an unsigned char array"
> >>
> >> Is it "code" or data that was computed with a copyrighted
> >> algorithm?
> >
> > How can you know, if it is not explained, and you cannot
> > reproduce it?
> 
> If you believe it is insufficiently documented, you - ideally
> before the commit - should ask for more documentation.
> (This can of course be done now.)
> 
> > How is it different from a binary blob?
> 
> I thought a "binary blob" is an executable program that
> you load into some hardware (or a simulator) and it
> gets executed.

How can you be sure that this is not obfuscated code?
See the issue about intel "open source" driver and its video decoder on Debian.

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Carl Eugen Hoyos
2018-06-28 10:52 GMT+02:00, Shlomi Fish :

> Attached is the 2nd take of the patch for vf_weave.c. Please review.

For future patches:

> The changes contained in this patch are hereby placed under the Expat licence.

If you add a new file (like a new filter or decoder) please feel free
to use the MIT license if you prefer it over the LGPL.
If you change a small number of lines in an existing file, please avoid
this, two developers already spent time on this unneeded line.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Carl Eugen Hoyos
2018-07-04 9:03 GMT+02:00, Jean-Baptiste Kempf :
> On Wed, 4 Jul 2018, at 01:22, Carl Eugen Hoyos wrote:
>> 2018-07-04 0:14 GMT+02:00, Jean-Baptiste Kempf :
>> > On Tue, 3 Jul 2018, at 20:59, Carl Eugen Hoyos wrote:
>> >> How is this case different from many arrays in libavcodec/*data*?
>> >
>> > It is very different: the arrays in *data* come either
>> > from a mathematical computation or a spec.
>>
>> (Apart from: Free and open specs?)
>> This is probably true for some of the arrays, I think it is
>> very unlikely that it's true for all of them.
>
> The point is: you can recreate all of those arrays.

I believe the only way to recreate (some of) the
arrays in libavcodec/*data* is to look into old
FFmpeg sources but I apparently misunderstand
you, sorry.

I always thought we can use these arrays of numbers
because arrays of numbers are in general not
copyrightable but you seem to disagree?

> If OP dies, you can still take over.

In the case of this filter, you can always recreate
the numbers using the github repository, no?

>> > Else, as some Debian Developer said: "It looks like code
>> > hidden in an unsigned char array"
>>
>> Is it "code" or data that was computed with a copyrighted
>> algorithm?
>
> How can you know, if it is not explained, and you cannot
> reproduce it?

If you believe it is insufficiently documented, you - ideally
before the commit - should ask for more documentation.
(This can of course be done now.)

> How is it different from a binary blob?

I thought a "binary blob" is an executable program that
you load into some hardware (or a simulator) and it
gets executed.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Paul B Mahol
On 7/4/18, Jean-Baptiste Kempf  wrote:
> On Tue, 3 Jul 2018, at 20:59, Carl Eugen Hoyos wrote:
>> How is this case different from many arrays in libavcodec/*data*?
>
> It is very different: the arrays in *data* come either from a mathematical
> computation or a spec.
>
> Else, as some Debian Developer said: "It looks like code hidden in an
> unsigned char array"

Lot of my code have that, so it should be removed from FFmpeg ASAP!
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Paul B Mahol
On 7/4/18, Shlomi Fish  wrote:
> On Thu, 28 Jun 2018 11:52:10 +0300
> Shlomi Fish  wrote:
>
>> Hi all!
>>
>> Attached is the 2nd take of the patch for vf_weave.c. Please review.
>>
>
> Ping.

If expat license is compatible with LGPL that it is ok for merge.

Otherwise it should not be committed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [RFC] New build system

2018-07-04 Thread Mathieu Duponchelle
Hey $list, not an FFmpeg developer, but I worked on the meson port and figured
I could address some of the points that were made.

Since the initial post I have also added support for compiling with Msys/MingW
on Window now in addition to MSVC.

## Performance comparison

A significant part of the discussion has focused on the configure script
being slow, often in a hard-to-predict manner. My findings confirm that:

| Method  | Linux  | Windows (msys-2 / mingw64) | MacOS high sierra 
|
| --- | -- | -- | - 
|
| meson   | 16s    | 1m 2s  | 25s   
|
| ./configure | 1m 21s (506 %) | 13m 5s (1266 %)    | 4m 20s (1040 %)   
|

I have no doubt the configure script could be optimized further, but it
is obviously a pretty complex piece of code, where a meson port would
have the advantage of shifting the burden of optimization to the meson
development team, see https://github.com/mesonbuild/meson/issues/3635 for
example.

The other question is if anyone is actually willing to work on optimising the
configure script, because if not it's a bit of a moot point. And it would have
to be optimised a lot to make it somewhat bearable on Windows again.

Profiling meson is also probably much easier than profiling the configure
script, I noticed one developer reporting their initial attempt at doing
so resulted in a window manager crash. On the other hand, meson recently
added native support for self-profiling, using the `--profile-self` switch
to trigger the creation of a profile graph.

It should be noted that build time does *not* seem to be any different
with meson or make, as FFmpeg's build is already well parallelized.

## Meson development practices

While meson is indeed a relatively new project, it has been adopted by many
projects, GNOME being a prominent one, but neither an early one nor the only
one.

It is neither a GNOME project nor a freedesktop project, you can find
a (non-exhaustive) list of users at http://mesonbuild.com/Users.html. It
has been adopted for example by xorg, wayland, mesa, and VLC could as
far as I understand soon be added to that list as well.

It has a policy of no regressions, and an extensive test suite to ensure
that.

## The port currently depends on meson master

I did debate waiting for a new meson release before publishing my work,
but (perhaps impatiently) decided against it.

The meson port currently depends on two features I added in meson for FFmpeg
specifically:

* A new dictionary built-in type (https://github.com/mesonbuild/meson/pull/3490)
* Native support for generating asm config files 
(https://github.com/mesonbuild/meson/pull/3636)

While I see how this can be used as an argument against the meson port,
my view on that is a bit different, as I think it shows meson's development
team welcomes new features, provided a good case is made for them.

Meson is usable directly from a git checkout, I figured it was a reasonably
low barrier to testing what is still obviously a semi-experimental port.

In any case, all the improvements that were made to meson for the FFmpeg
use case are now part of the latest release, 0.47 
(https://mesonbuild.com/Release-notes-for-0-47-0.html)
which can easily be installed using pip3 if you are not on a distro that
has the latest release.

## Duplicate maintenance burden

That is a very valid point, which an outsider to the project cannot really
argue with. What I can say is that I will be happy to assist with improving
and maintaining the port should the community decide that it would be a
valuable addition, and I am sure I would not be the only one with an interest
in keeping the Meson port up-to-date.

Anyone developing on Windows would likely appreciate it, and any projects that
depend on FFMpeg and use meson themselves as their build system would be able
to use the latest FFmpeg as a meson subproject should they wish to do so
instead of using the system-installed version.

## Points I have not seen discussed

While configure-time performance improvements are a clear advantage, I think
the main reasons a port to meson could prove useful in the long term are
maintainability and accessibility.

I think it is likely that newcomers to FFmpeg development find contributing
to the configure script a bit daunting, and that even long-time FFmpeg
developers must sometimes have a hard time with it.

On the other hand, my experience with meson is that it tends to help with
writing readable and elegant build definitions, I can't think of another
build system that does a better job at that.

If there are any other questions related to meson or the FFmpeg meson port
please feel free to ask and I'll do my best to answer them.

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Pedro Arthur
2018-07-04 4:03 GMT-03:00 Jean-Baptiste Kempf :
> On Wed, 4 Jul 2018, at 01:22, Carl Eugen Hoyos wrote:
>> 2018-07-04 0:14 GMT+02:00, Jean-Baptiste Kempf :
>> > On Tue, 3 Jul 2018, at 20:59, Carl Eugen Hoyos wrote:
>> >> How is this case different from many arrays in libavcodec/*data*?
>> >
>> > It is very different: the arrays in *data* come either from a
>> > mathematical computation or a spec.
>>
>> (Apart from: Free and open specs?)
>> This is probably true for some of the arrays, I think it is
>> very unlikely that it's true for all of them.
>
> The point is: you can recreate all of those arrays.
> If OP dies, you can still take over.
>
>> > Else, as some Debian Developer said: "It looks like code
>> > hidden in an unsigned char array"
>>
>> Is it "code" or data that was computed with a copyrighted
>> algorithm?
It is only data, namely the weights used in the filters.

> How can you know, if it is not explained, and you cannot reproduce it?
> How is it different from a binary blob?
>
> Anything related to NN is very annoying, if you don't share the dataset and 
> the methodology.

The paper cited in the code contains all relevant information for
anyone with basic CNN knowledge to understand the model and maintain
the code.
The whole point of training a NN is that you do it once, takes a lot
of time, and never do it again.
If you look at the publications in this area, the concept of
reproducibility is not the usually expected "bit exact" ,as other
mathematical fields.
It is more like achieving similar results, given the model and dataset.

For anyone interested in the training process, Sergey provided the
repo [1] with scripts for downloading the dataset and training.

[1] - https://github.com/HighVoltageRocknRoll/sr
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avutil/hwcontext_qsv: fix log level for session initialization error

2018-07-04 Thread Moritz Barsnick
While the error is not fatal, the message should not be displayed only
in verbose logging, as its consequences are of interest.

Also fix message formatting (missing space).

Signed-off-by: Moritz Barsnick 
---

Ideally, the returned mfxStatus would be evaluated and printed, but no
such function is available (yet). %d perhaps?

 libavutil/hwcontext_qsv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 250091c4e8..e7ffb42f37 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -474,7 +474,7 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
 
 err = MFXVideoVPP_Init(*session, );
 if (err != MFX_ERR_NONE) {
-av_log(ctx, AV_LOG_VERBOSE, "Error opening the internal VPP session."
+av_log(ctx, AV_LOG_WARNING, "Error opening the internal VPP session. "
"Surface upload/download will not be possible\n");
 MFXClose(*session);
 *session = NULL;
-- 
2.14.4
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/videotoolboxenc: fix undefined behavior with rc_max_rate=0

2018-07-04 Thread Thomas Guillem
On Wed, Jul 4, 2018, at 09:05, Thomas Guillem wrote:
> On macOS, a zero rc_max_rate cause an error from
> VTSessionSetProperty(kVTCompressionPropertyKey_DataRateLimits).
> 
> on iOS (depending on device/version), a zero rc_max_rate cause invalid
> arguments from the vtenc_output_callback after few frames and then a crash
> within the VideoToolbox library.

In fact, when setting a correct max_rate on iOS, you could still get random 
crashes the same way. It's happening on ios 11.4 but seems to be OK on iOS 12 
Beta.

> ---
>  libavcodec/videotoolboxenc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index ac847358ab..aa9aae7e05 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -1019,6 +1019,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
>  
>  if (vtctx->codec_id == AV_CODEC_ID_H264) {
>  // kVTCompressionPropertyKey_DataRateLimits is not available 
> for HEVC
> +if (max_rate > 0) {
>  bytes_per_second_value = max_rate >> 3;
>  bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
>kCFNumberSInt64Type,
> @@ -1058,6 +1059,7 @@ static int vtenc_create_encoder(AVCodecContext   
> *avctx,
>  av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate 
> property: %d\n", status);
>  return AVERROR_EXTERNAL;
>  }
> +}
>  
>  if (profile_level) {
>  status = VTSessionSetProperty(vtctx->session,
> -- 
> 2.18.0
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/truemotion2: Check len in tm2_read_stream()

2018-07-04 Thread Michael Niedermayer
On Mon, Jul 02, 2018 at 02:10:44AM +0200, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 8774/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TRUEMOTION2_fuzzer-5942199639343104
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> ---
>  libavcodec/truemotion2.c | 4 
>  1 file changed, 4 insertions(+)

will apply patchset

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

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



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


Re: [FFmpeg-devel] [PATCH] avcodec/mpeg4videodec: Remove use of FF_PROFILE_MPEG4_SIMPLE_STUDIO as indicator of studio profile

2018-07-04 Thread Michael Niedermayer
On Tue, Jul 03, 2018 at 01:08:58AM +0200, Michael Niedermayer wrote:
> The profile field is changed by code inside and outside the decoder,
> its not a reliable indicator of the internal codec state.
> Maintaining it consistency with studio_profile is messy.
> Its easier to just avoid it and use only studio_profile
> 
> Fixes: assertion failure
> Fixes: ffmpeg_crash_9.avi
> 
> Found-by: Thuan Pham, Marcel Böhme, Andrew Santosa and Alexandru Razvan 
> Caciulescu with AFLSmart
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/error_resilience.c | 3 +--
>  libavcodec/h263dec.c  | 6 --
>  libavcodec/mpeg4videodec.c| 1 -
>  3 files changed, 5 insertions(+), 5 deletions(-)

will apply

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

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato


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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/utils: report insane channel count errors

2018-07-04 Thread Michael Niedermayer
On Tue, Jul 03, 2018 at 12:51:11PM +0200, Marton Balint wrote:
> More than 64 is not *that* insane, so let's report the error at least.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavcodec/utils.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 59d41ccbb6..4ac73fcd92 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -674,6 +674,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
> *avctx, const AVCodec *code
>  av_freep(>subtitle_header);
>  
>  if (avctx->channels > FF_SANE_NB_CHANNELS) {
> +av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", 
> avctx->channels);
>  ret = AVERROR(EINVAL);
>  goto free_and_end;
>  }

LGTM, if nothing equivalent is otherwise printed

thx

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

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle


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


Re: [FFmpeg-devel] [PATCH] Refactor two near-identical clauses - take 2

2018-07-04 Thread Shlomi Fish
On Thu, 28 Jun 2018 11:52:10 +0300
Shlomi Fish  wrote:

> Hi all!
> 
> Attached is the 2nd take of the patch for vf_weave.c. Please review.
> 

Ping.

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

Television is a medium because anything well done is rare.
— attributed to both Fred Allen and Ernie Kovacs

Please reply to list if it's a mailing list post - http://shlom.in/reply .
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3 3/3] aadec: fix seeking in mp3 content

2018-07-04 Thread Karsten Otto

> Am 04.07.2018 um 03:26 schrieb Michael Niedermayer :
> 
> Signierter PGP-Teil
> On Tue, Jul 03, 2018 at 10:25:36PM +0200, Karsten Otto wrote:
>> TL;DR: I will drop patch 3/3, may rather spend some time investigating why
>> "ff ee 47 9d“ passes the mp3 header parser. Also, the aa file "index" cannot
>> be used for frame or chapter detection, unfortunately.
>> 
>> More details inline below.
>> 
>>> Am 03.07.2018 um 02:32 schrieb Michael Niedermayer :
>>> 
>>> Signierter PGP-Teil
>>> On Mon, Jul 02, 2018 at 07:21:43PM +0200, Karsten Otto wrote:
 
> Am 02.07.2018 um 10:59 schrieb Michael Niedermayer 
> :
> 
> Signierter PGP-Teil
> On Thu, Jun 21, 2018 at 06:58:26PM +0200, Karsten Otto wrote:
>> MP3 frames may not be aligned to aa chunk boundaries. After seeking,
>> scan for the next valid frame header. Then truncate the packet, and
>> also adjust timestamp information accordingly.
>> ---
>> libavformat/aadec.c | 33 -
>> 1 file changed, 28 insertions(+), 5 deletions(-)
> 
> Please see AVSTREAM_PARSE_TIMESTAMPS
> 
> This codec specific code in demuxers should not be needed
> 
 I tried that before, and you are right that it takes care of timestamp 
 adjustments.
 
 However, after a seek the parsed packet still contains a partial frame 
 before the
 next full one. I had expected libavformat/mpegaudio_parser.c to detect this
 situation and discard the fragment, but unfortunately it does not. Instead 
 it passes
 it unchanged to the codec, which plays it as a pop or even a very ugly 
 BLEEEP -
 painful while wearing headphones!
>>> 
>>> I think you mis-diagnose this at least somewhat
>>> your code searches for a specific mp3 header, the parser and decoder would
>>> accept a wider range of mp3 variants.
>>> But both can choose points that are not mp3 frame starts. (if that is the
>>> problem you are seeing, iam not completely sure it is)
>>> 
>> It took a closer look at what happens when I hear a BLEEP: The packet begins
>> with a partial frame, starting with the byte sequence "ff ee 47 9d“. 
>> Unfortunately,
>> the mp3 parser indeed accepts this as a valid mp3 header, causing the noise.
>> By looking for the more restricted header, my patch finds the real next 
>> frame at
>> offset 78.
>> 
>> BTW: Should this sequence actually pass? AFAIK 01 is not a valid MPEG audio
>> version ID?
>> 
>>> Also is the more restricted header you search for always used or could
>>> this be failing with some files ?
>>> 
>> Good question. So far, all mp3 aa files I tested with matched the format 
>> (MPEG 2
>> Layer III at 32 kbps and 22kHz). I doubt there are other variants, but can’t 
>> be sure.
>> 
>>> Either way, looking at the demuxer a bit deeper, theres a TOC list in the
>>> main header which points to chunks. The one file i found has 12 such chunks
>>> the first represents the whole file i suspect, the next largest the audio
>>> data, another one the metadata.
>>> I guess the remaining 2 large ones could be a cover image and an index.
>> Correct, seems like all aa files have the TOC, but its entries can be in a 
>> different
>> order in each file. I guess thats why the original aadec.c implementation 
>> just
>> looks for the largest chunk to play.
>> 
>>> I didnt really look at it, but theres a table in there with pairs of 32bit
>>> values. the first in the file i have goes from 0 to 3 the second starts
>>> multiple times from 0 and seems monotonly increasing and staying within
>>> the filesize.
>>> The sample i have does not store mp3 but it looks like this is a index
>>> maybe offsets for packets in each of the 3 chapters.
>>> 
>>> Please look at the data, if it can be used. It would be much better than
>>> scaning the file linearly and searching for some byte sequence to find
>>> packet starts.
>>> 
>> Short answer: Sorry, it is not possible to derive frame offsets nor chapter
>> offsets from the index.
>> 
> 
>> Long answer:
>> All offsets in the index are the same, and matching the "codec_second_size"
>> = crypto chunk size, roughly one second of audio:
>> - 1045 for format 2 (SIPR 8kbps)
>> - 2000 for format 3 (SIPR 16kbps)
>> - 3982 for format 4 (MP3 32kbps)
>> This is different from the respective frame size, which is 19, 20, and 
>> 104/105
> 
> The first 2 are exact multiples of the frame size.
> 
> I dont have a sample for the mp3 case so i cannot check but are you sure
> the actually writen numbers dont match up multiples of mp3 frames ?
> 
Yes, I have tested both with some old aa books I still had on disk, and some I
bought more recently. Using -fdebug ts, I can clearly see a packet size of
104 alternating with 105, as I would expect from mp3. Furthermore, using my
specialized header detection on every chunk, I see that the actual mp3 frame
header indeed starts at offset 0 in chunk 0. But then it changes for every
subsequent chunk, I have seen a maximum of 103, as 

Re: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: fix undefined behavior with rc_max_rate=0

2018-07-04 Thread Thomas Guillem

On Tue, Jul 3, 2018, at 20:53, Carl Eugen Hoyos wrote:
> 2018-07-03 17:05 GMT+02:00, Thomas Guillem :
> > On macOS, a zero rc_max_rate cause an error from
> > VTSessionSetProperty(kVTCompressionPropertyKey_DataRateLimits).
> >
> > on iOS (depending on device/version), a zero rc_max_rate cause invalid
> > arguments from the vtenc_output_callback after few frames and then a crash
> > within the VideoToolbox library.
> > ---
> >  libavcodec/videotoolboxenc.c | 72 ++--
> >  1 file changed, 37 insertions(+), 35 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> > index ac847358ab..050e5cefee 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -1019,44 +1019,46 @@ static int vtenc_create_encoder(AVCodecContext
> > *avctx,
> >
> >  if (vtctx->codec_id == AV_CODEC_ID_H264) {
> >  // kVTCompressionPropertyKey_DataRateLimits is not available for
> > HEVC
> > -bytes_per_second_value = max_rate >> 3;
> > -bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
> > -  kCFNumberSInt64Type,
> > -  _per_second_value);
> > -if (!bytes_per_second) {
> > -return AVERROR(ENOMEM);
> > -}
> > -one_second_value = 1;
> > -one_second = CFNumberCreate(kCFAllocatorDefault,
> > -kCFNumberSInt64Type,
> > -_second_value);
> > -if (!one_second) {
> > -CFRelease(bytes_per_second);
> > -return AVERROR(ENOMEM);
> > -}
> > -nums[0] = (void *)bytes_per_second;
> > -nums[1] = (void *)one_second;
> > -data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
> > - (const void **)nums,
> > - 2,
> > - );
> 
> Please do the re-indentation in a separate patch to make
> reviewing your change easier, both now and on the
> commit mailing list

OK, done, cf. http://ffmpeg.org/pipermail/ffmpeg-devel/2018-July/231931.html

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


[FFmpeg-devel] [PATCH 2/2] avcodec/videotoolboxenc: reindent after previous commit

2018-07-04 Thread Thomas Guillem
---
 libavcodec/videotoolboxenc.c | 72 ++--
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index aa9aae7e05..050e5cefee 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1020,45 +1020,45 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 if (vtctx->codec_id == AV_CODEC_ID_H264) {
 // kVTCompressionPropertyKey_DataRateLimits is not available for HEVC
 if (max_rate > 0) {
-bytes_per_second_value = max_rate >> 3;
-bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
-  kCFNumberSInt64Type,
-  _per_second_value);
-if (!bytes_per_second) {
-return AVERROR(ENOMEM);
-}
-one_second_value = 1;
-one_second = CFNumberCreate(kCFAllocatorDefault,
-kCFNumberSInt64Type,
-_second_value);
-if (!one_second) {
-CFRelease(bytes_per_second);
-return AVERROR(ENOMEM);
-}
-nums[0] = (void *)bytes_per_second;
-nums[1] = (void *)one_second;
-data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
- (const void **)nums,
- 2,
- );
-
-if (!data_rate_limits) {
+bytes_per_second_value = max_rate >> 3;
+bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
+  kCFNumberSInt64Type,
+  _per_second_value);
+if (!bytes_per_second) {
+return AVERROR(ENOMEM);
+}
+one_second_value = 1;
+one_second = CFNumberCreate(kCFAllocatorDefault,
+kCFNumberSInt64Type,
+_second_value);
+if (!one_second) {
+CFRelease(bytes_per_second);
+return AVERROR(ENOMEM);
+}
+nums[0] = (void *)bytes_per_second;
+nums[1] = (void *)one_second;
+data_rate_limits = CFArrayCreate(kCFAllocatorDefault,
+ (const void **)nums,
+ 2,
+ );
+
+if (!data_rate_limits) {
+CFRelease(bytes_per_second);
+CFRelease(one_second);
+return AVERROR(ENOMEM);
+}
+status = VTSessionSetProperty(vtctx->session,
+  
kVTCompressionPropertyKey_DataRateLimits,
+  data_rate_limits);
+
 CFRelease(bytes_per_second);
 CFRelease(one_second);
-return AVERROR(ENOMEM);
-}
-status = VTSessionSetProperty(vtctx->session,
-  kVTCompressionPropertyKey_DataRateLimits,
-  data_rate_limits);
+CFRelease(data_rate_limits);
 
-CFRelease(bytes_per_second);
-CFRelease(one_second);
-CFRelease(data_rate_limits);
-
-if (status) {
-av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate property: 
%d\n", status);
-return AVERROR_EXTERNAL;
-}
+if (status) {
+av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate 
property: %d\n", status);
+return AVERROR_EXTERNAL;
+}
 }
 
 if (profile_level) {
-- 
2.18.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/videotoolboxenc: fix undefined behavior with rc_max_rate=0

2018-07-04 Thread Thomas Guillem
On macOS, a zero rc_max_rate cause an error from
VTSessionSetProperty(kVTCompressionPropertyKey_DataRateLimits).

on iOS (depending on device/version), a zero rc_max_rate cause invalid
arguments from the vtenc_output_callback after few frames and then a crash
within the VideoToolbox library.
---
 libavcodec/videotoolboxenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index ac847358ab..aa9aae7e05 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1019,6 +1019,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 
 if (vtctx->codec_id == AV_CODEC_ID_H264) {
 // kVTCompressionPropertyKey_DataRateLimits is not available for HEVC
+if (max_rate > 0) {
 bytes_per_second_value = max_rate >> 3;
 bytes_per_second = CFNumberCreate(kCFAllocatorDefault,
   kCFNumberSInt64Type,
@@ -1058,6 +1059,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 av_log(avctx, AV_LOG_ERROR, "Error setting max bitrate property: 
%d\n", status);
 return AVERROR_EXTERNAL;
 }
+}
 
 if (profile_level) {
 status = VTSessionSetProperty(vtctx->session,
-- 
2.18.0

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


Re: [FFmpeg-devel] [PATCH] lavfi/minterpolate: fix blending calc issue.

2018-07-04 Thread myp...@gmail.com
On Wed, Jun 27, 2018 at 5:52 PM Jun Zhao  wrote:
>
> the right blending calc is:
> (alpha * Frame_2 + (MAX - alpha) * Frame_1 + 512) >> 10
>
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/vf_minterpolate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/vf_minterpolate.c b/libavfilter/vf_minterpolate.c
> index d534315..c6a5e63 100644
> --- a/libavfilter/vf_minterpolate.c
> +++ b/libavfilter/vf_minterpolate.c
> @@ -1122,8 +1122,8 @@ static void interpolate(AVFilterLink *inlink,
AVFrame *avf_out)
>  for (y = 0; y < height; y++) {
>  for (x = 0; x < width; x++) {
>  avf_out->data[plane][x + y * 
> avf_out->linesize[plane]]
=
> -  alpha  * 
> mi_ctx->frames[2].avf->data[plane][x
+ y * mi_ctx->frames[2].avf->linesize[plane]] +
> -((ALPHA_MAX - alpha) * 
> mi_ctx->frames[1].avf->data[plane][x
+ y * mi_ctx->frames[1].avf->linesize[plane]] + 512) >> 10;
> +(alpha  * mi_ctx->frames[2].avf->data[plane][x
+ y * mi_ctx->frames[2].avf->linesize[plane]] +
> + (ALPHA_MAX - alpha) * 
> mi_ctx->frames[1].avf->data[plane][x
+ y * mi_ctx->frames[1].avf->linesize[plane]] + 512) >> 10;
>  }
>  }
>  }
> --
> 2.7.4
>
ping, any comments for this fix?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [FFmpeg-cvslog] Adds ESPCN super resolution filter merged with SRCNN filter.

2018-07-04 Thread Jean-Baptiste Kempf
On Wed, 4 Jul 2018, at 01:22, Carl Eugen Hoyos wrote:
> 2018-07-04 0:14 GMT+02:00, Jean-Baptiste Kempf :
> > On Tue, 3 Jul 2018, at 20:59, Carl Eugen Hoyos wrote:
> >> How is this case different from many arrays in libavcodec/*data*?
> >
> > It is very different: the arrays in *data* come either from a
> > mathematical computation or a spec.
> 
> (Apart from: Free and open specs?)
> This is probably true for some of the arrays, I think it is
> very unlikely that it's true for all of them.

The point is: you can recreate all of those arrays.
If OP dies, you can still take over.

> > Else, as some Debian Developer said: "It looks like code
> > hidden in an unsigned char array"
> 
> Is it "code" or data that was computed with a copyrighted
> algorithm?

How can you know, if it is not explained, and you cannot reproduce it?
How is it different from a binary blob?

Anything related to NN is very annoying, if you don't share the dataset and the 
methodology.

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel