aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpeg4videoenc.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpegvideo: Move partitioned_frame to {H263Dec,MPVEnc}ContextAndreas Rheinhardt2025-07-031-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move fields to {H263Dec,MPVEnc}Context when possibleAndreas Rheinhardt2025-07-031-9/+9
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Add missing headersAndreas Rheinhardt2025-07-031-0/+1
| | | | | | | These files currently rely on implicit inclusions of avassert.h and/or mathops.h via get_bits.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Allocate blocks as part of MPVEncContextAndreas Rheinhardt2025-07-031-1/+1
| | | | | | | | This avoids mpegvideo.c having to deal with the fact that the encoders use two sets of blocks and is in preparation for not allocating blocks at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Fix data race when using AC predictionAndreas Rheinhardt2025-06-211-1/+1
| | | | | | | | | | | | | | | | | | | The check for whether we can use the fast path to process AC coefficients used the qscale value belonging to a different slice; this worked in practice, because the predicted AC values are zero in this case, so it does not matter whether we use the fast or the slow path. Fix this by checking for first_slice_line instead. This fixes all the races in the encoding part of the vsynth*-mpeg4-thread tests (and fixes them if no frame threading is in use for the decoding part). (The left prediction check may use data from a different slice, too, but said slice is always processed by the same thread, so that no race can happen. Given that out-of-slice AC values are zero, it does not matter whether we use the fast path or the slow path either.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/{ituh263,mpeg4video}enc: Simplify out-of-slice DC predictionAndreas Rheinhardt2025-06-211-1/+31
| | | | | | | | | Now that every slice (and therefore every thread) uses its own DC array, one can simply set the out-of-slice DC values to its expected values (this is not possible for the decoders due to error resilience). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0]Andreas Rheinhardt2025-06-211-1/+1
| | | | | | | The chroma dc_val pointers are mostly unused (accesses use dc_val[0] and block_index), so remove them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Only use a single ac_val pointerAndreas Rheinhardt2025-06-211-2/+2
| | | | | | The chroma pointers ac_val[1] and ac_val[2] are no longer used anywhere. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move mpeg_quant to {Mpeg4Dec,MPVEnc}ContextAndreas Rheinhardt2025-05-261-5/+5
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Use smaller scope for variableAndreas Rheinhardt2025-05-261-2/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Split writing blocks into intra and interAndreas Rheinhardt2025-05-261-47/+43
| | | | | | | | | | | These are sufficiently different to warrant their own functions; in particular, the earlier code had two callsites for the actual "write block" function, one for intra and one for inter, yet the "write block" function nevertheless performed a check (that the compiler can't optimize away) for whether the current MB is intra or not. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Remove no-output codeAndreas Rheinhardt2025-05-261-76/+0
| | | | | | | | | | | | | | | While it offers modest speedups compared to the ordinary code, removing it completely offers even bigger speedups; and given that these speedups also exist in the ordinary mode, they are even more important. The no-output code has a 7.8% performance improvement (based on benchmarking mpeg4_encode_mb()), yet removing the no-output code resulted in a 9.4% improvement. Furthermore, the no-output code was broken for the majority of its existence (until 9207dc3b0db368bb9cf5eb295cbc1129c2975e31) and no one complained, so it is likely not used at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Simplify creating LUTAndreas Rheinhardt2025-05-261-90/+71
| | | | | | | | | | | | | | | | | | | | There four cases for the LUT entry: An ordinary entry or one of three escaping methods. Three of these methods are only rarely possible --they correspond to the 102 codes of the underlying VLC and so only 102 of 16384 entries are possible. The earlier code would nevertheless try them all for every LUT entry and use the best one; the new code meanwhile only uses one method (the fallback one (i.e. the worst)) for them all and only processes the 102 valid entries afterwards. The implementation used also means that index_run, max_level and max_run of the RLTable are no longer needed; the earlier code would initialize said static tables although they are only used for a short time to initialize something else. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo encs: Add put_bits_assume_flushed() to encode_headerAndreas Rheinhardt2025-05-211-0/+3
| | | | | | | This allows the compiler to remove the implicit "Do I need to output the PutBitContext buffer here?" checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move [fb]_code to Mpeg4Dec and MPVEncContextAndreas Rheinhardt2025-05-161-11/+11
| | | | | | | | 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/mpeg4video: Pass parameters directlyAndreas Rheinhardt2025-05-161-1/+1
| | | | | | | Namely in ff_mpeg4_get_video_packet_prefix_length(). This will allow to move [fb]_code from MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move lambda, lambda2 to MPVEncContextAndreas Rheinhardt2025-03-261-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Add MPVEncContextAndreas Rheinhardt2025-03-261-253/+252
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/mpeg4videoenc: Move initializations before ff_mpv_encode_init()Andreas Rheinhardt2025-03-261-13/+13
| | | | | | | This avoids relying on ff_update_duplicate_context() to copy these fields to the slice contexts. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move MPVPicture arrays to MPVMainEncContextAndreas Rheinhardt2025-03-261-5/+6
| | | | | | Also avoid allocations while at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move max_b_frames to MPVMainEncContextAndreas Rheinhardt2025-03-261-8/+9
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Use func ptr for encoding macroblocksAndreas Rheinhardt2025-03-261-2/+3
| | | | | | | | | | | | | It gets rid of a switch (with accompanying CONFIG_*_ENCODER checks); for MJPEG, it even lets one perform the check for whether one is really encoding or only recording the macroblock once during init. Furthermore, the switch actually contained lots of dead code -- it is compiled three times (for different pixel formats: 420, 422, 444), yet most encoders only support 420. The approach used here automatically fixes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move fcode_tab to MPVMainEncContextAndreas Rheinhardt2025-03-261-1/+1
| | | | | | Only used by the main encoding thread. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Use function ptr for encode_picture_headerAndreas Rheinhardt2025-03-261-2/+5
| | | | | | | This gets rid of a switch and (in case of FMT_H263) several ifs. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move MPEG-4 specific check to mpeg4videoenc.cAndreas Rheinhardt2025-03-261-0/+9
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Add Mpeg4EncContext and move time_increment_bitsAndreas Rheinhardt2025-03-261-9/+27
| | | | | | It is only ever used by the main encoder thread. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Add MPVMainEncContextAndreas Rheinhardt2025-03-261-1/+1
| | | | | | | | This is in preparation for moving all the elements from MpegEncContext that are only used by the main encoder thread to MPVMainEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal, all: Use macros to set deprecated AVCodec fieldsAndreas Rheinhardt2025-03-101-1/+1
| | | | | | | | | | | | | | The aim of this is twofold: a) Clang warns when setting a deprecated field in a definition and because several of the widely set AVCodec fields are deprecated, one gets several hundred warnings from Clang for an ordinary build. Yet fortunately Clang (unlike GCC) allows to disable deprecation warnings inside a definition, so that one can create simple macros to set these fields that also suppress deprecation warnings for Clang. This has already been done in fdff1b9cbfd8cf5a9810c29efa4baf13a4786742 for AVCodec.channel_layouts. b) Using macros will allow to easily migrate these fields to internal ones. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc, motion_est: Pre-center fcode_tabAndreas Rheinhardt2025-03-071-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Split ff_mpeg4_pred_dc()Andreas Rheinhardt2025-03-071-2/+8
| | | | | | | | | | | | | | | | | | | | | It currently does two things: a) Get a prediction for the dc and the dc direction and b) process said prediction. Processing the prediction differs for encoding (getting a diff) and decoding (getting the level via diff+prediction). So having a common function performing b) makes no sense. Even worse, there is a decoding mode where the dc coefficient (diff) is not coded specially and therefore unavailable before entering the block decoding loop, so that one can only perform a). Before this commit, the decoder simply called ff_mpeg4_pred_dc() twice; the results of the b) part of the call before the loop were ignored (but the compiler could not elide them because they involved error messages) and a) was also performed twice. This commit changes this by splitting b) out of ff_mpeg4_pred_dc() and moving this code to decoder and encoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ituh263enc: Move MPEG-4 fcode_tab to mpeg4videoenc.cAndreas Rheinhardt2025-03-071-0/+11
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Remove dead FF_BUG_MS codeAndreas Rheinhardt2025-03-041-19/+9
| | | | | | | | | | | Added in 59fa3f96f48d12e189492ca3670991f91c316d4e, yet avctx->workaround_bugs is never copied to MpegEncContext.workaround_bugs, so this code is dead (it seems that this was true even when it was added). Furthermore, workaround_bugs is flagged as decoder-only, so just remove the code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Add AV_CODEC_CAP_DR1Andreas Rheinhardt2025-03-041-1/+2
| | | | | | | | | | The mpegvideo-based encoders do one uncommon thing with the packet's data given by ff_alloc_packet(): They potentially reallocate it. But this only affects the internal buffer and is not user-facing at all, so one can nevertheless use the AV_CODEC_CAP_DR1 for them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: add FFCodec.color_rangesNiklas Haas2024-09-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I went through all codecs and put them into five basic categories: 1. JPEG range only 2. MPEG range only 3. Explicitly tagged 4. Broken (codec supports both but encoder ignores tags) 5. N/A (headerless or pseudo-formats) Filters in category 5 remain untouched. The rest gain an explicit assignment of their supported color ranges, with codecs in category 4 being set to MPEG-only for safety. It might be considered redundant to distinguish between 0 (category 5) and MPEG+JPEG (category 3), but in doing so we effectively communicate that we can guarantee that these tags will be encoded, which is distinct from the situation where there are some codecs that simply don't have tagging or implied semantics (e.g. rawvideo). A full list of codecs follows: JPEG range only: - amv - roqvideo MPEG range only: - asv1, asv2 - avui - cfhd - cljr - dnxhd - dvvideo - ffv1 - flv - h261, h263, h263p - {h263,vp8}_v4l2m2m - huffyuv, ffvhuff - jpeg2000 - libopenjpeg - libtheora - libwebp, libwebp_anim - libx262 - libxavs, libxavs2 - libxvid - mpeg1video, mpeg2video - mpeg2_qsv - mpeg2_vaapi - mpeg4, msmpeg4, msmpeg4v2, wmv1, wmv2 - mpeg4_omx - prores, prores_aw, prores_ks - rv10, rv20 - snow - speedhq - svq1 - tiff - utvideo Explicitly tagged (MPEG/JPEG): - {av1,h264,hevc}_nvenc - {av1,h264,hevc}_vaapi - {av1,h264,hevc,vp8,vp9,mpeg4}_mediacodec - {av1,h264,hevc,vp9}_qsv - h264_amf - {h264,hevc,prores}_videotoolbox - libaom-av1 - libkvazaar - libopenh264 - librav1e - libsvtav1 - libvpx, libvpx-vp9 - libx264 - libx265 - ljpeg - mjpeg - vc2 Broken (encoder ignores tags): - {av1,hevc}_amf - {h264,hevc,mpeg4}_v4l2m2m - h264_omx - libxeve - magicyuv - {vp8,vp9,mjpeg}_vaapi N/A: - ayuv, yuv4, y41p, v308, v210, v410, v408 (headerless) - pgmyuv (headerless) - rawvideo, bitpacked (headerless) - vnull, wrapped_avframe (pseudocodecs)
* avcodec/mpegvideo: Move quant_precision to Mpeg4DecContextAndreas Rheinhardt2024-06-201-1/+1
| | | | | | | | It is an MPEG-4-only value; it is always five for the MPEG-4 encoder, so just hardcode this value and move the MpegEncContext field to Mpeg4DecContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Only keep what is used from MECmpContextAndreas Rheinhardt2024-06-201-1/+1
| | | | | | | | | | A MECmpContext is quite big (792B here) and given how ff_update_duplicate_context() works, it is (unfortunately) copied quite frequently when using slice threading. Therefore keep only what is needed from MECmpContext and remove MECmpContext from MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Simplify writing startcodesAndreas Rheinhardt2024-06-121-14/+7
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videoenc: Avoid branch for writing stuffingAndreas Rheinhardt2024-06-121-5/+3
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary PicAndreas Rheinhardt2024-06-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-15/+17
| | | | | | | | 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-8/+8
| | | | | | | | 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-3/+0
| | | | | | Write-only since 6cf0cb8935f515a7b5f79d2e3cf02bd0764943bf. 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>
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-201-0/+1
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-221-1/+0
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* definesAndreas Rheinhardt2023-09-071-2/+2
| | | | | | | | | These defines are also used in other contexts than just AVCodecContext ones, e.g. in libavformat. Furthermore, given that these defines are public, the AV-prefix is the right one, so deprecate (and not just move) the FF-macros. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: use the new AVFrame interlace flags in all decoders and encodersJames Almer2023-05-041-1/+1
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* lavc/mpegvideo_enc: handle frame durations and ↵Anton Khirnov2023-01-291-1/+2
| | | | | | | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE For delay-capable encoders, i.e. mpeg12 and mpeg4video. Generic code in encode.c already handles this for all other mpegvideo encoders.