| 1223 | } |
| 1224 | |
| 1225 | static av_cold int encode_init(AVCodecContext *avctx) |
| 1226 | { |
| 1227 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 1228 | Mpeg4EncContext *const m4 = avctx->priv_data; |
| 1229 | MPVMainEncContext *const m = &m4->m; |
| 1230 | MPVEncContext *const s = &m->s; |
| 1231 | int ret; |
| 1232 | |
| 1233 | if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) { |
| 1234 | av_log(avctx, AV_LOG_ERROR, "dimensions too large for MPEG-4\n"); |
| 1235 | return AVERROR(EINVAL); |
| 1236 | } |
| 1237 | |
| 1238 | m->encode_picture_header = mpeg4_encode_picture_header; |
| 1239 | s->encode_mb = mpeg4_encode_mb; |
| 1240 | |
| 1241 | m->fcode_tab = fcode_tab + MAX_MV; |
| 1242 | |
| 1243 | s->min_qcoeff = -2048; |
| 1244 | s->max_qcoeff = 2047; |
| 1245 | s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; |
| 1246 | s->intra_ac_vlc_last_length = uni_mpeg4_intra_rl_len + 128 * 64; |
| 1247 | s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len; |
| 1248 | s->inter_ac_vlc_last_length = uni_mpeg4_inter_rl_len + 128 * 64; |
| 1249 | s->luma_dc_vlc_length = uni_DCtab_lum_len; |
| 1250 | s->ac_esc_length = 7 + 2 + 1 + 6 + 1 + 12 + 1; |
| 1251 | s->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table; |
| 1252 | s->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table; |
| 1253 | |
| 1254 | ff_qpeldsp_init(&s->c.qdsp); |
| 1255 | if ((ret = ff_mpv_encode_init(avctx)) < 0) |
| 1256 | return ret; |
| 1257 | |
| 1258 | ff_thread_once(&init_static_once, mpeg4_encode_init_static); |
| 1259 | |
| 1260 | if (avctx->time_base.den > (1 << 16) - 1) { |
| 1261 | av_log(avctx, AV_LOG_ERROR, |
| 1262 | "timebase %d/%d not supported by MPEG 4 standard, " |
| 1263 | "the maximum admitted value for the timebase denominator " |
| 1264 | "is %d\n", avctx->time_base.num, avctx->time_base.den, |
| 1265 | (1 << 16) - 1); |
| 1266 | return AVERROR(EINVAL); |
| 1267 | } |
| 1268 | |
| 1269 | m4->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1; |
| 1270 | |
| 1271 | if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { |
| 1272 | avctx->extradata = av_malloc(1024); |
| 1273 | if (!avctx->extradata) |
| 1274 | return AVERROR(ENOMEM); |
| 1275 | init_put_bits(&s->pb, avctx->extradata, 1024); |
| 1276 | |
| 1277 | mpeg4_encode_visual_object_header(m); |
| 1278 | mpeg4_encode_vol_header(m4, 0, 0); |
| 1279 | |
| 1280 | // ff_mpeg4_stuffing(&s->pb); ? |
| 1281 | flush_put_bits(&s->pb); |
| 1282 | avctx->extradata_size = put_bytes_output(&s->pb); |
nothing calls this directly
no test coverage detected