47 0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
51 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
52 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73 for (i = 0; i < 128; i++) {
78 for (run = 0; run < 64; run++) {
80 int alevel =
FFABS(level);
111 for (i = 1; i < 14; i++) {
116 for (ext.
num=1; ext.
num <= 4; ext.
num++) {
117 for (ext.
den=1; ext.
den <= 32; ext.
den++) {
160 "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n",
183 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
188 else if (avctx->
width <= 1440)
195 if ((avctx->
width & 0xFFF) == 0 && (avctx->
height & 0xFFF) == 1) {
201 if ((avctx->
width & 0xFFF) == 0 || (avctx->
height & 0xFFF) == 0) {
202 av_log(avctx,
AV_LOG_ERROR,
"Width or Height are not allowed to be multiples of 4096\n"
213 "Drop frame time code only allowed with 1001/30000 fps\n");
240 unsigned int vbv_buffer_size, fps,
v;
241 int i, constraint_parameter_flag;
243 int64_t best_aspect_error = INT64_MAX;
246 if (aspect_ratio.
num == 0 || aspect_ratio.
den == 0)
258 for (i = 1; i < 15; i++) {
259 int64_t error = aspect_ratio.
num * (1LL<<32) / aspect_ratio.
den;
265 error =
FFABS(error);
267 if (error - 2 <= best_aspect_error) {
268 best_aspect_error = error;
289 vbv_buffer_size = ((20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
290 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
296 constraint_parameter_flag =
301 framerate.
num <= framerate.
den * 30 &&
304 vbv_buffer_size <= 20 &&
305 v <= 1856000 / 400 &&
308 put_bits(&s->
pb, 1, constraint_parameter_flag);
317 int use_seq_disp_ext;
342 width = pan_scan->
width >> 4;
343 height = pan_scan->
height >> 4;
347 use_seq_disp_ext = (width != s->
width ||
372 fps = (framerate.
num + framerate.
den / 2) / framerate.
den;
382 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
383 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
385 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
386 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
518 switch (stereo->
type) {
556 int has_mv,
int field_motion)
576 int code, sign,
bits;
577 int bit_size = f_or_b_code - 1;
578 int range = 1 << bit_size;
584 code = (val >> bit_size) + 1;
585 bits = val & (range - 1);
590 code = (val >> bit_size) + 1;
591 bits = val & (range - 1);
609 unsigned int diff_u = diff + 255;
623 (diff & ((1 << index) - 1)));
628 (diff & ((1 << index) - 1)));
643 int alevel,
level, last_non_zero,
dc,
diff, i, j,
run, last_index, sign;
651 component = (n <= 3 ? 0 : (n & 1) + 1);
653 diff = dc - s->
last_dc[component];
663 if (abs(level) == 1) {
664 code = ((uint32_t)level >> 31);
675 last_non_zero = i - 1;
677 for (; i <= last_index; i++) {
684 run = i - last_non_zero - 1;
694 (table_vlc[code][0] << 1) + sign);
697 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
717 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
721 int16_t
block[8][64],
722 int motion_x,
int motion_y,
726 const int mb_x = s->
mb_x;
727 const int mb_y = s->
mb_y;
732 for (i = 0; i < mb_block_count; i++)
734 cbp |= 1 << (mb_block_count - 1 - i);
742 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
743 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
745 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
746 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
792 if ((motion_x | motion_y) == 0) {
812 motion_x - s->
last_mv[0][0][0],
816 motion_y - s->
last_mv[0][0][1],
827 motion_x - s->
last_mv[0][0][0],
831 motion_y - s->
last_mv[0][0][1],
854 for (i = 0; i < 2; i++) {
860 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
863 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
945 for (i = 0; i < 2; i++) {
951 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
954 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
959 for (i = 0; i < 2; i++) {
965 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
968 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
987 for (i = 0; i < mb_block_count; i++)
988 if (cbp & (1 << (mb_block_count - 1 - i)))
999 int motion_x,
int motion_y)
1009 static int done = 0;
1022 for (i = 0; i < 64; i++) {
1032 for (i = -255; i < 256; i++) {
1037 adiff =
FFABS(diff);
1044 (diff & ((1 << index) - 1));
1049 (diff & ((1 << index) - 1));
1053 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
1060 int val, bit_size, code;
1062 bit_size = f_code - 1;
1068 code = (val >> bit_size) + 1;
1081 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1082 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1105 #define OFFSET(x) offsetof(MpegEncContext, x)
1106 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1107 #define COMMON_OPTS \
1108 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format", \
1109 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
1110 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1111 OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1112 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1113 OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1114 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1115 OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1125 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1126 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1127 {
"seq_disp_ext",
"Write sequence_display_extension blocks.",
OFFSET(seq_disp_ext),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE,
"seq_disp_ext" },
1135 #define mpeg12_class(x) \
1136 static const AVClass mpeg ## x ## _class = { \
1137 .class_name = "mpeg" # x "video encoder", \
1138 .item_name = av_default_item_name, \
1139 .option = mpeg ## x ## _options, \
1140 .version = LIBAVUTIL_VERSION_INT, \
1146 AVCodec ff_mpeg1video_encoder = {
1147 .
name =
"mpeg1video",
1159 .priv_class = &mpeg1_class,
1163 .
name =
"mpeg2video",
1176 .priv_class = &mpeg2_class,