summaryrefslogtreecommitdiffstats
path: root/libavcodec/vc2enc.c
Commit message (Collapse)AuthorAgeFilesLines
* vc2enc: properly promote operations to 64 bitsRostislav Pehlivanov2018-03-131-5/+5
| | | | | | | | | | | 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>
* vc2enc: replace quantization LUT with a smaller division LUTRostislav Pehlivanov2018-03-101-87/+31
| | | | | | | | | 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>
* avcodec/vc2enc: prevent bitrate overshootsRostislav Pehlivanov2018-01-311-8/+14
| | | | | | | 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>
* avcodec/vc2enc: Clear coef_buf on allocationMichael Niedermayer2017-11-151-1/+1
| | | | | | | | Fixes: Use of uninitialized memory Fixes: assertion failure Reviewed-by: <atomnuker> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* vc2enc_dwt: pad the temporary buffer by the slice sizeRostislav Pehlivanov2017-11-091-1/+2
| | | | | | | | | | | | | | | 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>
* avcodec: remove remaining uses of avcodec_get_chroma_sub_sampleMartin Vignali2017-11-061-2/+4
| | | | | | Replace them with av_pix_fmt_get_chroma_sub_sample. Signed-off-by: James Almer <jamrial@gmail.com>
* Revert "vc2enc: Calculate average slice quantiser correctly"Kieran Kunhya2017-11-041-3/+3
| | | | This reverts commit 626d200e76e15487cff20992256a55919432b0b3.
* vc2enc: Calculate average slice quantiser correctlyKieran Kunhya2017-11-041-3/+3
|
* vc2enc: decrease default strictness levelRostislav Pehlivanov2017-06-151-3/+3
| | | | | | 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.
* diractab: expose the maximum quantization index as a macroRostislav Pehlivanov2016-07-111-6/+3
| | | | | | | 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>
* vc2enc: prevent random dataChristophe Gisquet2016-05-061-0/+5
| | | | | | | | | | 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.
* vc2enc: do not print the lavc version if the bitexact flag is enabledRostislav Pehlivanov2016-05-051-2/+3
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: use 32x16 slices by defaultRostislav Pehlivanov2016-04-161-2/+2
| | | | | | | Approximately 1.25 times faster than 64x32, visually and statistically improves quality. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: don't require interlacing for 1080p50/60 base video formatsRostislav Pehlivanov2016-04-161-2/+2
| | | | | | Typo Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: optimize and simplify quantizationRostislav Pehlivanov2016-03-241-7/+8
| | | | | | Everything except ORing the sign is now done in the LUT. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: simplify calc_slice_sizes()Rostislav Pehlivanov2016-03-231-19/+13
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: correctly zero out the slice size cacheRostislav Pehlivanov2016-03-231-1/+1
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: macro out slice size roundingRostislav Pehlivanov2016-03-231-6/+9
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: add non-experimental support for all video formats from specRostislav Pehlivanov2016-03-221-35/+59
| | | | | | | | | 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>
* vc2enc: simplify count_hq_slice() and cachingRostislav Pehlivanov2016-03-211-15/+12
| | | | | | The count_hq_slice() function is always used with a SliceArgs struct Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: fix segfaultRostislav Pehlivanov2016-03-211-1/+1
| | | | | | | | Fixes trac bug #5353 Uninitialized memory for the initial quantization index Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: increase the starting value of the size scalerRostislav Pehlivanov2016-03-181-1/+1
| | | | | | | 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>
* vc2enc: minor cosmetic changesRostislav Pehlivanov2016-03-041-5/+4
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: remove useless alignment on slice encodingRostislav Pehlivanov2016-03-041-1/+0
| | | | | | | | 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>
* vc2enc: do not allocate packet until exact frame size is knownRostislav Pehlivanov2016-03-041-166/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* vc2enc: fix packet underallocation and minimum bitrate with interlacingRostislav Pehlivanov2016-03-011-1/+3
| | | | | | | | | This was a regression introduced by commit e7345abe052 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>
* vc2enc: simplify slice cost cachingRostislav Pehlivanov2016-03-011-31/+13
| | | | | | | 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>
* vc2enc: remove redundant put_padding() and use skip_put_bytes() insteadRostislav Pehlivanov2016-03-011-15/+3
| | | | Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: redistribute leftover bytesRostislav Pehlivanov2016-02-281-5/+55
| | | | | | | | | | | 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>
* vc2enc: allocate the DWT context with the current plane sizeRostislav Pehlivanov2016-02-281-2/+2
| | | | | | Previously used the luma size only. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* 2enc: clip and warn when user bitrate set too lowRostislav Pehlivanov2016-02-281-2/+2
| | | | | | | The encoder crashed on verly low bitrates since there wasn't enough space allocated. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: clip and warn when user bitrate set too lowRostislav Pehlivanov2016-02-281-0/+23
| | | | | | | The encoder crashed on verly low bitrates since there wasn't enough space allocated. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: carry over quantization index across frames as a starting pointRostislav Pehlivanov2016-02-281-6/+6
| | | | | | | | 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>
* vc2enc: use 32 bits for quantized coefficients LUTRostislav Pehlivanov2016-02-281-9/+9
| | | | | | | 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>
* vc2enc: cache bits per quantizer, calculate wasted bitsRostislav Pehlivanov2016-02-281-5/+32
| | | | | | Needed for following commits, also a speed increase. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: calculate the minimum slice size only onceRostislav Pehlivanov2016-02-261-3/+7
| | | | | | | 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>
* vc2enc: halve allocated table size, refactor and optimize quantizationRostislav Pehlivanov2016-02-261-58/+50
| | | | | | | | | | | | | 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>
* vc2enc: use FFABS() instead of abs()Rostislav Pehlivanov2016-02-261-3/+3
| | | | | | Provides a minor speedup. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: correctly zero out coefficient array paddingRostislav Pehlivanov2016-02-261-1/+1
| | | | | | Credit for figuring this out goes to James Darnley. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: mark as FF_CODEC_CAP_INIT_THREADSAFE and align AVCodec entriesRostislav Pehlivanov2016-02-261-11/+12
| | | | | | The encoder does not modify any global variables. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: set quantization ceiling to 50Rostislav Pehlivanov2016-02-221-1/+1
| | | | | | | | 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>
* vc2enc: use LAVC_INDENT instead of FFMPEG_VERSION for encoder commentRostislav Pehlivanov2016-02-211-2/+2
| | | | | | Prevents from having to recompile vc2enc on every single commit. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: add support for Haar wavelet transformsRostislav Pehlivanov2016-02-201-2/+4
| | | | | | | This commit adds support for the (simple, allowed in the spec, but inferior in quality) Haar wavelet transforms. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: print the average quantization index at the endRostislav Pehlivanov2016-02-151-0/+2
| | | | | | | | Similar to how the AAC encoder does it. 0 means the video's been compressed losslessly/almost losslessly thoughout. Generally, the higher, the worse. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: fix use of uninitialized variables in the rate control systemRostislav Pehlivanov2016-02-151-5/+5
| | | | | | | Fixes: CID1352550 Fixes: CID1352549 Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* avcodec: add a native SMPTE VC-2 HQ encoderRostislav Pehlivanov2016-02-101-0/+1196
This commit adds a new encoder capable of creating BBC/SMPTE Dirac/VC-2 HQ profile files. Dirac is a wavelet based codec created by the BBC a little more than 10 years ago. Since then, wavelets have mostly gone out of style as they did not provide adequate encoding gains at lower bitrates. Dirac was a fully featured video codec equipped with perceptual masking, support for most popular pixel formats, interlacing, overlapped-block motion compensation, and other features. It found new life after being stripped of various features and standardized as the VC-2 codec by the SMPTE with an extra profile, the HQ profile that this encoder supports, added. The HQ profile was based off of the Low-Delay profile previously existing in Dirac. The profile forbids DC prediction and arithmetic coding to focus on high performance and low delay at higher bitrates. The standard bitrates for this profile vary but generally 1:4 compression is expected (~525 Mbps vs the 2200 Mbps for uncompressed 1080p50). The codec only supports I-frames, hence the high bitrates. The structure of this encoder is simple: do a DWT transform on the entire image, split it into multiple slices (specified by the user) and encode them in parallel. All of the slices are of the same size, making rate control and threading very trivial. Although only in C, this encoder is capable of 30 frames per second on an 4 core 8 threads Ivy Bridge. A lookup table is used to encode most of the coefficients. No code was used from the GSoC encoder from 2007 except for the 2 transform functions in diracenc_transforms.c. All other code was written from scratch. This encoder outperforms any other encoders in quality, usability and in features. Other existing implementations do not support 4 level transforms or 64x64 blocks (slices), which greatly increase compression. As previously said, the codec is meant for broadcasting, hence support for non-broadcasting image widths, heights, bit depths, aspect ratios, etc. are limited by the "level". Although this codec supports a few chroma subsamplings (420, 422, 444), signalling those is generally outside the specifications of the level used (3) and the reference decoder will outright refuse to read any image with such a flag signalled (it only supports 1920x1080 yuv422p10). However, most implementations will happily read files with alternate dimensions, framerates and formats signalled. Therefore, in order to encode files other than 1080p50 yuv422p10le, you need to provide an "-strict -2" argument to the command line. The FFmpeg decoder will happily read any files made with non-standard parameters, dimensions and subsamplings, and so will other implementations. IMO this should be "-strict -1", but I'll leave that up for discussion. There are still plenty of stuff to implement, for instance 5 more wavelet transforms are still in the specs and supported by the decoder. The encoder can be lossless, given a high enough bitrate. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
OpenPOWER on IntegriCloud