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

avcodec/mpeg12enc, speedhqenc: Optimize writing escape codes

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-19 12:26:47 +01:00
parent a064d34a32
commit 6ebc810e6f
2 changed files with 8 additions and 10 deletions

View File

@ -628,12 +628,11 @@ next_coef:
put_bits(&s->pb, table_vlc[code][1] + 1,
(table_vlc[code][0] << 1) + sign);
} else {
/* Escape seems to be pretty rare <5% so I do not optimize it;
* the following value is the common escape value for both
* possible tables (i.e. table_vlc[111]). */
put_bits(&s->pb, 6, 0x01);
/* Escape seems to be pretty rare <5% so I do not optimize it.
* The following encodes run together with the common escape
* value of both tables 000001b. */
put_bits(&s->pb, 6 + 6, 0x01 << 6 | run);
/* escape: only clip in this case */
put_bits(&s->pb, 6, run);
if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO) {
if (alevel < 128) {
put_sbits(&s->pb, 8, level);

View File

@ -194,11 +194,10 @@ static void encode_block(MPVEncContext *const s, const int16_t block[], int n)
ff_speedhq_vlc_table[code][0] | (sign << ff_speedhq_vlc_table[code][1]));
} else {
/* escape seems to be pretty rare <5% so I do not optimize it;
* the values correspond to ff_speedhq_vlc_table[121] */
put_bits_le(&s->pb, 6, 32);
/* escape: only clip in this case */
put_bits_le(&s->pb, 6, run);
put_bits_le(&s->pb, 12, level + 2048);
* The following encodes the escape value 100000b together with
* run and level. */
put_bits_le(&s->pb, 6 + 6 + 12, 0x20 | run << 6 |
(level + 2048) << 12);
}
last_non_zero = i;
}