46 0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
50 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
51 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
72 for (i = 0; i < 128; i++) {
77 for (run = 0; run < 64; run++) {
79 int alevel =
FFABS(level);
110 for (i = 1; i < 14; i++) {
115 for (ext.
num=1; ext.
num <= 4; ext.
num++) {
116 for (ext.
den=1; ext.
den <= 32; ext.
den++) {
159 "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n",
182 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
187 else if (avctx->
width <= 1440)
194 if ((avctx->
width & 0xFFF) == 0 && (avctx->
height & 0xFFF) == 1) {
200 if ((avctx->
width & 0xFFF) == 0 || (avctx->
height & 0xFFF) == 0) {
201 av_log(avctx,
AV_LOG_ERROR,
"Width or Height are not allowed to be multiplies of 4096\n"
212 "Drop frame time code only allowed with 1001/30000 fps\n");
239 unsigned int vbv_buffer_size, fps,
v;
240 int i, constraint_parameter_flag;
242 float best_aspect_error = 1E10;
245 if (aspect_ratio == 0.0)
257 for (i = 1; i < 15; i++) {
258 float error = aspect_ratio;
264 error =
FFABS(error);
266 if (error < best_aspect_error) {
267 best_aspect_error = error;
288 vbv_buffer_size = ((20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
289 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
295 constraint_parameter_flag =
300 framerate.
num <= framerate.
den * 30 &&
303 vbv_buffer_size <= 20 &&
304 v <= 1856000 / 400 &&
307 put_bits(&s->
pb, 1, constraint_parameter_flag);
337 fps = (framerate.
num + framerate.
den / 2) / framerate.
den;
347 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
348 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
350 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
351 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
483 switch (stereo->
type) {
521 int has_mv,
int field_motion)
541 int code, sign,
bits;
542 int bit_size = f_or_b_code - 1;
543 int range = 1 << bit_size;
549 code = (val >> bit_size) + 1;
550 bits = val & (range - 1);
555 code = (val >> bit_size) + 1;
556 bits = val & (range - 1);
574 if (((
unsigned) (diff + 255)) >= 511) {
587 (diff & ((1 << index) - 1)));
592 (diff & ((1 << index) - 1)));
607 int alevel,
level, last_non_zero,
dc, diff, i, j,
run, last_index, sign;
615 component = (n <= 3 ? 0 : (n & 1) + 1);
617 diff = dc - s->
last_dc[component];
627 if (abs(level) == 1) {
628 code = ((uint32_t)level >> 31);
639 last_non_zero = i - 1;
641 for (; i <= last_index; i++) {
648 run = i - last_non_zero - 1;
658 (table_vlc[code][0] << 1) + sign);
661 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
681 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
685 int16_t
block[6][64],
686 int motion_x,
int motion_y,
690 const int mb_x = s->
mb_x;
691 const int mb_y = s->
mb_y;
696 for (i = 0; i < mb_block_count; i++)
698 cbp |= 1 << (mb_block_count - 1 - i);
706 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
707 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
709 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
710 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
756 if ((motion_x | motion_y) == 0) {
776 motion_x - s->
last_mv[0][0][0],
780 motion_y - s->
last_mv[0][0][1],
791 motion_x - s->
last_mv[0][0][0],
795 motion_y - s->
last_mv[0][0][1],
818 for (i = 0; i < 2; i++) {
824 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
827 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
909 for (i = 0; i < 2; i++) {
915 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
918 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
923 for (i = 0; i < 2; i++) {
929 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
932 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
951 for (i = 0; i < mb_block_count; i++)
952 if (cbp & (1 << (mb_block_count - 1 - i)))
963 int motion_x,
int motion_y)
986 for (i = 0; i < 64; i++) {
996 for (i = -255; i < 256; i++) {
1001 adiff =
FFABS(diff);
1008 (diff & ((1 << index) - 1));
1013 (diff & ((1 << index) - 1));
1017 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
1024 int val, bit_size, code;
1026 bit_size = f_code - 1;
1032 code = (val >> bit_size) + 1;
1045 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1046 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1069 #define OFFSET(x) offsetof(MpegEncContext, x)
1070 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1071 #define COMMON_OPTS \
1072 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format", \
1073 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
1074 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1075 OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1076 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1077 OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1078 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1079 OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1089 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1090 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1095 #define mpeg12_class(x) \
1096 static const AVClass mpeg ## x ## _class = { \
1097 .class_name = "mpeg" # x "video encoder", \
1098 .item_name = av_default_item_name, \
1099 .option = mpeg ## x ## _options, \
1100 .version = LIBAVUTIL_VERSION_INT, \
1106 AVCodec ff_mpeg1video_encoder = {
1107 .
name =
"mpeg1video",
1119 .priv_class = &mpeg1_class,
1123 .
name =
"mpeg2video",
1136 .priv_class = &mpeg2_class,