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 */) {
137 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
138 if (avctx->
flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)
140 if (avctx->
flags & CODEC_FLAG_SVCD_SCAN_OFFSET)
164 else avctx->
level = 2;
167 av_log(avctx,
AV_LOG_ERROR,
"Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
171 else if(avctx->
width <= 1440) avctx->
level = 6;
172 else avctx->
level = 4;
177 av_log(avctx,
AV_LOG_ERROR,
"Drop frame time code only allowed with 1001/30000 fps\n");
194 unsigned int vbv_buffer_size;
198 float best_aspect_error= 1E10;
200 int constraint_parameter_flag;
202 if(aspect_ratio==0.0) aspect_ratio= 1.0;
214 float error= aspect_ratio;
222 if(error < best_aspect_error){
223 best_aspect_error= error;
243 vbv_buffer_size = (( 20 * s->
bit_rate) / (1151929 / 2)) * 8 * 1024;
244 vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
250 constraint_parameter_flag=
254 framerate.
num <= framerate.
den*30 &&
256 vbv_buffer_size <= 20 &&
260 put_bits(&s->
pb, 1, constraint_parameter_flag);
290 fps = (framerate.
num + framerate.
den/2)/ framerate.
den;
296 int d = time_code / 17982;
297 int m = time_code % 17982;
299 time_code += 18 * d + 2 * ((m - 2) / 1798);
301 put_bits(&s->
pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
302 put_bits(&s->
pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
304 put_bits(&s->
pb, 6, (uint32_t)((time_code / fps) % 60));
305 put_bits(&s->
pb, 6, (uint32_t)((time_code % fps)));
431 int has_mv,
int field_motion)
443 int motion_x,
int motion_y,
447 const int mb_x = s->
mb_x;
448 const int mb_y = s->
mb_y;
453 for(i=0;i<mb_block_count;i++) {
455 cbp |= 1 << (mb_block_count - 1 - i);
504 if ((motion_x|motion_y) == 0) {
653 for(i=0;i<mb_block_count;i++) {
654 if (cbp & (1 << (mb_block_count - 1 - i))) {
681 int code, sign,
bits;
682 int bit_size = f_or_b_code - 1;
683 int range = 1 << bit_size;
689 code = (val >> bit_size) + 1;
690 bits = val & (range - 1);
695 code = (val >> bit_size) + 1;
696 bits = val & (range - 1);
700 assert(code > 0 && code <= 16);
739 for(i=-255; i<256; i++)
747 index = av_log2(2*adiff);
758 for(f_code=1; f_code<=
MAX_FCODE; f_code++){
764 int val, bit_size, code;
766 bit_size = f_code - 1;
772 code = (val >> bit_size) + 1;
785 for(f_code=
MAX_FCODE; f_code>0; f_code--){
786 for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
813 if(((
unsigned) (diff+255)) >= 511){
817 index= av_log2_16bit(-2*diff);
820 index= av_log2_16bit(2*diff);
822 if (component == 0) {
834 if (component == 0) {
852 int alevel,
level, last_non_zero, dc, diff, i, j,
run, last_index, sign;
860 component = (n <= 3 ? 0 : (n&1) + 1);
862 diff = dc - s->
last_dc[component];
872 if (abs(level) == 1) {
873 code = ((uint32_t)level >> 31);
884 last_non_zero = i - 1;
886 for(;i<=last_index;i++) {
892 run = i - last_non_zero - 1;
901 put_bits(&s->
pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
904 put_bits(&s->
pb, table_vlc[111][1], table_vlc[111][0]);
925 put_bits(&s->
pb, table_vlc[112][1], table_vlc[112][0]);
928 #define OFFSET(x) offsetof(MpegEncContext, x)
929 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
931 { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },\
932 { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, \
933 { "scan_offset", "Reserve space for SVCD scan offset user data.", OFFSET(scan_offset), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
947 #define mpeg12_class(x)\
948 static const AVClass mpeg## x ##_class = {\
949 .class_name = "mpeg" #x "video encoder",\
950 .item_name = av_default_item_name,\
951 .option = mpeg## x ##_options,\
952 .version = LIBAVUTIL_VERSION_INT,\
958 AVCodec ff_mpeg1video_encoder = {
959 .
name =
"mpeg1video",
970 .priv_class = &mpeg1_class,
974 .
name =
"mpeg2video",
985 .priv_class = &mpeg2_class,
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static uint8_t uni_mpeg1_ac_vlc_len[64 *64 *2]
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
AVCodec ff_mpeg2video_encoder
struct MpegEncContext MpegEncContext
MpegEncContext.
uint8_t * fcode_tab
smallest fcode needed for each MV
#define MV_TYPE_FIELD
2 vectors, one per field
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG1 & B-frame MPEG4
static const uint8_t inv_non_linear_qscale[13]
static int find_frame_rate_index(MpegEncContext *s)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
int MPV_encode_init(AVCodecContext *avctx)
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int scan_offset
reserve space for SVCD scan offset user data.
const AVRational avpriv_frame_rate_tab[16]
int min_qcoeff
minimum encodable coefficient
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
uint8_t * intra_ac_vlc_length
#define UNI_AC_ENC_INDEX(run, level)
#define SLICE_MIN_START_CODE
static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len)
static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y, int mb_block_count)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static uint32_t mpeg1_lum_dc_uni[512]
static void encode_mb_skip_run(MpegEncContext *s, int run)
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
const float ff_mpeg1_aspect[16]
int misc_bits
cbp, mb_type
static const AVOption mpeg1_options[]
Picture current_picture
copy of the current picture structure.
static double av_q2d(AVRational a)
Convert rational to double.
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
static int8_t mpeg1_max_level[2][64]
int8_t * max_level[2]
encoding & decoding
int mb_height
number of MBs horizontally & vertically
int max_qcoeff
maximum encodable coefficient
int dquant
qscale difference to prev qscale
int gop_picture_number
index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
static int init(AVCodecParserContext *s)
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
preferred ID for MPEG-1/2 video decoding
static int get_bits_diff(MpegEncContext *s)
int last_dc[3]
last DC values for MPEG1
static void put_mb_modes(MpegEncContext *s, int n, int bits, int has_mv, int field_motion)
uint8_t * inter_ac_vlc_last_length
int strict_std_compliance
strictly follow the std (MPEG4, ...)
int MPV_encode_end(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
static void encode_dc(MpegEncContext *s, int diff, int component)
int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
int rc_max_rate
maximum bitrate
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
int low_delay
no reordering needed / has no b-frames
static void mpeg1_encode_sequence_header(MpegEncContext *s)
static void mpeg1_encode_block(MpegEncContext *s, DCTELEM *block, int component)
static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
static int put_bits_count(PutBitContext *s)
void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
int resync_mb_x
x position of last resync marker
int rc_buffer_size
decoder bitstream buffer size
uint8_t * intra_ac_vlc_last_length
int64_t timecode_frame_start
GOP timecode frame start number, in non drop frame format.
uint8_t * vbv_delay_ptr
pointer to vbv_delay in the bitstream
const uint16_t(* table_vlc)[2]
static uint8_t fcode_tab[MAX_MV *2+1]
int width
picture width / height.
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
Picture * current_picture_ptr
pointer to the current picture
#define FF_PROFILE_UNKNOWN
static uint8_t uni_mpeg2_ac_vlc_len[64 *64 *2]
int block_last_index[12]
last non zero coefficient in block
static void put_header(MpegEncContext *s, int header)
#define MASK_ABS(mask, level)
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
static const int8_t mv[256][2]
#define MV_TYPE_16X16
1 vector for the whole mb
int coded_picture_number
picture number in bitstream order
int concealment_motion_vectors
main external API structure.
static void close(AVCodecParserContext *s)
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t * inter_ac_vlc_length
static uint8_t mpeg1_index_run[2][64]
uint16_t * intra_matrix
custom intra quantization matrix
rational number numerator/denominator
uint8_t * index_run[2]
encoding only
int f_code
forward MV resolution
uint16_t * inter_matrix
custom inter quantization matrix
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
int bit_rate
wanted bit rate
static av_const int sign_extend(int val, unsigned bits)
int last_mv_dir
last mv_dir, used for b frame encoding
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
static av_cold int encode_init(AVCodecContext *avctx)
struct AVCodecContext * avctx
#define CODEC_FLAG_CLOSED_GOP
PutBitContext pb
bit output
const AVRational ff_mpeg2_aspect[16]
static av_always_inline void put_qscale(MpegEncContext *s)
static uint32_t mpeg1_chr_dc_uni[512]
static const AVOption mpeg2_options[]
uint8_t ff_mpeg12_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
const uint8_t ff_mpeg12_mbPatTable[64][2]
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
int last_bits
temp var used for calculating the above vars
void ff_mpeg12_common_init(MpegEncContext *s)
int top_field_first
If the content is interlaced, is top field displayed first.
int drop_frame_timecode
timecode is in drop frame format.
int resync_mb_y
y position of last resync marker
static const uint8_t svcd_scan_offset_placeholder[14]
const uint8_t ff_mpeg12_mbAddrIncrTable[36][2]
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
int key_frame
1 -> keyframe, 0-> not
void ff_mpeg1_encode_init(MpegEncContext *s)
int flags
AVCodecContext.flags (HQ, MV4, ...)
const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]
#define PICTURE_START_CODE
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int b_code
backward MV resolution for B Frames (mpeg4)
int strict_std_compliance
strictly follow the standard (MPEG4, ...).