44 0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
48 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
49 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70 for (i = 0; i < 128; i++) {
75 for (run = 0; run < 64; run++) {
77 int alevel =
FFABS(level);
104 int64_t dmin = INT64_MAX;
107 for (i = 1; i < 14; i++) {
143 "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n",
166 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
171 else if (avctx->
width <= 1440)
180 "Drop frame time code only allowed with 1001/30000 fps\n");
197 unsigned int vbv_buffer_size, fps, v;
198 int i, constraint_parameter_flag;
200 float best_aspect_error = 1E10;
203 if (aspect_ratio == 0.0)
215 for (i = 1; i < 15; i++) {
216 float error = aspect_ratio;
222 error =
FFABS(error);
224 if (error < best_aspect_error) {
225 best_aspect_error = error;
246 vbv_buffer_size = ((20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
247 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
253 constraint_parameter_flag =
258 framerate.
num <= framerate.
den * 30 &&
261 vbv_buffer_size <= 20 &&
262 v <= 1856000 / 400 &&
265 put_bits(&s->
pb, 1, constraint_parameter_flag);
295 fps = (framerate.
num + framerate.
den / 2) / framerate.
den;
302 int d = time_code / 17982;
303 int m = time_code % 17982;
307 time_code += 18 * d + 2 * ((m - 2) / 1798);
309 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
310 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
312 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
313 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
445 switch (stereo->
type) {
483 int has_mv,
int field_motion)
503 int code, sign,
bits;
504 int bit_size = f_or_b_code - 1;
505 int range = 1 << bit_size;
511 code = (val >> bit_size) + 1;
512 bits = val & (range - 1);
517 code = (val >> bit_size) + 1;
518 bits = val & (range - 1);
522 assert(code > 0 && code <= 16);
536 if (((
unsigned) (diff + 255)) >= 511) {
549 (diff & ((1 << index) - 1)));
554 (diff & ((1 << index) - 1)));
569 int alevel,
level, last_non_zero,
dc, diff, i, j,
run, last_index, sign;
577 component = (n <= 3 ? 0 : (n & 1) + 1);
579 diff = dc - s->
last_dc[component];
589 if (abs(level) == 1) {
590 code = ((uint32_t)level >> 31);
601 last_non_zero = i - 1;
603 for (; i <= last_index; i++) {
610 run = i - last_non_zero - 1;
620 (table_vlc[code][0] << 1) + sign);
623 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
643 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
647 int16_t
block[6][64],
648 int motion_x,
int motion_y,
652 const int mb_x = s->
mb_x;
653 const int mb_y = s->
mb_y;
658 for (i = 0; i < mb_block_count; i++)
660 cbp |= 1 << (mb_block_count - 1 - i);
668 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
669 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
671 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
672 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
718 if ((motion_x | motion_y) == 0) {
738 motion_x - s->
last_mv[0][0][0],
742 motion_y - s->
last_mv[0][0][1],
753 motion_x - s->
last_mv[0][0][0],
757 motion_y - s->
last_mv[0][0][1],
780 for (i = 0; i < 2; i++) {
786 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
789 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
871 for (i = 0; i < 2; i++) {
877 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
880 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
885 for (i = 0; i < 2; i++) {
891 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
894 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
913 for (i = 0; i < mb_block_count; i++)
914 if (cbp & (1 << (mb_block_count - 1 - i)))
925 int motion_x,
int motion_y)
948 for (i = 0; i < 64; i++) {
958 for (i = -255; i < 256; i++) {
970 (diff & ((1 << index) - 1));
975 (diff & ((1 << index) - 1));
979 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
986 int val, bit_size, code;
988 bit_size = f_code - 1;
994 code = (val >> bit_size) + 1;
1007 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1008 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1031 #define OFFSET(x) offsetof(MpegEncContext, x)
1032 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1033 #define COMMON_OPTS \
1034 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1035 OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1036 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1037 OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1038 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1039 OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1049 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1050 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1055 #define mpeg12_class(x) \
1056 static const AVClass mpeg ## x ## _class = { \
1057 .class_name = "mpeg" # x "video encoder", \
1058 .item_name = av_default_item_name, \
1059 .option = mpeg ## x ## _options, \
1060 .version = LIBAVUTIL_VERSION_INT, \
1066 AVCodec ff_mpeg1video_encoder = {
1067 .
name =
"mpeg1video",
1079 .priv_class = &mpeg1_class,
1083 .
name =
"mpeg2video",
1096 .priv_class = &mpeg2_class,