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 if (((
unsigned) (diff + 255)) >= 511) {
622 (diff & ((1 << index) - 1)));
627 (diff & ((1 << index) - 1)));
642 int alevel,
level, last_non_zero,
dc, diff, i, j,
run, last_index, sign;
650 component = (n <= 3 ? 0 : (n & 1) + 1);
652 diff = dc - s->
last_dc[component];
662 if (abs(level) == 1) {
663 code = ((uint32_t)level >> 31);
674 last_non_zero = i - 1;
676 for (; i <= last_index; i++) {
683 run = i - last_non_zero - 1;
693 (table_vlc[code][0] << 1) + sign);
696 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
716 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
720 int16_t
block[8][64],
721 int motion_x,
int motion_y,
725 const int mb_x = s->
mb_x;
726 const int mb_y = s->
mb_y;
731 for (i = 0; i < mb_block_count; i++)
733 cbp |= 1 << (mb_block_count - 1 - i);
741 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
742 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
744 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
745 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
791 if ((motion_x | motion_y) == 0) {
811 motion_x - s->
last_mv[0][0][0],
815 motion_y - s->
last_mv[0][0][1],
826 motion_x - s->
last_mv[0][0][0],
830 motion_y - s->
last_mv[0][0][1],
853 for (i = 0; i < 2; i++) {
859 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
862 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
944 for (i = 0; i < 2; i++) {
950 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
953 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
958 for (i = 0; i < 2; i++) {
964 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
967 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
986 for (i = 0; i < mb_block_count; i++)
987 if (cbp & (1 << (mb_block_count - 1 - i)))
998 int motion_x,
int motion_y)
1008 static int done = 0;
1021 for (i = 0; i < 64; i++) {
1031 for (i = -255; i < 256; i++) {
1036 adiff =
FFABS(diff);
1043 (diff & ((1 << index) - 1));
1048 (diff & ((1 << index) - 1));
1052 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
1059 int val, bit_size, code;
1061 bit_size = f_code - 1;
1067 code = (val >> bit_size) + 1;
1080 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1081 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1104 #define OFFSET(x) offsetof(MpegEncContext, x)
1105 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1106 #define COMMON_OPTS \
1107 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format", \
1108 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
1109 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1110 OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1111 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1112 OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1113 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1114 OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1124 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1125 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1126 {
"seq_disp_ext",
"Write sequence_display_extension blocks.",
OFFSET(seq_disp_ext),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE,
"seq_disp_ext" },
1134 #define mpeg12_class(x) \
1135 static const AVClass mpeg ## x ## _class = { \
1136 .class_name = "mpeg" # x "video encoder", \
1137 .item_name = av_default_item_name, \
1138 .option = mpeg ## x ## _options, \
1139 .version = LIBAVUTIL_VERSION_INT, \
1145 AVCodec ff_mpeg1video_encoder = {
1146 .
name =
"mpeg1video",
1158 .priv_class = &mpeg1_class,
1162 .
name =
"mpeg2video",
1175 .priv_class = &mpeg2_class,