2010-01-07 23:53:49 +00:00
|
|
|
/*
|
|
|
|
* MPEG4 encoder.
|
|
|
|
* Copyright (c) 2000,2001 Fabrice Bellard
|
|
|
|
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2010-01-07 23:53:49 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2010-01-07 23:53:49 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2010-01-07 23:53:49 +00:00
|
|
|
* 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
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2010-01-07 23:53:49 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2013-02-01 09:31:59 +00:00
|
|
|
#include "libavutil/attributes.h"
|
2011-08-27 08:16:14 +00:00
|
|
|
#include "libavutil/log.h"
|
|
|
|
#include "libavutil/opt.h"
|
2014-02-28 12:40:54 +00:00
|
|
|
#include "mpegutils.h"
|
2010-01-07 23:53:49 +00:00
|
|
|
#include "mpegvideo.h"
|
|
|
|
#include "h263.h"
|
|
|
|
#include "mpeg4video.h"
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
/* The uni_DCtab_* tables below contain unified bits+length tables to encode DC
|
|
|
|
* differences in mpeg4. Unified in the sense that the specification specifies
|
|
|
|
* this encoding in several steps. */
|
|
|
|
static uint8_t uni_DCtab_lum_len[512];
|
|
|
|
static uint8_t uni_DCtab_chrom_len[512];
|
2010-01-07 23:53:49 +00:00
|
|
|
static uint16_t uni_DCtab_lum_bits[512];
|
|
|
|
static uint16_t uni_DCtab_chrom_bits[512];
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
/* Unified encoding tables for run length encoding of coefficients.
|
|
|
|
* Unified in the sense that the specification specifies the encoding in several steps. */
|
|
|
|
static uint32_t uni_mpeg4_intra_rl_bits[64 * 64 * 2 * 2];
|
|
|
|
static uint8_t uni_mpeg4_intra_rl_len[64 * 64 * 2 * 2];
|
|
|
|
static uint32_t uni_mpeg4_inter_rl_bits[64 * 64 * 2 * 2];
|
|
|
|
static uint8_t uni_mpeg4_inter_rl_len[64 * 64 * 2 * 2];
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-11-19 15:45:51 +00:00
|
|
|
//#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 + (run) * 256 + (level))
|
|
|
|
//#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) + (level) * 64)
|
|
|
|
#define UNI_MPEG4_ENC_INDEX(last, run, level) ((last) * 128 * 64 + (run) * 128 + (level))
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
/* mpeg4
|
|
|
|
* inter
|
|
|
|
* max level: 24/6
|
|
|
|
* max run: 53/63
|
|
|
|
*
|
|
|
|
* intra
|
|
|
|
* max level: 53/16
|
|
|
|
* max run: 29/41
|
|
|
|
*/
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Return the number of bits that encoding the 8x8 block in block would need.
|
2010-01-07 23:53:49 +00:00
|
|
|
* @param[in] block_last_index last index in scantable order that refers to a non zero element in block.
|
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline int get_block_rate(MpegEncContext *s, int16_t block[64],
|
|
|
|
int block_last_index, uint8_t scantable[64])
|
|
|
|
{
|
|
|
|
int last = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
int j;
|
2013-10-28 17:30:01 +00:00
|
|
|
int rate = 0;
|
|
|
|
|
|
|
|
for (j = 1; j <= block_last_index; j++) {
|
|
|
|
const int index = scantable[j];
|
|
|
|
int level = block[index];
|
|
|
|
if (level) {
|
|
|
|
level += 64;
|
|
|
|
if ((level & (~127)) == 0) {
|
|
|
|
if (j < block_last_index)
|
|
|
|
rate += s->intra_ac_vlc_length[UNI_AC_ENC_INDEX(j - last - 1, level)];
|
|
|
|
else
|
|
|
|
rate += s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j - last - 1, level)];
|
|
|
|
} else
|
2010-01-07 23:53:49 +00:00
|
|
|
rate += s->ac_esc_length;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
last = j;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Restore the ac coefficients in block that have been changed by decide_ac_pred().
|
2010-01-07 23:53:49 +00:00
|
|
|
* This function also restores s->block_last_index.
|
|
|
|
* @param[in,out] block MB coefficients, these will be restored
|
|
|
|
* @param[in] dir ac prediction direction for each 8x8 block
|
|
|
|
* @param[out] st scantable for each 8x8 block
|
2012-12-19 17:48:21 +00:00
|
|
|
* @param[in] zigzag_last_index index referring to the last non zero coefficient in zigzag order
|
2010-01-07 23:53:49 +00:00
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline void restore_ac_coeffs(MpegEncContext *s, int16_t block[6][64],
|
|
|
|
const int dir[6], uint8_t *st[6],
|
|
|
|
const int zigzag_last_index[6])
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
2013-10-28 17:30:01 +00:00
|
|
|
memcpy(s->block_last_index, zigzag_last_index, sizeof(int) * 6);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (n = 0; n < 6; n++) {
|
2010-01-07 23:53:49 +00:00
|
|
|
int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
st[n] = s->intra_scantable.permutated;
|
|
|
|
if (dir[n]) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* top prediction */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++)
|
2014-01-24 10:55:16 +00:00
|
|
|
block[n][s->idsp.idct_permutation[i]] = ac_val[i + 8];
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* left prediction */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++)
|
2014-01-24 10:55:16 +00:00
|
|
|
block[n][s->idsp.idct_permutation[i << 3]] = ac_val[i];
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Return the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4.
|
2010-01-07 23:53:49 +00:00
|
|
|
* This function will also update s->block_last_index and s->ac_val.
|
|
|
|
* @param[in,out] block MB coefficients, these will be updated if 1 is returned
|
|
|
|
* @param[in] dir ac prediction direction for each 8x8 block
|
|
|
|
* @param[out] st scantable for each 8x8 block
|
2012-12-19 17:48:21 +00:00
|
|
|
* @param[out] zigzag_last_index index referring to the last non zero coefficient in zigzag order
|
2010-01-07 23:53:49 +00:00
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline int decide_ac_pred(MpegEncContext *s, int16_t block[6][64],
|
|
|
|
const int dir[6], uint8_t *st[6],
|
|
|
|
int zigzag_last_index[6])
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
2013-10-28 17:30:01 +00:00
|
|
|
int score = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
int i, n;
|
2013-10-28 17:30:01 +00:00
|
|
|
int8_t *const qscale_table = s->current_picture.qscale_table;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
memcpy(zigzag_last_index, s->block_last_index, sizeof(int) * 6);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (n = 0; n < 6; n++) {
|
2010-01-07 23:53:49 +00:00
|
|
|
int16_t *ac_val, *ac_val1;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
score -= get_block_rate(s, block[n], s->block_last_index[n],
|
|
|
|
s->intra_scantable.permutated);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
|
|
|
|
ac_val1 = ac_val;
|
|
|
|
if (dir[n]) {
|
|
|
|
const int xy = s->mb_x + s->mb_y * s->mb_stride - s->mb_stride;
|
2010-01-07 23:53:49 +00:00
|
|
|
/* top prediction */
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val -= s->block_wrap[n] * 16;
|
|
|
|
if (s->mb_y == 0 || s->qscale == qscale_table[xy] || n == 2 || n == 3) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* same qscale */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++) {
|
2014-01-24 10:55:16 +00:00
|
|
|
const int level = block[n][s->idsp.idct_permutation[i]];
|
|
|
|
block[n][s->idsp.idct_permutation[i]] = level - ac_val[i + 8];
|
|
|
|
ac_val1[i] = block[n][s->idsp.idct_permutation[i << 3]];
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val1[i + 8] = level;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* different qscale, we must rescale */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++) {
|
2014-01-24 10:55:16 +00:00
|
|
|
const int level = block[n][s->idsp.idct_permutation[i]];
|
|
|
|
block[n][s->idsp.idct_permutation[i]] = level - ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], s->qscale);
|
|
|
|
ac_val1[i] = block[n][s->idsp.idct_permutation[i << 3]];
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val1[i + 8] = level;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
st[n] = s->intra_h_scantable.permutated;
|
|
|
|
} else {
|
|
|
|
const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride;
|
2010-01-07 23:53:49 +00:00
|
|
|
/* left prediction */
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val -= 16;
|
|
|
|
if (s->mb_x == 0 || s->qscale == qscale_table[xy] || n == 1 || n == 3) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* same qscale */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++) {
|
2014-01-24 10:55:16 +00:00
|
|
|
const int level = block[n][s->idsp.idct_permutation[i << 3]];
|
|
|
|
block[n][s->idsp.idct_permutation[i << 3]] = level - ac_val[i];
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val1[i] = level;
|
2014-01-24 10:55:16 +00:00
|
|
|
ac_val1[i + 8] = block[n][s->idsp.idct_permutation[i]];
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* different qscale, we must rescale */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < 8; i++) {
|
2014-01-24 10:55:16 +00:00
|
|
|
const int level = block[n][s->idsp.idct_permutation[i << 3]];
|
|
|
|
block[n][s->idsp.idct_permutation[i << 3]] = level - ROUNDED_DIV(ac_val[i] * qscale_table[xy], s->qscale);
|
2013-10-28 17:30:01 +00:00
|
|
|
ac_val1[i] = level;
|
2014-01-24 10:55:16 +00:00
|
|
|
ac_val1[i + 8] = block[n][s->idsp.idct_permutation[i]];
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
st[n] = s->intra_v_scantable.permutated;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 63; i > 0; i--) // FIXME optimize
|
|
|
|
if (block[n][st[n][i]])
|
|
|
|
break;
|
|
|
|
s->block_last_index[n] = i;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
score += get_block_rate(s, block[n], s->block_last_index[n], st[n]);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (score < 0) {
|
2010-01-07 23:53:49 +00:00
|
|
|
return 1;
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
restore_ac_coeffs(s, block, dir, st, zigzag_last_index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* modify mb_type & qscale so that encoding is acually possible in mpeg4
|
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
void ff_clean_mpeg4_qscales(MpegEncContext *s)
|
|
|
|
{
|
2010-01-07 23:53:49 +00:00
|
|
|
int i;
|
2013-10-28 17:30:01 +00:00
|
|
|
int8_t *const qscale_table = s->current_picture.qscale_table;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
ff_clean_h263_qscales(s);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
|
|
|
int odd = 0;
|
|
|
|
/* ok, come on, this isn't funny anymore, there's more code for
|
|
|
|
* handling this mpeg4 mess than for the actual adaptive quantization */
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < s->mb_num; i++) {
|
|
|
|
int mb_xy = s->mb_index2xy[i];
|
|
|
|
odd += qscale_table[mb_xy] & 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (2 * odd > s->mb_num)
|
|
|
|
odd = 1;
|
|
|
|
else
|
|
|
|
odd = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < s->mb_num; i++) {
|
|
|
|
int mb_xy = s->mb_index2xy[i];
|
|
|
|
if ((qscale_table[mb_xy] & 1) != odd)
|
2010-01-07 23:53:49 +00:00
|
|
|
qscale_table[mb_xy]++;
|
2013-10-28 17:30:01 +00:00
|
|
|
if (qscale_table[mb_xy] > 31)
|
|
|
|
qscale_table[mb_xy] = 31;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 1; i < s->mb_num; i++) {
|
|
|
|
int mb_xy = s->mb_index2xy[i];
|
|
|
|
if (qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i - 1]] &&
|
|
|
|
(s->mb_type[mb_xy] & CANDIDATE_MB_TYPE_DIRECT)) {
|
|
|
|
s->mb_type[mb_xy] |= CANDIDATE_MB_TYPE_BIDIR;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-07 12:03:53 +00:00
|
|
|
* Encode the dc value.
|
2010-01-07 23:53:49 +00:00
|
|
|
* @param n block index (0-3 are luma, 4-5 are chroma)
|
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline void mpeg4_encode_dc(PutBitContext *s, int level, int n)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
#if 1
|
2010-01-08 10:00:56 +00:00
|
|
|
/* DC will overflow if level is outside the [-255,255] range. */
|
2013-10-28 17:30:01 +00:00
|
|
|
level += 256;
|
2010-01-07 23:53:49 +00:00
|
|
|
if (n < 4) {
|
|
|
|
/* luminance */
|
|
|
|
put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
|
|
|
|
} else {
|
|
|
|
/* chrominance */
|
|
|
|
put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int size, v;
|
|
|
|
/* find number of bits */
|
|
|
|
size = 0;
|
2013-10-28 17:30:01 +00:00
|
|
|
v = abs(level);
|
2010-01-07 23:53:49 +00:00
|
|
|
while (v) {
|
|
|
|
v >>= 1;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 4) {
|
|
|
|
/* luminance */
|
2010-01-08 17:28:43 +00:00
|
|
|
put_bits(&s->pb, ff_mpeg4_DCtab_lum[size][1], ff_mpeg4_DCtab_lum[size][0]);
|
2010-01-07 23:53:49 +00:00
|
|
|
} else {
|
|
|
|
/* chrominance */
|
2010-01-08 17:28:43 +00:00
|
|
|
put_bits(&s->pb, ff_mpeg4_DCtab_chrom[size][1], ff_mpeg4_DCtab_chrom[size][0]);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* encode remaining bits */
|
|
|
|
if (size > 0) {
|
|
|
|
if (level < 0)
|
|
|
|
level = (-level) ^ ((1 << size) - 1);
|
|
|
|
put_bits(&s->pb, size, level);
|
|
|
|
if (size > 8)
|
|
|
|
put_bits(&s->pb, 1, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline int mpeg4_get_dc_length(int level, int n)
|
|
|
|
{
|
|
|
|
if (n < 4)
|
2010-01-07 23:53:49 +00:00
|
|
|
return uni_DCtab_lum_len[level + 256];
|
2013-10-28 17:30:01 +00:00
|
|
|
else
|
2010-01-07 23:53:49 +00:00
|
|
|
return uni_DCtab_chrom_len[level + 256];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-07 12:03:53 +00:00
|
|
|
* Encode an 8x8 block.
|
2010-01-07 23:53:49 +00:00
|
|
|
* @param n block index (0-3 are luma, 4-5 are chroma)
|
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline void mpeg4_encode_block(MpegEncContext *s,
|
|
|
|
int16_t *block, int n, int intra_dc,
|
|
|
|
uint8_t *scan_table, PutBitContext *dc_pb,
|
|
|
|
PutBitContext *ac_pb)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int i, last_non_zero;
|
|
|
|
uint32_t *bits_tab;
|
|
|
|
uint8_t *len_tab;
|
|
|
|
const int last_index = s->block_last_index[n];
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mb_intra) { // Note gcc (3.2.1 at least) will optimize this away
|
2010-01-07 23:53:49 +00:00
|
|
|
/* mpeg4 based DC predictor */
|
|
|
|
mpeg4_encode_dc(dc_pb, intra_dc, n);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (last_index < 1)
|
|
|
|
return;
|
2010-01-07 23:53:49 +00:00
|
|
|
i = 1;
|
2013-10-28 17:30:01 +00:00
|
|
|
bits_tab = uni_mpeg4_intra_rl_bits;
|
|
|
|
len_tab = uni_mpeg4_intra_rl_len;
|
2010-01-07 23:53:49 +00:00
|
|
|
} else {
|
2013-10-28 17:30:01 +00:00
|
|
|
if (last_index < 0)
|
|
|
|
return;
|
2010-01-07 23:53:49 +00:00
|
|
|
i = 0;
|
2013-10-28 17:30:01 +00:00
|
|
|
bits_tab = uni_mpeg4_inter_rl_bits;
|
|
|
|
len_tab = uni_mpeg4_inter_rl_len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AC coefs */
|
|
|
|
last_non_zero = i - 1;
|
|
|
|
for (; i < last_index; i++) {
|
2013-10-28 17:30:01 +00:00
|
|
|
int level = block[scan_table[i]];
|
2010-01-07 23:53:49 +00:00
|
|
|
if (level) {
|
|
|
|
int run = i - last_non_zero - 1;
|
2013-10-28 17:30:01 +00:00
|
|
|
level += 64;
|
|
|
|
if ((level & (~127)) == 0) {
|
|
|
|
const int index = UNI_MPEG4_ENC_INDEX(0, run, level);
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(ac_pb, len_tab[index], bits_tab[index]);
|
2013-10-28 17:30:01 +00:00
|
|
|
} else { // ESC3
|
|
|
|
put_bits(ac_pb,
|
|
|
|
7 + 2 + 1 + 6 + 1 + 12 + 1,
|
|
|
|
(3 << 23) + (3 << 21) + (0 << 20) + (run << 14) +
|
|
|
|
(1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
last_non_zero = i;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
/* if (i <= last_index) */ {
|
|
|
|
int level = block[scan_table[i]];
|
|
|
|
int run = i - last_non_zero - 1;
|
|
|
|
level += 64;
|
|
|
|
if ((level & (~127)) == 0) {
|
|
|
|
const int index = UNI_MPEG4_ENC_INDEX(1, run, level);
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(ac_pb, len_tab[index], bits_tab[index]);
|
2013-10-28 17:30:01 +00:00
|
|
|
} else { // ESC3
|
|
|
|
put_bits(ac_pb,
|
|
|
|
7 + 2 + 1 + 6 + 1 + 12 + 1,
|
|
|
|
(3 << 23) + (3 << 21) + (1 << 20) + (run << 14) +
|
|
|
|
(1 << 13) + (((level - 64) & 0xfff) << 1) + 1);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static int mpeg4_get_block_length(MpegEncContext *s,
|
|
|
|
int16_t *block, int n,
|
|
|
|
int intra_dc, uint8_t *scan_table)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int i, last_non_zero;
|
|
|
|
uint8_t *len_tab;
|
|
|
|
const int last_index = s->block_last_index[n];
|
2013-10-28 17:30:01 +00:00
|
|
|
int len = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mb_intra) { // Note gcc (3.2.1 at least) will optimize this away
|
2010-01-07 23:53:49 +00:00
|
|
|
/* mpeg4 based DC predictor */
|
|
|
|
len += mpeg4_get_dc_length(intra_dc, n);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (last_index < 1)
|
|
|
|
return len;
|
2010-01-07 23:53:49 +00:00
|
|
|
i = 1;
|
|
|
|
len_tab = uni_mpeg4_intra_rl_len;
|
|
|
|
} else {
|
2013-10-28 17:30:01 +00:00
|
|
|
if (last_index < 0)
|
|
|
|
return 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
i = 0;
|
|
|
|
len_tab = uni_mpeg4_inter_rl_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AC coefs */
|
|
|
|
last_non_zero = i - 1;
|
|
|
|
for (; i < last_index; i++) {
|
2013-10-28 17:30:01 +00:00
|
|
|
int level = block[scan_table[i]];
|
2010-01-07 23:53:49 +00:00
|
|
|
if (level) {
|
|
|
|
int run = i - last_non_zero - 1;
|
2013-10-28 17:30:01 +00:00
|
|
|
level += 64;
|
|
|
|
if ((level & (~127)) == 0) {
|
|
|
|
const int index = UNI_MPEG4_ENC_INDEX(0, run, level);
|
2010-01-07 23:53:49 +00:00
|
|
|
len += len_tab[index];
|
2013-10-28 17:30:01 +00:00
|
|
|
} else { // ESC3
|
|
|
|
len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
last_non_zero = i;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
/* if (i <= last_index) */ {
|
|
|
|
int level = block[scan_table[i]];
|
|
|
|
int run = i - last_non_zero - 1;
|
|
|
|
level += 64;
|
|
|
|
if ((level & (~127)) == 0) {
|
|
|
|
const int index = UNI_MPEG4_ENC_INDEX(1, run, level);
|
2010-01-07 23:53:49 +00:00
|
|
|
len += len_tab[index];
|
2013-10-28 17:30:01 +00:00
|
|
|
} else { // ESC3
|
|
|
|
len += 7 + 2 + 1 + 6 + 1 + 12 + 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline void mpeg4_encode_blocks(MpegEncContext *s, int16_t block[6][64],
|
|
|
|
int intra_dc[6], uint8_t **scan_table,
|
|
|
|
PutBitContext *dc_pb,
|
|
|
|
PutBitContext *ac_pb)
|
|
|
|
{
|
2010-01-07 23:53:49 +00:00
|
|
|
int i;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (scan_table) {
|
2015-06-29 19:59:37 +00:00
|
|
|
if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) {
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
skip_put_bits(&s->pb,
|
|
|
|
mpeg4_get_block_length(s, block[i], i,
|
|
|
|
intra_dc[i], scan_table[i]));
|
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* encode each block */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
mpeg4_encode_block(s, block[i], i,
|
|
|
|
intra_dc[i], scan_table[i], dc_pb, ac_pb);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2015-06-29 19:59:37 +00:00
|
|
|
if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) {
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
skip_put_bits(&s->pb,
|
|
|
|
mpeg4_get_block_length(s, block[i], i, 0,
|
|
|
|
s->intra_scantable.permutated));
|
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* encode each block */
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
mpeg4_encode_block(s, block[i], i, 0,
|
|
|
|
s->intra_scantable.permutated, dc_pb, ac_pb);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static inline int get_b_cbp(MpegEncContext *s, int16_t block[6][64],
|
2011-10-21 14:02:29 +00:00
|
|
|
int motion_x, int motion_y, int mb_type)
|
|
|
|
{
|
|
|
|
int cbp = 0, i;
|
|
|
|
|
2012-02-27 11:23:19 +00:00
|
|
|
if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
|
2013-10-28 17:30:01 +00:00
|
|
|
int score = 0;
|
2011-10-21 14:02:29 +00:00
|
|
|
const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++) {
|
2011-10-21 14:02:29 +00:00
|
|
|
if (s->coded_score[i] < 0) {
|
|
|
|
score += s->coded_score[i];
|
|
|
|
cbp |= 1 << (5 - i);
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
}
|
2011-10-21 14:02:29 +00:00
|
|
|
|
|
|
|
if (cbp) {
|
|
|
|
int zero_score = -6;
|
|
|
|
if ((motion_x | motion_y | s->dquant | mb_type) == 0)
|
2013-10-28 17:30:01 +00:00
|
|
|
zero_score -= 4; // 2 * MV + mb_type + cbp bit
|
2011-10-21 14:02:29 +00:00
|
|
|
|
|
|
|
zero_score *= lambda;
|
|
|
|
if (zero_score <= score)
|
|
|
|
cbp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i)) & 1) == 0) {
|
|
|
|
s->block_last_index[i] = -1;
|
2014-01-14 09:33:47 +00:00
|
|
|
s->bdsp.clear_block(s->block[i]);
|
2011-10-21 14:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
if (s->block_last_index[i] >= 0)
|
|
|
|
cbp |= 1 << (5 - i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cbp;
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
// FIXME this is duplicated to h263.c
|
|
|
|
static const int dquant_code[5] = { 1, 0, 9, 2, 3 };
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
2012-02-15 10:36:50 +00:00
|
|
|
int motion_x, int motion_y)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int cbpc, cbpy, pred_x, pred_y;
|
2013-10-28 17:30:01 +00:00
|
|
|
PutBitContext *const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
|
|
|
|
PutBitContext *const tex_pb = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb;
|
|
|
|
PutBitContext *const dc_pb = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb;
|
2015-06-29 19:59:37 +00:00
|
|
|
const int interleaved_stats = (s->avctx->flags & AV_CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
if (!s->mb_intra) {
|
|
|
|
int i, cbp;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
|
|
|
/* convert from mv_dir to type */
|
|
|
|
static const int mb_type_table[8] = { -1, 3, 2, 1, -1, -1, -1, 0 };
|
|
|
|
int mb_type = mb_type_table[s->mv_dir];
|
|
|
|
|
|
|
|
if (s->mb_x == 0) {
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
s->last_mv[i][0][0] =
|
|
|
|
s->last_mv[i][0][1] =
|
|
|
|
s->last_mv[i][1][0] =
|
|
|
|
s->last_mv[i][1][1] = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
assert(s->dquant >= -2 && s->dquant <= 2);
|
|
|
|
assert((s->dquant & 1) == 0);
|
|
|
|
assert(mb_type >= 0);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* nothing to do if this MB was skipped in the next P Frame */
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { // FIXME avoid DCT & ...
|
2010-01-07 23:53:49 +00:00
|
|
|
s->skip_count++;
|
2013-10-28 17:30:01 +00:00
|
|
|
s->mv[0][0][0] =
|
|
|
|
s->mv[0][0][1] =
|
|
|
|
s->mv[1][0][0] =
|
|
|
|
s->mv[1][0][1] = 0;
|
|
|
|
s->mv_dir = MV_DIR_FORWARD; // doesn't matter
|
2010-01-07 23:53:49 +00:00
|
|
|
s->qscale -= s->dquant;
|
2013-10-28 17:30:01 +00:00
|
|
|
// s->mb_skipped = 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
cbp = get_b_cbp(s, block, motion_x, motion_y, mb_type);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if ((cbp | motion_x | motion_y | mb_type) == 0) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* direct MB with MV={0,0} */
|
2013-10-28 17:30:01 +00:00
|
|
|
assert(s->dquant == 0);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats) {
|
2010-01-07 23:53:49 +00:00
|
|
|
s->misc_bits++;
|
|
|
|
s->last_bits++;
|
|
|
|
}
|
|
|
|
s->skip_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
|
|
|
|
put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ // FIXME merge
|
|
|
|
put_bits(&s->pb, mb_type + 1, 1); // this table is so simple that we don't need it :)
|
|
|
|
if (cbp)
|
|
|
|
put_bits(&s->pb, 6, cbp);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (cbp && mb_type) {
|
|
|
|
if (s->dquant)
|
|
|
|
put_bits(&s->pb, 2, (s->dquant >> 2) + 3);
|
2010-01-07 23:53:49 +00:00
|
|
|
else
|
|
|
|
put_bits(&s->pb, 1, 0);
|
2013-10-28 17:30:01 +00:00
|
|
|
} else
|
2010-01-07 23:53:49 +00:00
|
|
|
s->qscale -= s->dquant;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!s->progressive_sequence) {
|
|
|
|
if (cbp)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->interlaced_dct);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (mb_type) // not direct mode
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->misc_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!mb_type) {
|
2010-01-07 23:53:49 +00:00
|
|
|
assert(s->mv_dir & MV_DIRECT);
|
|
|
|
ff_h263_encode_motion_vector(s, motion_x, motion_y, 1);
|
|
|
|
s->b_count++;
|
|
|
|
s->f_count++;
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
assert(mb_type > 0 && mb_type < 4);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_type != MV_TYPE_FIELD) {
|
|
|
|
if (s->mv_dir & MV_DIR_FORWARD) {
|
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[0][0][0] - s->last_mv[0][0][0],
|
|
|
|
s->mv[0][0][1] - s->last_mv[0][0][1],
|
|
|
|
s->f_code);
|
|
|
|
s->last_mv[0][0][0] =
|
|
|
|
s->last_mv[0][1][0] = s->mv[0][0][0];
|
|
|
|
s->last_mv[0][0][1] =
|
|
|
|
s->last_mv[0][1][1] = s->mv[0][0][1];
|
2010-01-07 23:53:49 +00:00
|
|
|
s->f_count++;
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_dir & MV_DIR_BACKWARD) {
|
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[1][0][0] - s->last_mv[1][0][0],
|
|
|
|
s->mv[1][0][1] - s->last_mv[1][0][1],
|
|
|
|
s->b_code);
|
|
|
|
s->last_mv[1][0][0] =
|
|
|
|
s->last_mv[1][1][0] = s->mv[1][0][0];
|
|
|
|
s->last_mv[1][0][1] =
|
|
|
|
s->last_mv[1][1][1] = s->mv[1][0][1];
|
2010-01-07 23:53:49 +00:00
|
|
|
s->b_count++;
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
|
|
|
if (s->mv_dir & MV_DIR_FORWARD) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->field_select[0][0]);
|
|
|
|
put_bits(&s->pb, 1, s->field_select[0][1]);
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_dir & MV_DIR_BACKWARD) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->field_select[1][0]);
|
|
|
|
put_bits(&s->pb, 1, s->field_select[1][1]);
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_dir & MV_DIR_FORWARD) {
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[0][i][0] - s->last_mv[0][i][0],
|
|
|
|
s->mv[0][i][1] - s->last_mv[0][i][1] / 2,
|
|
|
|
s->f_code);
|
|
|
|
s->last_mv[0][i][0] = s->mv[0][i][0];
|
|
|
|
s->last_mv[0][i][1] = s->mv[0][i][1] * 2;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
s->f_count++;
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_dir & MV_DIR_BACKWARD) {
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[1][i][0] - s->last_mv[1][i][0],
|
|
|
|
s->mv[1][i][1] - s->last_mv[1][i][1] / 2,
|
|
|
|
s->b_code);
|
|
|
|
s->last_mv[1][i][0] = s->mv[1][i][0];
|
|
|
|
s->last_mv[1][i][1] = s->mv[1][i][1] * 2;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
s->b_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->mv_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->p_tex_bits += get_bits_diff(s);
|
|
|
|
} else { /* s->pict_type==AV_PICTURE_TYPE_B */
|
|
|
|
cbp = get_p_cbp(s, block, motion_x, motion_y);
|
|
|
|
|
|
|
|
if ((cbp | motion_x | motion_y | s->dquant) == 0 &&
|
|
|
|
s->mv_type == MV_TYPE_16X16) {
|
|
|
|
/* check if the B frames can skip it too, as we must skip it
|
|
|
|
* if we skip here why didn't they just compress
|
|
|
|
* the skip-mb bits instead of reusing them ?! */
|
|
|
|
if (s->max_b_frames > 0) {
|
2010-01-07 23:53:49 +00:00
|
|
|
int i;
|
2013-10-28 17:30:01 +00:00
|
|
|
int x, y, offset;
|
2010-01-07 23:53:49 +00:00
|
|
|
uint8_t *p_pic;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
x = s->mb_x * 16;
|
|
|
|
y = s->mb_y * 16;
|
|
|
|
if (x + 16 > s->width)
|
|
|
|
x = s->width - 16;
|
|
|
|
if (y + 16 > s->height)
|
|
|
|
y = s->height - 16;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
offset = x + y * s->linesize;
|
2014-03-31 17:46:29 +00:00
|
|
|
p_pic = s->new_picture.f->data[0] + offset;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
s->mb_skipped = 1;
|
|
|
|
for (i = 0; i < s->max_b_frames; i++) {
|
2010-01-07 23:53:49 +00:00
|
|
|
uint8_t *b_pic;
|
|
|
|
int diff;
|
2013-10-28 17:30:01 +00:00
|
|
|
Picture *pic = s->reordered_input_picture[i + 1];
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2014-03-31 17:46:29 +00:00
|
|
|
if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B)
|
2011-07-06 18:08:30 +00:00
|
|
|
break;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2014-03-31 17:46:29 +00:00
|
|
|
b_pic = pic->f->data[0] + offset;
|
2012-11-21 20:34:46 +00:00
|
|
|
if (!pic->shared)
|
2013-10-28 17:30:01 +00:00
|
|
|
b_pic += INPLACE_OFFSET;
|
2014-02-08 01:59:58 +00:00
|
|
|
diff = s->mecc.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (diff > s->qscale * 70) { // FIXME check that 70 is optimal
|
|
|
|
s->mb_skipped = 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
} else
|
|
|
|
s->mb_skipped = 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mb_skipped == 1) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* skip macroblock */
|
|
|
|
put_bits(&s->pb, 1, 1);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats) {
|
2010-01-07 23:53:49 +00:00
|
|
|
s->misc_bits++;
|
|
|
|
s->last_bits++;
|
|
|
|
}
|
|
|
|
s->skip_count++;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0); /* mb coded */
|
2013-10-28 17:30:01 +00:00
|
|
|
cbpc = cbp & 3;
|
|
|
|
cbpy = cbp >> 2;
|
2010-01-07 23:53:49 +00:00
|
|
|
cbpy ^= 0xf;
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mv_type == MV_TYPE_16X16) {
|
|
|
|
if (s->dquant)
|
|
|
|
cbpc += 8;
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb,
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_inter_MCBPC_bits[cbpc],
|
|
|
|
ff_h263_inter_MCBPC_code[cbpc]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2010-01-08 17:51:48 +00:00
|
|
|
put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->dquant)
|
|
|
|
put_bits(pb2, 2, dquant_code[s->dquant + 2]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!s->progressive_sequence) {
|
|
|
|
if (cbp)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(pb2, 1, s->interlaced_dct);
|
|
|
|
put_bits(pb2, 1, 0);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->misc_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* motion vectors: 16x16 mode */
|
2012-02-09 09:28:46 +00:00
|
|
|
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
motion_x - pred_x,
|
|
|
|
motion_y - pred_y,
|
|
|
|
s->f_code);
|
|
|
|
} else if (s->mv_type == MV_TYPE_FIELD) {
|
|
|
|
if (s->dquant)
|
|
|
|
cbpc += 8;
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb,
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_inter_MCBPC_bits[cbpc],
|
|
|
|
ff_h263_inter_MCBPC_code[cbpc]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2010-01-08 17:51:48 +00:00
|
|
|
put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->dquant)
|
|
|
|
put_bits(pb2, 2, dquant_code[s->dquant + 2]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
assert(!s->progressive_sequence);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (cbp)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(pb2, 1, s->interlaced_dct);
|
|
|
|
put_bits(pb2, 1, 1);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->misc_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* motion vectors: 16x8 interlaced mode */
|
2012-02-09 09:28:46 +00:00
|
|
|
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
|
2013-10-28 17:30:01 +00:00
|
|
|
pred_y /= 2;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 1, s->field_select[0][0]);
|
|
|
|
put_bits(&s->pb, 1, s->field_select[0][1]);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[0][0][0] - pred_x,
|
|
|
|
s->mv[0][0][1] - pred_y,
|
|
|
|
s->f_code);
|
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->mv[0][1][0] - pred_x,
|
|
|
|
s->mv[0][1][1] - pred_y,
|
|
|
|
s->f_code);
|
|
|
|
} else {
|
|
|
|
assert(s->mv_type == MV_TYPE_8X8);
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb,
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_inter_MCBPC_bits[cbpc + 16],
|
|
|
|
ff_h263_inter_MCBPC_code[cbpc + 16]);
|
2010-01-08 17:51:48 +00:00
|
|
|
put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!s->progressive_sequence && cbp)
|
|
|
|
put_bits(pb2, 1, s->interlaced_dct);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->misc_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2010-01-07 23:53:49 +00:00
|
|
|
/* motion vectors: 8x8 mode*/
|
2012-02-09 09:28:46 +00:00
|
|
|
ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_encode_motion_vector(s,
|
|
|
|
s->current_picture.motion_val[0][s->block_index[i]][0] - pred_x,
|
|
|
|
s->current_picture.motion_val[0][s->block_index[i]][1] - pred_y,
|
|
|
|
s->f_code);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->mv_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->p_tex_bits += get_bits_diff(s);
|
|
|
|
|
2010-01-07 23:53:49 +00:00
|
|
|
s->f_count++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int cbp;
|
2013-10-28 17:30:01 +00:00
|
|
|
int dc_diff[6]; // dc values with the dc prediction subtracted
|
|
|
|
int dir[6]; // prediction direction
|
2010-01-07 23:53:49 +00:00
|
|
|
int zigzag_last_index[6];
|
|
|
|
uint8_t *scan_table[6];
|
|
|
|
int i;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
dc_diff[i] = ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2015-06-29 19:59:37 +00:00
|
|
|
if (s->avctx->flags & AV_CODEC_FLAG_AC_PRED) {
|
2013-10-28 17:30:01 +00:00
|
|
|
s->ac_pred = decide_ac_pred(s, block, dir, scan_table, zigzag_last_index);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
scan_table[i] = s->intra_scantable.permutated;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compute cbp */
|
|
|
|
cbp = 0;
|
2013-10-28 17:30:01 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
2010-01-07 23:53:49 +00:00
|
|
|
if (s->block_last_index[i] >= 1)
|
|
|
|
cbp |= 1 << (5 - i);
|
|
|
|
|
|
|
|
cbpc = cbp & 3;
|
2011-04-29 16:53:57 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_I) {
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->dquant)
|
|
|
|
cbpc += 4;
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb,
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_intra_MCBPC_bits[cbpc],
|
|
|
|
ff_h263_intra_MCBPC_code[cbpc]);
|
2010-01-07 23:53:49 +00:00
|
|
|
} else {
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->dquant)
|
|
|
|
cbpc += 8;
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* mb coded */
|
|
|
|
put_bits(&s->pb,
|
2013-10-28 17:30:01 +00:00
|
|
|
ff_h263_inter_MCBPC_bits[cbpc + 4],
|
|
|
|
ff_h263_inter_MCBPC_code[cbpc + 4]);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
put_bits(pb2, 1, s->ac_pred);
|
|
|
|
cbpy = cbp >> 2;
|
2010-01-08 17:51:48 +00:00
|
|
|
put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->dquant)
|
|
|
|
put_bits(dc_pb, 2, dquant_code[s->dquant + 2]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!s->progressive_sequence)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(dc_pb, 1, s->interlaced_dct);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->misc_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (interleaved_stats)
|
|
|
|
s->i_tex_bits += get_bits_diff(s);
|
2010-01-07 23:53:49 +00:00
|
|
|
s->i_count++;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
/* restore ac coeffs & last_index stuff
|
|
|
|
* if we messed them up with the prediction */
|
|
|
|
if (s->ac_pred)
|
2010-01-07 23:53:49 +00:00
|
|
|
restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add mpeg4 stuffing bits (01...1)
|
|
|
|
*/
|
2013-10-28 17:30:01 +00:00
|
|
|
void ff_mpeg4_stuffing(PutBitContext *pbc)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int length;
|
|
|
|
put_bits(pbc, 1, 0);
|
2013-10-28 17:30:01 +00:00
|
|
|
length = (-put_bits_count(pbc)) & 7;
|
|
|
|
if (length)
|
|
|
|
put_bits(pbc, length, (1 << length) - 1);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called before writing the header */
|
2013-10-28 17:30:01 +00:00
|
|
|
void ff_set_mpeg4_time(MpegEncContext *s)
|
|
|
|
{
|
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B) {
|
2010-01-07 23:53:49 +00:00
|
|
|
ff_mpeg4_init_direct_mv(s);
|
2013-10-28 17:30:01 +00:00
|
|
|
} else {
|
|
|
|
s->last_time_base = s->time_base;
|
|
|
|
s->time_base = s->time / s->avctx->time_base.den;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static void mpeg4_encode_gop_header(MpegEncContext *s)
|
|
|
|
{
|
2010-01-07 23:53:49 +00:00
|
|
|
int hours, minutes, seconds;
|
|
|
|
int64_t time;
|
|
|
|
|
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, GOP_STARTCODE);
|
|
|
|
|
2014-03-31 17:46:29 +00:00
|
|
|
time = s->current_picture_ptr->f->pts;
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->reordered_input_picture[1])
|
2014-03-31 17:46:29 +00:00
|
|
|
time = FFMIN(time, s->reordered_input_picture[1]->f->pts);
|
2013-10-28 17:30:01 +00:00
|
|
|
time = time * s->avctx->time_base.num;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
seconds = time / s->avctx->time_base.den;
|
|
|
|
minutes = seconds / 60;
|
|
|
|
seconds %= 60;
|
|
|
|
hours = minutes / 60;
|
|
|
|
minutes %= 60;
|
|
|
|
hours %= 24;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 5, hours);
|
|
|
|
put_bits(&s->pb, 6, minutes);
|
|
|
|
put_bits(&s->pb, 1, 1);
|
|
|
|
put_bits(&s->pb, 6, seconds);
|
|
|
|
|
2015-06-29 19:59:37 +00:00
|
|
|
put_bits(&s->pb, 1, !!(s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP));
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 1, 0); // broken link == NO
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
s->last_time_base = time / s->avctx->time_base.den;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
ff_mpeg4_stuffing(&s->pb);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static void mpeg4_encode_visual_object_header(MpegEncContext *s)
|
|
|
|
{
|
2010-01-07 23:53:49 +00:00
|
|
|
int profile_and_level_indication;
|
|
|
|
int vo_ver_id;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->avctx->profile != FF_PROFILE_UNKNOWN) {
|
2010-01-07 23:53:49 +00:00
|
|
|
profile_and_level_indication = s->avctx->profile << 4;
|
2013-10-28 17:30:01 +00:00
|
|
|
} else if (s->max_b_frames || s->quarter_sample) {
|
|
|
|
profile_and_level_indication = 0xF0; // adv simple
|
|
|
|
} else {
|
|
|
|
profile_and_level_indication = 0x00; // simple
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->avctx->level != FF_LEVEL_UNKNOWN)
|
2010-01-07 23:53:49 +00:00
|
|
|
profile_and_level_indication |= s->avctx->level;
|
2013-10-28 17:30:01 +00:00
|
|
|
else
|
|
|
|
profile_and_level_indication |= 1; // level 1
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (profile_and_level_indication >> 4 == 0xF)
|
|
|
|
vo_ver_id = 5;
|
|
|
|
else
|
|
|
|
vo_ver_id = 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
// FIXME levels
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, VOS_STARTCODE);
|
|
|
|
|
|
|
|
put_bits(&s->pb, 8, profile_and_level_indication);
|
|
|
|
|
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
|
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 1);
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 4, vo_ver_id);
|
|
|
|
put_bits(&s->pb, 3, 1); // priority
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 4, 1); // visual obj type== video obj
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 1, 0); // video signal type == no clue // FIXME
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
ff_mpeg4_stuffing(&s->pb);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
static void mpeg4_encode_vol_header(MpegEncContext *s,
|
|
|
|
int vo_number,
|
|
|
|
int vol_number)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int vo_ver_id;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!CONFIG_MPEG4_ENCODER)
|
|
|
|
return;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->max_b_frames || s->quarter_sample) {
|
|
|
|
vo_ver_id = 5;
|
|
|
|
s->vo_type = ADV_SIMPLE_VO_TYPE;
|
|
|
|
} else {
|
|
|
|
vo_ver_id = 1;
|
|
|
|
s->vo_type = SIMPLE_VO_TYPE;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */
|
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */
|
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0); /* random access vol */
|
|
|
|
put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->workaround_bugs & FF_BUG_MS) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* is obj layer id= no */
|
|
|
|
} else {
|
|
|
|
put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
|
|
|
|
put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
|
|
|
|
put_bits(&s->pb, 3, 1); /* is obj layer priority */
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
s->aspect_ratio_info = ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 4, s->aspect_ratio_info); /* aspect ratio info */
|
|
|
|
if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
|
|
|
|
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->workaround_bugs & FF_BUG_MS) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
|
|
|
|
} else {
|
|
|
|
put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
|
|
|
|
put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
|
|
|
|
put_bits(&s->pb, 1, s->low_delay);
|
|
|
|
put_bits(&s->pb, 1, 0); /* vbv parameters= no */
|
|
|
|
}
|
|
|
|
|
|
|
|
put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker bit */
|
|
|
|
|
|
|
|
put_bits(&s->pb, 16, s->avctx->time_base.den);
|
|
|
|
if (s->time_increment_bits < 1)
|
|
|
|
s->time_increment_bits = 1;
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker bit */
|
|
|
|
put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker bit */
|
|
|
|
put_bits(&s->pb, 13, s->width); /* vol width */
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker bit */
|
|
|
|
put_bits(&s->pb, 13, s->height); /* vol height */
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker bit */
|
|
|
|
put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
|
|
|
|
put_bits(&s->pb, 1, 1); /* obmc disable */
|
2013-10-28 17:30:01 +00:00
|
|
|
if (vo_ver_id == 1)
|
2013-11-26 10:37:59 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* sprite enable */
|
2013-10-28 17:30:01 +00:00
|
|
|
else
|
2013-11-26 10:37:59 +00:00
|
|
|
put_bits(&s->pb, 2, 0); /* sprite enable */
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0); /* not 8 bit == false */
|
|
|
|
put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->mpeg_quant) {
|
2010-01-07 23:53:49 +00:00
|
|
|
ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
|
|
|
|
ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vo_ver_id != 1)
|
|
|
|
put_bits(&s->pb, 1, s->quarter_sample);
|
|
|
|
put_bits(&s->pb, 1, 1); /* complexity estimation disable */
|
2013-11-26 11:14:13 +00:00
|
|
|
put_bits(&s->pb, 1, s->rtp_mode ? 0 : 1); /* resync marker disable */
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->data_partitioning)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* no rvlc */
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (vo_ver_id != 1) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 0); /* newpred */
|
|
|
|
put_bits(&s->pb, 1, 0); /* reduced res vop */
|
|
|
|
}
|
|
|
|
put_bits(&s->pb, 1, 0); /* scalability */
|
|
|
|
|
|
|
|
ff_mpeg4_stuffing(&s->pb);
|
|
|
|
|
|
|
|
/* user data */
|
2015-06-29 19:59:37 +00:00
|
|
|
if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT)) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 16, 0);
|
|
|
|
put_bits(&s->pb, 16, 0x1B2); /* user_data */
|
2012-09-09 13:03:52 +00:00
|
|
|
avpriv_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write mpeg4 VOP header */
|
2013-10-28 17:30:01 +00:00
|
|
|
void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int time_incr;
|
|
|
|
int time_div, time_mod;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_I) {
|
2015-06-29 19:59:37 +00:00
|
|
|
if (!(s->avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) {
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy
|
2010-01-07 23:53:49 +00:00
|
|
|
mpeg4_encode_visual_object_header(s);
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number == 0) // HACK, the reference sw is buggy
|
2010-01-07 23:53:49 +00:00
|
|
|
mpeg4_encode_vol_header(s, 0, 0);
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!(s->workaround_bugs & FF_BUG_MS))
|
2010-01-07 23:53:49 +00:00
|
|
|
mpeg4_encode_gop_header(s);
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 16, 0); /* vop header */
|
|
|
|
put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
|
|
|
|
put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
assert(s->time >= 0);
|
|
|
|
time_div = s->time / s->avctx->time_base.den;
|
|
|
|
time_mod = s->time % s->avctx->time_base.den;
|
|
|
|
time_incr = time_div - s->last_time_base;
|
2010-01-07 23:53:49 +00:00
|
|
|
assert(time_incr >= 0);
|
2013-10-28 17:30:01 +00:00
|
|
|
while (time_incr--)
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, 1);
|
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 0);
|
|
|
|
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker */
|
|
|
|
put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
|
|
|
|
put_bits(&s->pb, 1, 1); /* marker */
|
|
|
|
put_bits(&s->pb, 1, 1); /* vop coded */
|
2013-11-26 10:37:59 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_P) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
|
|
|
|
}
|
|
|
|
put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!s->progressive_sequence) {
|
2014-03-31 17:46:29 +00:00
|
|
|
put_bits(&s->pb, 1, s->current_picture_ptr->f->top_field_first);
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 1, s->alternate_scan);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
// FIXME sprite stuff
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, 5, s->qscale);
|
|
|
|
|
2011-04-29 16:53:57 +00:00
|
|
|
if (s->pict_type != AV_PICTURE_TYPE_I)
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 3, s->f_code); /* fcode_for */
|
2011-04-29 16:53:57 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B)
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, 3, s->b_code); /* fcode_back */
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 09:31:59 +00:00
|
|
|
static av_cold void init_uni_dc_tab(void)
|
2010-01-07 23:53:49 +00:00
|
|
|
{
|
|
|
|
int level, uni_code, uni_len;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
for (level = -256; level < 256; level++) {
|
2010-01-07 23:53:49 +00:00
|
|
|
int size, v, l;
|
|
|
|
/* find number of bits */
|
|
|
|
size = 0;
|
2013-10-28 17:30:01 +00:00
|
|
|
v = abs(level);
|
2010-01-07 23:53:49 +00:00
|
|
|
while (v) {
|
|
|
|
v >>= 1;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level < 0)
|
2013-10-28 17:30:01 +00:00
|
|
|
l = (-level) ^ ((1 << size) - 1);
|
2010-01-07 23:53:49 +00:00
|
|
|
else
|
2013-10-28 17:30:01 +00:00
|
|
|
l = level;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* luminance */
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_code = ff_mpeg4_DCtab_lum[size][0];
|
|
|
|
uni_len = ff_mpeg4_DCtab_lum[size][1];
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
if (size > 0) {
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_code <<= size;
|
|
|
|
uni_code |= l;
|
|
|
|
uni_len += size;
|
|
|
|
if (size > 8) {
|
|
|
|
uni_code <<= 1;
|
|
|
|
uni_code |= 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
uni_len++;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_DCtab_lum_bits[level + 256] = uni_code;
|
|
|
|
uni_DCtab_lum_len[level + 256] = uni_len;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* chrominance */
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_code = ff_mpeg4_DCtab_chrom[size][0];
|
|
|
|
uni_len = ff_mpeg4_DCtab_chrom[size][1];
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
if (size > 0) {
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_code <<= size;
|
|
|
|
uni_code |= l;
|
|
|
|
uni_len += size;
|
|
|
|
if (size > 8) {
|
|
|
|
uni_code <<= 1;
|
|
|
|
uni_code |= 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
uni_len++;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 17:30:01 +00:00
|
|
|
uni_DCtab_chrom_bits[level + 256] = uni_code;
|
|
|
|
uni_DCtab_chrom_len[level + 256] = uni_len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 09:31:59 +00:00
|
|
|
static av_cold void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab,
|
|
|
|
uint8_t *len_tab)
|
|
|
|
{
|
2010-01-07 23:53:49 +00:00
|
|
|
int slevel, run, last;
|
|
|
|
|
|
|
|
assert(MAX_LEVEL >= 64);
|
2013-10-28 17:30:01 +00:00
|
|
|
assert(MAX_RUN >= 63);
|
|
|
|
|
|
|
|
for (slevel = -64; slevel < 64; slevel++) {
|
|
|
|
if (slevel == 0)
|
|
|
|
continue;
|
|
|
|
for (run = 0; run < 64; run++) {
|
|
|
|
for (last = 0; last <= 1; last++) {
|
|
|
|
const int index = UNI_MPEG4_ENC_INDEX(last, run, slevel + 64);
|
|
|
|
int level = slevel < 0 ? -slevel : slevel;
|
|
|
|
int sign = slevel < 0 ? 1 : 0;
|
2010-01-07 23:53:49 +00:00
|
|
|
int bits, len, code;
|
|
|
|
int level1, run1;
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
len_tab[index] = 100;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
/* ESC0 */
|
2013-10-28 17:30:01 +00:00
|
|
|
code = get_rl_index(rl, last, run, level);
|
|
|
|
bits = rl->table_vlc[code][0];
|
|
|
|
len = rl->table_vlc[code][1];
|
|
|
|
bits = bits * 2 + sign;
|
|
|
|
len++;
|
|
|
|
|
|
|
|
if (code != rl->n && len < len_tab[index]) {
|
|
|
|
bits_tab[index] = bits;
|
|
|
|
len_tab[index] = len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
/* ESC1 */
|
2013-10-28 17:30:01 +00:00
|
|
|
bits = rl->table_vlc[rl->n][0];
|
|
|
|
len = rl->table_vlc[rl->n][1];
|
|
|
|
bits = bits * 2;
|
|
|
|
len++; // esc1
|
|
|
|
level1 = level - rl->max_level[last][run];
|
|
|
|
if (level1 > 0) {
|
|
|
|
code = get_rl_index(rl, last, run, level1);
|
|
|
|
bits <<= rl->table_vlc[code][1];
|
|
|
|
len += rl->table_vlc[code][1];
|
|
|
|
bits += rl->table_vlc[code][0];
|
|
|
|
bits = bits * 2 + sign;
|
|
|
|
len++;
|
|
|
|
|
|
|
|
if (code != rl->n && len < len_tab[index]) {
|
|
|
|
bits_tab[index] = bits;
|
|
|
|
len_tab[index] = len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* ESC2 */
|
2013-10-28 17:30:01 +00:00
|
|
|
bits = rl->table_vlc[rl->n][0];
|
|
|
|
len = rl->table_vlc[rl->n][1];
|
|
|
|
bits = bits * 4 + 2;
|
|
|
|
len += 2; // esc2
|
2010-01-07 23:53:49 +00:00
|
|
|
run1 = run - rl->max_run[last][level] - 1;
|
2013-10-28 17:30:01 +00:00
|
|
|
if (run1 >= 0) {
|
|
|
|
code = get_rl_index(rl, last, run1, level);
|
|
|
|
bits <<= rl->table_vlc[code][1];
|
|
|
|
len += rl->table_vlc[code][1];
|
|
|
|
bits += rl->table_vlc[code][0];
|
|
|
|
bits = bits * 2 + sign;
|
|
|
|
len++;
|
|
|
|
|
|
|
|
if (code != rl->n && len < len_tab[index]) {
|
|
|
|
bits_tab[index] = bits;
|
|
|
|
len_tab[index] = len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* ESC3 */
|
2013-10-28 17:30:01 +00:00
|
|
|
bits = rl->table_vlc[rl->n][0];
|
|
|
|
len = rl->table_vlc[rl->n][1];
|
|
|
|
bits = bits * 4 + 3;
|
|
|
|
len += 2; // esc3
|
|
|
|
bits = bits * 2 + last;
|
|
|
|
len++;
|
|
|
|
bits = bits * 64 + run;
|
|
|
|
len += 6;
|
|
|
|
bits = bits * 2 + 1;
|
|
|
|
len++; // marker
|
|
|
|
bits = bits * 4096 + (slevel & 0xfff);
|
|
|
|
len += 12;
|
|
|
|
bits = bits * 2 + 1;
|
|
|
|
len++; // marker
|
|
|
|
|
|
|
|
if (len < len_tab[index]) {
|
|
|
|
bits_tab[index] = bits;
|
|
|
|
len_tab[index] = len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int encode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
MpegEncContext *s = avctx->priv_data;
|
|
|
|
int ret;
|
|
|
|
static int done = 0;
|
|
|
|
|
2014-08-10 15:25:12 +00:00
|
|
|
if ((ret = ff_mpv_encode_init(avctx)) < 0)
|
2010-01-07 23:53:49 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
init_uni_dc_tab();
|
|
|
|
|
2015-05-22 18:50:12 +00:00
|
|
|
ff_rl_init(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2010-01-08 17:41:14 +00:00
|
|
|
init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
|
2010-01-08 17:51:48 +00:00
|
|
|
init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
s->min_qcoeff = -2048;
|
|
|
|
s->max_qcoeff = 2047;
|
|
|
|
s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;
|
|
|
|
s->intra_ac_vlc_last_length = uni_mpeg4_intra_rl_len + 128 * 64;
|
|
|
|
s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len;
|
|
|
|
s->inter_ac_vlc_last_length = uni_mpeg4_inter_rl_len + 128 * 64;
|
|
|
|
s->luma_dc_vlc_length = uni_DCtab_lum_len;
|
|
|
|
s->ac_esc_length = 7 + 2 + 1 + 6 + 1 + 12 + 1;
|
|
|
|
s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
|
|
|
|
s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
|
|
|
|
|
2015-06-29 19:59:37 +00:00
|
|
|
if (s->avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
|
2013-10-28 17:30:01 +00:00
|
|
|
s->avctx->extradata = av_malloc(1024);
|
2010-01-07 23:53:49 +00:00
|
|
|
init_put_bits(&s->pb, s->avctx->extradata, 1024);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (!(s->workaround_bugs & FF_BUG_MS))
|
2010-01-07 23:53:49 +00:00
|
|
|
mpeg4_encode_visual_object_header(s);
|
|
|
|
mpeg4_encode_vol_header(s, 0, 0);
|
|
|
|
|
|
|
|
// ff_mpeg4_stuffing(&s->pb); ?
|
|
|
|
flush_put_bits(&s->pb);
|
2013-10-28 17:30:01 +00:00
|
|
|
s->avctx->extradata_size = (put_bits_count(&s->pb) + 7) >> 3;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ff_mpeg4_init_partitions(MpegEncContext *s)
|
|
|
|
{
|
2013-10-28 17:30:01 +00:00
|
|
|
uint8_t *start = put_bits_ptr(&s->pb);
|
|
|
|
uint8_t *end = s->pb.buf_end;
|
|
|
|
int size = end - start;
|
|
|
|
int pb_size = (((intptr_t)start + size / 3) & (~3)) - (intptr_t)start;
|
|
|
|
int tex_size = (size - 2 * pb_size) & (~3);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
set_put_bits_buffer_size(&s->pb, pb_size);
|
2013-10-28 17:30:01 +00:00
|
|
|
init_put_bits(&s->tex_pb, start + pb_size, tex_size);
|
|
|
|
init_put_bits(&s->pb2, start + pb_size + tex_size, pb_size);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff_mpeg4_merge_partitions(MpegEncContext *s)
|
|
|
|
{
|
2013-10-28 17:30:01 +00:00
|
|
|
const int pb2_len = put_bits_count(&s->pb2);
|
|
|
|
const int tex_pb_len = put_bits_count(&s->tex_pb);
|
|
|
|
const int bits = put_bits_count(&s->pb);
|
2010-01-07 23:53:49 +00:00
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_I) {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 19, DC_MARKER);
|
2013-10-28 17:30:01 +00:00
|
|
|
s->misc_bits += 19 + pb2_len + bits - s->last_bits;
|
|
|
|
s->i_tex_bits += tex_pb_len;
|
|
|
|
} else {
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, 17, MOTION_MARKER);
|
2013-10-28 17:30:01 +00:00
|
|
|
s->misc_bits += 17 + pb2_len;
|
|
|
|
s->mv_bits += bits - s->last_bits;
|
|
|
|
s->p_tex_bits += tex_pb_len;
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flush_put_bits(&s->pb2);
|
|
|
|
flush_put_bits(&s->tex_pb);
|
|
|
|
|
|
|
|
set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
|
2013-10-28 17:30:01 +00:00
|
|
|
avpriv_copy_bits(&s->pb, s->pb2.buf, pb2_len);
|
2011-10-17 08:10:42 +00:00
|
|
|
avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
|
2013-10-28 17:30:01 +00:00
|
|
|
s->last_bits = put_bits_count(&s->pb);
|
2010-01-07 23:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
|
|
|
|
{
|
2013-10-28 17:30:01 +00:00
|
|
|
int mb_num_bits = av_log2(s->mb_num - 1) + 1;
|
2010-01-07 23:53:49 +00:00
|
|
|
|
|
|
|
put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0);
|
|
|
|
put_bits(&s->pb, 1, 1);
|
|
|
|
|
2013-10-28 17:30:01 +00:00
|
|
|
put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y * s->mb_width);
|
2010-01-07 23:53:49 +00:00
|
|
|
put_bits(&s->pb, s->quant_precision, s->qscale);
|
|
|
|
put_bits(&s->pb, 1, 0); /* no HEC */
|
|
|
|
}
|
|
|
|
|
2011-08-27 08:16:14 +00:00
|
|
|
#define OFFSET(x) offsetof(MpegEncContext, x)
|
|
|
|
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
|
|
|
static const AVOption options[] = {
|
2013-10-28 17:30:01 +00:00
|
|
|
{ "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
|
|
|
|
{ "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
|
2012-02-27 11:12:19 +00:00
|
|
|
FF_MPV_COMMON_OPTS
|
2011-08-27 08:16:14 +00:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass mpeg4enc_class = {
|
|
|
|
.class_name = "MPEG4 encoder",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_mpeg4_encoder = {
|
2011-07-17 10:54:31 +00:00
|
|
|
.name = "mpeg4",
|
2013-10-03 20:57:53 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
|
2011-07-17 10:54:31 +00:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.id = AV_CODEC_ID_MPEG4,
|
2011-07-17 10:54:31 +00:00
|
|
|
.priv_data_size = sizeof(MpegEncContext),
|
|
|
|
.init = encode_init,
|
2014-08-10 15:25:12 +00:00
|
|
|
.encode2 = ff_mpv_encode_picture,
|
|
|
|
.close = ff_mpv_encode_end,
|
2013-10-28 17:30:01 +00:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
|
2015-07-07 00:41:27 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
|
2011-08-27 08:16:14 +00:00
|
|
|
.priv_class = &mpeg4enc_class,
|
2010-01-07 23:53:49 +00:00
|
|
|
};
|