42 0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
46 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80,
47 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
68 for (i = 0; i < 128; i++) {
73 for (run = 0; run < 64; run++) {
75 int alevel =
FFABS(level);
106 for (i = 1; i < 14; i++) {
111 for (ext.
num=1; ext.
num <= 4; ext.
num++) {
112 for (ext.
den=1; ext.
den <= 32; ext.
den++) {
155 "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n",
178 "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
183 else if (avctx->
width <= 1440)
190 if ((avctx->
width & 0xFFF) == 0 && (avctx->
height & 0xFFF) == 1) {
196 if ((avctx->
width & 0xFFF) == 0 || (avctx->
height & 0xFFF) == 0) {
197 av_log(avctx,
AV_LOG_ERROR,
"Width or Height are not allowed to be multiplies of 4096\n"
208 "Drop frame time code only allowed with 1001/30000 fps\n");
235 unsigned int vbv_buffer_size, fps,
v;
236 int i, constraint_parameter_flag;
238 float best_aspect_error = 1E10;
241 if (aspect_ratio == 0.0)
253 for (i = 1; i < 15; i++) {
254 float error = aspect_ratio;
260 error =
FFABS(error);
262 if (error < best_aspect_error) {
263 best_aspect_error = error;
284 vbv_buffer_size = ((20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
285 vbv_buffer_size = (vbv_buffer_size + 16383) / 16384;
291 constraint_parameter_flag =
296 framerate.
num <= framerate.
den * 30 &&
299 vbv_buffer_size <= 20 &&
300 v <= 1856000 / 400 &&
303 put_bits(&s->
pb, 1, constraint_parameter_flag);
333 fps = (framerate.
num + framerate.
den / 2) / framerate.
den;
343 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
344 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
346 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
347 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
478 int has_mv,
int field_motion)
498 int code, sign,
bits;
499 int bit_size = f_or_b_code - 1;
500 int range = 1 << bit_size;
506 code = (val >> bit_size) + 1;
507 bits = val & (range - 1);
512 code = (val >> bit_size) + 1;
513 bits = val & (range - 1);
531 if (((
unsigned) (diff + 255)) >= 511) {
544 (diff & ((1 << index) - 1)));
549 (diff & ((1 << index) - 1)));
564 int alevel,
level, last_non_zero,
dc, diff, i, j,
run, last_index, sign;
572 component = (n <= 3 ? 0 : (n & 1) + 1);
574 diff = dc - s->
last_dc[component];
584 if (abs(level) == 1) {
585 code = ((uint32_t)level >> 31);
596 last_non_zero = i - 1;
598 for (; i <= last_index; i++) {
605 run = i - last_non_zero - 1;
615 (table_vlc[code][0] << 1) + sign);
618 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
638 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
642 int16_t
block[6][64],
643 int motion_x,
int motion_y,
647 const int mb_x = s->
mb_x;
648 const int mb_y = s->
mb_y;
653 for (i = 0; i < mb_block_count; i++)
655 cbp |= 1 << (mb_block_count - 1 - i);
663 ? ((s->
mv[0][0][0] - s->
last_mv[0][0][0]) |
664 (s->
mv[0][0][1] - s->
last_mv[0][0][1])) : 0) |
666 ? ((s->
mv[1][0][0] - s->
last_mv[1][0][0]) |
667 (s->
mv[1][0][1] - s->
last_mv[1][0][1])) : 0)) == 0))) {
713 if ((motion_x | motion_y) == 0) {
733 motion_x - s->
last_mv[0][0][0],
737 motion_y - s->
last_mv[0][0][1],
748 motion_x - s->
last_mv[0][0][0],
752 motion_y - s->
last_mv[0][0][1],
775 for (i = 0; i < 2; i++) {
781 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
784 s->
last_mv[0][i][1] = 2 * s->
mv[0][i][1];
866 for (i = 0; i < 2; i++) {
872 s->
mv[0][i][1] - (s->
last_mv[0][i][1] >> 1),
875 s->
last_mv[0][i][1] = s->
mv[0][i][1] * 2;
880 for (i = 0; i < 2; i++) {
886 s->
mv[1][i][1] - (s->
last_mv[1][i][1] >> 1),
889 s->
last_mv[1][i][1] = s->
mv[1][i][1] * 2;
908 for (i = 0; i < mb_block_count; i++)
909 if (cbp & (1 << (mb_block_count - 1 - i)))
920 int motion_x,
int motion_y)
943 for (i = 0; i < 64; i++) {
953 for (i = -255; i < 256; i++) {
965 (diff & ((1 << index) - 1));
970 (diff & ((1 << index) - 1));
974 for (f_code = 1; f_code <=
MAX_FCODE; f_code++)
981 int val, bit_size, code;
983 bit_size = f_code - 1;
989 code = (val >> bit_size) + 1;
1002 for (f_code =
MAX_FCODE; f_code > 0; f_code--)
1003 for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
1026 #define OFFSET(x) offsetof(MpegEncContext, x)
1027 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
1028 #define COMMON_OPTS \
1029 { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format", \
1030 OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
1031 { "intra_vlc", "Use MPEG-2 intra VLC table.", \
1032 OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1033 { "drop_frame_timecode", "Timecode is in drop frame format.", \
1034 OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
1035 { "scan_offset", "Reserve space for SVCD scan offset user data.", \
1036 OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1046 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1047 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
1052 #define mpeg12_class(x) \
1053 static const AVClass mpeg ## x ## _class = { \
1054 .class_name = "mpeg" # x "video encoder", \
1055 .item_name = av_default_item_name, \
1056 .option = mpeg ## x ## _options, \
1057 .version = LIBAVUTIL_VERSION_INT, \
1063 AVCodec ff_mpeg1video_encoder = {
1064 .
name =
"mpeg1video",
1076 .priv_class = &mpeg1_class,
1080 .
name =
"mpeg2video",
1093 .priv_class = &mpeg2_class,