2007-05-21 15:51:29 +03:00
|
|
|
/*
|
2016-04-27 19:45:23 +02:00
|
|
|
* H.261 encoder
|
2007-05-21 15:51:29 +03:00
|
|
|
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
* Copyright (c) 2004 Maarten Daniels
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2007-05-21 15:51:29 +03:00
|
|
|
* H.261 encoder.
|
|
|
|
*/
|
|
|
|
|
2013-02-01 12:31:59 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2012-06-07 22:32:32 +03:00
|
|
|
#include "libavutil/avassert.h"
|
2020-12-09 14:13:33 +02:00
|
|
|
#include "libavutil/thread.h"
|
2007-05-21 15:51:29 +03:00
|
|
|
#include "avcodec.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2014-02-28 15:40:54 +03:00
|
|
|
#include "mpegutils.h"
|
2007-05-21 15:51:29 +03:00
|
|
|
#include "mpegvideo.h"
|
|
|
|
#include "h261.h"
|
2022-02-01 07:39:35 +02:00
|
|
|
#include "h261enc.h"
|
2022-01-28 02:14:42 +02:00
|
|
|
#include "mpegvideoenc.h"
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2024-06-15 17:26:14 +02:00
|
|
|
#define H261_MAX_RUN 26
|
|
|
|
#define H261_MAX_LEVEL 15
|
2024-06-15 18:44:18 +02:00
|
|
|
#define H261_ESC_LEN (6 + 6 + 8)
|
2024-06-15 17:26:14 +02:00
|
|
|
|
|
|
|
static struct VLCLUT {
|
|
|
|
uint8_t len;
|
|
|
|
uint16_t code;
|
|
|
|
} vlc_lut[H261_MAX_RUN + 1][32 /* 0..2 * H261_MAX_LEN are used */];
|
|
|
|
|
2024-06-15 18:44:18 +02:00
|
|
|
static uint8_t uni_h261_rl_len [64 * 128];
|
|
|
|
static uint8_t uni_h261_rl_len_last[64 * 128];
|
2013-11-17 17:05:51 +03:00
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
typedef struct H261EncContext {
|
|
|
|
MpegEncContext s;
|
|
|
|
|
|
|
|
H261Context common;
|
|
|
|
|
|
|
|
int gob_number;
|
2022-10-02 22:00:01 +02:00
|
|
|
enum {
|
|
|
|
H261_QCIF = 0,
|
|
|
|
H261_CIF = 1,
|
|
|
|
} format;
|
2022-01-27 23:49:52 +02:00
|
|
|
} H261EncContext;
|
|
|
|
|
2023-01-22 02:06:56 +02:00
|
|
|
void ff_h261_encode_picture_header(MpegEncContext *s)
|
2013-04-04 15:31:58 +03:00
|
|
|
{
|
2022-01-27 23:49:52 +02:00
|
|
|
H261EncContext *const h = (H261EncContext *)s;
|
2022-10-02 22:00:01 +02:00
|
|
|
int temp_ref;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2020-10-26 14:36:06 +02:00
|
|
|
align_put_bits(&s->pb);
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
/* Update the pointer to last GOB */
|
2009-04-13 19:59:38 +03:00
|
|
|
s->ptr_lastgob = put_bits_ptr(&s->pb);
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
put_bits(&s->pb, 20, 0x10); /* PSC */
|
|
|
|
|
2015-02-01 20:13:38 +02:00
|
|
|
temp_ref = s->picture_number * 30000LL * s->avctx->time_base.num /
|
|
|
|
(1001LL * s->avctx->time_base.den); // FIXME maybe this should use a timestamp
|
2008-07-13 17:27:48 +03:00
|
|
|
put_sbits(&s->pb, 5, temp_ref); /* TemporalReference */
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0); /* split screen off */
|
|
|
|
put_bits(&s->pb, 1, 0); /* camera off */
|
2014-12-02 19:55:13 +02:00
|
|
|
put_bits(&s->pb, 1, s->pict_type == AV_PICTURE_TYPE_I); /* freeze picture release on/off */
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2022-10-02 22:00:01 +02:00
|
|
|
put_bits(&s->pb, 1, h->format); /* 0 == QCIF, 1 == CIF */
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2014-12-12 17:08:19 +02:00
|
|
|
put_bits(&s->pb, 1, 1); /* still image mode */
|
|
|
|
put_bits(&s->pb, 1, 1); /* reserved */
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0); /* no PEI */
|
2022-10-02 22:00:01 +02:00
|
|
|
h->gob_number = h->format - 1;
|
2013-11-20 17:11:21 +03:00
|
|
|
s->mb_skip_run = 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-30 18:38:06 +03:00
|
|
|
* Encode a group of blocks header.
|
2007-05-21 15:51:29 +03:00
|
|
|
*/
|
2013-04-04 15:31:58 +03:00
|
|
|
static void h261_encode_gob_header(MpegEncContext *s, int mb_line)
|
|
|
|
{
|
2022-01-27 23:49:52 +02:00
|
|
|
H261EncContext *const h = (H261EncContext *)s;
|
2022-10-02 22:00:01 +02:00
|
|
|
if (h->format == H261_QCIF) {
|
2013-04-04 15:31:58 +03:00
|
|
|
h->gob_number += 2; // QCIF
|
|
|
|
} else {
|
|
|
|
h->gob_number++; // CIF
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
2013-04-04 15:31:58 +03:00
|
|
|
put_bits(&s->pb, 16, 1); /* GBSC */
|
2007-05-21 15:51:29 +03:00
|
|
|
put_bits(&s->pb, 4, h->gob_number); /* GN */
|
2013-04-04 15:31:58 +03:00
|
|
|
put_bits(&s->pb, 5, s->qscale); /* GQUANT */
|
|
|
|
put_bits(&s->pb, 1, 0); /* no GEI */
|
2013-11-20 17:11:21 +03:00
|
|
|
s->mb_skip_run = 0;
|
2013-11-20 17:28:46 +03:00
|
|
|
s->last_mv[0][0][0] = 0;
|
|
|
|
s->last_mv[0][0][1] = 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
void ff_h261_reorder_mb_index(MpegEncContext *s)
|
|
|
|
{
|
2022-10-02 22:00:01 +02:00
|
|
|
const H261EncContext *const h = (H261EncContext*)s;
|
2013-04-04 15:31:58 +03:00
|
|
|
int index = s->mb_x + s->mb_y * s->mb_width;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2013-11-20 17:11:21 +03:00
|
|
|
if (index % 11 == 0) {
|
|
|
|
if (index % 33 == 0)
|
|
|
|
h261_encode_gob_header(s, 0);
|
2013-11-20 17:28:46 +03:00
|
|
|
s->last_mv[0][0][0] = 0;
|
|
|
|
s->last_mv[0][0][1] = 0;
|
2013-11-20 17:11:21 +03:00
|
|
|
}
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
/* for CIF the GOB's are fragmented in the middle of a scanline
|
2013-04-04 15:31:58 +03:00
|
|
|
* that's why we need to adjust the x and y index of the macroblocks */
|
2022-10-02 22:00:01 +02:00
|
|
|
if (h->format == H261_CIF) {
|
2013-04-04 15:31:58 +03:00
|
|
|
s->mb_x = index % 11;
|
|
|
|
index /= 11;
|
|
|
|
s->mb_y = index % 3;
|
|
|
|
index /= 3;
|
|
|
|
s->mb_x += 11 * (index % 2);
|
|
|
|
index /= 2;
|
|
|
|
s->mb_y += 3 * index;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
ff_init_block_index(s);
|
2022-07-26 20:02:25 +02:00
|
|
|
ff_update_block_index(s, 8, 0, 1);
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 20:27:14 +02:00
|
|
|
static void h261_encode_motion(PutBitContext *pb, int val)
|
2013-04-04 15:31:58 +03:00
|
|
|
{
|
2007-05-21 15:51:29 +03:00
|
|
|
int sign, code;
|
2013-04-04 15:31:58 +03:00
|
|
|
if (val == 0) {
|
2024-06-15 06:53:37 +02:00
|
|
|
// Corresponds to ff_h261_mv_tab[0]
|
|
|
|
put_bits(pb, 1, 1);
|
2013-04-04 15:31:58 +03:00
|
|
|
} else {
|
|
|
|
if (val > 15)
|
|
|
|
val -= 32;
|
|
|
|
if (val < -16)
|
|
|
|
val += 32;
|
2007-05-21 15:51:29 +03:00
|
|
|
sign = val < 0;
|
|
|
|
code = sign ? -val : val;
|
2022-01-28 20:27:14 +02:00
|
|
|
put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
|
|
|
|
put_bits(pb, 1, sign);
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
static inline int get_cbp(MpegEncContext *s, int16_t block[6][64])
|
2007-05-21 15:51:29 +03:00
|
|
|
{
|
|
|
|
int i, cbp;
|
2013-04-04 15:31:58 +03:00
|
|
|
cbp = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
2007-05-21 15:51:29 +03:00
|
|
|
if (s->block_last_index[i] >= 0)
|
|
|
|
cbp |= 1 << (5 - i);
|
|
|
|
return cbp;
|
|
|
|
}
|
2013-04-04 15:31:58 +03:00
|
|
|
|
2013-04-04 15:33:55 +03:00
|
|
|
/**
|
|
|
|
* Encode an 8x8 block.
|
|
|
|
* @param block the 8x8 block
|
|
|
|
* @param n block index (0-3 are luma, 4-5 are chroma)
|
|
|
|
*/
|
2022-01-27 23:49:52 +02:00
|
|
|
static void h261_encode_block(H261EncContext *h, int16_t *block, int n)
|
2013-04-04 15:33:55 +03:00
|
|
|
{
|
|
|
|
MpegEncContext *const s = &h->s;
|
2024-06-15 17:26:14 +02:00
|
|
|
int level, run, i, j, last_index, last_non_zero;
|
2013-04-04 15:33:55 +03:00
|
|
|
|
|
|
|
if (s->mb_intra) {
|
|
|
|
/* DC coef */
|
|
|
|
level = block[0];
|
|
|
|
/* 255 cannot be represented, so we clamp */
|
|
|
|
if (level > 254) {
|
|
|
|
level = 254;
|
|
|
|
block[0] = 254;
|
|
|
|
}
|
|
|
|
/* 0 cannot be represented also */
|
|
|
|
else if (level < 1) {
|
|
|
|
level = 1;
|
|
|
|
block[0] = 1;
|
|
|
|
}
|
|
|
|
if (level == 128)
|
|
|
|
put_bits(&s->pb, 8, 0xff);
|
|
|
|
else
|
|
|
|
put_bits(&s->pb, 8, level);
|
|
|
|
i = 1;
|
|
|
|
} else if ((block[0] == 1 || block[0] == -1) &&
|
|
|
|
(s->block_last_index[n] > -1)) {
|
|
|
|
// special case
|
|
|
|
put_bits(&s->pb, 2, block[0] > 0 ? 2 : 3);
|
|
|
|
i = 1;
|
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AC coefs */
|
|
|
|
last_index = s->block_last_index[n];
|
|
|
|
last_non_zero = i - 1;
|
|
|
|
for (; i <= last_index; i++) {
|
|
|
|
j = s->intra_scantable.permutated[i];
|
|
|
|
level = block[j];
|
|
|
|
if (level) {
|
|
|
|
run = i - last_non_zero - 1;
|
2024-06-15 17:26:14 +02:00
|
|
|
|
|
|
|
if (run <= H261_MAX_RUN &&
|
|
|
|
(unsigned)(level + H261_MAX_LEVEL) <= 2 * H261_MAX_LEVEL &&
|
|
|
|
vlc_lut[run][level + H261_MAX_LEVEL].len) {
|
|
|
|
put_bits(&s->pb, vlc_lut[run][level + H261_MAX_LEVEL].len,
|
|
|
|
vlc_lut[run][level + H261_MAX_LEVEL].code);
|
2013-04-04 15:33:55 +03:00
|
|
|
} else {
|
2024-06-15 17:26:14 +02:00
|
|
|
/* Escape */
|
|
|
|
put_bits(&s->pb, 6 + 6, (1 << 6) | run);
|
|
|
|
av_assert1(level != 0);
|
|
|
|
av_assert1(FFABS(level) <= 127);
|
|
|
|
put_sbits(&s->pb, 8, level);
|
2013-04-04 15:33:55 +03:00
|
|
|
}
|
|
|
|
last_non_zero = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (last_index > -1)
|
2024-06-15 06:53:37 +02:00
|
|
|
put_bits(&s->pb, 2, 0x2); // EOB
|
2013-04-04 15:33:55 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
|
|
|
int motion_x, int motion_y)
|
2007-05-21 15:51:29 +03:00
|
|
|
{
|
2022-01-27 23:49:52 +02:00
|
|
|
/* The following is only allowed because this encoder
|
|
|
|
* does not use slice threading. */
|
|
|
|
H261EncContext *const h = (H261EncContext *)s;
|
|
|
|
H261Context *const com = &h->common;
|
2007-05-21 15:51:29 +03:00
|
|
|
int mvd, mv_diff_x, mv_diff_y, i, cbp;
|
|
|
|
cbp = 63; // avoid warning
|
|
|
|
mvd = 0;
|
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype = 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
if (!s->mb_intra) {
|
2007-05-21 15:51:29 +03:00
|
|
|
/* compute cbp */
|
2013-04-04 15:31:58 +03:00
|
|
|
cbp = get_cbp(s, block);
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
/* mvd indicates if this block is motion compensated */
|
|
|
|
mvd = motion_x | motion_y;
|
|
|
|
|
2015-01-31 05:57:50 +02:00
|
|
|
if ((cbp | mvd) == 0) {
|
2007-05-21 15:51:29 +03:00
|
|
|
/* skip macroblock */
|
2013-11-20 17:11:21 +03:00
|
|
|
s->mb_skip_run++;
|
2013-11-20 17:28:46 +03:00
|
|
|
s->last_mv[0][0][0] = 0;
|
|
|
|
s->last_mv[0][0][1] = 0;
|
2015-01-31 05:57:50 +02:00
|
|
|
s->qscale -= s->dquant;
|
2007-05-21 15:51:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MB is not skipped, encode MBA */
|
2013-04-04 15:56:01 +03:00
|
|
|
put_bits(&s->pb,
|
2013-11-20 17:11:21 +03:00
|
|
|
ff_h261_mba_bits[s->mb_skip_run],
|
|
|
|
ff_h261_mba_code[s->mb_skip_run]);
|
|
|
|
s->mb_skip_run = 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
|
|
|
/* calculate MTYPE */
|
2013-04-04 15:31:58 +03:00
|
|
|
if (!s->mb_intra) {
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype++;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
if (mvd || s->loop_filter)
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype += 3;
|
2013-04-04 15:31:58 +03:00
|
|
|
if (s->loop_filter)
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype += 3;
|
2015-01-31 05:57:50 +02:00
|
|
|
if (cbp)
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype++;
|
|
|
|
av_assert1(com->mtype > 1);
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
2015-01-31 05:57:50 +02:00
|
|
|
if (s->dquant && cbp) {
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype++;
|
2015-01-31 05:57:50 +02:00
|
|
|
} else
|
|
|
|
s->qscale -= s->dquant;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2013-04-04 15:56:01 +03:00
|
|
|
put_bits(&s->pb,
|
2022-01-27 23:49:52 +02:00
|
|
|
ff_h261_mtype_bits[com->mtype],
|
|
|
|
ff_h261_mtype_code[com->mtype]);
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
com->mtype = ff_h261_mtype_map[com->mtype];
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
if (IS_QUANT(com->mtype)) {
|
2013-04-04 15:31:58 +03:00
|
|
|
ff_set_qscale(s, s->qscale + s->dquant);
|
2007-05-21 15:51:29 +03:00
|
|
|
put_bits(&s->pb, 5, s->qscale);
|
|
|
|
}
|
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
if (IS_16X16(com->mtype)) {
|
2013-11-20 17:28:46 +03:00
|
|
|
mv_diff_x = (motion_x >> 1) - s->last_mv[0][0][0];
|
|
|
|
mv_diff_y = (motion_y >> 1) - s->last_mv[0][0][1];
|
|
|
|
s->last_mv[0][0][0] = (motion_x >> 1);
|
|
|
|
s->last_mv[0][0][1] = (motion_y >> 1);
|
2022-01-28 20:27:14 +02:00
|
|
|
h261_encode_motion(&s->pb, mv_diff_x);
|
|
|
|
h261_encode_motion(&s->pb, mv_diff_y);
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
if (HAS_CBP(com->mtype)) {
|
2013-04-05 22:53:57 +03:00
|
|
|
av_assert1(cbp > 0);
|
2013-04-04 15:56:01 +03:00
|
|
|
put_bits(&s->pb,
|
|
|
|
ff_h261_cbp_tab[cbp - 1][1],
|
|
|
|
ff_h261_cbp_tab[cbp - 1][0]);
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
2013-04-04 15:31:58 +03:00
|
|
|
for (i = 0; i < 6; i++)
|
2007-05-21 15:51:29 +03:00
|
|
|
/* encode each block */
|
|
|
|
h261_encode_block(h, block[i], i);
|
|
|
|
|
2022-01-27 23:49:52 +02:00
|
|
|
if (!IS_16X16(com->mtype)) {
|
2013-11-20 17:28:46 +03:00
|
|
|
s->last_mv[0][0][0] = 0;
|
|
|
|
s->last_mv[0][0][1] = 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 14:13:33 +02:00
|
|
|
static av_cold void h261_encode_init_static(void)
|
|
|
|
{
|
2024-06-15 18:44:18 +02:00
|
|
|
memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len));
|
|
|
|
memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last));
|
2024-06-15 17:26:14 +02:00
|
|
|
|
|
|
|
// The following loop is over the ordinary elements, not EOB or escape.
|
|
|
|
for (size_t i = 1; i < FF_ARRAY_ELEMS(ff_h261_tcoeff_vlc) - 1; i++) {
|
|
|
|
unsigned run = ff_h261_tcoeff_run[i];
|
|
|
|
unsigned level = ff_h261_tcoeff_level[i];
|
|
|
|
unsigned len = ff_h261_tcoeff_vlc[i][1] + 1 /* sign */;
|
|
|
|
unsigned code = ff_h261_tcoeff_vlc[i][0];
|
|
|
|
|
|
|
|
vlc_lut[run][H261_MAX_LEVEL + level] = (struct VLCLUT){ len, code << 1 };
|
|
|
|
vlc_lut[run][H261_MAX_LEVEL - level] = (struct VLCLUT){ len, (code << 1) | 1 };
|
2024-06-15 18:44:18 +02:00
|
|
|
|
|
|
|
uni_h261_rl_len [UNI_AC_ENC_INDEX(run, 64 + level)] = len;
|
|
|
|
uni_h261_rl_len [UNI_AC_ENC_INDEX(run, 64 - level)] = len;
|
|
|
|
uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2;
|
|
|
|
uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2;
|
2024-06-15 17:26:14 +02:00
|
|
|
}
|
2020-12-09 14:13:33 +02:00
|
|
|
}
|
|
|
|
|
2022-10-02 21:49:53 +02:00
|
|
|
av_cold int ff_h261_encode_init(MpegEncContext *s)
|
2013-04-04 15:31:58 +03:00
|
|
|
{
|
2022-01-27 23:49:52 +02:00
|
|
|
H261EncContext *const h = (H261EncContext*)s;
|
2020-12-09 14:13:33 +02:00
|
|
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
2007-05-21 15:51:29 +03:00
|
|
|
|
2022-10-02 22:00:01 +02:00
|
|
|
if (s->width == 176 && s->height == 144) {
|
|
|
|
h->format = H261_QCIF;
|
|
|
|
} else if (s->width == 352 && s->height == 288) {
|
|
|
|
h->format = H261_CIF;
|
|
|
|
} else {
|
2022-10-02 21:49:53 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR,
|
|
|
|
"The specified picture size of %dx%d is not valid for the "
|
|
|
|
"H.261 codec.\nValid sizes are 176x144, 352x288\n",
|
|
|
|
s->width, s->height);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2022-01-27 23:49:52 +02:00
|
|
|
s->private_ctx = &h->common;
|
|
|
|
|
2013-04-04 15:31:58 +03:00
|
|
|
s->min_qcoeff = -127;
|
|
|
|
s->max_qcoeff = 127;
|
2024-06-15 18:44:18 +02:00
|
|
|
s->ac_esc_length = H261_ESC_LEN;
|
2013-11-17 17:05:51 +03:00
|
|
|
|
|
|
|
s->intra_ac_vlc_length = s->inter_ac_vlc_length = uni_h261_rl_len;
|
2024-06-15 18:44:18 +02:00
|
|
|
s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = uni_h261_rl_len_last;
|
2020-12-09 14:13:33 +02:00
|
|
|
ff_thread_once(&init_static_once, h261_encode_init_static);
|
2022-10-02 21:49:53 +02:00
|
|
|
|
|
|
|
return 0;
|
2007-05-21 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_h261_encoder = {
|
|
|
|
.p.name = "h261",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("H.261"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_H261,
|
|
|
|
.p.priv_class = &ff_mpv_enc_class,
|
2022-01-27 23:49:52 +02:00
|
|
|
.priv_data_size = sizeof(H261EncContext),
|
2014-08-10 18:25:12 +03:00
|
|
|
.init = ff_mpv_encode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
|
2014-08-10 18:25:12 +03:00
|
|
|
.close = ff_mpv_encode_end,
|
2022-07-10 00:05:45 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
|
2013-04-04 15:31:58 +03:00
|
|
|
AV_PIX_FMT_NONE },
|
avcodec/internal: add FFCodec.color_ranges
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)
2023-10-11 16:09:33 +02:00
|
|
|
.color_ranges = AVCOL_RANGE_MPEG,
|
2022-11-27 14:37:10 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
|
2007-05-21 15:51:29 +03:00
|
|
|
};
|