summaryrefslogtreecommitdiff
path: root/libavcodec/encode.c
Commit message (Collapse)AuthorAge
* avcodec/encode:: generate ICC profilesNiklas Haas2022-07-30
| | | | | | | | | | | | | | | | Only if requested, and only if the codec signals support for ICC profiles. Implementation roughly matches the functionality of the existing vf_iccgen filter, albeit with some reduced flexibility and no caching. Ideally, we'd also only do this on the first frame (e.g. mjpeg, apng), but there's no meaningful way for us to distinguish between this case and e.g. somebody using the image2 muxer, in which case we'd want to attach ICC profiles to every frame in the stream. Closes: #9672 Signed-off-by: Niklas Haas <git@haasn.dev>
* lavc: use AVFrame.duration instead of AVFrame.pkt_durationAnton Khirnov2022-07-19
|
* avcodec/encode: Avoid check whose result is known in advanceAndreas Rheinhardt2022-07-09
| | | | | | | | | | | | | | | encode_send_frame_internal() is always only called if the buffer packet is empty and except when we are dealing with an audio codec that does not allow variable frame size it stays that way until a call to av_frame_ref() at the end of encode_send_frame_internal(). In case we are dealing with the small last frame of an audio encoder requiring constant frame size the frame will be allocated by pad_last_frame() and this the only case where this is so. So by returning directly after pad_last_frame(), we can avoid having to recheck whether the frame is still empty before av_frame_ref(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/encode: add an encoder-specific get_buffer() variantAnton Khirnov2022-05-11
| | | | | | | | | | | Several encoders (roqvideo, svq1, snow, and the mpegvideo family) currently call ff_get_buffer(). However this function is written assuming it is called by a decoder. Though nothing has been obviously broken by this until now, that may change in the future. To avoid potential future issues, introduce a simple encode-specific wrapper around avcodec_default_get_buffer2() and enforce its use in encoders.
* avcodec/encode: Fix check for encoders impl. encode-simple APIAndreas Rheinhardt2022-04-13
| | | | | | | FFCodec.cb is a union. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/encode: pick a sane default for bits_per_raw_sample if it's not setAnton Khirnov2022-04-13
| | | | Fixes #9563.
* lavc/encode: reindentAnton Khirnov2022-04-13
|
* lavc/encode: factor audio/video-specific parts out of ff_encode_preinit()Anton Khirnov2022-04-13
|
* lavc/encode: drop EncodeSimpleContextAnton Khirnov2022-04-13
| | | | It has only a single member.
* lavc/avcodec: only allocate the encoding frame for encodersAnton Khirnov2022-04-13
| | | | And only when needed, i.e. for encoders using the simple API.
* avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-05
| | | | | | | | | | | This is possible, because every given FFCodec has to implement exactly one of these. Doing so decreases sizeof(FFCodec) and therefore decreases the size of the binary. Notice that in case of position-independent code the decrease is in .data.rel.ro, so that this translates to decreased memory consumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-21
| | | | | | | | | | | | | | | | Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc: drop temporary compat wrappers for channel layout API changeAnton Khirnov2022-03-15
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* lavc: switch to the new channel layout APIVittorio Giovara2022-03-15
| | | | | | | | Since the request_channel_layout is used only by a handful of codecs, move the option to codec private contexts. Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* lavc/encode: set frame_number for encoders using receive_packet()Anton Khirnov2021-12-17
| | | | | It is currently set in encode_simple_internal(), which is only called for encoders using the "simple" encoding API.
* lavc/encode: improve the empty frame checkAnton Khirnov2021-12-17
| | | | | Test for buf[0] rather than data[0] (which is broken for some hwaccel formats).
* avcodec/encode: Set AV_PKT_FLAG_KEY based upon AV_CODEC_PROP_INTRA_ONLYAndreas Rheinhardt2021-09-28
| | | | | | | | | | | Currently, the AV_PKT_FLAG_KEY is automatically set for audio encoders; yet this is wrong, as both MLP and TrueHD have non-keyframes. So set it based upon AV_CODEC_PROP_INTRA_ONLY (from the corresponding AVCodecDescriptor) instead. This also sets it for some video codecs, which is intended. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Stop including channel_layout.h in avcodec.hAndreas Rheinhardt2021-07-22
| | | | | | Also include channel_layout.h directly wherever used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()Andreas Rheinhardt2021-06-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec: Remove deprecated old encode/decode APIsAndreas Rheinhardt2021-04-27
| | | | | | | | Deprecated in commits 7fc329e2dd6226dfecaa4a1d7adf353bf2773726 and 31f6a4b4b83aca1d73f3cfc99ce2b39331970bf3. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Remove deprecated AVCodecContext.coded_frameAndreas Rheinhardt2021-04-27
| | | | | | | | | | Deprecated in 40cf1bbacc6220a0aa6bed5c331871d43f9ce370. (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>
* avcodec/encode: Zero padding in ff_get_encode_buffer()Andreas Rheinhardt2021-04-27
| | | | | | | | | | | | | The documentation of the get_encode_buffer() callback does not require to zero the padding; therefore we do it in ff_get_encode_buffer(). This also constitutes an implicit check for whether the buffer is actually allocated with padding. The memset in avcodec_default_get_encode_buffer() is now redundant and has been removed. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mjpegenc: Include all supported pix_fmts in mpegenc pix_fmtsAndreas Rheinhardt2021-04-10
| | | | | | | | | | | | | | | Currently said list contains only the pixel formats that are always supported irrespective of the range and the value of strict_std_compliance. This makes the MJPEG encoder an outlier as all other codecs put all potentially supported pixel formats into said list and error out if the chosen pixel format is unsupported. This commit brings it therefore in line with the other encoders. The behaviour of fftools/ffmpeg_filter.c has been preserved. A more informed decision would be possible if colour range were available at this point, but it isn't. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/encode: Fix check for allowed LJPEG pixel formatsAndreas Rheinhardt2021-04-08
| | | | | | | | | | | | | | | The pix_fmts of the LJPEG encoder already contain all supported pixel formats (including the ones only supported when strictness is unofficial or less); yet the check in ff_encode_preinit() ignored this list in case strictness is unofficial or less. But the encoder presumed that it is always applied and blacklists some of the entries in pix_fmts when strictness is > unofficial. The result is that if one uses an entry not on that list and sets strictness to unofficial, said entry passes both checks and this can lead to segfaults lateron (e.g. when using gray). Fix this by removing the exception for LJPEG in ff_encode_preinit(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/encode: silence a deprecation warning about av_init_packet()James Almer2021-03-17
| | | | | | No need to adapt this code as it will be removed long before av_init_packet() Signed-off-by: James Almer <jamrial@gmail.com>
* lavc/encode: reindent after previous commitAnton Khirnov2021-03-16
|
* lavc: factor out encoder init/validation from avcodec_open2()Anton Khirnov2021-03-16
| | | | | | avcodec_open2() is massive, splitting it makes it more readable. Also, add a missing error code to ticks_per_frame sanity check.
* avcodec: add a get_encode_buffer() callback to AVCodecContextJames Almer2021-03-12
| | | | | | | | | | | This callback is functionally the same as get_buffer2() is for decoders, and implements for the new encode API the functionality of the old encode API had where the user could provide their own buffers. Reviewed-by: Lynne <dev@lynne.ee> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/frame_thread_encoder: Avoid creating reference to frameAndreas Rheinhardt2021-02-16
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavc: shedule old encoding/decoding API for removalAnton Khirnov2021-01-26
| | | | | | | | It has been deprecated for 4 years and certain new codecs do not work with it. Also include AVCodecContext.refcounted_frames, as it has no effect with the new API.
* avcodec/encode: unref the packet on AVCodec.receive_packet() failureJames Almer2020-09-01
| | | | | | | | | | | Fixes memleaks with some encoders that don't unref the packet before returning. This is consistent with the behavior of AVCodec.encode() implementations in encode_simple_internal(). Found-by: mkver Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/encode: restructure the old encode APIJames Almer2020-06-18
| | | | | | | Following the same logic as 061a0c14bb, this commit turns the old encode API into a wrapper for the new one. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/encode: restructure the core encoding codeJames Almer2020-06-18
| | | | | | | | | | | | | | | | This commit follows the same logic as 061a0c14bb, but for the encode API: The new public encoding API will no longer be a wrapper around the old deprecated one, and the internal API used by the encoders now consists of a single receive_packet() callback that pulls frames as required. amf encoders adapted by James Almer librav1e encoder adapted by James Almer nvidia encoders adapted by James Almer MediaFoundation encoders adapted by James Almer vaapi encoders adapted by Linjie Fu v4l2_m2m encoders adapted by Andriy Gelman Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/encode: Remove ff_alloc_packetAndreas Rheinhardt2020-06-01
| | | | | | | It is no longer used anymore. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/frame_thread_encoder: remove usage of avcodec_encode_video2()James Almer2020-05-25
| | | | | | Call the encoder's internal AVCodec.encode2() function instead. Signed-off-by: James Almer <jamrial@gmail.com>
* Stop hardcoding align=32 in av_frame_get_buffer() calls.Anton Khirnov2020-05-22
| | | | Use 0, which selects the alignment automatically.
* avcodec/encode: add missing assert to avcodec_receive_packet()James Almer2019-11-14
| | | | | | | | | | Encoders must return reference counted packets. This was checked only for encoders using the AVCodec->encode2() API, while blindly accepting whatever encoders using the AVCodec->receive_packet() API were returning. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/encode: only allow undersized audio frames if they are the lastMarton Balint2019-08-11
| | | | | | | | | | | | | | | Otherwise the user might get a silence padded frame in the beginning or in the middle of the encoding. Some other bug uncovered this: ./ffmpeg -loglevel verbose -y -f data -i /dev/zero \ -filter_complex "nullsrc=s=60x60:d=10[v0];sine=d=10[a]" \ -map '[v0]' -c:v:0 rawvideo \ -map '[a]' -c:a:0 mp2 \ -f mpegts out.ts Signed-off-by: Marton Balint <cus@passwd.hu>
* lavc/encode: fix frame_number double-countedZhong Li2018-08-27
| | | | | | | | | | Encoder frame_number may be double-counted if some frames are cached and then flushed. Take qsv encoder (some frames are cached firsty for asynchronism) as example, ./ffmpeg -loglevel verbose -hwaccel qsv -c:v h264_qsv -i in.mp4 -vframes 100 -c:v h264_qsv out.mp4 frame_number passed to encoder is double-counted and larger than the accurate value. Libx264 encoding with B frames can also reproduce it. Signed-off-by: Zhong Li <zhong.li@intel.com>
* lavc/encode: remove redundant av_init_packet after av_packet_unref.Jun Zhao2018-08-23
| | | | | | | remove redundant av_init_packet after av_packet_unref. av_packet_unref have call av_init_packet and reset the packet size. Signed-off-by: Jun Zhao <mypopydev@gmail.com>
* avcodec/encode: use av_packet_make_refcounted to ensure packets are ref countedJames Almer2018-04-01
| | | | | | Simplifies code. Signed-off-by: James Almer <jamrial@gmail.com>
* Merge commit '48bb0da050329e5111b00a12dfc154b7e78fb3a3'James Almer2017-10-23
|\ | | | | | | | | | | | | * commit '48bb0da050329e5111b00a12dfc154b7e78fb3a3': lavc: Drop deprecated way of setting audio delay on encode Merged-by: James Almer <jamrial@gmail.com>
| * lavc: Drop deprecated way of setting audio delay on encodeVittorio Giovara2017-03-23
| | | | | | | | Deprecated in 08/2014.
* | avcodec/encode: do proper cleanup on failureJames Almer2017-10-03
| | | | | | | | | | | | Fixes the last remaining memleaks introduced by a22c6a4796ca1f2cbee6784262515da876fbec22. Signed-off-by: James Almer <jamrial@gmail.com>
* | avcodec/encode: free non-referenced packets' side data in the old encode API ↵James Almer2017-10-02
| | | | | | | | | | | | functions Fixes memleaks introduced by a22c6a4796ca1f2cbee6784262515da876fbec22.
* | avcodec/encode: remove usage of av_dup_packet()James Almer2017-10-02
| | | | | | | | | | Reviewed-by: wm4 <nfxjfg@googlemail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* | avcodec: do not use AVFrame accessorMuhammad Faiz2017-04-23
| | | | | | | | | | Reviewed-by: wm4 <nfxjfg@googlemail.com> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
* | Merge commit '328cd2b599bc2d0d38f3c12606fa2a66eeec016e'James Almer2017-04-07
|/ | | | | | | * commit '328cd2b599bc2d0d38f3c12606fa2a66eeec016e': lavc: move encoding-related code from utils.c to a new file Merged-by: James Almer <jamrial@gmail.com>
* lavc: move encoding-related code from utils.c to a new fileAnton Khirnov2016-11-29