42 9,10,11,12,13,14,15,16,
79 for(run=0; run<64; run++){
82 int alevel=
FFABS(level);
89 if (code < 111 /* rl->n */) {
110 int64_t dmin= INT64_MAX;
157 else avctx->
level = 2;
160 av_log(avctx,
AV_LOG_ERROR,
"Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
164 else if(avctx->
width <= 1440) avctx->
level = 6;
165 else avctx->
level = 4;
170 av_log(avctx,
AV_LOG_ERROR,
"Drop frame time code only allowed with 1001/30000 fps\n");
187 unsigned int vbv_buffer_size;
191 float best_aspect_error= 1E10;
193 int constraint_parameter_flag;
195 if(aspect_ratio==0.0) aspect_ratio= 1.0;
207 float error= aspect_ratio;
215 if(error < best_aspect_error){
216 best_aspect_error= error;
236 vbv_buffer_size = (( 20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
237 vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
243 constraint_parameter_flag=
247 framerate.
num <= framerate.
den*30 &&
249 vbv_buffer_size <= 20 &&
253 put_bits(&s->
pb, 1, constraint_parameter_flag);
283 fps = (framerate.
num + framerate.
den/2)/ framerate.
den;
289 int d = time_code / 17982;
290 int m = time_code % 17982;
292 time_code += 18 * d + 2 * ((m - 2) / 1798);
294 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
295 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
297 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
298 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
424 int has_mv,
int field_motion)
436 int motion_x,
int motion_y,
440 const int mb_x = s->
mb_x;
441 const int mb_y = s->
mb_y;
446 for(i=0;i<mb_block_count;i++) {
448 cbp |= 1 << (mb_block_count - 1 - i);
497 if ((motion_x|motion_y) == 0) {
646 for(i=0;i<mb_block_count;i++) {
647 if (cbp & (1 << (mb_block_count - 1 - i))) {
674 int code, sign,
bits;
675 int bit_size = f_or_b_code - 1;
676 int range = 1 << bit_size;
682 code = (val >> bit_size) + 1;
683 bits = val & (range - 1);
688 code = (val >> bit_size) + 1;
689 bits = val & (range - 1);
693 assert(code > 0 && code <= 16);
732 for(i=-255; i<256; i++)
751 for(f_code=1; f_code<=
MAX_FCODE; f_code++){
757 int val, bit_size, code;
759 bit_size = f_code - 1;
765 code = (val >> bit_size) + 1;
778 for(f_code=
MAX_FCODE; f_code>0; f_code--){
779 for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
806 if(((
unsigned) (diff+255)) >= 511){
815 if (component == 0) {
827 if (component == 0) {
845 int alevel,
level, last_non_zero, dc, diff, i, j,
run, last_index, sign;
853 component = (n <= 3 ? 0 : (n&1) + 1);
855 diff = dc - s->
last_dc[component];
865 if (abs(level) == 1) {
866 code = ((uint32_t)level >> 31);
877 last_non_zero = i - 1;
879 for(;i<=last_index;i++) {
885 run = i - last_non_zero - 1;
894 put_bits(&s->
pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
897 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
918 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
921 #define OFFSET(x) offsetof(MpegEncContext, x)
922 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
924 { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },\
925 { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE}, \
926 { "scan_offset", "Reserve space for SVCD scan offset user data.", OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
936 {
"non_linear_quant",
"Use nonlinear quantizer.",
OFFSET(q_scale_type),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
937 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VE },
942 #define mpeg12_class(x)\
943 static const AVClass mpeg## x ##_class = {\
944 .class_name = "mpeg" #x "video encoder",\
945 .item_name = av_default_item_name,\
946 .option = mpeg## x ##_options,\
947 .version = LIBAVUTIL_VERSION_INT,\
953 AVCodec ff_mpeg1video_encoder = {
954 .
name =
"mpeg1video",
966 .priv_class = &mpeg1_class,
970 .
name =
"mpeg2video",
983 .priv_class = &mpeg2_class,