aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ratecontrol.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpegvideo: Move fields to {H263Dec,MPVEnc}Context when possibleAndreas Rheinhardt2025-07-031-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Fix wrong sizeof expressionAndreas Rheinhardt2025-05-211-1/+1
| | | | | | | Fixes Coverity issue #1644200. Introduced in 89a8033fc918b2f0ef435e5a3077455ceb8ff913. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move [fb]_code to Mpeg4Dec and MPVEncContextAndreas Rheinhardt2025-05-161-6/+6
| | | | | | | | It is only used by the MPEG-4 decoder and the encoders. Notice that this field is a per-frame property and therefore does not need to by synced in mpeg4_update_thread_context(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: remove deprecated FF_API_TICKS_PER_FRAMEJames Almer2025-03-281-6/+0
| | | | | | Deprecated since 2023-05-15. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/mpegvideoenc: Add MPVEncContextAndreas Rheinhardt2025-03-261-130/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many of the fields of MpegEncContext (which is also used by decoders) are actually only used by encoders. Therefore this commit adds a new encoder-only structure and moves all of the encoder-only fields to it except for those which require more explicit synchronisation between the main slice context and the other slice contexts. This synchronisation is currently mainly provided by ff_update_thread_context() which simply copies most of the main slice context over the other slice contexts. Fields which are moved to the new MPVEncContext no longer participate in this (which is desired, because it is horrible and for the fields b) below wasteful) which means that some fields can only be moved when explicit synchronisation code is added in later commits. More explicitly, this commit moves the following fields: a) Fields not copied by ff_update_duplicate_context(): dct_error_sum and dct_count; the former does not need synchronisation, the latter is synchronised in merge_context_after_encode(). b) Fields which do not change after initialisation (these fields could also be put into MPVMainEncContext at the cost of an indirection to access them): lambda_table, adaptive_quant, {luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp, {p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table, [pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff, {inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields, the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info, mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function pointers, mpv_flags, quantizer_noise_shaping, frame_reconstruction_bitfield, error_rate and intra_penalty. c) Fields which are already (re)set explicitly: The PutBitContexts pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir, esc_pos (reset when writing the header). d) Fields which are only used by encoders not supporting slice threading for which synchronisation doesn't matter: esc3_level_length and the remaining mb_info fields. e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD is set (which implies trellis) and even then it is only used for non-intra blocks. For these blocks dct_quantize_trellis_c() either sets coded_score[n] or returns a last_non_zero value of -1 in which case coded_score will be reset in encode_mb_internal(). Therefore no old values are ever used. The MotionEstContext has not been moved yet. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move last-pic information to MPVMainEncContextAndreas Rheinhardt2025-03-261-2/+2
| | | | | | | last_pict_type, last_non_b_pict_type and last_lambda_for are only used by the encoder's main thread. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Add bit_rate to MPVMainEncContextAndreas Rheinhardt2025-03-261-8/+8
| | | | | | | Use it instead of the MpegEncContext field which will be removed soon. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move max_b_frames to MPVMainEncContextAndreas Rheinhardt2025-03-261-3/+3
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move header_bits to MPVMainEncContextAndreas Rheinhardt2025-03-261-1/+1
| | | | | | | | The header is always written by the main thread, so it is not surprising that header_bits can be moved to MPVMainEncContext as well. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move macroblock-variance stats to MPVMainEncContextAndreas Rheinhardt2025-03-261-8/+8
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move ratecontrol-adjacent fields to MPVMainEncContextAndreas Rheinhardt2025-03-261-8/+10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move sequence-level properties to MPVMainEncContextAndreas Rheinhardt2025-03-261-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Move ratecontrol to MPVMainEncContextAndreas Rheinhardt2025-03-261-33/+42
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Don't log to private contextAndreas Rheinhardt2025-03-081-6/+6
| | | | | | | While it is save for these codecs (they all have private contexts), it is customary to always use the AVCodecContext for logging. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move temp ratecontrol bufs to RateControlContextAndreas Rheinhardt2025-03-071-4/+15
| | | | | | | Also only allocate them when they are needed (namely iff adaptive quant is true) and allocate them jointly. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move ratecontrol-only options to RateControlContextAndreas Rheinhardt2025-03-071-12/+13
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Handle wanted bits overflowMichael Niedermayer2024-07-161-2/+8
| | | | | | | | Fixes: 5.92611e+20 is outside the range of representable values of type 'unsigned long' Fixes: 68984/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-5155755073273856 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ratecontrol: Try to keep fps as a rationalMichael Niedermayer2024-06-261-8/+14
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary PicAndreas Rheinhardt2024-06-121-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two types of MPVPictures: Three (cur_pic, last_pic, next_pic) that are directly part of MpegEncContext and an array of MPVPictures that are separately allocated and are mostly accessed via pointers (cur|last|next)_pic_ptr; they are also used to store AVFrames in the encoder (necessary due to B-frames). As the name implies, each of the former is directly associated with one of the _ptr pointers: They actually share the same underlying buffers, but the ones that are part of the context can have their data pointers offset and their linesize doubled for field pictures. Up until now, each of these had their own references; in particular, there was an underlying av_frame_ref() to sync cur_pic and cur_pic_ptr etc. This is wasteful. This commit changes this relationship: cur_pic, last_pic and next_pic now become MPVWorkPictures; this structure does not have an AVFrame at all any more, but only the cached values of data and linesize. It also contains a pointer to the corresponding MPVPicture, establishing a more natural relationsship between the two. This already means that creating the context-pictures from the pointers can no longer fail. What has not been changed is the fact that the MPVPicture* pointers are not ownership pointers and that the MPVPictures are part of an array of MPVPictures that is owned by a single AVCodecContext. Doing so will be done in a latter commit. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Rename Picture->MPVPictureAndreas Rheinhardt2024-06-121-1/+1
| | | | | | Picture is just too generic. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Add const where appropriateAndreas Rheinhardt2024-06-121-11/+11
| | | | | | | | Specifically, add const to the pointed-to-type of pointers that point to something static or that belong to last_pic or next_pic (because modifying these might lead to data races). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Shorten variable namesAndreas Rheinhardt2024-06-121-5/+5
| | | | | | | | current_picture->cur_pic, last_picture->last_pic, similarly for new_picture and next_picture. Also rename the corresponding *_ptr fields. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo, ratecontrol: Remove write-only skip_countAndreas Rheinhardt2024-06-121-5/+9
| | | | | | Write-only since 6cf0cb8935f515a7b5f79d2e3cf02bd0764943bf. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Don't call ff_rate_control_uninit() ourselvesAndreas Rheinhardt2024-06-121-4/+3
| | | | | | | | | | | | | | | It is currently done inconsistently: Only one error path (namely the one from init_pass2()) made ff_rate_control_init() call ff_rate_control_uninit(); in other error paths cleanup was left to the caller. Given that the only caller of this function already performs the necessary cleanup this commit changes this to always rely on the caller to perform cleanup on error. Also return the error code from init_pass2(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Pass RCContext directly in ff_rate_control_uninit()Andreas Rheinhardt2024-06-121-3/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Fix double free on errorAndreas Rheinhardt2024-06-121-0/+1
| | | | | | Happens on init_pass2() failure. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegutils: Move definitions to better placesAndreas Rheinhardt2024-04-081-1/+0
| | | | | | | | | FRAME_SKIPPED -> h263dec.h CANDIDATE_MB_TYPE_* -> mpegvideoenc.h INPLACE_OFFSET -> mpegvideoenc.h enum OutputFormat -> mpegvideo.h Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/common: Don't auto-include mem.hAndreas Rheinhardt2024-03-311-0/+1
| | | | | | | | | | | There are lots of files that don't need it: The number of object files that actually need it went down from 2011 to 884 here. Keep it for external users in order to not cause breakages. Also improve the other headers a bit while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Avoid function pointer castsAndreas Rheinhardt2024-03-281-2/+12
| | | | | | | | It is undefined behaviour to call a function with a different signature for the call than the actual function signature; there are no exceptions for void* and RateControlEntry*. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/internal: Don't auto-include emms.hAndreas Rheinhardt2023-09-041-0/+1
| | | | | | Instead include emms.h wherever it is needed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc: deprecate AVCodecContext.ticks_per_frameAnton Khirnov2023-05-151-1/+7
| | | | | | | | For encoding, this field is entirely redundant with AVCodecContext.framerate. For decoding, this field is entirely redundant with AV_CODEC_PROP_FIELDS.
* lavc/ratecontrol: use AVCodecContext.framerate when availableAnton Khirnov2023-05-151-0/+3
|
* avcodec/mpegvideo_enc: do not use AVFrame.*_picture_number for encodingMarton Balint2023-02-131-2/+2
| | | | | | Move these fields to MPEGPicture instead and use that. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/mpegpicture: Move encoding_error and mb_var_sum to MpegEncCtxAndreas Rheinhardt2022-08-101-9/+8
| | | | | | | | These fields are only ever set by the encoder for the current picture and for no other picture. So only one set of these values needs to exist, so move them to MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtxAndreas Rheinhardt2022-08-091-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These tables are only used by encoders and only for the current picture; ergo they need not be put into the picture at all, but rather into the encoder's context. They also don't need to be refcounted, because there is only one owner. In contrast to this, the earlier code refcounts them which incurs unnecessary overhead. These references are not unreferenced in ff_mpeg_unref_picture() (they are kept in order to have something like a buffer pool), so that several buffers are kept at the same time, although only one is needed, thereby wasting memory. The code also propagates references to other pictures not part of the pictures array (namely the copy of the current/next/last picture in the MpegEncContext which get references of their own). These references are not unreferenced in ff_mpeg_unref_picture() (the buffers are probably kept in order to have something like a pool), yet if the current picture is a B-frame, it gets unreferenced at the end of ff_mpv_encode_picture() and its slot in the picture array will therefore be reused the next time; but the copy of the current picture also still has its references and therefore these buffers will be made duplicated in order to make them writable in the next call to ff_mpv_encode_picture(). This is of course unnecessary. Finally, ff_find_unused_picture() is supposed to just return any unused picture and the code is supposed to work with it; yet for the vsynth*-mpeg4-adap tests the result depends upon the content of these buffers; given that this patchset changes the content of these buffers (the initial content is now the state of these buffers after encoding the last frame; before this patch the buffers used came from the last picture that occupied the same slot in the picture array) their ref-files needed to be changed. This points to a bug somewhere (if one removes the initialization, one gets uninitialized reads in adaptive_quantization in ratecontrol.c). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move encoder-only stuff to a new headerAndreas Rheinhardt2022-02-131-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: Remove unnecessary libavcodec/internal.h inclusionsAndreas Rheinhardt2022-02-081-1/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: fix the integer overflow after long time runLimin Wang2020-06-031-2/+2
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* Merge commit '3b50dbc51fb0978d09c1a5b83d4bf5a59d170e1e'James Almer2017-03-311-2/+2
|\ | | | | | | | | | | | | * commit '3b50dbc51fb0978d09c1a5b83d4bf5a59d170e1e': ratecontrol: Use correct function pointer casts instead of void* Merged-by: James Almer <jamrial@gmail.com>
| * ratecontrol: Use correct function pointer casts instead of void*Diego Biurrun2016-11-121-2/+2
| | | | | | | | | | libavcodec/ratecontrol.c:120:9: warning: ISO C forbids initialization between function pointer and ‘void *’ [-Wpedantic] libavcodec/ratecontrol.c:121:9: warning: ISO C forbids initialization between function pointer and ‘void *’ [-Wpedantic]
* | Merge commit 'a1f6a2dfdaf9beb42ca66e49d10bfaf5905a0128'Clément Bœsch2017-02-011-402/+392
|\| | | | | | | | | | | | | | | | | | | * commit 'a1f6a2dfdaf9beb42ca66e49d10bfaf5905a0128': ratecontrol: Reorder functions to avoid forward declarations Merged, but this seems to break the clear separation of 1-pass vs 2-pass. Merged-by: Clément Bœsch <u@pkh.me>
| * ratecontrol: Reorder functions to avoid forward declarationsVittorio Giovara2016-07-201-396/+386
| |
* | Merge commit 'd639dcdae022130078c9c84b7b691c5e9694786c'Clément Bœsch2017-02-011-32/+0
|\| | | | | | | | | | | | | * commit 'd639dcdae022130078c9c84b7b691c5e9694786c': ratecontrol: Move Xvid-related functions to the place they are actually used Merged-by: Clément Bœsch <u@pkh.me>
| * ratecontrol: Move Xvid-related functions to the place they are actually usedVittorio Giovara2016-07-201-28/+0
| | | | | | | | This will simplify the de-MpegEncContextualization.
| * ratecontrol: Move mpegenc-only function where it is usedVittorio Giovara2016-07-201-21/+0
| |
* | Merge commit 'b4bb9593834460bbbe0e70823f2c503cb01ad052'James Almer2017-01-311-12/+0
|\| | | | | | | | | | | | | * commit 'b4bb9593834460bbbe0e70823f2c503cb01ad052': ratecontrol: Drop commented out cruft Merged-by: James Almer <jamrial@gmail.com>
| * ratecontrol: Drop commented out cruftVittorio Giovara2016-07-201-12/+0
| |
* | Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'Clément Bœsch2016-06-211-5/+5
|\| | | | | | | | | | | | | * commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb': cosmetics: Fix spelling mistakes Merged-by: Clément Bœsch <u@pkh.me>
| * cosmetics: Fix spelling mistakesVittorio Giovara2016-05-041-5/+5
| | | | | | | | Signed-off-by: Diego Biurrun <diego@biurrun.de>
* | avcodec/mpegvideo: use constants for rc_strategyClément Bœsch2015-12-041-3/+7
| |