ffmpeg.git
3 months agolavf/url: rewrite ff_make_absolute_url() using ff_url_decompose().
Nicolas George [Wed, 29 Jul 2020 22:02:10 +0000 (00:02 +0200)]
lavf/url: rewrite ff_make_absolute_url() using ff_url_decompose().

Also add and update some tests.

Change the semantic a little, because for filesytem paths
symlinks complicate things.
See the comments in the code for detail.

Fix trac tickets #8813 and 8814.

3 months agolavf/url: add ff_url_decompose().
Nicolas George [Wed, 29 Jul 2020 12:39:20 +0000 (14:39 +0200)]
lavf/url: add ff_url_decompose().

3 months agoavformat/mxfenc: Write color metadata to MXF
Harry Mallon [Thu, 6 Aug 2020 14:27:48 +0000 (15:27 +0100)]
avformat/mxfenc: Write color metadata to MXF

Writes color_primaries, color_trc and color_space to mxf
headers. ULs are from https://registry.smpte-ra.org/ site.

Signed-off-by: Harry Mallon <harry.mallon@codex.online>
3 months agoavcodec/sheervideo: reduce size of vlc tables to normal values
Paul B Mahol [Wed, 12 Aug 2020 06:14:08 +0000 (08:14 +0200)]
avcodec/sheervideo: reduce size of vlc tables to normal values

3 months agodnn: add backend options when load the model
Guo, Yejun [Fri, 7 Aug 2020 06:32:55 +0000 (14:32 +0800)]
dnn: add backend options when load the model

different backend might need different options for a better performance,
so, add the parameter into dnn interface, as a preparation.

Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
3 months agodnn_backend_native_layer_mathunary: add round support
Mingyu Yin [Mon, 10 Aug 2020 11:05:42 +0000 (19:05 +0800)]
dnn_backend_native_layer_mathunary: add round support

Signed-off-by: Mingyu Yin <mingyu.yin@intel.com>
Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
3 months agoavcodec/libsvtav1: fix copy and paste error
Limin Wang [Sat, 1 Aug 2020 04:34:29 +0000 (12:34 +0800)]
avcodec/libsvtav1: fix copy and paste error

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
3 months agoavformat/ty: Remove write-only array and variable
Andreas Rheinhardt [Tue, 11 Aug 2020 00:28:16 +0000 (02:28 +0200)]
avformat/ty: Remove write-only array and variable

Up until now, the TiVo demuxer parse an array of SEQ entries, yet it has
never ever made any use of them. In fact, parse_master, the function
parsing said table, only influenced the outside world in three ways: Via
an excessive amount of error message in case a certain parameter is not
what it expected; via an allocation (the aforementioned write-only
array); and by setting a certain parameter (ty->cur_chunk_pos), but that
parameter is always overwritten before it is used (it is overwritten
in get_chunk() on success and if get_chunk() fails, the error is
returned to the caller anyway). So remove the array and the function
used to parse it.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agotools/target_dec_fuzzer: Adjust threshold for AGM
Michael Niedermayer [Mon, 10 Aug 2020 21:58:06 +0000 (23:58 +0200)]
tools/target_dec_fuzzer: Adjust threshold for AGM

Fixes: Timeout (142sec -> 2sec)
Fixes: 24426/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5639724379930624

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoavcodec/agm: Mark fill_pixels() as av_always_inline
Michael Niedermayer [Mon, 10 Aug 2020 21:47:29 +0000 (23:47 +0200)]
avcodec/agm: Mark fill_pixels() as av_always_inline

Speedup from 275sec to 142sec
Testcase: 24426/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5639724379930624

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agodoc/general: mark that CFHD have encoder now
Paul B Mahol [Tue, 11 Aug 2020 10:25:33 +0000 (12:25 +0200)]
doc/general: mark that CFHD have encoder now

3 months agodoc/general: mention AGM codecs
Paul B Mahol [Tue, 11 Aug 2020 10:31:25 +0000 (12:31 +0200)]
doc/general: mention AGM codecs

3 months agoavfilter/vf_xfade: check that fps between inputs are valid
Paul B Mahol [Tue, 11 Aug 2020 08:55:16 +0000 (10:55 +0200)]
avfilter/vf_xfade: check that fps between inputs are valid

3 months agoavcodec/cfhdenc: mark filter as always inline
Paul B Mahol [Tue, 11 Aug 2020 07:56:19 +0000 (09:56 +0200)]
avcodec/cfhdenc: mark filter as always inline

3 months agoavcodec/cfhdenc: optimize writting of small runcodes
Paul B Mahol [Mon, 10 Aug 2020 07:35:10 +0000 (09:35 +0200)]
avcodec/cfhdenc: optimize writting of small runcodes

3 months agoavcodec/cfhdenc: improve quality vs size ratio
Paul B Mahol [Tue, 11 Aug 2020 07:49:24 +0000 (09:49 +0200)]
avcodec/cfhdenc: improve quality vs size ratio

3 months agoavformat/argo_asf: strip file extension from name
Zane van Iperen [Fri, 7 Aug 2020 23:44:48 +0000 (09:44 +1000)]
avformat/argo_asf: strip file extension from name

Only when the user hasn't manually specified one.
Matches the original files more closely.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/argo_asf: add name option
Zane van Iperen [Fri, 7 Aug 2020 23:17:51 +0000 (09:17 +1000)]
avformat/argo_asf: add name option

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/argo_asf: add version_major and version_minor options
Zane van Iperen [Wed, 5 Aug 2020 02:15:30 +0000 (12:15 +1000)]
avformat/argo_asf: add version_major and version_minor options

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/argo_asf: don't check file version
Zane van Iperen [Sun, 9 Aug 2020 22:37:47 +0000 (08:37 +1000)]
avformat/argo_asf: don't check file version

It has no bearing on structure. Determined by looking at the ASF
files from several Argonaut games:
  - FX Fighter,
  - Croc,
  - Croc 2,
  - The Emperor's New Groove, and
  - Disney's Aladdin in Nasira's Revenge

The only versions that appear are 1.1, 1.2, and 2.1, and their
structure is identical.

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/argo_asf: add games to version list
Zane van Iperen [Sun, 9 Aug 2020 22:20:48 +0000 (08:20 +1000)]
avformat/argo_asf: add games to version list

Reviewed-by: Alexander Strasser <eclipse7@gmx.net>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/mpegts: Don't leave context in inconsistent state upon error
Andreas Rheinhardt [Mon, 10 Aug 2020 12:20:58 +0000 (14:20 +0200)]
avformat/mpegts: Don't leave context in inconsistent state upon error

Up until now, opening a section filter works as follows: A filter is
opened and (on success) attached to the MpegTSContext. Then a buffer for
said filter is allocated and upon success attached to the section
filter; on error, the filter is simply freed without removing it from
the MpegTSContext, leaving the latter in an inconsistent state. This
leads to use-after-frees lateron.

This commit fixes this by allocating the buffer first; the filter is
only opened if the buffer could be successfully allocated.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavcodec/jpeg2000dec: Check remaining data in packed_headers_stream before use
Michael Niedermayer [Sat, 1 Aug 2020 23:15:34 +0000 (01:15 +0200)]
avcodec/jpeg2000dec: Check remaining data in packed_headers_stream before use

Fixes: out of array read
Fixes: 24487/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5165847820369920
Fixes: 24636/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5700973918683136
Fixes: 24683/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6202883897556992

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoFATE/dnn: add unit test for dnn avgpool layer
Ting Fu [Sun, 9 Aug 2020 16:33:14 +0000 (00:33 +0800)]
FATE/dnn: add unit test for dnn avgpool layer

'make fate-dnn-layer-avgpool' to run the test

Signed-off-by: Ting Fu <ting.fu@intel.com>
Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
3 months agodnn/native: add native support for avg_pool
Ting Fu [Sun, 9 Aug 2020 16:33:13 +0000 (00:33 +0800)]
dnn/native: add native support for avg_pool

Not support pooling strides in channel dimension yet.

Signed-off-by: Ting Fu <ting.fu@intel.com>
Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
3 months agoavformat/hlsenc: write temp file for append single file by encryption mode
Steven Liu [Wed, 22 Jul 2020 09:15:29 +0000 (17:15 +0800)]
avformat/hlsenc: write temp file for append single file by encryption mode

fix ticket: 8783
Because in single file by encryption mode, it cannot get the last one
block of the file, it need ff_format_io_close for get full file size,
then hlsenc can get the total size of the encryption content,
so write the content into temp file first, and get the temp file content
append the temp file content into append to single file, then hlsenc can
get the correct file/content size and offset.

Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
3 months agoavformat/hls: support avio_seek in encryption mode
Steven Liu [Wed, 22 Jul 2020 09:15:28 +0000 (17:15 +0800)]
avformat/hls: support avio_seek in encryption mode

Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
3 months agokmsgrab: Add more supported formats
Mark Thompson [Sat, 1 Aug 2020 17:57:35 +0000 (18:57 +0100)]
kmsgrab: Add more supported formats

X2RGB10 tested on both Intel Gen9 and AMD Polaris 11.  NV12 tested on
Intel Gen9 only - since it has multiple planes, this requires GetFB2.

Also add some comments to split the list up a bit.

3 months agodoc/indevs: Note improved behaviour of kmsgrab with Linux 5.7
Mark Thompson [Sun, 5 Jul 2020 15:49:46 +0000 (16:49 +0100)]
doc/indevs: Note improved behaviour of kmsgrab with Linux 5.7

3 months agokmsgrab: Don't require the user to set framebuffer format
Mark Thompson [Sun, 5 Jul 2020 15:49:45 +0000 (16:49 +0100)]
kmsgrab: Don't require the user to set framebuffer format

This is provided by GetFB2, but we still need the option for cases where
that isn't available.

3 months agokmsgrab: Use GetFB2 if available
Mark Thompson [Sun, 5 Jul 2020 15:49:44 +0000 (16:49 +0100)]
kmsgrab: Use GetFB2 if available

The most useful feature here is the ability to automatically extract the
framebuffer format and modifiers.  It also makes support for multi-plane
framebuffers possible, though none are added to the format table in this
patch.

This requires libdrm 2.4.101 (from April 2020) to build, so it includes a
configure check to allow compatibility with existing distributions.  Even
with libdrm support, it still won't do anything at runtime if you are
running Linux < 5.7 (before June 2020).

3 months agokmsgrab: Refactor and clean error cases
Mark Thompson [Sun, 5 Jul 2020 15:49:43 +0000 (16:49 +0100)]
kmsgrab: Refactor and clean error cases

3 months agoavformat/sierravmd: Don't return packets for non-existing stream
Andreas Rheinhardt [Wed, 5 Aug 2020 23:21:38 +0000 (01:21 +0200)]
avformat/sierravmd: Don't return packets for non-existing stream

It leads to an assert in ff_read_packet().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavformat/vividas: Check allocation for success
Andreas Rheinhardt [Wed, 5 Aug 2020 22:59:37 +0000 (00:59 +0200)]
avformat/vividas: Check allocation for success

Reviewed-by: Zane van Iperen <zane@zanevaniperen.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavformat/vividas: Check return value before storing it in smaller type
Andreas Rheinhardt [Wed, 5 Aug 2020 22:44:55 +0000 (00:44 +0200)]
avformat/vividas: Check return value before storing it in smaller type

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavcodec/cfhd: improve SampleIndex tag output
Paul B Mahol [Sun, 9 Aug 2020 11:26:55 +0000 (13:26 +0200)]
avcodec/cfhd: improve SampleIndex tag output

This tag is used for jumping to different channels in bitstream.

3 months agoavcodec/cfhd: log version tags too
Paul B Mahol [Sun, 9 Aug 2020 11:21:34 +0000 (13:21 +0200)]
avcodec/cfhd: log version tags too

3 months agoavcodec/cfhd: read prescale table tag
Paul B Mahol [Sun, 9 Aug 2020 11:02:46 +0000 (13:02 +0200)]
avcodec/cfhd: read prescale table tag

Currently unused. Remove prescale shift tag as it
is not part of this codec.

3 months agoavcodec/cfhd: use init_get_bits8()
Paul B Mahol [Sun, 9 Aug 2020 09:54:52 +0000 (11:54 +0200)]
avcodec/cfhd: use init_get_bits8()

3 months agoavcodec/cfhd: reindent
Paul B Mahol [Sun, 9 Aug 2020 09:48:28 +0000 (11:48 +0200)]
avcodec/cfhd: reindent

3 months agoavcodec/cfhd: check if band encoding is valid
Paul B Mahol [Sun, 9 Aug 2020 09:00:07 +0000 (11:00 +0200)]
avcodec/cfhd: check if band encoding is valid

Also simplify lossless check as value of 5 for band encoding
always specify lossless mode.

3 months agolibavcodec/j2kenc: Support for all Progression orders
Gautam Ramakrishnan [Thu, 6 Aug 2020 17:39:32 +0000 (23:09 +0530)]
libavcodec/j2kenc: Support for all Progression orders

This patch allows for selecting the progression order
in the j2k encoder. However, all components and resolution
levels will use the same progression order and will not
feature the use of progression order change markers.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoavcodec/cfhdenc: free alpha buffer on closing
Paul B Mahol [Sat, 8 Aug 2020 17:59:06 +0000 (19:59 +0200)]
avcodec/cfhdenc: free alpha buffer on closing

3 months agoavcodec/cfhdenc: add gbrap12 pixel format support
Paul B Mahol [Sat, 8 Aug 2020 17:40:34 +0000 (19:40 +0200)]
avcodec/cfhdenc: add gbrap12 pixel format support

3 months agoavcodec/cfhdenc: compand coefficients
Paul B Mahol [Fri, 7 Aug 2020 14:12:33 +0000 (16:12 +0200)]
avcodec/cfhdenc: compand coefficients

Also use -quality private option and add more modes.

3 months agoavcodec/cfhd: add 3d transform support
Paul B Mahol [Tue, 4 Aug 2020 12:45:48 +0000 (14:45 +0200)]
avcodec/cfhd: add 3d transform support

Based on Gagandeep Singh patch.

3 months agoavcodec/cfhd: remove some unused or only write items
Paul B Mahol [Tue, 4 Aug 2020 09:45:37 +0000 (11:45 +0200)]
avcodec/cfhd: remove some unused or only write items

3 months agoavcodec/cfhdenc: also write FrameNumber tag
Paul B Mahol [Tue, 4 Aug 2020 09:25:25 +0000 (11:25 +0200)]
avcodec/cfhdenc: also write FrameNumber tag

3 months agoswscale: do not drop half of bits from 16bit bayer formats
Paul B Mahol [Sun, 2 Aug 2020 13:55:38 +0000 (15:55 +0200)]
swscale: do not drop half of bits from 16bit bayer formats

3 months agodoc/fftools-common-opts: document ffmpeg -h protocol=protocol_name
Jun Zhao [Fri, 7 Aug 2020 13:20:05 +0000 (21:20 +0800)]
doc/fftools-common-opts: document ffmpeg -h protocol=protocol_name

document ffmpeg -h protocol=protocol_name

Reviewed-by: Gyan Doshi <ffmpeg@gyani.pro>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
3 months agodoc/fftools-common-opts: fix typo (name => named)
Jun Zhao [Fri, 7 Aug 2020 13:22:47 +0000 (21:22 +0800)]
doc/fftools-common-opts: fix typo (name => named)

fix typo (name => named)

Reviewed-by: Gyan Doshi <ffmpeg@gyani.pro>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
3 months agodoc/filters: update filter buffer/abuffer interface file name
tomajsjiang [Thu, 6 Aug 2020 01:51:11 +0000 (09:51 +0800)]
doc/filters: update filter buffer/abuffer interface file name

Update filter buffer/abuffer interface file name, from
libavfilter/{vsrc|asrc_buffer.h} to libavfilter/buffersrc.h

Reviewed-by: Gyan Doshi <ffmpeg@gyani.pro>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
Signed-off-by: tomajsjiang <tomajsjiang@tencent.com>
3 months agoavcodec/put_bits: Make skip_put_bits() less dangerous
Andreas Rheinhardt [Fri, 31 Jul 2020 06:32:55 +0000 (08:32 +0200)]
avcodec/put_bits: Make skip_put_bits() less dangerous

Before c63c303a1f2b58677d480505ec93a90f77dd25b5 (the commit which
introduced a typedef for the type of the buffer of a PutBitContext)
skip_put_bits() was as follows:

static inline void skip_put_bits(PutBitContext *s, int n)
{
    s->bit_left -= n;
    s->buf_ptr  -= 4 * (s->bit_left >> 5);
    s->bit_left &= 31;
}

If s->bit_left was negative after the first subtraction, then the next
line will divide this by 32 with rounding towards -inf and multiply by
four; the result will be negative, of course.

The aforementioned commit changed this to:

static inline void skip_put_bits(PutBitContext *s, int n)
{
    s->bit_left -= n;
    s->buf_ptr  -= sizeof(BitBuf) * ((unsigned)s->bit_left / BUF_BITS);
    s->bit_left &= (BUF_BITS - 1);
}

Casting s->bit_left to unsigned meant that the rounding is still towards
-inf; yet the right side is now always positive (it transformed the
arithmetic shift into a logical shift), so that s->buf_ptr will always
be decremented (by about UINT_MAX / 8 unless n is huge) which leads to
segfaults on further usage and is already undefined pointer arithmetic
before that. This can be reproduced with the mpeg4 encoder with the
AV_CODEC_FLAG2_NO_OUTPUT flag set.

Furthermore, the earlier version as well as the new version share
another bug: s->bit_left will be in the range of 0..(BUF_BITS - 1)
afterwards, although the assumption throughout the other PutBitContext
functions is that it is in the range of 1..BUF_BITS. This might lead to
a shift by BUF_BITS in little-endian mode. This has been fixed, too.
The new version is furthermore able to skip zero bits, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agofate: cosmetics
Zane van Iperen [Sun, 2 Aug 2020 00:05:40 +0000 (10:05 +1000)]
fate: cosmetics

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agofate: add adpcm_argo test
Zane van Iperen [Sun, 2 Aug 2020 00:05:04 +0000 (10:05 +1000)]
fate: add adpcm_argo test

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat: add argo_asf muxer
Zane van Iperen [Mon, 27 Jul 2020 12:53:24 +0000 (22:53 +1000)]
avformat: add argo_asf muxer

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavcodec: add adpcm_argo encoder
Zane van Iperen [Sun, 26 Jul 2020 14:23:14 +0000 (00:23 +1000)]
avcodec: add adpcm_argo encoder

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavcodec/adpcm_argo: add ff_adpcm_argo_expand_nibble() and cleanup parameters
Zane van Iperen [Wed, 29 Jul 2020 12:58:52 +0000 (22:58 +1000)]
avcodec/adpcm_argo: add ff_adpcm_argo_expand_nibble() and cleanup parameters

Replaces adpcm_argo_expand_nibble(). Preparation for the encoder.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavformat/argo_asf: check sample count in demuxer
Zane van Iperen [Sun, 2 Aug 2020 12:22:42 +0000 (22:22 +1000)]
avformat/argo_asf: check sample count in demuxer

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 months agoavcodec/tiff: Check bpp/bppcount for 0
Michael Niedermayer [Thu, 6 Aug 2020 19:42:43 +0000 (21:42 +0200)]
avcodec/tiff: Check bpp/bppcount for 0

Fixes: division by zero
Fixes: 24253/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-6250318007107584

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoavcodec/snowdec: Sanity check hcoeff
Michael Niedermayer [Thu, 6 Aug 2020 19:35:06 +0000 (21:35 +0200)]
avcodec/snowdec: Sanity check hcoeff

Fixes: signed integer overflow: -2147483648 * -1 cannot be represented in type 'int'
Fixes: 24011/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-5486376610168832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agodnn_backend_native_layer_mathunary: add floor support
Mingyu Yin [Thu, 6 Aug 2020 06:47:16 +0000 (14:47 +0800)]
dnn_backend_native_layer_mathunary: add floor support

It can be tested with the model generated with below python script:

import tensorflow as tf
import os
import numpy as np
import imageio
from tensorflow.python.framework import graph_util
name = 'floor'

pb_file_path = os.getcwd()
if not os.path.exists(pb_file_path+'/{}_savemodel/'.format(name)):
    os.mkdir(pb_file_path+'/{}_savemodel/'.format(name))

with tf.Session(graph=tf.Graph()) as sess:
    in_img = imageio.imread('detection.jpg')
    in_img = in_img.astype(np.float32)
    in_data = in_img[np.newaxis, :]
    input_x = tf.placeholder(tf.float32, shape=[1, None, None, 3], name='dnn_in')
    y_ = tf.math.floor(input_x*255)/255
    y = tf.identity(y_, name='dnn_out')
    sess.run(tf.global_variables_initializer())
    constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['dnn_out'])

    with tf.gfile.FastGFile(pb_file_path+'/{}_savemodel/model.pb'.format(name), mode='wb') as f:
        f.write(constant_graph.SerializeToString())

    print("model.pb generated, please in ffmpeg path use\n \n \
    python tools/python/convert.py {}_savemodel/model.pb --outdir={}_savemodel/ \n \nto generate model.model\n".format(name,name))

    output = sess.run(y, feed_dict={ input_x: in_data})
    imageio.imsave("out.jpg", np.squeeze(output))

    print("To verify, please ffmpeg path use\n \n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model={}_savemodel/model.pb:input=dnn_in:output=dnn_out:dnn_backend=tensorflow -f framemd5 {}_savemodel/tensorflow_out.md5\n  \
    or\n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model={}_savemodel/model.pb:input=dnn_in:output=dnn_out:dnn_backend=tensorflow {}_savemodel/out_tensorflow.jpg\n \nto generate output result of tensorflow model\n".format(name, name, name, name))

    print("To verify, please ffmpeg path use\n \n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model={}_savemodel/model.model:input=dnn_in:output=dnn_out:dnn_backend=native -f framemd5 {}_savemodel/native_out.md5\n  \
    or \n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model={}_savemodel/model.model:input=dnn_in:output=dnn_out:dnn_backend=native {}_savemodel/out_native.jpg\n \nto generate output result of native model\n".format(name, name, name, name))

Signed-off-by: Mingyu Yin <mingyu.yin@intel.com>
3 months agoavformat/mxfdec: Read color metadata from MXF
Harry Mallon [Fri, 31 Jul 2020 10:09:54 +0000 (11:09 +0100)]
avformat/mxfdec: Read color metadata from MXF

Reads color_primaries, color_trc and color_space from mxf
headers. ULs are from https://registry.smpte-ra.org/ site.

Signed-off-by: Harry Mallon <harry.mallon@codex.online>
3 months agoavcodec/libx264: fix chroma quantizer offset usage
Takio Yamaoka [Tue, 28 Jul 2020 12:22:02 +0000 (21:22 +0900)]
avcodec/libx264: fix chroma quantizer offset usage

The default for the chromaoffset field in AVCodecContext
is zero, which until now always ended up overriding the
AVOption-set value, thus leading to the AVOption not working.

Additionally, the previous usage prevented the usage of
negative values, while both the variable as well as x264's
API would successfully handle such.

Thus, the default value of the AVOption is changed to match
the default of x264 (and what is currently the default for
the AVCodecContext chromaoffset field), and the checks are
changed to check for nonzero values.

This way:
1. the library default is still utilized if the value is zero.
2. both negative and positive values are correctly passed to
   x264.

For historical context, this was initially similarly
implemented in 5764d38173661c29d954711dd5abfddf709e9ba4, and
then b340bd8a58c32453172404a8e4240e3317e341da broke the
value.

Partially reverts commit b340bd8a58c32453172404a8e4240e3317e341da.

Signed-off-by: Takio Yamaoka <y.takio@gmail.com>
3 months agoavcodec/mpegaudiodec_template: Fix some whitespace issues
Michael Niedermayer [Wed, 5 Aug 2020 06:54:13 +0000 (08:54 +0200)]
avcodec/mpegaudiodec_template: Fix some whitespace issues

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoavcodec/jpeg2000dec: Handle reducedresno of 32
Michael Niedermayer [Tue, 4 Aug 2020 20:42:21 +0000 (22:42 +0200)]
avcodec/jpeg2000dec: Handle reducedresno of 32

Fixes: shift exponent 32 is too large for 32-bit type 'int'
Fixes: 24566/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6033783737024512

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agolibavcodec/j2kenc: Allow Encoder to use SOP and EPH markers
Gautam Ramakrishnan [Tue, 4 Aug 2020 12:58:02 +0000 (18:28 +0530)]
libavcodec/j2kenc: Allow Encoder to use SOP and EPH markers

This patch allows the encoder to use SOP and EPH
markers. This would be useful as these markers
provide better error detection mechanisms.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 months agoavformat/dv: Avoid allocation for reading timecode
Andreas Rheinhardt [Sat, 1 Aug 2020 22:58:48 +0000 (00:58 +0200)]
avformat/dv: Avoid allocation for reading timecode

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavformat/dv: Avoid alloction of DVDemuxContext
Andreas Rheinhardt [Sat, 1 Aug 2020 22:41:31 +0000 (00:41 +0200)]
avformat/dv: Avoid alloction of DVDemuxContext

This commit avoids allocating a DVDemuxContext when demuxing raw DV by
making it part of the demuxer's context. This also allows to remove
dv_read_close().

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agoavformat/3dostr: Return directly after having read packet
Andreas Rheinhardt [Mon, 27 Jul 2020 03:19:18 +0000 (05:19 +0200)]
avformat/3dostr: Return directly after having read packet

Avoids an avio_skip(s->pb, 0).

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 months agolavc/libopenh264enc: use framerate if available
Jun Zhao [Sun, 26 Jul 2020 11:16:43 +0000 (19:16 +0800)]
lavc/libopenh264enc: use framerate if available

Respecting the framerate in the libopenh264enc codec context.

Both the libx264 and libx265 encoders already contain similar logic
to first check the framerate before falling back to the timebase.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
4 months agoavformat/mov: Check comp_brand_size
Michael Niedermayer [Sat, 1 Aug 2020 22:51:12 +0000 (00:51 +0200)]
avformat/mov: Check comp_brand_size

Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
Fixes: 24457/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5760093644390400

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
4 months agoavcodec/mpegaudiodec_template: Check CRCs for layer1 and layer2
Michael Niedermayer [Mon, 3 Aug 2020 14:33:56 +0000 (16:33 +0200)]
avcodec/mpegaudiodec_template: Check CRCs for layer1 and layer2

This differs from the MPEG specification as the actual real world
files do compute their CRC over variable areas and not the fixed
ones listed in the specification. This is also the reason for
the complexity of this code and the need to perform the CRC
check for layer2 in the middle of layer2 decoding.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
4 months agodnn_backend_native_layer_mathunary: add ceil support
Mingyu Yin [Fri, 31 Jul 2020 07:41:24 +0000 (15:41 +0800)]
dnn_backend_native_layer_mathunary: add ceil support

It can be tested with the model generated with below python script:

import tensorflow as tf
import os
import numpy as np
import imageio
from tensorflow.python.framework import graph_util
name = 'ceil'

pb_file_path = os.getcwd()
if not os.path.exists(pb_file_path+'/{}_savemodel/'.format(name)):
    os.mkdir(pb_file_path+'/{}_savemodel/'.format(name))

with tf.Session(graph=tf.Graph()) as sess:
    in_img = imageio.imread('detection.jpg')
    in_img = in_img.astype(np.float32)
    in_data = in_img[np.newaxis, :]
    input_x = tf.placeholder(tf.float32, shape=[1, None, None, 3], name='dnn_in')
    y = tf.math.ceil( input_x, name='dnn_out')
    sess.run(tf.global_variables_initializer())
    constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['dnn_out'])

    with tf.gfile.FastGFile(pb_file_path+'/{}_savemodel/model.pb'.format(name), mode='wb') as f:
        f.write(constant_graph.SerializeToString())

    print("model.pb generated, please in ffmpeg path use\n \n \
    python tools/python/convert.py ceil_savemodel/model.pb --outdir=ceil_savemodel/ \n \n \
    to generate model.model\n")

    output = sess.run(y, feed_dict={ input_x: in_data})
    imageio.imsave("out.jpg", np.squeeze(output))

    print("To verify, please ffmpeg path use\n \n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model=ceil_savemodel/model.pb:input=dnn_in:output=dnn_out:dnn_backend=tensorflow -f framemd5 ceil_savemodel/tensorflow_out.md5\n \n \
    to generate output result of tensorflow model\n")

    print("To verify, please ffmpeg path use\n \n \
    ./ffmpeg -i detection.jpg -vf format=rgb24,dnn_processing=model=ceil_savemodel/model.model:input=dnn_in:output=dnn_out:dnn_backend=native -f framemd5 ceil_savemodel/native_out.md5\n \n \
    to generate output result of native model\n")

Signed-off-by: Mingyu Yin <mingyu.yin@intel.com>
Reviewed-by: Guo, Yejun <yejun.guo@intel.com>
4 months agoavcodec/adpcm_argo: fix incorrect documentation
Zane van Iperen [Sat, 1 Aug 2020 23:20:15 +0000 (09:20 +1000)]
avcodec/adpcm_argo: fix incorrect documentation

Flag bit was in the wrong place.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
4 months agoavcodec/cfhd: fix overflow in multiplication in LUT calculation
Paul B Mahol [Tue, 4 Aug 2020 06:20:36 +0000 (08:20 +0200)]
avcodec/cfhd: fix overflow in multiplication in LUT calculation

4 months agoavcodec/aacdec_template: add support for 22.2 / channel_config 13
Jan Ekström [Sat, 13 Jun 2020 12:05:30 +0000 (15:05 +0300)]
avcodec/aacdec_template: add support for 22.2 / channel_config 13

4 months agoavcodec/aacdec_template: mark second LFE element as LFE2
Jan Ekström [Sat, 13 Jun 2020 11:34:44 +0000 (14:34 +0300)]
avcodec/aacdec_template: mark second LFE element as LFE2

We now have the capability to do this.

4 months agoavcodec/aacdectab: add mapping for 22.2
Jan Ekström [Wed, 10 Jun 2020 22:49:07 +0000 (01:49 +0300)]
avcodec/aacdectab: add mapping for 22.2

Utilizes the newly added 22.2 channel layout for channel_layout 13.

4 months agoavcodec/mpeg4audio: add newer channel_coding mappings
Jan Ekström [Wed, 10 Jun 2020 21:07:15 +0000 (00:07 +0300)]
avcodec/mpeg4audio: add newer channel_coding mappings

Additionally, add comments regarding their definitions. Based on
ARIB STD-B32, which bases on 14496-3:2009 and 14496-3:2009/AMD4.

4 months agoswresample/rematrix: treat 22.2 as 5.1 (back) when mixing
Jan Ekström [Fri, 31 Jul 2020 22:55:39 +0000 (01:55 +0300)]
swresample/rematrix: treat 22.2 as 5.1 (back) when mixing

Only this sub-set of channels actually follows the bit mask order
in the official 22.2 channel mapping. Additionally, the 5.1 channels
are there for backwards compatibility with the previous system.

This enables the utilization of 22.2 content until a proper down/up
matrix is added into swresample.

4 months agoswresample/matrix: switch internal clean_layout function to not drop high bits
Jan Ekström [Fri, 31 Jul 2020 22:52:08 +0000 (01:52 +0300)]
swresample/matrix: switch internal clean_layout function to not drop high bits

These bits are utilized by channel layouts such as 22.2. If those
are dropped, the returned channel layout is no longer a match
against the AV_CH_LAYOUT define when returned from this function.

4 months agoavutil/channel_layout: add 22.2 layout
Jan Ekström [Thu, 11 Jun 2020 19:08:30 +0000 (22:08 +0300)]
avutil/channel_layout: add 22.2 layout

Requires some extraneous top side and bottom front channels to be
defined.

According to STD-B59v2, the defined channel layout is:
- FL
- FR
- FC
- LFE1
- BL
- BR
- FLc
- FRc
- BC
- LFE2
- SiL
- SiR
- TpFL
- TpFR
- TpFC
- TpC
- TpBL
- TpBR
- TpSiL
- TpSiR
- TpBC
- BtFC
- BtFL
- BtFR

4 months agotest: hlsenc: Use unique init/segment file names for the fmp4_ac3 test
Martin Storsjö [Sat, 1 Aug 2020 21:28:18 +0000 (00:28 +0300)]
test: hlsenc: Use unique init/segment file names for the fmp4_ac3 test

Previously, the hls-fmp4 and hls-fmp4_ac3 tests used the same file
names for init and segment files, which occasionally could cause
corruption and failed tests, if the input files for both tests are
generated in parallel, as they could overwrite each other.

This happened to work some of the time, as the fmp4_ac3 test actually
only checked the init segment file (which the fmp4 test case never
wrote, due to using the incorrect hls_segment_type option) and the
fmp4 test case always regenerated the input files due to mismatched
target and file names.

Signed-off-by: Martin Storsjö <martin@martin.st>
4 months agotest: hlsenc: Make the hls_fmp4 sample file name match the target
Martin Storsjö [Sat, 1 Aug 2020 21:20:27 +0000 (00:20 +0300)]
test: hlsenc: Make the hls_fmp4 sample file name match the target

Previously, with the file name not matching the target, the files
were regenerated every time fate is rerun - contrary to the other
test targets in the same file. (While regenerating it every time
might be desireable, as that's what the test is about, the file
at least has a dependency on the ffmpeg executable, making them
regenerated every time the executable is updated - and this change
at least makes it consistent with the rest.)

Signed-off-by: Martin Storsjö <martin@martin.st>
4 months agoavcodec/cfhd: correct 71 tag usage
Paul B Mahol [Mon, 3 Aug 2020 20:41:45 +0000 (22:41 +0200)]
avcodec/cfhd: correct 71 tag usage

It stores input format and never codebook.

4 months agoavcodec/cfhdenc: fix setting default compression level
Paul B Mahol [Mon, 3 Aug 2020 20:18:47 +0000 (22:18 +0200)]
avcodec/cfhdenc: fix setting default compression level

4 months agoavcodec/cfhdenc: extend quantization table
Paul B Mahol [Mon, 3 Aug 2020 20:14:14 +0000 (22:14 +0200)]
avcodec/cfhdenc: extend quantization table

Should give better quality.

4 months agoavcodec/cfhd: use LUT for 9 and 18 codebook decompanding
Paul B Mahol [Mon, 3 Aug 2020 07:33:36 +0000 (09:33 +0200)]
avcodec/cfhd: use LUT for 9 and 18 codebook decompanding

Also fix codebook 9 decompanding, fixing artifact with codebook 9
samples. Reused Gagandeep Singh patch.

4 months agoavcodec/cfhdenc: fix PrescaleTable for YUV422P10
Paul B Mahol [Mon, 3 Aug 2020 17:31:31 +0000 (19:31 +0200)]
avcodec/cfhdenc: fix PrescaleTable for YUV422P10

4 months agoavcodec/mpegaudiodec_template: disable CRC checking for layers 1 and 2
James Almer [Mon, 3 Aug 2020 13:40:10 +0000 (10:40 -0300)]
avcodec/mpegaudiodec_template: disable CRC checking for layers 1 and 2

Layers 1 and 2 use lengths in bits which are not a multiple of 8,
and our CRC works on a per-byte basis.

Based on b48397e7b8

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: James Almer <jamrial@gmail.com>
4 months agoRevert "mpegaudiodec_template: disable CRC checking for layers 1 and 2"
James Almer [Mon, 3 Aug 2020 13:27:21 +0000 (10:27 -0300)]
Revert "mpegaudiodec_template: disable CRC checking for layers 1 and 2"

This reverts commit b48397e7b84864f2d4c70361a4c4bed93e826753.

The change did not disable crc checks for layer 1 & 2, it removed reading
the CRC field.

Fixes decoding some mp2 samples and FATE test failures.

Signed-off-by: James Almer <jamrial@gmail.com>
4 months agofate/aac: add missing bitexact flag to some encoder tests
James Almer [Sun, 2 Aug 2020 23:38:58 +0000 (20:38 -0300)]
fate/aac: add missing bitexact flag to some encoder tests

Will prevet FATE from breaking once LIBAVCODEC_VERSION_MINOR is bumped to 100.

Reported-by: zane
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
4 months agompegaudiodec_template: disable CRC checking for layers 1 and 2
Lynne [Sun, 2 Aug 2020 20:45:00 +0000 (22:45 +0200)]
mpegaudiodec_template: disable CRC checking for layers 1 and 2

Layers 1 and 2 use lengths in bits which are not a multiple of 8,
and our CRC works on a per-byte basis.

4 months agohwcontext_vulkan: remove plane size alignment checks when host importing
Lynne [Mon, 20 Jul 2020 12:36:47 +0000 (12:36 +0000)]
hwcontext_vulkan: remove plane size alignment checks when host importing

The process space is guaranteed to be aligned to the page size, hence we're
never going to map outside of our address space.
There are more optimizations to do with respect to chroma plane alignment and
buffer offsets, but that can be done later.

4 months agoavcodec/v4l2_m2m: reindent after last commit
Andriy Gelman [Sun, 2 Aug 2020 18:36:04 +0000 (14:36 -0400)]
avcodec/v4l2_m2m: reindent after last commit

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
4 months agoavcodec/v4l2_m2m: adapt to call close() on init fail
Andriy Gelman [Sun, 2 Aug 2020 18:31:22 +0000 (14:31 -0400)]
avcodec/v4l2_m2m: adapt to call close() on init fail

This fixes several mem leaks when init of encoder/decoder failed.

Fixes ticket #8285

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
4 months agoavcodec/cfhd: set correct bits_per_raw_sample
Paul B Mahol [Sun, 2 Aug 2020 06:39:37 +0000 (08:39 +0200)]
avcodec/cfhd: set correct bits_per_raw_sample

4 months agoavcodec/cfhd: add more tag names
Paul B Mahol [Sat, 1 Aug 2020 09:08:34 +0000 (11:08 +0200)]
avcodec/cfhd: add more tag names

4 months agoavcodec: add CFHD encoder
Paul B Mahol [Sat, 25 Jul 2020 16:18:18 +0000 (18:18 +0200)]
avcodec: add CFHD encoder