1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00
Commit Graph

119238 Commits

Author SHA1 Message Date
8397351221 avcodec/mpegvideo_enc: Call ff_mpv_common_init() later
Namely after the main slice context has already been initialized,
so that this initialized state is directly copied to the newly
created slice contexts without relying on it being copied
by ff_update_duplicate_context(). This is in preparation for further
commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:57 +01:00
a2ba5b8242 avcodec/mpegvideoenc: Remove declaration of inexistent function
ff_MPV_encode_init_x86() has been renamed to ff_dct_encode_init_x86()
in 6b33e91899 in FFmpeg; libav renamed
it to ff_mpv_encode_init_x86() in commit
6b33e91899. This hasn't been noticed
in c1df467d73 when merging.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:27 +01:00
363fe86115 avcodec/{h261,ituh263}enc: Don't set ptr_lastgob unnecessarily
It will be overwritten later in encode_thread() anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:02 +01:00
fa630b481c avcodec/mpegvideo: Move last-pic information to MPVMainEncContext
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>
2025-03-26 03:44:30 +01:00
f293f95632 avcodec/mpegvideo: Support custom slice context sizes
This is in preparation for adding a special slice context for
the encoders and moving all the encoder-specific fields to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:43:58 +01:00
1b537de8d4 avcodec/mpegvideo: Move noise_reduction to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:43:25 +01:00
f2ba0676b6 avcodec/mpegvideo_enc: Move allocating remaining buffers to init_buffers
Also allocate mb_type, mc_mb_var, mb_var and mb_mean jointly
while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:52 +01:00
a1f18b195e avcodec/mpegvideo_enc: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:26 +01:00
9f43de06fa avcodec/mpegvideo_enc: Don't allocate B-frame bufs without B frames
(Checking in the same way for intra_only is not straightforward,
because at least p_mv_table is written to even in intra_only
mode.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:00 +01:00
7b5fb2e4ff avcodec/mpegvideo: Move encoder-only base arrays to MPVMainEncContext
Also allocate them jointly (thereby reducing the number of base
arrays considerably) and already set them on all slice contexts;
don't rely on ff_update_duplicate_context().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:40:27 +01:00
a5a2fc04ee avcodec/mpegvideo: Move allocating encoder buffers to mpegvideoenc.c
dct_error_sum and me.map are allocated per slice-context
and therefore their allocation has not been moved to
mpegvideoenc.c in 0154fb43e3.

This commit changes this by allocating them jointly and
moving said allocations to mpegvideo_enc.c like the other
encoder-only buffers.
The buffers are suitably aligned to ensure that no false
sharing occurs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:58 +01:00
9964212545 avcodec/mpegvideo: Move MSMPEG4 fields to MSMPEG4 contexts
Several fields are not used by any generic code and can therefore
be moved to more specialized contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:25 +01:00
967f8a924e avcodec/msmpeg4enc: Avoid using MVTable
Switch to using the length+symbol table combination that is
also used by the decoder and remove MVTable as well as
the old tables altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:01 +01:00
3d9a581ec1 avcodec/msmpeg4dec: Avoid lookups when decoding motion vector
Up until now, the decoder uses VLCs to determine whether
this is an escape element or an index in two separate tables
giving the x and y components of the motion vector.
Given that both these components fit into an int16_t and therefore
into a VLCElem's symbol one can simply use a symbol table
to avoid the latter lookups.

This necessitated to combine the two tables for x and y components.
While just at it, also switch to ff_vlc_init_tables_from_lengths().
This will allow to get rid of the code tables (about 4KiB) once
the encoder has been ported, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:38:36 +01:00
82a856e2e9 avcodec/msmpeg4enc: Use LUT to write motion vectors
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:38:11 +01:00
6d47d569d7 avcodec/mpegvideo: Move bit_rate field to MSMP4DecContext
Also make it an int as that is all MSMP4 needs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:37:39 +01:00
f733cfca28 avcodec/msmpeg4dec: Add MSMPEG4DecContext
This is in preparation for further commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:37:14 +01:00
0a9f58a7a1 avcodec/mpeg12dec: Add bit_rate field to Mpeg1Context
Use it instead of MpegEncContext.bit_rate which will be removed soon.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:36:49 +01:00
9f469e244e avcodec/mpegvideoenc: Add bit_rate to MPVMainEncContext
Use it instead of the MpegEncContext field which will
be removed soon.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:36:20 +01:00
bceeb35857 avcodec/mpegvideo: Move vbv_delay_pos to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:35:47 +01:00
bf4dedd6b5 avcodec/mpegvideo: Move MPVPicture arrays to MPVMainEncContext
Also avoid allocations while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:35:16 +01:00
72bf3d3c12 avcodec/mpegvideo: Move max_b_frames to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:34:44 +01:00
6e02882656 avcodec/mpegvideo: Add pointer to main context to slice contexts
It is a pointer to const to allow the slice threads to inspect
values without modifying them; also make it a simple cast
for codecs that don't support slice threading.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:34:12 +01:00
78391f20c8 avcodec/mjpegenc: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:33:48 +01:00
5affd0221e avcodec/mpegvideo_enc: Use func ptr for encoding macroblocks
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>
2025-03-26 03:33:15 +01:00
2f73a197a1 avcodec/mjpegenc: Move mjpeg_encode_init() down
Will avoid a forward declaration later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:32:51 +01:00
5308eeae5c avcodec/speedhqenc: Remove declaration of non-existent function
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:32:26 +01:00
7751b0cbed avcodec/mpegvideo: Move fcode_tab to MPVMainEncContext
Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:31:55 +01:00
ecba58311c avcodec/mpegvideo_enc: Use function ptr for encode_picture_header
This gets rid of a switch and (in case of FMT_H263) several
ifs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:31:26 +01:00
b2393a5ab1 avcodec/wmv2enc: Move wmv2_encode_init() down
Will avoid forward declarations later.
While just at it, forward ff_mpv_encode_init() errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:31:02 +01:00
e308292a31 avcodec/speedhqenc: Move speedhq_encode_init() down
Will avoid forward declarations later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:30:38 +01:00
6b6b34df35 avcodec/mpegvideo: Move header_bits to MPVMainEncContext
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>
2025-03-26 03:30:07 +01:00
b038c7af0c avcodec/mpegvideo: Move macroblock-variance stats to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:29:35 +01:00
553fc3a764 avcodec/mpegvideoenc: Disable scenechange threshold opt for MJPEG, AMV
It makes no sense for them. Also do the same for the mv0 flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:29:07 +01:00
d1fd8665fb avcodec/mpegvideo: Move ratecontrol-adjacent fields to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:17:52 +01:00
b710698571 avcodec/mpegvideo: Move sequence-level properties to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:16:03 +01:00
d9dea7088d avcodec/mpegvideo_enc: Move MPEG-4 specific check to mpeg4videoenc.c
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:15:37 +01:00
fca1ac2cba avcodec/mpeg4videoenc: Add Mpeg4EncContext and move time_increment_bits
It is only ever used by the main encoder thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:15:05 +01:00
e8a8a13128 avutil/slicethread: Mark avpriv_slicethread_{create,free} as av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:14:41 +01:00
f9fe1e07ad avutil/slicethread: Remove NULL pointer check when freeing
avpriv_slicethread_free() is one of our functions that takes
a pointer to a pointer and resets the pointer when done.
It is legal for such functions to be passed a pointer to a NULL
pointer, yet passing a NULL pointer would be insane and should
not be tolerated.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:14:17 +01:00
7d1bf0ac7a avcodec/pthread_slice: Return error on error
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:13:53 +01:00
c82101c9ce avcodec/pthread_slice: Remove MPEG-1 height hack
This is no longer necessary given that the MPEG-1 encoder
now adapts the size of the last slice to ensure that
no slice header has an invalid slice_start_code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:13:29 +01:00
4eb86951fc avcodec/mpeg12enc: Don't write invalid MPEG-1 slice headers
The valid values for slice_start_code are 0x1..0xAF, which implies
that one can't start a slice with row nb > 174 (zero-based).
This problem can be encountered with files of sufficient height
(more than 2800 pixels) either by using the slice option or by
imposing an RTP payload limit.

Fix this by making the last slice start on the maximum allowed
slice row if necessary and divide the first 174 rows to the remaining
slices. This will impede parallelism both in the decoder and encoder,
but that is unavoidable.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:13:04 +01:00
6ecdbcc454 avcodec/mpeg12enc: Merge ff_mpeg1_encode_init() into ordinary init
Everything except setting the dc_scale_tables can be done
before calling ff_mpv_encode_init(); setting the dc_scale_tables
unfortunately still has to be performed via a (now inlined)
callback performed by ff_mpv_encode_init() as it relies
on intra_dc_precision having been sanitized.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:12:38 +01:00
34557b1d30 avcodec/mpeg12enc: Move encode_init() to the end of the file
Will avoid forward declarations later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:12:14 +01:00
edebd1d9a4 avcodec/mpegvideo_enc: Only set fcode_tab if unset
This is in preparation for merging ff_mpeg1_encode_init()
into the MPEG-1/2 encoder's init function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:11:49 +01:00
24dbc4c2e8 avcodec/mjpegenc: Simplify allocating huffman table
Reuse the already computed value of macroblocks; use an array
instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
at compile-time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:11:26 +01:00
dcd4daee8c avcodec/mjpegenc: Make mjpeg_encode_init() call ff_mpv_encode_init()
Right now, ff_mpv_encode_init() is set as FFCodec.init and
calls ff_speedhq_encode_init(). The opposite is more natural,
avoids a non-static function and allows to reuse e.g.
slice_context_count instead of duplicating the logic from
ff_mpv_common_init().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:11:00 +01:00
9928b9e9fa avcodec/speedhqenc: Avoid indirection
Namely use avctx directly instead of s->avctx. While just at it,
also move the switch to the other checks involving avctx.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:10:37 +01:00
565e57ea87 avcodec/speedhqenc: Make speedhq_encode_init() call ff_mpv_encode_init()
Right now, ff_mpv_encode_init() is set as FFCodec.init and
calls ff_speedhq_encode_init(). The opposite is more natural
and avoids a non-static function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:10:12 +01:00