Commit 3ada94ba authored by Benoit Fouet's avatar Benoit Fouet
Browse files

Description: split mpegvideo.c

Originally committed as revision 9467 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 82634fee
......@@ -67,6 +67,7 @@ OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o
OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o
OBJS-$(CONFIG_DXA_DECODER) += dxa.o
OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o
OBJS-$(CONFIG_ENCODERS) += mpegvideo_enc.o
OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o golomb.o
OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o
OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o
......
......@@ -30,6 +30,7 @@
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "mpegvideo_common.h"
#include "mjpegenc.h"
#include "msmpeg4.h"
#include "faandct.h"
......@@ -38,9 +39,6 @@
//#undef NDEBUG
//#include <assert.h>
#ifdef CONFIG_ENCODERS
static int encode_picture(MpegEncContext *s, int picture_number);
#endif //CONFIG_ENCODERS
static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s,
......@@ -56,13 +54,6 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
static void dct_unquantize_h263_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
#ifdef CONFIG_ENCODERS
static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale);
static int sse_mb(MpegEncContext *s);
static void denoise_dct_c(MpegEncContext *s, DCTELEM *block);
#endif //CONFIG_ENCODERS
#ifdef HAVE_XVMC
extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx);
......@@ -79,20 +70,6 @@ void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_e
//#define DEBUG
#ifdef CONFIG_ENCODERS
static const uint16_t aanscales[64] = {
/* precomputed values scaled up by 14 bits */
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
};
#endif //CONFIG_ENCODERS
static const uint8_t h263_chroma_roundtab[16] = {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
......@@ -103,94 +80,6 @@ static const uint8_t ff_default_chroma_qscale_table[32]={
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
};
#ifdef CONFIG_ENCODERS
static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
static uint8_t default_fcode_tab[MAX_MV*2+1];
enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
{
int qscale;
int shift=0;
for(qscale=qmin; qscale<=qmax; qscale++){
int i;
if (dsp->fdct == ff_jpeg_fdct_islow
#ifdef FAAN_POSTSCALE
|| dsp->fdct == ff_faandct
#endif
) {
for(i=0;i<64;i++) {
const int j= dsp->idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905 */
/* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
/* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
/* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
(qscale * quant_matrix[j]));
}
} else if (dsp->fdct == fdct_ifast
#ifndef FAAN_POSTSCALE
|| dsp->fdct == ff_faandct
#endif
) {
for(i=0;i<64;i++) {
const int j= dsp->idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905 */
/* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
/* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
/* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) /
(aanscales[i] * qscale * quant_matrix[j]));
}
} else {
for(i=0;i<64;i++) {
const int j= dsp->idct_permutation[i];
/* We can safely suppose that 16 <= quant_matrix[i] <= 255
So 16 <= qscale * quant_matrix[i] <= 7905
so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
*/
qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1;
qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]);
}
}
for(i=intra; i<64; i++){
int64_t max= 8191;
if (dsp->fdct == fdct_ifast
#ifndef FAAN_POSTSCALE
|| dsp->fdct == ff_faandct
#endif
) {
max= (8191LL*aanscales[i]) >> 14;
}
while(((max * qmat[qscale][i]) >> shift) > INT_MAX){
shift++;
}
}
}
if(shift){
av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift);
}
}
static inline void update_qscale(MpegEncContext *s){
s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
}
#endif //CONFIG_ENCODERS
void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
int i;
int end;
......@@ -215,20 +104,6 @@ void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_s
}
}
#ifdef CONFIG_ENCODERS
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
int i;
if(matrix){
put_bits(pb, 1, 1);
for(i=0;i<64;i++) {
put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
}
}else
put_bits(pb, 1, 0);
}
#endif //CONFIG_ENCODERS
const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
int i;
......@@ -316,57 +191,16 @@ int DCT_common_init(MpegEncContext *s)
return 0;
}
static void copy_picture(Picture *dst, Picture *src){
void copy_picture(Picture *dst, Picture *src){
*dst = *src;
dst->type= FF_BUFFER_TYPE_COPY;
}
#ifdef CONFIG_ENCODERS
static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
int i;
dst->pict_type = src->pict_type;
dst->quality = src->quality;
dst->coded_picture_number = src->coded_picture_number;
dst->display_picture_number = src->display_picture_number;
// dst->reference = src->reference;
dst->pts = src->pts;
dst->interlaced_frame = src->interlaced_frame;
dst->top_field_first = src->top_field_first;
if(s->avctx->me_threshold){
if(!src->motion_val[0])
av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n");
if(!src->mb_type)
av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n");
if(!src->ref_index[0])
av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n");
if(src->motion_subsample_log2 != dst->motion_subsample_log2)
av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
src->motion_subsample_log2, dst->motion_subsample_log2);
memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
for(i=0; i<2; i++){
int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
int height= ((16*s->mb_height)>>src->motion_subsample_log2);
if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){
memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t));
}
if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){
memcpy(dst->ref_index[i], src->ref_index[i], s->b8_stride*2*s->mb_height*sizeof(int8_t));
}
}
}
}
#endif
/**
* allocates a Picture
* The pixels are allocated/set by calling get_buffer() if shared=0
*/
static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11
const int mb_array_size= s->mb_stride*s->mb_height;
const int b8_array_size= s->b8_stride*s->mb_height*2;
......@@ -563,30 +397,11 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){
//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
}
#ifdef CONFIG_ENCODERS
static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){
#define COPY(a) dst->a= src->a
COPY(pict_type);
COPY(current_picture);
COPY(f_code);
COPY(b_code);
COPY(qscale);
COPY(lambda);
COPY(lambda2);
COPY(picture_in_gop_number);
COPY(gop_picture_number);
COPY(frame_pred_frame_dct); //FIXME don't set in encode_header
COPY(progressive_frame); //FIXME don't set in encode_header
COPY(partitioned_frame); //FIXME don't set in encode_header
#undef COPY
}
#endif
/**
* sets the given MpegEncContext to common defaults (same for encoding and decoding).
* the changed fields will not depend upon the prior state of the MpegEncContext.
*/
static void MPV_common_defaults(MpegEncContext *s){
void MPV_common_defaults(MpegEncContext *s){
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
s->chroma_qscale_table= ff_default_chroma_qscale_table;
......@@ -612,24 +427,6 @@ void MPV_decode_defaults(MpegEncContext *s){
MPV_common_defaults(s);
}
/**
* sets the given MpegEncContext to defaults for encoding.
* the changed fields will not depend upon the prior state of the MpegEncContext.
*/
#ifdef CONFIG_ENCODERS
static void MPV_encode_defaults(MpegEncContext *s){
int i;
MPV_common_defaults(s);
for(i=-16; i<16; i++){
default_fcode_tab[i + MAX_MV]= 1;
}
s->me.mv_penalty= default_mv_penalty;
s->fcode_tab= default_fcode_tab;
}
#endif //CONFIG_ENCODERS
/**
* init common structure for both encoder and decoder.
* this assumes that some variables like width/height are already set
......@@ -907,509 +704,6 @@ void MPV_common_end(MpegEncContext *s)
avcodec_default_free_buffers(s->avctx);
}
#ifdef CONFIG_ENCODERS
/* init video encoder */
int MPV_encode_init(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
int i;
int chroma_h_shift, chroma_v_shift;
MPV_encode_defaults(s);
switch (avctx->codec_id) {
case CODEC_ID_MPEG2VIDEO:
if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){
av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n");
return -1;
}
break;
case CODEC_ID_LJPEG:
case CODEC_ID_MJPEG:
if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){
av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
return -1;
}
break;
default:
if(avctx->pix_fmt != PIX_FMT_YUV420P){
av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
return -1;
}
}
switch (avctx->pix_fmt) {
case PIX_FMT_YUVJ422P:
case PIX_FMT_YUV422P:
s->chroma_format = CHROMA_422;
break;
case PIX_FMT_YUVJ420P:
case PIX_FMT_YUV420P:
default:
s->chroma_format = CHROMA_420;
break;
}
s->bit_rate = avctx->bit_rate;
s->width = avctx->width;
s->height = avctx->height;
if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){
av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n");
avctx->gop_size=600;
}
s->gop_size = avctx->gop_size;
s->avctx = avctx;
s->flags= avctx->flags;
s->flags2= avctx->flags2;
s->max_b_frames= avctx->max_b_frames;
s->codec_id= avctx->codec->id;
s->luma_elim_threshold = avctx->luma_elim_threshold;
s->chroma_elim_threshold= avctx->chroma_elim_threshold;
s->strict_std_compliance= avctx->strict_std_compliance;
s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
s->mpeg_quant= avctx->mpeg_quant;
s->rtp_mode= !!avctx->rtp_payload_size;
s->intra_dc_precision= avctx->intra_dc_precision;
s->user_specified_pts = AV_NOPTS_VALUE;
if (s->gop_size <= 1) {
s->intra_only = 1;
s->gop_size = 12;
} else {
s->intra_only = 0;
}
s->me_method = avctx->me_method;
/* Fixed QSCALE */
s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
s->adaptive_quant= ( s->avctx->lumi_masking
|| s->avctx->dark_masking
|| s->avctx->temporal_cplx_masking
|| s->avctx->spatial_cplx_masking
|| s->avctx->p_masking
|| s->avctx->border_masking
|| (s->flags&CODEC_FLAG_QP_RD))
&& !s->fixed_qscale;
s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
if(avctx->rc_max_rate && !avctx->rc_buffer_size){
av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
return -1;
}
if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){
av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
}
if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){
av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n");
return -1;
}
if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){
av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
return -1;
}
if(avctx->rc_buffer_size && avctx->bit_rate*av_q2d(avctx->time_base) > avctx->rc_buffer_size){
av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n");
return -1;
}
if(avctx->bit_rate*av_q2d(avctx->time_base) > avctx->bit_rate_tolerance){
av_log(avctx, AV_LOG_ERROR, "bitrate tolerance too small for bitrate\n");
return -1;
}
if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate
&& (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO)
&& 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){
av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n");
}
if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4
&& s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){
av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
return -1;
}
if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){
av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n");
return -1;
}
if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){
av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
return -1;
}
if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
return -1;
}
if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
return -1;
}
if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
return -1;
}
if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN))
&& s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n");
return -1;
}
if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n");
return -1;
}
if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){
av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
return -1;
}
if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){
av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
return -1;
}
if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){
av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet, set threshold to 1000000000\n");
return -1;
}
if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n");
return -1;
}
if(s->flags & CODEC_FLAG_LOW_DELAY){
if (s->codec_id != CODEC_ID_MPEG2VIDEO && s->codec_id != CODEC_ID_MPEG1VIDEO){
av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg1/2\n");
return -1;
}
if (s->max_b_frames != 0){
av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n");
return -1;
}
}
if(s->q_scale_type == 1){
if(s->codec_id != CODEC_ID_MPEG2VIDEO){
av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n");
return -1;
}
if(avctx->qmax > 12){
av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n");
return -1;
}
}
if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
&& s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
&& (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n");
return -1;
}
if(s->avctx->thread_count > 1)
s->rtp_mode= 1;
if(!avctx->time_base.den || !avctx->time_base.num){
av_log(avctx, AV_LOG_ERROR, "framerate not set\n");
return -1;
}
i= (INT_MAX/2+128)>>8;
if(avctx->me_threshold >= i){
av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1);
return -1;
}
if(avctx->mb_threshold >= i){
av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1);
return -1;
}
if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){
av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n");
avctx->b_frame_strategy = 0;
}
i= ff_gcd(avctx->time_base.den, avctx->time_base.num);
if(i > 1){
av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
avctx->time_base.den /= i;
avctx->time_base.num /= i;
// return -1;
}
if(s->codec_id==CODEC_ID_MJPEG){
s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
s->inter_quant_bias= 0;
}else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){
s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
s->inter_quant_bias= 0;
}else{
s->intra_quant_bias=0;
s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
}
if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
s->intra_quant_bias= avctx->intra_quant_bias;
if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
s->inter_quant_bias= avctx->inter_quant_bias;
avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){
av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n");
return -1;
}
s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
switch(avctx->codec->id) {
case CODEC_ID_MPEG1VIDEO:
s->out_format = FMT_MPEG1;
s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
break;
case CODEC_ID_MPEG2VIDEO:
s->out_format = FMT_MPEG1;
s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
s->rtp_mode= 1;
break;
case CODEC_ID_LJPEG:
case CODEC_ID_MJPEG:
s->out_format = FMT_MJPEG;
s->intra_only = 1; /* force intra only for jpeg */
s->mjpeg_vsample[0] = 2;
s->mjpeg_vsample[1] = 2>>chroma_v_shift;
s->mjpeg_vsample[2] = 2>>chroma_v_shift;
s->mjpeg_hsample[0] = 2;
s->mjpeg_hsample[1] = 2>>chroma_h_shift;
s->mjpeg_hsample[2] = 2>>chroma_h_shift;
if (!(ENABLE_MJPEG_ENCODER || ENABLE_LJPEG_ENCODER)
|| ff_mjpeg_encode_init(s) < 0)
return -1;
avctx->delay=0;
s->low_delay=1;