#include "libavutil/attributes.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
+#include "libavutil/thread.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "h263.h"
#include "mpeg4video.h"
+#include "profiles.h"
/* The uni_DCtab_* tables below contain unified bits+length tables to encode DC
* differences in MPEG-4. Unified in the sense that the specification specifies
memcpy(s->block_last_index, zigzag_last_index, sizeof(int) * 6);
for (n = 0; n < 6; n++) {
- int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ int16_t *ac_val = &s->ac_val[0][0][0] + s->block_index[n] * 16;
st[n] = s->intra_scantable.permutated;
if (dir[n]) {
score -= get_block_rate(s, block[n], s->block_last_index[n],
s->intra_scantable.permutated);
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val = &s->ac_val[0][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;
{
int vo_ver_id;
- if (!CONFIG_MPEG4_ENCODER)
- return;
-
if (s->max_b_frames || s->quarter_sample) {
vo_ver_id = 5;
s->vo_type = ADV_SIMPLE_VO_TYPE;
if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT)) {
put_bits(&s->pb, 16, 0);
put_bits(&s->pb, 16, 0x1B2); /* user_data */
- avpriv_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
+ ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
}
}
}
}
+static av_cold void mpeg4_encode_init_static(void)
+{
+ init_uni_dc_tab();
+
+ ff_mpeg4_init_rl_intra();
+
+ init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
+ init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
+}
+
static av_cold int encode_init(AVCodecContext *avctx)
{
+ static AVOnce init_static_once = AV_ONCE_INIT;
MpegEncContext *s = avctx->priv_data;
int ret;
- static int done = 0;
if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
av_log(avctx, AV_LOG_ERROR, "dimensions too large for MPEG-4\n");
if ((ret = ff_mpv_encode_init(avctx)) < 0)
return ret;
- if (!done) {
- done = 1;
-
- init_uni_dc_tab();
-
- ff_rl_init(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
-
- init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
- init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
- }
+ ff_thread_once(&init_static_once, mpeg4_encode_init_static);
s->min_qcoeff = -2048;
s->max_qcoeff = 2047;
if (s->avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
s->avctx->extradata = av_malloc(1024);
+ if (!s->avctx->extradata)
+ return AVERROR(ENOMEM);
init_put_bits(&s->pb, s->avctx->extradata, 1024);
if (!(s->workaround_bugs & FF_BUG_MS))
// ff_mpeg4_stuffing(&s->pb); ?
flush_put_bits(&s->pb);
- s->avctx->extradata_size = (put_bits_count(&s->pb) + 7) >> 3;
+ s->avctx->extradata_size = put_bytes_output(&s->pb);
}
return 0;
}
flush_put_bits(&s->tex_pb);
set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
- avpriv_copy_bits(&s->pb, s->pb2.buf, pb2_len);
- avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
+ ff_copy_bits(&s->pb, s->pb2.buf, pb2_len);
+ ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
s->last_bits = put_bits_count(&s->pb);
}
static const AVOption options[] = {
{ "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "mpeg_quant", "Use MPEG quantizers instead of H.263",
+ OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, VE },
+ FF_MPV_COMMON_BFRAME_OPTS
FF_MPV_COMMON_OPTS
+#if FF_API_MPEGVIDEO_OPTS
+ FF_MPV_DEPRECATED_A53_CC_OPT
+ FF_MPV_DEPRECATED_MATRIX_OPT
+#endif
+ FF_MPEG4_PROFILE_OPTS
{ NULL },
};
.version = LIBAVUTIL_VERSION_INT,
};
-AVCodec ff_mpeg4_encoder = {
+const AVCodec ff_mpeg4_encoder = {
.name = "mpeg4",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
.type = AVMEDIA_TYPE_VIDEO,
.close = ff_mpv_encode_end,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
.priv_class = &mpeg4enc_class,
};