summaryrefslogtreecommitdiff
path: root/libavcodec/encode.c
Commit message (Collapse)AuthorAge
* 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