summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_enc.c
Commit message (Collapse)AuthorAge
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-20
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* avcodec/mpegvideo_enc: Use ptrdiff_t for strideMichael Niedermayer2023-12-30
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mpegvideo_enc: Dont copy beyond the imageMichael Niedermayer2023-12-30
| | | | | | | | | Fixes: out of array access Fixes: tickets/10754/poc17ffmpeg Discovered by Zeng Yunxiang. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-22
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/pthread_frame: Remove ff_thread_release_buffer()Andreas Rheinhardt2023-10-22
| | | | | | | | | | | | | | It is unnecessary since the removal of non-thread-safe callbacks in e0786a8eeb9e7c8feb057e83f284491f0a87e463. Since then, the AVCodecContext has only been used as logcontext. Removing ff_thread_release_buffer() allowed to remove AVCodecContext* parameters from several other functions (not only unref functions, but also e.g. ff_h264_ref_picture() which calls ff_h264_unref_picture() on error). Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Move caller-specific parts of function to callersAndreas Rheinhardt2023-10-10
| | | | | | | | | Since at least commit c954cf1e1b766a0d1992d5be0a8be0055a8e1a6a (adding ff_encode_alloc_frame()), a large part of ff_alloc_picture() is completely separate for the two callers. Move the caller-specific parts out to the callers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't call av_frame_copy_props() unnecessarilyAndreas Rheinhardt2023-10-10
| | | | | | | | It is unnecessary in case of user-supplied frames, because it happens directly after a av_frame_ref() with the same src and dst. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't allocate buffers unnecessarilyAndreas Rheinhardt2023-10-10
| | | | | | | | | | | | | | | | | ff_alloc_picture() performs two tasks: a) In most instances, it allocates frame buffers and b) it allocates certain auxiliary buffers. The exception to a) is the case when the encoder can reuse user-supplied frames. And for these frames the auxiliary buffers are unused, because this frame will never be used as current_picture (and therefore also not as next_picture or last_picture); see select_input_picture(). This means that we can simply avoid calling ff_alloc_picture() with user-supplied frames at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Remove dead blockAndreas Rheinhardt2023-10-10
| | | | | | | | None of the mpegvideo encoders support anything but coded frames; and if this were to change, it is unclear whether they would need the adjustment here. So remove it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't set write-only propertiesAndreas Rheinhardt2023-10-10
| | | | | | | The frame is immediately reset in the ff_mpeg_unref_picture() call below. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't overallocate arraysAndreas Rheinhardt2023-10-10
| | | | | | | Only entries 0..max_b_frames are ever used. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't reget known valuesAndreas Rheinhardt2023-10-10
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't pretend input to be non-refcountedAndreas Rheinhardt2023-10-10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: ReindentationAndreas Rheinhardt2023-10-10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Remove always-false checksAndreas Rheinhardt2023-10-10
| | | | | | | | | In case "!direct" we are not reusing the input buffers (due to e.g. insufficient alignment), but allocating new ones. These of course do not alias with the ones provided by the user, so these checks are always-false. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Fix abort on allocation errorsAndreas Rheinhardt2023-10-10
| | | | | | | | | | | | mpegvideo_enc uses a fixed-size array of Pictures; a slot is considered taken if the Picture's AVFrame is set. When an error happens after a slot has been taken, this Picture has typically not been reset and is therefore not usable for future requests. The code aborts when one runs out of slots and this can happen in case of allocation failures. Fix this by always unreferencing a Picture in case of errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move allocating new_picture to the encoderAndreas Rheinhardt2023-10-06
| | | | | | | | It is only used by encoders; this unfortunately necessitated to add separate allocations to the SVQ1 encoder which uses motion estimation without being a full member of mpegvideo. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/utils: move ff_add_cpb_side_data() to encoder codeJames Almer2023-09-06
| | | | | | It's only used by encoders, so move it to prevent wrong usage. Signed-off-by: James Almer <jamrial@gmail.com>
* avutil/internal: Don't auto-include emms.hAndreas Rheinhardt2023-09-04
| | | | | | Instead include emms.h wherever it is needed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/dct: Move fdct function declarations to fdctdsp.hAndreas Rheinhardt2023-07-29
| | | | | | | | | It is the more proper place for them given that this is the only API using them. Also use a forward-declaration of AVCodecContext in fdctdsp.h to avoid including avcodec.h in jfdct(fst|int).c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: use the new AVFrame key_frame flag in all decoders and encodersJames Almer2023-05-04
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/mpegvideo_enc: ensure lmin is smaller than lmaxJames Almer2023-04-18
| | | | | | Fixes ticket #10234 Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/mp_cmp: reject invalid comparison function valuesJames Almer2023-04-14
| | | | | | Fixes tickets #10306 and #10318. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/mpegvideo_enc: do not use AVFrame.*_picture_number for encodingMarton Balint2023-02-13
| | | | | | Move these fields to MPEGPicture instead and use that. Signed-off-by: Marton Balint <cus@passwd.hu>
* lavc/mpegvideo_enc: handle frame durations and ↵Anton Khirnov2023-01-29
| | | | | | | 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.
* avcodec/mpegvideo_enc: remove picture_number parameter from encode functionsMarton Balint2023-01-26
| | | | | | They are unused. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/mpegvideo_enc: Move initializing QpelDSPCtx to mpeg4videoenc.cAndreas Rheinhardt2022-11-06
| | | | | | | | It is the only encoder supporting quarter samples. This also allows to remove the qpeldsp dependency from mpegvideo_enc. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideodata: Join mpeg1/2 dc scale tablesAndreas Rheinhardt2022-10-31
| | | | | | Avoids relocations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Initialize dct_unquantize_int(ra|er) only onceAndreas Rheinhardt2022-10-30
| | | | | | | | For encoders, mpeg_quant is an option of the MPEG-4 encoder and therefore constant. This implies that one can set the dct_unquantize_(intra|inter) function pointers during init. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder partAndreas Rheinhardt2022-10-20
| | | | | | | | | | | | | | | | | | | | | | This has the advantage of not having to check for whether a given MpegEncContext is actually a decoder or an encoder context at runtime. To do so, mpv_reconstruct_mb_internal() is moved into a new template file that is included by both mpegvideo_enc.c and mpegvideo_dec.c; the decoder-only code (mainly lowres) are also moved to mpegvideo_dec.c. The is_encoder checks are changed to #if IS_ENCODER in order to avoid having to include headers for decoder-only functions in mpegvideo_enc.c. This approach also has the advantage that it is easy to adapt mpv_reconstruct_mb_internal() to using different structures for decoders and encoders (e.g. the check for whether a macroblock should be processed for the encoder or not uses MpegEncContext elements that make no sense for decoders and should not be part of their context). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Call ff_mpeg1_encode_init() earlierAndreas Rheinhardt2022-10-06
| | | | | | | | | | It does not require anything that is being set between the new position where it is called and the old position where it used to be called; and nothing that it sets gets overwritten between these two positions. Doing so allows to remove a check lateron. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move H.261 size check to h261enc.cAndreas Rheinhardt2022-10-06
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Call ff_h261_encode_init() earlierAndreas Rheinhardt2022-10-06
| | | | | | | | | It does not require anything that is being set between the new position where it is called and the old position where it used to be called; and nothing that it sets gets overwritten between these two positions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move SpeedHQ check to speedhqenc.cAndreas Rheinhardt2022-10-06
| | | | | | Also set this only once and not for every frame. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg12: Move ff_mpeg1_clean_buffers decl to a new headerAndreas Rheinhardt2022-10-04
| | | | | | It allows to avoid including mpegvideo.h when including mpeg12.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Allocate encoder-only tables in mpegvideo_enc.cAndreas Rheinhardt2022-08-21
| | | | | | | | | | | | | | | This commit moves the encoder-only allocations of the tables owned solely by the main encoder context to mpegvideo_enc.c. This avoids checks in mpegvideo.c for whether we are dealing with an encoder; it also improves modularity (if encoders are disabled, this code will no longer be included in the binary). And it also avoids having to reset these pointers at the beginning of ff_mpv_common_init() (in case the dst context is uninitialized, ff_mpeg_update_thread_context() simply copies the src context into dst which therefore may contain pointers not owned by it, but this does not happen for encoders at all). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Remove redundant castAndreas Rheinhardt2022-08-10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Remove redundant checkAndreas Rheinhardt2022-08-10
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't copy Picture unnecessarilyAndreas Rheinhardt2022-08-10
| | | | | | Also add const where possible. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Move encoding_error and mb_var_sum to MpegEncCtxAndreas Rheinhardt2022-08-10
| | | | | | | | 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-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Constify frame->data pointers for encoders where possibleAndreas Rheinhardt2022-08-05
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* configure: Add msmpeg4(dec|enc) subsystemsAndreas Rheinhardt2022-08-03
| | | | | | | | | | The msmpeg4 decoders/encoders share a common set of prerequisites, ergo it makes sense to use common subsystems for them. This also allows to remove the CONFIG_MSMPEG4_DECODER/ENCODER ad-hoc defines (which violated the CONFIG_ namespace). Reviewed-by: Martin Storsjö <martin@martin.st> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Inline values in ff_update_block_index()Andreas Rheinhardt2022-07-31
| | | | | | | | | This is possible for most of the callers, because e.g. only the MPEG-4 decoder can have bits_per_raw_sample > 8. Also most mpegvideo-based codecs are 420 only. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Unify the code styleWenbin Chen2022-07-09
| | | | | | | Change whitespace and add newline to unify the code style. Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/mpegvideo_enc: Fix a chroma mb size error in sse_mb()Wenbin Chen2022-07-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | For 422 frames we should not use hard coded 8 to calculate mb size for uv plane. Chroma shift should be taken into consideration to be compatiple with different sampling format. The error is reported by fate test when av_cpu_max_align() return 64 on the platform supporting AVX512. This is a hidden error and it is exposed after commit 17a59a634c39b00a680c6ebbaea58db95594d13d. mpeg2enc has a mechanism to reuse frames. When it computes SSE (sum of squared error) on current mb, reconstructed mb will be wrote to the previous mb space, so that the memory can be saved. However if the align is 64, the frame is shared in somewhere else, so the frame cannot be reused and a new frame to store reconstrued data is created. Because the height of mb is wrong when compute sse on 422 frame, starting from the second line of macro block, changed data is read when frame is reused (we need to read row 16 rather than row 8 if frame is 422), and unchanged data is read when frame is not reused (a new frame is created so the original frame will not be changed). That is why commit 17a59a634c39b00a680c6ebbaea58db95594d13d exposes this issue, because it add av_cpu_max_align() and this function return 64 on platform supporting AVX512 which lead to creating a frame in mpeg2enc, and this lead to the different outputs. Signed-off-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Marton Balint <cus@passwd.hu>
* all: Replace if (ARCH_FOO) checks by #if ARCH_FOOAndreas Rheinhardt2022-06-15
| | | | | | | | | | | | | | | | | | This is more spec-compliant because it does not rely on dead-code elimination by the compiler. Especially MSVC has problems with this, as can be seen in https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/296373.html or https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/297022.html This commit does not eliminate every instance where we rely on dead code elimination: It only tackles branching to the initialization of arch-specific dsp code, not e.g. all uses of CONFIG_ and HAVE_ checks. But maybe it is already enough to compile FFmpeg with MSVC with whole-programm-optimizations enabled (if one does not disable too many components). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Remove ineffective optionsAndreas Rheinhardt2022-05-24
| | | | | | | | | | | | | | | | This commit removes the ineffective FF_MPV_DEPRECATED_ options, namely mpeg_quant (this is only an option for MPEG-4), a53cc (this is only an option for MPEG-2), force_duplicated_matrix (applies only to MJPEG) and b_strategy, b_sensitivity and brd_scale (these options only make sense for encoders supporting B-frames, which currently means the MPEG-1/2 and MPEG-4 encoders). Given that these options never changed the outcome of encoding, they are removed at once. Notice that the options for the encoders for which it made sense are not affected by this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mjpegenc: Remove pointless motion-estimation optionsAndreas Rheinhardt2022-05-24
| | | | | | | | (M)JPEG does not use motion estimation/motion vectors at all. These options therefore don't affect the output at all. So remove them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Remove always-true checkAndreas Rheinhardt2022-04-14
| | | | | | | It is a remnant of the old way for user-supplied buffers; it is always-true since 93016f5d1d280f9cb7856883af287fa66affc04c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>