| @@ -71,6 +71,17 @@ static uint8_t uni_mpeg4_inter_rl_len[64 * 64 * 2 * 2]; · 70 unmodified lines |
| 71 | * max run: 29/41 | 71 | * max run: 29/41 |
| 72 | */ | 72 | */ |
| 73 | | 73 | |
| | 74 | typedef struct Mpeg4EncContext { |
| | 75 | MPVMainEncContext m; |
| | 76 | /// number of bits to represent the fractional part of time |
| | 77 | int time_increment_bits; |
| | 78 | } Mpeg4EncContext; |
| | 79 | |
| | 80 | static inline Mpeg4EncContext *mainctx_to_mpeg4(MPVMainEncContext *m) |
| | 81 | { |
| | 82 | return (Mpeg4EncContext*)m; |
| | 83 | } |
| | 84 | |
| 74 | /** | 85 | /** |
| 75 | * Return the number of bits that encoding the 8x8 block in block would need. | 86 | * Return the number of bits that encoding the 8x8 block in block would need. |
| 76 | * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. | 87 | * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. |
| @@ -960,10 +971,11 @@ static void mpeg4_encode_visual_object_header(MpegEncContext *s) · 883 unmodified lines |
| 960 | ff_mpeg4_stuffing(&s->pb); | 971 | ff_mpeg4_stuffing(&s->pb); |
| 961 | } | 972 | } |
| 962 | | 973 | |
| 963 | static void mpeg4_encode_vol_header(MpegEncContext *s, | 974 | static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4, |
| 964 | int vo_number, | 975 | int vo_number, |
| 965 | int vol_number) | 976 | int vol_number) |
| 966 | { | 977 | { |
| | 978 | MpegEncContext *const s = &m4->m.s; |
| 967 | int vo_ver_id, vo_type, aspect_ratio_info; | 979 | int vo_ver_id, vo_type, aspect_ratio_info; |
| 968 | | 980 | |
| 969 | if (s->max_b_frames || s->quarter_sample) { | 981 | if (s->max_b_frames || s->quarter_sample) { |
| @@ -1002,8 +1014,8 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 32 unmodified lines |
| 1002 | put_bits(&s->pb, 1, 1); /* marker bit */ | 1014 | put_bits(&s->pb, 1, 1); /* marker bit */ |
| 1003 | | 1015 | |
| 1004 | put_bits(&s->pb, 16, s->avctx->time_base.den); | 1016 | put_bits(&s->pb, 16, s->avctx->time_base.den); |
| 1005 | if (s->time_increment_bits < 1) | 1017 | if (m4->time_increment_bits < 1) |
| 1006 | s->time_increment_bits = 1; | 1018 | m4->time_increment_bits = 1; |
| 1007 | put_bits(&s->pb, 1, 1); /* marker bit */ | 1019 | put_bits(&s->pb, 1, 1); /* marker bit */ |
| 1008 | put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ | 1020 | put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ |
| 1009 | put_bits(&s->pb, 1, 1); /* marker bit */ | 1021 | put_bits(&s->pb, 1, 1); /* marker bit */ |
| @@ -1050,8 +1062,10 @@ static void mpeg4_encode_vol_header(MpegEncContext *s, · 40 unmodified lines |
| 1050 | } | 1062 | } |
| 1051 | | 1063 | |
| 1052 | /* write MPEG-4 VOP header */ | 1064 | /* write MPEG-4 VOP header */ |
| 1053 | int ff_mpeg4_encode_picture_header(MpegEncContext *s) | 1065 | int ff_mpeg4_encode_picture_header(MPVMainEncContext *const m) |
| 1054 | { | 1066 | { |
| | 1067 | Mpeg4EncContext *const m4 = mainctx_to_mpeg4(m); |
| | 1068 | MpegEncContext *const s = &m->s; |
| 1055 | uint64_t time_incr; | 1069 | uint64_t time_incr; |
| 1056 | int64_t time_div, time_mod; | 1070 | int64_t time_div, time_mod; |
| 1057 | | 1071 | |
| @@ -1060,7 +1074,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 2 unmodified lines |
| 1060 | if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy | 1074 | if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy |
| 1061 | mpeg4_encode_visual_object_header(s); | 1075 | mpeg4_encode_visual_object_header(s); |
| 1062 | if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy | 1076 | if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy |
| 1063 | mpeg4_encode_vol_header(s, 0, 0); | 1077 | mpeg4_encode_vol_header(m4, 0, 0); |
| 1064 | } | 1078 | } |
| 1065 | mpeg4_encode_gop_header(s); | 1079 | mpeg4_encode_gop_header(s); |
| 1066 | } | 1080 | } |
| @@ -1085,7 +1099,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 18 unmodified lines |
| 1085 | put_bits(&s->pb, 1, 0); | 1099 | put_bits(&s->pb, 1, 0); |
| 1086 | | 1100 | |
| 1087 | put_bits(&s->pb, 1, 1); /* marker */ | 1101 | put_bits(&s->pb, 1, 1); /* marker */ |
| 1088 | put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ | 1102 | put_bits(&s->pb, m4->time_increment_bits, time_mod); /* time increment */ |
| 1089 | put_bits(&s->pb, 1, 1); /* marker */ | 1103 | put_bits(&s->pb, 1, 1); /* marker */ |
| 1090 | put_bits(&s->pb, 1, 1); /* vop coded */ | 1104 | put_bits(&s->pb, 1, 1); /* vop coded */ |
| 1091 | if (s->pict_type == AV_PICTURE_TYPE_P) { | 1105 | if (s->pict_type == AV_PICTURE_TYPE_P) { |
| @@ -1276,7 +1290,8 @@ static av_cold void mpeg4_encode_init_static(void) · 184 unmodified lines |
| 1276 | static av_cold int encode_init(AVCodecContext *avctx) | 1290 | static av_cold int encode_init(AVCodecContext *avctx) |
| 1277 | { | 1291 | { |
| 1278 | static AVOnce init_static_once = AV_ONCE_INIT; | 1292 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 1279 | MpegEncContext *s = avctx->priv_data; | 1293 | Mpeg4EncContext *const m4 = avctx->priv_data; |
| | 1294 | MpegEncContext *const s = &m4->m.s; |
| 1280 | int ret; | 1295 | int ret; |
| 1281 | | 1296 | |
| 1282 | if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) { | 1297 | if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) { |
| @@ -1290,7 +1305,10 @@ static av_cold int encode_init(AVCodecContext *avctx) · 7 unmodified lines |
| 1290 | | 1305 | |
| 1291 | ff_thread_once(&init_static_once, mpeg4_encode_init_static); | 1306 | ff_thread_once(&init_static_once, mpeg4_encode_init_static); |
| 1292 | | 1307 | |
| | 1308 | m4->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1; |
| | 1309 | |
| 1293 | s->fcode_tab = fcode_tab + MAX_MV; | 1310 | s->fcode_tab = fcode_tab + MAX_MV; |
| | 1311 | |
| 1294 | s->min_qcoeff = -2048; | 1312 | s->min_qcoeff = -2048; |
| 1295 | s->max_qcoeff = 2047; | 1313 | s->max_qcoeff = 2047; |
| 1296 | s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; | 1314 | s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; |
| @@ -1309,7 +1327,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 12 unmodified lines |
| 1309 | init_put_bits(&s->pb, s->avctx->extradata, 1024); | 1327 | init_put_bits(&s->pb, s->avctx->extradata, 1024); |
| 1310 | | 1328 | |
| 1311 | mpeg4_encode_visual_object_header(s); | 1329 | mpeg4_encode_visual_object_header(s); |
| 1312 | mpeg4_encode_vol_header(s, 0, 0); | 1330 | mpeg4_encode_vol_header(m4, 0, 0); |
| 1313 | | 1331 | |
| 1314 | // ff_mpeg4_stuffing(&s->pb); ? | 1332 | // ff_mpeg4_stuffing(&s->pb); ? |
| 1315 | flush_put_bits(&s->pb); | 1333 | flush_put_bits(&s->pb); |
| @@ -1395,7 +1413,7 @@ const FFCodec ff_mpeg4_encoder = { · 79 unmodified lines |
| 1395 | CODEC_LONG_NAME("MPEG-4 part 2"), | 1413 | CODEC_LONG_NAME("MPEG-4 part 2"), |
| 1396 | .p.type = AVMEDIA_TYPE_VIDEO, | 1414 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 1397 | .p.id = AV_CODEC_ID_MPEG4, | 1415 | .p.id = AV_CODEC_ID_MPEG4, |
| 1398 | .priv_data_size = sizeof(MPVMainEncContext), | 1416 | .priv_data_size = sizeof(Mpeg4EncContext), |
| 1399 | .init = encode_init, | 1417 | .init = encode_init, |
| 1400 | FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), | 1418 | FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), |
| 1401 | .close = ff_mpv_encode_end, | 1419 | .close = ff_mpv_encode_end, |