1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

55 Commits

Author SHA1 Message Date
Michael Niedermayer
f7862e8268 avcodec/vc2enc: Check for non negative slice bounds
Fixes: invalid shifts
Fixes: Ticket 8221

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-08 18:00:05 +02:00
Andreas Rheinhardt
ed8a7c25cd avcodec/vc2enc: Allow user-supplied buffers
Trivial for an encoder that has a very good estimate of the size
of the output packet in advance.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-15 12:14:41 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Andreas Rheinhardt
aa2e0b868d avcodec/vc2enc: Actually zero padding
This encoder sets the min_size in ff_alloc_packet2(), so it can not rely
on av_packet_make_refcounted() to zero the padding.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-26 20:07:21 +02:00
Mark Thompson
ac05413dfb vc2enc: Add missing static to local variables 2021-02-02 22:34:55 +00:00
Anton Khirnov
944ba30db0 put_bits: make avpriv_put_string() lavc-local
It has not been used outside of libavcodec since
20f325f320
2020-10-28 13:53:23 +01:00
Anton Khirnov
717503f716 put_bits: make avpriv_align_put_bits() inline
This function is so extremely simple that it is preferable to make it
inline rather than deal with all the complications arising from it being
an exported symbol.

Keep avpriv_align_put_bits() around until the next major bump to
preserve ABI compatibility.
2020-10-28 13:53:23 +01:00
Andreas Rheinhardt
8129c32e48 avcodec, avfilter, avformat: Remove redundant avpriv_align_put_bits
flush_put_bits() already fills the bitstream with zeroes, so it is
unnecessary to align the bitstream before.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-01 18:56:32 +02:00
Lynne
377a095dc3
vc2enc: zero padding of the coefficient buffer
Wavelet types with large amounts of overreading/writing like 9_7 would
write into the padding at high wavelet depths, which would remain and be
read by the next frame's transform and quickly cause artifacts to appear
for subsequent frames.
This fix affects all frames encoded with a non-power-of-two width, with
the artifacts varying between non-observable to very noticeable,
depending on encoder settings, so reencoding is advisable.
2019-12-17 14:56:33 +00:00
Rostislav Pehlivanov
688060fbb7 vc2enc: properly promote operations to 64 bits
On Windows machines, the UL suffix still means 32 bits.
The only parts that need 64 bits are (1ULL << (m + 32)) and
(t*qf + qf). Hence, use the proper ULL suffix for the former
and just increase the type of the qf constant for the latter.
No overflows can happen as long as these are done in 64 bits and
the quantization table doesn't change.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2018-03-13 01:43:30 +00:00
Rostislav Pehlivanov
ea6973a573 vc2enc: replace quantization LUT with a smaller division LUT
This commit replaces the huge and impractical LUT which converted coeffs
and a quantizer to bits to encode and instead uses a standard multiplication
and a shift to replace the division and then codes the values using the
regular golomb coding functions.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2018-03-10 14:40:29 +00:00
Rostislav Pehlivanov
61a4ee8ab4 avcodec/vc2enc: prevent bitrate overshoots
The rounding caused by the size scaler wasn't compensated for and the
slice sizes grew beyond what is allowed per frame.

Signed-off-by: Rostislav Pehlivanov <rpehlivanov@obe.tv>
2018-01-31 17:29:45 +01:00
Michael Niedermayer
6d00905f81 avcodec/vc2enc: Clear coef_buf on allocation
Fixes: Use of uninitialized memory
Fixes: assertion failure

Reviewed-by: <atomnuker>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-15 17:31:09 +01:00
Rostislav Pehlivanov
3228ac730c vc2enc_dwt: pad the temporary buffer by the slice size
Since non-Haar wavelets need to look into pixels outside the frame, we
need to pad the buffer. The old factor of two seemed to be a workaround
that fact and only padded to the left and bottom. This correctly pads
by the slice size and as such reduces memory usage and potential
exploits.
Reported by Liu Bingchang.

Ideally, there should be no temporary buffer but the encoder is designed
to deinterleave the coefficients into the classical wavelet structure
with the lower frequency values in the top left corner.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2017-11-09 00:05:48 +00:00
Martin Vignali
4ada428aae avcodec: remove remaining uses of avcodec_get_chroma_sub_sample
Replace them with av_pix_fmt_get_chroma_sub_sample.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-06 19:13:03 -03:00
Kieran Kunhya
1358f7ddb3 Revert "vc2enc: Calculate average slice quantiser correctly"
This reverts commit 626d200e76.
2017-11-04 18:31:59 +00:00
Kieran Kunhya
626d200e76 vc2enc: Calculate average slice quantiser correctly 2017-11-04 18:18:25 +00:00
Rostislav Pehlivanov
b52b398c30 vc2enc: decrease default strictness level
Given how incredibly limited the official specifications are (limiting all use
to only the most common broadcasting formats), permit all supported inputs
by default. This makes the encoder more useful.
2017-06-15 18:30:08 +01:00
Rostislav Pehlivanov
09d89d9406 diractab: expose the maximum quantization index as a macro
Prevents having to have random magic values in the decoder and a
separate macro in the encoder.

Signed-off-by: Rostislav Pehlivanov <rpehlivanov@obe.tv>
2016-07-11 23:38:01 +01:00
Christophe Gisquet
9c1aa14bf0 vc2enc: prevent random data
The slice prefix is 0 in the reference encoder and the decoder ignores it.
Writing 0 there seems like the best temporary solution.

The padding could have contained uninitialized data, but reference VC2
encoders put 0xFF there, hence the memset value.

Overall this allows producing bistreams with no random data for use by fate.
2016-05-06 01:12:51 +01:00
Rostislav Pehlivanov
770d3c85af vc2enc: do not print the lavc version if the bitexact flag is enabled
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-05-05 00:20:11 +01:00
Rostislav Pehlivanov
9e138c4813 vc2enc: use 32x16 slices by default
Approximately 1.25 times faster than 64x32, visually and
statistically improves quality.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-04-16 23:59:36 +01:00
Rostislav Pehlivanov
77fb7177af vc2enc: don't require interlacing for 1080p50/60 base video formats
Typo

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-04-16 23:59:36 +01:00
Rostislav Pehlivanov
72e1360007 vc2enc: optimize and simplify quantization
Everything except ORing the sign is now done in the LUT.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-24 13:04:59 +00:00
Rostislav Pehlivanov
a14d4c076d vc2enc: simplify calc_slice_sizes()
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-23 18:04:05 +00:00
Rostislav Pehlivanov
a010e36f23 vc2enc: correctly zero out the slice size cache
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-23 17:52:53 +00:00
Rostislav Pehlivanov
14b41e061d vc2enc: macro out slice size rounding
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-23 17:52:53 +00:00
Rostislav Pehlivanov
2aebdfb451 vc2enc: add non-experimental support for all video formats from spec
Until now, for formats which were in the spec but not in the encoder's
list of supported formats required the -strict -1 flag. This enables
support for all video formats which are specified, all the way from
QSIF525 to 8K.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-22 14:07:56 +00:00
Rostislav Pehlivanov
d4773c94a6 vc2enc: simplify count_hq_slice() and caching
The count_hq_slice() function is always used with a SliceArgs struct

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-21 11:04:49 +00:00
Rostislav Pehlivanov
500dc20dee vc2enc: fix segfault
Fixes trac bug #5353

Uninitialized memory for the initial quantization index

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-21 11:01:01 +00:00
Rostislav Pehlivanov
f4b30beac0 vc2enc: increase the starting value of the size scaler
In some cases this caused the slice size rounding to generate invalid
slice sizes and overwrite some slices.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-18 11:55:48 +00:00
Rostislav Pehlivanov
c45b1aa824 vc2enc: minor cosmetic changes
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-04 22:41:20 +00:00
Rostislav Pehlivanov
f21cf2b383 vc2enc: remove useless alignment on slice encoding
This was a leftover from before the slices were encoded in parallel.
Since the put_bits context is initialized per slice aligning it
aferwards is pointless.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-04 22:41:15 +00:00
Rostislav Pehlivanov
b88be742fa vc2enc: do not allocate packet until exact frame size is known
This commit solves most of the crashes and issues with the encoder and
the bitrate setting. Now the encoder will always allocate the absolute
lowest amount of memory regardless of what the bitrate has been set to.
Therefore if a user inputs a very low bitrate the encoder will use the
maximum possible quantization (basically zero out all coefficients),
allocate a packet and encode it. There is no coupling between the
bitrate and the allocation size and so no crashes because the buffer
isn't large enough.

The maximum quantizer was raised to the size of the table now to both
keep the overshoot at ridiculous bitrates low and to improve quality
with higher bit depths (since the coefficients grow larger per transform
quantizing them to the same relative level requires larger quantization
indices).

Since the quantization index start follows the previous quantization
index for that slice, the quantization step was reduced to a static 1
to improve performance. Previously with quant/5 the step was usually
set to 0 upon start (and was later clipped to 1), that isn't a big change.
As the step size increases so does the amount of bits leftover and so
the redistribution algorithm has to iterate more and thus waste more
time.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-04 22:40:58 +00:00
Rostislav Pehlivanov
7bcc57ad99 vc2enc: fix packet underallocation and minimum bitrate with interlacing
This was a regression introduced by commit e7345abe05 which
enabled full use of the allocated packet but due to the overhead of
using field coding the buffer was too small and triggered warnings and
crashes.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-01 13:44:18 +00:00
Rostislav Pehlivanov
41985d40c6 vc2enc: simplify slice cost caching
The fact that now all quantization indices costs are cached justifies
storing 20 more integers in a structure already allocated on heap.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-01 13:04:40 +00:00
Rostislav Pehlivanov
6061b78e83 vc2enc: remove redundant put_padding() and use skip_put_bytes() instead
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-03-01 11:39:30 +00:00
Rostislav Pehlivanov
e7345abe05 vc2enc: redistribute leftover bytes
This commit redistributes the leftover bytes amongst the top 150 slices
in terms of size (in the hopes that they'll be the ones pretty bitrate
starved).

A more perceptual method would probably need to cut bits off from slices
which don't need much, but that'll be implemented later.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
bbcd5e99c3 vc2enc: allocate the DWT context with the current plane size
Previously used the luma size only.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
2f19583911 2enc: clip and warn when user bitrate set too low
The encoder crashed on verly low bitrates since there wasn't enough
space allocated.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
6e5c6d61bd vc2enc: clip and warn when user bitrate set too low
The encoder crashed on verly low bitrates since there wasn't enough
space allocated.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
0a2adf0f47 vc2enc: carry over quantization index across frames as a starting point
Previously a global average was used. Using the previous quantizer
resulted in a fairly significant speedup as slice size selection settled
down quicker.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
fc1d3cbfdc vc2enc: use 32 bits for quantized coefficients LUT
16 bits were definitely not enough and caused artifacts to appear on
images at barely compressed images.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
5cc53c2e53 vc2enc: cache bits per quantizer, calculate wasted bits
Needed for following commits, also a speed increase.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-28 19:06:29 +00:00
Rostislav Pehlivanov
bc7beb6574 vc2enc: calculate the minimum slice size only once
This commit moves the minimum bits per slice calculations outside of the
rate control function as it is identical for every slice.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-26 15:38:26 +00:00
Rostislav Pehlivanov
2b811e4605 vc2enc: halve allocated table size, refactor and optimize quantization
Since coefficients differ only in the last bit when writing to the
bitstream it was possible to remove the sign from the tables, thus
halving them. Also now all quantization is done in the unsigned domain
as the sign is completely separate, which gets rid of the need to do
quantization on 32 bit signed integers.

Overall, this slightly speeds up the encoder depending on the machine.
The commit still generates bit-identical files as before the commit.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-26 14:47:06 +00:00
Rostislav Pehlivanov
7db2e757c5 vc2enc: use FFABS() instead of abs()
Provides a minor speedup.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-26 12:55:34 +00:00
Rostislav Pehlivanov
3ef10406e1 vc2enc: correctly zero out coefficient array padding
Credit for figuring this out goes to James Darnley.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-26 12:21:36 +00:00
Rostislav Pehlivanov
35346c7b0f vc2enc: mark as FF_CODEC_CAP_INIT_THREADSAFE and align AVCodec entries
The encoder does not modify any global variables.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-26 12:17:42 +00:00
Rostislav Pehlivanov
1387f3a051 vc2enc: set quantization ceiling to 50
The reference encoder limits it to 64, but testing revealed that there
is absolutely no difference for indices above 50 in amount of zeroed
coefficients.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-02-22 17:25:13 +00:00