1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-07-26 06:01:30 +02:00
Commit Graph

139 Commits

Author SHA1 Message Date
Andreas Rheinhardt
56e9e0273a avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Up until now, ff_alloc_packet2() has a min_size parameter:
It is supposed to be a lower bound on the final size of the packet
to allocate. If it is not too far from the upper bound (namely,
if it is at least half the upper bound), then ff_alloc_packet2()
already allocates the final, already refcounted packet; if it is
not, then the packet is not refcounted and its data only points to
a buffer owned by the AVCodecContext (in this case, the packet will
be made refcounted in encode_simple_internal() in libavcodec/encode.c).
The goal of this was to avoid data copies and intermediate buffers
if one has a precise lower bound.

Yet those encoders for which precise lower bounds exist have recently
been switched to ff_get_encode_buffer() (which automatically allocates
final buffers), leaving only two encoders to actually set the min_size
to something else than zero (namely aliaspixenc and hapenc). Both of
these encoders use a very low lower bound that is not helpful in any
nontrivial case.

This commit therefore removes the min_size parameter as well as the
codepath in ff_alloc_packet2() for the allocation of final buffers.
Furthermore, the function has been renamed to ff_alloc_packet() and
moved to encode.h alongside ff_get_encode_buffer().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:50 +02:00
Michael Niedermayer
c297f7e57a avcodec/svq1enc: Do not print debug RD value before it has been computed
Avoids floating point division by 0

Fixes: Ticket8191

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-02 17:30:24 +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
11bc790893 avcodec: Remove deprecated AVCodecContext.coded_frame
Deprecated in 40cf1bbacc.
(The currently disabled filter vf_mcdeint and vf_uspp were users of
this field; they have not been changed, so that whoever wants to fix
them can see the state of these filters when they were disabled.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:12 -03:00
Andreas Rheinhardt
fea1f42e5f avcodec/ituh263enc: Make static initializations thread-safe
This already makes several encoders (namely FLV, H.263, H.263+ and
RealVideo 1.0 and 2.0 and SVQ1) that use this init-threadsafe.

It also makes the Snow encoder init-threadsafe; it was already marked
as such since commit d49210788b, because
it was thought to be harmless if one and the same object was
initialized by multiple threads at the same time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-27 00:30:36 +02:00
Andreas Rheinhardt
c81b8e04aa Avoid intermediate bitcount for number of bytes in PutBitContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:32 +02:00
Andreas Rheinhardt
67f6e7ed6d avcodec: Remove cumbersome way of checking for amount of bytes left
Several encoders used code like the following to check for the amount of
bytes left in a PutBitContext:
pb->buf_end - pb->buf - (put_bits_count(pb) >> 3)
Besides the fact that using the pointers directly might pose
a maintainence burden in the future this also leads to suboptimal code:
The above code reads all three pointers (buf, buf_ptr and buf_end), but
touching buf is unnecessary and switching to put_bytes_left()
automatically fixes this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:32 +02:00
Anton Khirnov
dc1099442e put_bits: make avpriv_copy_bits() lavc-local
It is not used outside of lavc anymore. Keep the avpriv exported symbol
around until the next bump to preserve ABI compatibility.
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
Limin Wang
4b2863ff01 avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-13 06:59:18 +08:00
James Almer
6e1903938b avcodec/internal: move packet related functions to their own header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-02 19:02:12 -03:00
Ramiro Polla
531fbce0b2 mpegvideo_enc: add intra_penalty option for p frames
This option allows more control over the use of intra macroblocks in
predictive frames.

By using '-intra_penalty max', intra macroblocks are never used in
predictive frames.

It is useful for glitch artists to generate input material. This option
allows them to split and merge two video files while maintaining fluid
motion from the second video without having intra macroblocks restoring
chunks of the first video.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-10-24 19:45:17 +02:00
James Almer
bfab430856 Merge commit '94eed68ace9f2416af8457fcbf142b175928c06b'
* commit '94eed68ace9f2416af8457fcbf142b175928c06b':
  lavc: Drop deprecated options moved to private contexts

Merged-by: James Almer <jamrial@gmail.com>
2017-10-23 17:08:32 -03:00
Vittorio Giovara
94eed68ace lavc: Drop deprecated options moved to private contexts
Deprecated in 10/2014 and 07/2015.
2017-03-23 10:09:17 +01:00
Michael Niedermayer
70dc6bbf1b avcodec/svq1enc: Clear MMX state after svq1_encode_plane()
svq1_encode_plane() uses SIMD and we call libc memory allocation functions after it

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-10-22 13:45:59 +02:00
Clément Bœsch
8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Vittorio Giovara
41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Andreas Cadhalpun
9079e99d2c svq1enc: fix out of bounds reads
level can be 5, but there are only four codebooks.

Fixes ubsan runtime error: index 5 out of bounds for type 'int8_t
[4][96]'

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-01-27 00:08:23 +01:00
Michael Niedermayer
88fe45e0fe avcodec/svq1enc: Check dimensions
Fixes assertion failure

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-15 15:06:01 +02:00
Michael Niedermayer
29d147c94d Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'
* commit '059a934806d61f7af9ab3fd9f74994b838ea5eba':
  lavc: Consistently prefix input buffer defines

Conflicts:
	doc/examples/decoding_encoding.c
	libavcodec/4xm.c
	libavcodec/aac_adtstoasc_bsf.c
	libavcodec/aacdec.c
	libavcodec/aacenc.c
	libavcodec/ac3dec.h
	libavcodec/asvenc.c
	libavcodec/avcodec.h
	libavcodec/avpacket.c
	libavcodec/dvdec.c
	libavcodec/ffv1enc.c
	libavcodec/g2meet.c
	libavcodec/gif.c
	libavcodec/h264.c
	libavcodec/h264_mp4toannexb_bsf.c
	libavcodec/huffyuvdec.c
	libavcodec/huffyuvenc.c
	libavcodec/jpeglsenc.c
	libavcodec/libxvid.c
	libavcodec/mdec.c
	libavcodec/motionpixels.c
	libavcodec/mpeg4videodec.c
	libavcodec/mpegvideo.c
	libavcodec/noise_bsf.c
	libavcodec/nuv.c
	libavcodec/nvenc.c
	libavcodec/options.c
	libavcodec/parser.c
	libavcodec/pngenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/qsvdec.c
	libavcodec/svq1enc.c
	libavcodec/tiffenc.c
	libavcodec/truemotion2.c
	libavcodec/utils.c
	libavcodec/utvideoenc.c
	libavcodec/vc1dec.c
	libavcodec/wmalosslessdec.c
	libavformat/adxdec.c
	libavformat/aiffdec.c
	libavformat/apc.c
	libavformat/apetag.c
	libavformat/avidec.c
	libavformat/bink.c
	libavformat/cafdec.c
	libavformat/flvdec.c
	libavformat/id3v2.c
	libavformat/isom.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/mpc.c
	libavformat/mpc8.c
	libavformat/mpegts.c
	libavformat/mvi.c
	libavformat/mxfdec.c
	libavformat/mxg.c
	libavformat/nutdec.c
	libavformat/oggdec.c
	libavformat/oggparsecelt.c
	libavformat/oggparseflac.c
	libavformat/oggparseopus.c
	libavformat/oggparsespeex.c
	libavformat/omadec.c
	libavformat/rawdec.c
	libavformat/riffdec.c
	libavformat/rl2.c
	libavformat/rmdec.c
	libavformat/rtpdec_latm.c
	libavformat/rtpdec_mpeg4.c
	libavformat/rtpdec_qdm2.c
	libavformat/rtpdec_svq3.c
	libavformat/sierravmd.c
	libavformat/smacker.c
	libavformat/smush.c
	libavformat/spdifenc.c
	libavformat/takdec.c
	libavformat/tta.c
	libavformat/utils.c
	libavformat/vqf.c
	libavformat/westwood_vqa.c
	libavformat/xmv.c
	libavformat/xwma.c
	libavformat/yop.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 23:15:19 +02:00
Vittorio Giovara
059a934806 lavc: Consistently prefix input buffer defines
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-27 15:24:59 +01:00
Vittorio Giovara
4b6b1082a7 lavc: Deprecate avctx.me_method
This option is extremely codec specific and only a few codecs employ it.
Move it to codec private options instead: mpegenc family supports only 3
values, xavs and x264 use 5, and xvid has a different metric entirely.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-27 15:24:56 +01:00
Michael Niedermayer
0b6f092ed3 Merge commit '4b6b1082a73907c7c3de2646c6398bc61320f2c6'
* commit '4b6b1082a73907c7c3de2646c6398bc61320f2c6':
  lavc: Deprecate avctx.me_method

Conflicts:
	doc/encoders.texi
	libavcodec/avcodec.h
	libavcodec/libx264.c
	libavcodec/motion_est.c
	libavcodec/options_table.h
	libavcodec/version.h

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 21:03:20 +02:00
Michael Niedermayer
e36db49b7b avcodec: Add a min size parameter to ff_alloc_packet2()
This parameter can be used to inform the allocation code about how much
downsizing might occur, and can be used to optimize how to allocate the
packet

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 19:57:52 +02:00
Michael Niedermayer
5362df2ee3 avcodec: remove unused sd variables
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-22 21:04:17 +02:00
Michael Niedermayer
c40ecffd31 Replace AV_PKT_DATA_QUALITY_FACTOR by AV_PKT_DATA_QUALITY_STATS
The stats are a superset of the quality factor, also allowing the picture type and encoder "PSNR" stats to be exported
This also replaces the native by fixed little endian order for the affected side data

AV_PKT_DATA_QUALITY_FACTOR is left as a synonym of AV_PKT_DATA_QUALITY_STATS

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-22 19:31:52 +02:00
Michael Niedermayer
495eee0123 Merge commit '40cf1bbacc6220a0aa6bed5c331871d43f9ce370'
* commit '40cf1bbacc6220a0aa6bed5c331871d43f9ce370':
  Deprecate avctx.coded_frame

Conflicts:
	ffmpeg.c
	libavcodec/a64multienc.c
	libavcodec/asvenc.c
	libavcodec/cljrenc.c
	libavcodec/dpxenc.c
	libavcodec/gif.c
	libavcodec/mpegvideo_enc.c
	libavcodec/nvenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/pthread_frame.c
	libavcodec/rawenc.c
	libavcodec/sunrastenc.c
	libavcodec/tiffenc.c
	libavcodec/version.h
	libavcodec/xbmenc.c
	libavcodec/xwdenc.c
	libavdevice/v4l2.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-21 01:17:15 +02:00
Michael Niedermayer
e5bae39f46 Merge commit '5d3addb937946eca5391e40b5e6308e74ac6f77b'
* commit '5d3addb937946eca5391e40b5e6308e74ac6f77b':
  Add a quality factor packet side data

Conflicts:
	doc/APIchanges
	ffmpeg.c
	libavcodec/avcodec.h
	libavcodec/mpegvideo_enc.c
	libavcodec/version.h

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-21 00:54:42 +02:00
Michael Niedermayer
b1fad7ac20 Merge commit 'd6604b29ef544793479d7fb4e05ef6622bb3e534'
* commit 'd6604b29ef544793479d7fb4e05ef6622bb3e534':
  Gather all coded_frame allocations and free functions to a single place

Conflicts:
	libavcodec/a64multienc.c
	libavcodec/asvenc.c
	libavcodec/cljrenc.c
	libavcodec/dpxenc.c
	libavcodec/dvenc.c
	libavcodec/gif.c
	libavcodec/huffyuvenc.c
	libavcodec/jpeglsenc.c
	libavcodec/libopenjpegenc.c
	libavcodec/libtheoraenc.c
	libavcodec/libvpxenc.c
	libavcodec/mpegvideo_enc.c
	libavcodec/nvenc.c
	libavcodec/pngenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/sunrastenc.c
	libavcodec/tiffenc.c
	libavcodec/utils.c
	libavcodec/utvideoenc.c
	libavcodec/v210enc.c
	libavcodec/v410enc.c
	libavcodec/xbmenc.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-20 23:43:05 +02:00
Michael Niedermayer
033144c0d1 Merge commit '56672aeaee19216d2fd8eeb9964b1f71f0af2919'
* commit '56672aeaee19216d2fd8eeb9964b1f71f0af2919':
  svq1enc: Do not entangle coded_frame

Conflicts:
	libavcodec/svq1enc.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-20 21:53:09 +02:00
Vittorio Giovara
40cf1bbacc Deprecate avctx.coded_frame
The rationale is that coded_frame was only used to communicate key_frame,
pict_type and quality to the caller, as well as a few other random fields,
in a non predictable, let alone consistent way.

There was agreement that there was no use case for coded_frame, as it is
a full-sized AVFrame container used for just 2-3 int-sized properties,
which shouldn't even belong into the AVCodecContext in the first place.

The appropriate AVPacket flag can be used instead of key_frame, while
quality is exported with the new AVPacketSideData quality factor.
There is no replacement for the other fields as they were unreliable,
mishandled or just not used at all.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-20 15:06:50 +01:00
Vittorio Giovara
5d3addb937 Add a quality factor packet side data
This is necessary to preserve the quality information currently exported
with coded_frame. Add the new side data to every encoder that needs it,
and use it in avconv.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-20 15:06:47 +01:00
Vittorio Giovara
d6604b29ef Gather all coded_frame allocations and free functions to a single place
Allocating coded_frame is what most encoders do anyway, so it makes
sense to always allocate and free it in a single place. Moreover a lot
of encoders freed the frame with av_freep() instead of the correct API
av_frame_free().

This bring uniformity to encoder behaviour and prevents applications
from erroneusly accessing this field when not allocated. Additionally
this helps isolating encoders that export information with coded_frame,
and heavily simplifies its deprecation.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-20 14:16:15 +01:00
Vittorio Giovara
56672aeaee svq1enc: Do not entangle coded_frame 2015-07-20 14:13:42 +01:00
Michael Niedermayer
f24b7d7616 Merge commit '28fb80dcbf6f63eedfcfffc725a6bf0069d03fab'
* commit '28fb80dcbf6f63eedfcfffc725a6bf0069d03fab':
  svq1: Check memory allocation

Conflicts:
	libavcodec/svq1enc.c

See: 2a3af77284
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-01 02:38:06 +02:00
Vittorio Giovara
28fb80dcbf svq1: Check memory allocation 2015-05-31 15:03:31 +02:00
Michael Niedermayer
404fe63e23 avcodec: Pass PutBitContext into ff_h263_encode_motion() instead of MpegEncContext
This avoids the need to dereference MpegEncContext->pb if it is
already available outside ff_h263_encode_motion()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-24 17:15:18 +02:00
Michael Niedermayer
d9b264bc73 Merge commit '848e86f74d3e6e87fa592ee8ba8c184cc5fd9a42'
* commit '848e86f74d3e6e87fa592ee8ba8c184cc5fd9a42':
  mpegvideo: Drop flags and flags2

Conflicts:
	libavcodec/mpeg12dec.c
	libavcodec/mpeg12enc.c
	libavcodec/mpegvideo.c
	libavcodec/mpegvideo_enc.c
	libavcodec/mpegvideo_motion.c
	libavcodec/ratecontrol.c
	libavcodec/vc1_block.c
	libavcodec/vc1_loopfilter.c
	libavcodec/vc1_mc.c
	libavcodec/vc1dec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-22 20:24:41 +02:00
Vittorio Giovara
848e86f74d mpegvideo: Drop flags and flags2
They are just duplicates of AVCodecContext members so use those instead.
2015-05-22 15:34:39 +01:00
Michael Niedermayer
acfb4ede2f Merge commit '6f7a32839d1b913be8170e91c3ac9816b314da21'
* commit '6f7a32839d1b913be8170e91c3ac9816b314da21':
  svq1enc: correctly handle memory error and allocations

Conflicts:
	libavcodec/svq1enc.c

See: 79888388e7
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-03 22:40:46 +01:00
Michael Niedermayer
6f7a32839d svq1enc: correctly handle memory error and allocations
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-02-03 15:23:21 +00:00
Michael Niedermayer
79888388e7 avcodec/svq1enc: fix error handling/cleanup in case of ff_get_buffer() or scratchbuffer alloc failure
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-18 21:25:06 +01:00
Michael Niedermayer
2a3af77284 avcodec/svq1enc: Check memory allocations
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-18 21:21:44 +01:00
Reimar Döffinger
d0682b5eb0 svq1enc: reduce stack usage of recursively-called function.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-11-23 06:51:18 +01:00
Vittorio Giovara
59846452af svq1enc: check ff_get_buffer return value
CC: libav-stable@libav.org
Bug-Id: CID 747723
2014-11-13 01:41:27 +01:00
James Almer
a829870b2f avcodec/svq1enc: align buffer used by simd functions
Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
2014-09-25 16:00:20 -03:00
Reimar Döffinger
fcfc90ed65 svq1enc: remove pointless array element.
Not sure it was meant to be used for something at some point though.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-09-03 21:22:58 +02:00
Michael Niedermayer
c1df467d73 Merge commit '835f798c7d20bca89eb4f3593846251ad0d84e4b'
* commit '835f798c7d20bca89eb4f3593846251ad0d84e4b':
  mpegvideo: cosmetics: Lowercase ugly uppercase MPV_ function name prefixes

Conflicts:
	libavcodec/h261dec.c
	libavcodec/intrax8.c
	libavcodec/mjpegenc.c
	libavcodec/mpeg12dec.c
	libavcodec/mpeg12enc.c
	libavcodec/mpeg4videoenc.c
	libavcodec/mpegvideo.c
	libavcodec/mpegvideo.h
	libavcodec/mpegvideo_enc.c
	libavcodec/rv10.c
	libavcodec/x86/mpegvideoenc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-08-15 20:11:56 +02:00
Diego Biurrun
835f798c7d mpegvideo: cosmetics: Lowercase ugly uppercase MPV_ function name prefixes 2014-08-15 01:26:33 -07:00
Michael Niedermayer
3a2d1465c8 Merge commit '2d60444331fca1910510038dd3817bea885c2367'
* commit '2d60444331fca1910510038dd3817bea885c2367':
  dsputil: Split motion estimation compare bits off into their own context

Conflicts:
	configure
	libavcodec/Makefile
	libavcodec/arm/Makefile
	libavcodec/dvenc.c
	libavcodec/error_resilience.c
	libavcodec/h264.h
	libavcodec/h264_slice.c
	libavcodec/me_cmp.c
	libavcodec/me_cmp.h
	libavcodec/motion_est.c
	libavcodec/motion_est_template.c
	libavcodec/mpeg4videoenc.c
	libavcodec/mpegvideo.c
	libavcodec/mpegvideo_enc.c
	libavcodec/x86/Makefile
	libavcodec/x86/me_cmp_init.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-07-17 23:27:40 +02:00