Unified · Split
| @@ -59,16 +59,18 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | //#define DEBUG |
| 61 | 61 | |
| 62 | −static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; | |
| 63 | −static uint8_t default_fcode_tab[MAX_MV*2+1]; | |
| 62 | +static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1]; | |
| 63 | +static uint8_t default_fcode_tab[MAX_MV * 2 + 1]; | |
| 64 | 64 | |
| 65 | −void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], | |
| 66 | − const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) | |
| 65 | +void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], | |
| 66 | + uint16_t (*qmat16)[2][64], | |
| 67 | + const uint16_t *quant_matrix, | |
| 68 | + int bias, int qmin, int qmax, int intra) | |
| 67 | 69 | { |
| 68 | 70 | int qscale; |
| 69 | − int shift=0; | |
| 71 | + int shift = 0; | |
| 70 | 72 | |
| 71 | − for(qscale=qmin; qscale<=qmax; qscale++){ | |
| 73 | + for (qscale = qmin; qscale <= qmax; qscale++) { | |
| 72 | 74 | int i; |
| 73 | 75 | if (dsp->fdct == ff_jpeg_fdct_islow_8 || |
| 74 | 76 | dsp->fdct == ff_jpeg_fdct_islow_10 |
| @@ -76,140 +78,169 @@ void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][6 · 1 unmodified line | ||
| 76 | 78 | || dsp->fdct == ff_faandct |
| 77 | 79 | #endif |
| 78 | 80 | ) { |
| 79 | − for(i=0;i<64;i++) { | |
| 80 | − const int j= dsp->idct_permutation[i]; | |
| 81 | − /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
| 82 | − /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
| 83 | − /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1 << 36) / 249205026 */ | |
| 84 | − /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 81 | + for (i = 0; i < 64; i++) { | |
| 82 | + const int j = dsp->idct_permutation[i]; | |
| 83 | + /* 16 <= qscale * quant_matrix[i] <= 7905 | |
| 84 | + * Assume x = ff_aanscales[i] * qscale * quant_matrix[i] | |
| 85 | + * 19952 <= x <= 249205026 | |
| 86 | + * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026 | |
| 87 | + * 3444240 >= (1 << 36) / (x) >= 275 */ | |
| 85 | 88 | |
| 86 | 89 | qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / |
| 87 | − (qscale * quant_matrix[j])); | |
| 90 | + (qscale * quant_matrix[j])); | |
| 88 | 91 | } |
| 89 | 92 | } else if (dsp->fdct == fdct_ifast |
| 90 | 93 | #ifndef FAAN_POSTSCALE |
| 91 | 94 | || dsp->fdct == ff_faandct |
| 92 | 95 | #endif |
| 93 | 96 | ) { |
| 94 | − for(i=0;i<64;i++) { | |
| 95 | − const int j= dsp->idct_permutation[i]; | |
| 96 | − /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
| 97 | − /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
| 98 | − /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
| 99 | − /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 97 | + for (i = 0; i < 64; i++) { | |
| 98 | + const int j = dsp->idct_permutation[i]; | |
| 99 | + /* 16 <= qscale * quant_matrix[i] <= 7905 | |
| 100 | + * Assume x = ff_aanscales[i] * qscale * quant_matrix[i] | |
| 101 | + * 19952 <= x <= 249205026 | |
| 102 | + * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026 | |
| 103 | + * 3444240 >= (1 << 36) / (x) >= 275 */ | |
| 100 | 104 | |
| 101 | 105 | qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) / |
| 102 | − (ff_aanscales[i] * qscale * quant_matrix[j])); | |
| 106 | + (ff_aanscales[i] * qscale * | |
| 107 | + quant_matrix[j])); | |
| 103 | 108 | } |
| 104 | 109 | } else { |
| 105 | − for(i=0;i<64;i++) { | |
| 106 | − const int j= dsp->idct_permutation[i]; | |
| 110 | + for (i = 0; i < 64; i++) { | |
| 111 | + const int j = dsp->idct_permutation[i]; | |
| 107 | 112 | /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
| 108 | − So 16 <= qscale * quant_matrix[i] <= 7905 | |
| 109 | − so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
| 110 | − so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
| 111 | − */ | |
| 112 | − qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); | |
| 113 | −// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); | |
| 114 | − qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); | |
| 113 | + * Assume x = qscale * quant_matrix[i] | |
| 114 | + * So 16 <= x <= 7905 | |
| 115 | + * so (1 << 19) / 16 >= (1 << 19) / (x) >= (1 << 19) / 7905 | |
| 116 | + * so 32768 >= (1 << 19) / (x) >= 67 */ | |
| 117 | + qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / | |
| 118 | + (qscale * quant_matrix[j])); | |
| 119 | + //qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / | |
| 120 | + // (qscale * quant_matrix[i]); | |
| 121 | + qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / | |
| 122 | + (qscale * quant_matrix[j]); | |
| 115 | 123 | |
| 116 | − if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; | |
| 117 | − qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); | |
| 124 | + if (qmat16[qscale][0][i] == 0 || | |
| 125 | + qmat16[qscale][0][i] == 128 * 256) | |
| 126 | + qmat16[qscale][0][i] = 128 * 256 - 1; | |
| 127 | + qmat16[qscale][1][i] = | |
| 128 | + ROUNDED_DIV(bias << (16 - QUANT_BIAS_SHIFT), | |
| 129 | + qmat16[qscale][0][i]); | |
| 118 | 130 | } |
| 119 | 131 | } |
| 120 | 132 | |
| 121 | − for(i=intra; i<64; i++){ | |
| 122 | − int64_t max= 8191; | |
| 133 | + for (i = intra; i < 64; i++) { | |
| 134 | + int64_t max = 8191; | |
| 123 | 135 | if (dsp->fdct == fdct_ifast |
| 124 | 136 | #ifndef FAAN_POSTSCALE |
| 125 | − || dsp->fdct == ff_faandct | |
| 137 | + || dsp->fdct == ff_faandct | |
| 126 | 138 | #endif |
| 127 | − ) { | |
| 128 | − max = (8191LL*ff_aanscales[i]) >> 14; | |
| 139 | + ) { | |
| 140 | + max = (8191LL * ff_aanscales[i]) >> 14; | |
| 129 | 141 | } |
| 130 | − while(((max * qmat[qscale][i]) >> shift) > INT_MAX){ | |
| 142 | + while (((max * qmat[qscale][i]) >> shift) > INT_MAX) { | |
| 131 | 143 | shift++; |
| 132 | 144 | } |
| 133 | 145 | } |
| 134 | 146 | } |
| 135 | − if(shift){ | |
| 136 | − av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift); | |
| 147 | + if (shift) { | |
| 148 | + av_log(NULL, AV_LOG_INFO, | |
| 149 | + "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", | |
| 150 | + QMAT_SHIFT - shift); | |
| 137 | 151 | } |
| 138 | 152 | } |
| 139 | 153 | |
| 140 | −static inline void update_qscale(MpegEncContext *s){ | |
| 141 | − s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | |
| 142 | − s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); | |
| 154 | +static inline void update_qscale(MpegEncContext *s) | |
| 155 | +{ | |
| 156 | + s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >> | |
| 157 | + (FF_LAMBDA_SHIFT + 7); | |
| 158 | + s->qscale = av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); | |
| 143 | 159 | |
| 144 | − s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; | |
| 160 | + s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >> | |
| 161 | + FF_LAMBDA_SHIFT; | |
| 145 | 162 | } |
| 146 | 163 | |
| 147 | −void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){ | |
| 164 | +void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix) | |
| 165 | +{ | |
| 148 | 166 | int i; |
| 149 | 167 | |
| 150 | − if(matrix){ | |
| 168 | + if (matrix) { | |
| 151 | 169 | put_bits(pb, 1, 1); |
| 152 | − for(i=0;i<64;i++) { | |
| 153 | − put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); | |
| 170 | + for (i = 0; i < 64; i++) { | |
| 171 | + put_bits(pb, 8, matrix[ff_zigzag_direct[i]]); | |
| 154 | 172 | } |
| 155 | − }else | |
| 173 | + } else | |
| 156 | 174 | put_bits(pb, 1, 0); |
| 157 | 175 | } |
| 158 | 176 | |
| 159 | 177 | /** |
| 160 | 178 | * init s->current_picture.qscale_table from s->lambda_table |
| 161 | 179 | */ |
| 162 | −void ff_init_qscale_tab(MpegEncContext *s){ | |
| 180 | +void ff_init_qscale_tab(MpegEncContext *s) | |
| 181 | +{ | |
| 163 | 182 | int8_t * const qscale_table = s->current_picture.f.qscale_table; |
| 164 | 183 | int i; |
| 165 | 184 | |
| 166 | − for(i=0; i<s->mb_num; i++){ | |
| 167 | − unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ]; | |
| 168 | − int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); | |
| 169 | − qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax); | |
| 185 | + for (i = 0; i < s->mb_num; i++) { | |
| 186 | + unsigned int lam = s->lambda_table[s->mb_index2xy[i]]; | |
| 187 | + int qp = (lam * 139 + FF_LAMBDA_SCALE * 64) >> (FF_LAMBDA_SHIFT + 7); | |
| 188 | + qscale_table[s->mb_index2xy[i]] = av_clip(qp, s->avctx->qmin, | |
| 189 | + s->avctx->qmax); | |
| 170 | 190 | } |
| 171 | 191 | } |
| 172 | 192 | |
| 173 | −static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ | |
| 193 | +static void copy_picture_attributes(MpegEncContext *s, | |
| 194 | + AVFrame *dst, | |
| 195 | + AVFrame *src) | |
| 196 | +{ | |
| 174 | 197 | int i; |
| 175 | 198 | |
| 176 | 199 | dst->pict_type = src->pict_type; |
| 177 | 200 | dst->quality = src->quality; |
| 178 | 201 | dst->coded_picture_number = src->coded_picture_number; |
| 179 | 202 | dst->display_picture_number = src->display_picture_number; |
| 180 | −// dst->reference = src->reference; | |
| 203 | + //dst->reference = src->reference; | |
| 181 | 204 | dst->pts = src->pts; |
| 182 | 205 | dst->interlaced_frame = src->interlaced_frame; |
| 183 | 206 | dst->top_field_first = src->top_field_first; |
| 184 | 207 | |
| 185 | − if(s->avctx->me_threshold){ | |
| 186 | − if(!src->motion_val[0]) | |
| 208 | + if (s->avctx->me_threshold) { | |
| 209 | + if (!src->motion_val[0]) | |
| 187 | 210 | av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n"); |
| 188 | − if(!src->mb_type) | |
| 211 | + if (!src->mb_type) | |
| 189 | 212 | av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n"); |
| 190 | − if(!src->ref_index[0]) | |
| 213 | + if (!src->ref_index[0]) | |
| 191 | 214 | av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n"); |
| 192 | − if(src->motion_subsample_log2 != dst->motion_subsample_log2) | |
| 193 | − av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", | |
| 194 | − src->motion_subsample_log2, dst->motion_subsample_log2); | |
| 215 | + if (src->motion_subsample_log2 != dst->motion_subsample_log2) | |
| 216 | + av_log(s->avctx, AV_LOG_ERROR, | |
| 217 | + "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", | |
| 218 | + src->motion_subsample_log2, dst->motion_subsample_log2); | |
| 195 | 219 | |
| 196 | − memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); | |
| 220 | + memcpy(dst->mb_type, src->mb_type, | |
| 221 | + s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); | |
| 197 | 222 | |
| 198 | − for(i=0; i<2; i++){ | |
| 199 | − int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1; | |
| 200 | − int height= ((16*s->mb_height)>>src->motion_subsample_log2); | |
| 223 | + for (i = 0; i < 2; i++) { | |
| 224 | + int stride = ((16 * s->mb_width ) >> | |
| 225 | + src->motion_subsample_log2) + 1; | |
| 226 | + int height = ((16 * s->mb_height) >> src->motion_subsample_log2); | |
| 201 | 227 | |
| 202 | − if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){ | |
| 203 | − memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); | |
| 228 | + if (src->motion_val[i] && | |
| 229 | + src->motion_val[i] != dst->motion_val[i]) { | |
| 230 | + memcpy(dst->motion_val[i], src->motion_val[i], | |
| 231 | + 2 * stride * height * sizeof(int16_t)); | |
| 204 | 232 | } |
| 205 | − if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ | |
| 206 | − memcpy(dst->ref_index[i], src->ref_index[i], s->mb_stride*4*s->mb_height*sizeof(int8_t)); | |
| 233 | + if (src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]) { | |
| 234 | + memcpy(dst->ref_index[i], src->ref_index[i], | |
| 235 | + s->mb_stride * 4 * s->mb_height * sizeof(int8_t)); | |
| 207 | 236 | } |
| 208 | 237 | } |
| 209 | 238 | } |
| 210 | 239 | } |
| 211 | 240 | |
| 212 | −static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ | |
| 241 | +static void update_duplicate_context_after_me(MpegEncContext *dst, | |
| 242 | + MpegEncContext *src) | |
| 243 | +{ | |
| 213 | 244 | #define COPY(a) dst->a= src->a |
| 214 | 245 | COPY(pict_type); |
| 215 | 246 | COPY(current_picture); |
| @@ -220,9 +251,9 @@ static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContex · 4 unmodified lines | ||
| 220 | 251 | COPY(lambda2); |
| 221 | 252 | COPY(picture_in_gop_number); |
| 222 | 253 | COPY(gop_picture_number); |
| 223 | − COPY(frame_pred_frame_dct); //FIXME don't set in encode_header | |
| 224 | − COPY(progressive_frame); //FIXME don't set in encode_header | |
| 225 | − COPY(partitioned_frame); //FIXME don't set in encode_header | |
| 254 | + COPY(frame_pred_frame_dct); // FIXME don't set in encode_header | |
| 255 | + COPY(progressive_frame); // FIXME don't set in encode_header | |
| 256 | + COPY(partitioned_frame); // FIXME don't set in encode_header | |
| 226 | 257 | #undef COPY |
| 227 | 258 | } |
| 228 | 259 | |
| @@ -230,15 +261,16 @@ static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContex · 1 unmodified line | ||
| 230 | 261 | * Set the given MpegEncContext to defaults for encoding. |
| 231 | 262 | * the changed fields will not depend upon the prior state of the MpegEncContext. |
| 232 | 263 | */ |
| 233 | −static void MPV_encode_defaults(MpegEncContext *s){ | |
| 264 | +static void MPV_encode_defaults(MpegEncContext *s) | |
| 265 | +{ | |
| 234 | 266 | int i; |
| 235 | 267 | MPV_common_defaults(s); |
| 236 | 268 | |
| 237 | − for(i=-16; i<16; i++){ | |
| 238 | − default_fcode_tab[i + MAX_MV]= 1; | |
| 269 | + for (i = -16; i < 16; i++) { | |
| 270 | + default_fcode_tab[i + MAX_MV] = 1; | |
| 239 | 271 | } |
| 240 | − s->me.mv_penalty= default_mv_penalty; | |
| 241 | − s->fcode_tab= default_fcode_tab; | |
| 272 | + s->me.mv_penalty = default_mv_penalty; | |
| 273 | + s->fcode_tab = default_fcode_tab; | |
| 242 | 274 | } |
| 243 | 275 | |
| 244 | 276 | /* init video encoder */ |
| @@ -252,27 +284,38 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 7 unmodified lines | ||
| 252 | 284 | |
| 253 | 285 | switch (avctx->codec_id) { |
| 254 | 286 | case CODEC_ID_MPEG2VIDEO: |
| 255 | − if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){ | |
| 256 | − av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n"); | |
| 287 | + if (avctx->pix_fmt != PIX_FMT_YUV420P && | |
| 288 | + avctx->pix_fmt != PIX_FMT_YUV422P) { | |
| 289 | + av_log(avctx, AV_LOG_ERROR, | |
| 290 | + "only YUV420 and YUV422 are supported\n"); | |
| 257 | 291 | return -1; |
| 258 | 292 | } |
| 259 | 293 | break; |
| 260 | 294 | case CODEC_ID_LJPEG: |
| 261 | − if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && avctx->pix_fmt != PIX_FMT_YUVJ444P && avctx->pix_fmt != PIX_FMT_BGRA && | |
| 262 | − ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P && avctx->pix_fmt != PIX_FMT_YUV444P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ | |
| 295 | + if (avctx->pix_fmt != PIX_FMT_YUVJ420P && | |
| 296 | + avctx->pix_fmt != PIX_FMT_YUVJ422P && | |
| 297 | + avctx->pix_fmt != PIX_FMT_YUVJ444P && | |
| 298 | + avctx->pix_fmt != PIX_FMT_BGRA && | |
| 299 | + ((avctx->pix_fmt != PIX_FMT_YUV420P && | |
| 300 | + avctx->pix_fmt != PIX_FMT_YUV422P && | |
| 301 | + avctx->pix_fmt != PIX_FMT_YUV444P) || | |
| 302 | + avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) { | |
| 263 | 303 | av_log(avctx, AV_LOG_ERROR, "colorspace not supported in LJPEG\n"); |
| 264 | 304 | return -1; |
| 265 | 305 | } |
| 266 | 306 | break; |
| 267 | 307 | case CODEC_ID_MJPEG: |
| 268 | − if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && | |
| 269 | − ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ | |
| 308 | + if (avctx->pix_fmt != PIX_FMT_YUVJ420P && | |
| 309 | + avctx->pix_fmt != PIX_FMT_YUVJ422P && | |
| 310 | + ((avctx->pix_fmt != PIX_FMT_YUV420P && | |
| 311 | + avctx->pix_fmt != PIX_FMT_YUV422P) || | |
| 312 | + avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) { | |
| 270 | 313 | av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); |
| 271 | 314 | return -1; |
| 272 | 315 | } |
| 273 | 316 | break; |
| 274 | 317 | default: |
| 275 | − if(avctx->pix_fmt != PIX_FMT_YUV420P){ | |
| 318 | + if (avctx->pix_fmt != PIX_FMT_YUV420P) { | |
| 276 | 319 | av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n"); |
| 277 | 320 | return -1; |
| 278 | 321 | } |
| @@ -291,34 +334,36 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 12 unmodified lines | ||
| 291 | 334 | } |
| 292 | 335 | |
| 293 | 336 | s->bit_rate = avctx->bit_rate; |
| 294 | − s->width = avctx->width; | |
| 295 | − s->height = avctx->height; | |
| 296 | − if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){ | |
| 297 | − av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); | |
| 298 | − avctx->gop_size=600; | |
| 299 | − } | |
| 300 | − s->gop_size = avctx->gop_size; | |
| 301 | − s->avctx = avctx; | |
| 302 | − s->flags= avctx->flags; | |
| 303 | − s->flags2= avctx->flags2; | |
| 304 | − s->max_b_frames= avctx->max_b_frames; | |
| 305 | − s->codec_id= avctx->codec->id; | |
| 306 | − s->luma_elim_threshold = avctx->luma_elim_threshold; | |
| 307 | − s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
| 308 | − s->strict_std_compliance= avctx->strict_std_compliance; | |
| 337 | + s->width = avctx->width; | |
| 338 | + s->height = avctx->height; | |
| 339 | + if (avctx->gop_size > 600 && | |
| 340 | + avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { | |
| 341 | + av_log(avctx, AV_LOG_ERROR, | |
| 342 | + "Warning keyframe interval too large! reducing it ...\n"); | |
| 343 | + avctx->gop_size = 600; | |
| 344 | + } | |
| 345 | + s->gop_size = avctx->gop_size; | |
| 346 | + s->avctx = avctx; | |
| 347 | + s->flags = avctx->flags; | |
| 348 | + s->flags2 = avctx->flags2; | |
| 349 | + s->max_b_frames = avctx->max_b_frames; | |
| 350 | + s->codec_id = avctx->codec->id; | |
| 351 | + s->luma_elim_threshold = avctx->luma_elim_threshold; | |
| 352 | + s->chroma_elim_threshold = avctx->chroma_elim_threshold; | |
| 353 | + s->strict_std_compliance = avctx->strict_std_compliance; | |
| 309 | 354 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 310 | 355 | if (avctx->flags & CODEC_FLAG_PART) |
| 311 | 356 | s->data_partitioning = 1; |
| 312 | 357 | #endif |
| 313 | − s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; | |
| 314 | − s->mpeg_quant= avctx->mpeg_quant; | |
| 315 | − s->rtp_mode= !!avctx->rtp_payload_size; | |
| 316 | − s->intra_dc_precision= avctx->intra_dc_precision; | |
| 358 | + s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0; | |
| 359 | + s->mpeg_quant = avctx->mpeg_quant; | |
| 360 | + s->rtp_mode = !!avctx->rtp_payload_size; | |
| 361 | + s->intra_dc_precision = avctx->intra_dc_precision; | |
| 317 | 362 | s->user_specified_pts = AV_NOPTS_VALUE; |
| 318 | 363 | |
| 319 | 364 | if (s->gop_size <= 1) { |
| 320 | 365 | s->intra_only = 1; |
| 321 | − s->gop_size = 12; | |
| 366 | + s->gop_size = 12; | |
| 322 | 367 | } else { |
| 323 | 368 | s->intra_only = 0; |
| 324 | 369 | } |
| @@ -328,284 +373,349 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 3 unmodified lines | ||
| 328 | 373 | /* Fixed QSCALE */ |
| 329 | 374 | s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); |
| 330 | 375 | |
| 331 | − s->adaptive_quant= ( s->avctx->lumi_masking | |
| 332 | − || s->avctx->dark_masking | |
| 333 | − || s->avctx->temporal_cplx_masking | |
| 334 | − || s->avctx->spatial_cplx_masking | |
| 335 | − || s->avctx->p_masking | |
| 336 | − || s->avctx->border_masking | |
| 337 | − || (s->flags&CODEC_FLAG_QP_RD)) | |
| 338 | − && !s->fixed_qscale; | |
| 376 | + s->adaptive_quant = (s->avctx->lumi_masking || | |
| 377 | + s->avctx->dark_masking || | |
| 378 | + s->avctx->temporal_cplx_masking || | |
| 379 | + s->avctx->spatial_cplx_masking || | |
| 380 | + s->avctx->p_masking || | |
| 381 | + s->avctx->border_masking || | |
| 382 | + (s->flags & CODEC_FLAG_QP_RD)) && | |
| 383 | + !s->fixed_qscale; | |
| 339 | 384 | |
| 340 | − s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); | |
| 385 | + s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER); | |
| 341 | 386 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 342 | − s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); | |
| 343 | − s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); | |
| 344 | − s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); | |
| 345 | − s->obmc= !!(s->flags & CODEC_FLAG_OBMC); | |
| 387 | + s->alternate_scan = !!(s->flags & CODEC_FLAG_ALT_SCAN); | |
| 388 | + s->intra_vlc_format = !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); | |
| 389 | + s->q_scale_type = !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); | |
| 390 | + s->obmc = !!(s->flags & CODEC_FLAG_OBMC); | |
| 346 | 391 | #endif |
| 347 | 392 | |
| 348 | − if(avctx->rc_max_rate && !avctx->rc_buffer_size){ | |
| 349 | − av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); | |
| 393 | + if (avctx->rc_max_rate && !avctx->rc_buffer_size) { | |
| 394 | + av_log(avctx, AV_LOG_ERROR, | |
| 395 | + "a vbv buffer size is needed, " | |
| 396 | + "for encoding with a maximum bitrate\n"); | |
| 350 | 397 | return -1; |
| 351 | 398 | } |
| 352 | 399 | |
| 353 | − if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ | |
| 354 | − av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); | |
| 400 | + if (avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate) { | |
| 401 | + av_log(avctx, AV_LOG_INFO, | |
| 402 | + "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); | |
| 355 | 403 | } |
| 356 | 404 | |
| 357 | − if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ | |
| 405 | + if (avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate) { | |
| 358 | 406 | av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n"); |
| 359 | 407 | return -1; |
| 360 | 408 | } |
| 361 | 409 | |
| 362 | − if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ | |
| 410 | + if (avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate) { | |
| 363 | 411 | av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); |
| 364 | 412 | return -1; |
| 365 | 413 | } |
| 366 | 414 | |
| 367 | − if(avctx->rc_max_rate && avctx->rc_max_rate == avctx->bit_rate && avctx->rc_max_rate != avctx->rc_min_rate){ | |
| 368 | − av_log(avctx, AV_LOG_INFO, "impossible bitrate constraints, this will fail\n"); | |
| 415 | + if (avctx->rc_max_rate && | |
| 416 | + avctx->rc_max_rate == avctx->bit_rate && | |
| 417 | + avctx->rc_max_rate != avctx->rc_min_rate) { | |
| 418 | + av_log(avctx, AV_LOG_INFO, | |
| 419 | + "impossible bitrate constraints, this will fail\n"); | |
| 369 | 420 | } |
| 370 | 421 | |
| 371 | − if(avctx->rc_buffer_size && avctx->bit_rate*(int64_t)avctx->time_base.num > avctx->rc_buffer_size * (int64_t)avctx->time_base.den){ | |
| 422 | + if (avctx->rc_buffer_size && | |
| 423 | + avctx->bit_rate * (int64_t)avctx->time_base.num > | |
| 424 | + avctx->rc_buffer_size * (int64_t)avctx->time_base.den) { | |
| 372 | 425 | av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n"); |
| 373 | 426 | return -1; |
| 374 | 427 | } |
| 375 | 428 | |
| 376 | − if(!s->fixed_qscale && avctx->bit_rate*av_q2d(avctx->time_base) > avctx->bit_rate_tolerance){ | |
| 377 | − av_log(avctx, AV_LOG_ERROR, "bitrate tolerance too small for bitrate\n"); | |
| 429 | + if (!s->fixed_qscale && | |
| 430 | + avctx->bit_rate * av_q2d(avctx->time_base) > | |
| 431 | + avctx->bit_rate_tolerance) { | |
| 432 | + av_log(avctx, AV_LOG_ERROR, | |
| 433 | + "bitrate tolerance too small for bitrate\n"); | |
| 378 | 434 | return -1; |
| 379 | 435 | } |
| 380 | 436 | |
| 381 | − if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate | |
| 382 | − && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) | |
| 383 | − && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ | |
| 384 | − | |
| 385 | − 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"); | |
| 437 | + if (s->avctx->rc_max_rate && | |
| 438 | + s->avctx->rc_min_rate == s->avctx->rc_max_rate && | |
| 439 | + (s->codec_id == CODEC_ID_MPEG1VIDEO || | |
| 440 | + s->codec_id == CODEC_ID_MPEG2VIDEO) && | |
| 441 | + 90000LL * (avctx->rc_buffer_size - 1) > | |
| 442 | + s->avctx->rc_max_rate * 0xFFFFLL) { | |
| 443 | + av_log(avctx, AV_LOG_INFO, | |
| 444 | + "Warning vbv_delay will be set to 0xFFFF (=VBR) as the " | |
| 445 | + "specified vbv buffer is too large for the given bitrate!\n"); | |
| 386 | 446 | } |
| 387 | 447 | |
| 388 | − if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 | |
| 389 | − && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){ | |
| 448 | + if ((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 && | |
| 449 | + s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && | |
| 450 | + s->codec_id != CODEC_ID_FLV1) { | |
| 390 | 451 | av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); |
| 391 | 452 | return -1; |
| 392 | 453 | } |
| 393 | 454 | |
| 394 | − if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ | |
| 395 | − av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n"); | |
| 455 | + if (s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE) { | |
| 456 | + av_log(avctx, AV_LOG_ERROR, | |
| 457 | + "OBMC is only supported with simple mb decision\n"); | |
| 396 | 458 | return -1; |
| 397 | 459 | } |
| 398 | 460 | |
| 399 | 461 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 400 | − if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ | |
| 462 | + if (s->obmc && s->codec_id != CODEC_ID_H263 && | |
| 463 | + s->codec_id != CODEC_ID_H263P) { | |
| 401 | 464 | av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); |
| 402 | 465 | return -1; |
| 403 | 466 | } |
| 404 | 467 | #endif |
| 405 | 468 | |
| 406 | − if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ | |
| 469 | + if (s->quarter_sample && s->codec_id != CODEC_ID_MPEG4) { | |
| 407 | 470 | av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); |
| 408 | 471 | return -1; |
| 409 | 472 | } |
| 410 | 473 | |
| 411 | 474 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 412 | − if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ | |
| 413 | − av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); | |
| 475 | + if (s->data_partitioning && s->codec_id != CODEC_ID_MPEG4) { | |
| 476 | + av_log(avctx, AV_LOG_ERROR, | |
| 477 | + "data partitioning not supported by codec\n"); | |
| 414 | 478 | return -1; |
| 415 | 479 | } |
| 416 | 480 | #endif |
| 417 | 481 | |
| 418 | − if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 482 | + if (s->max_b_frames && | |
| 483 | + s->codec_id != CODEC_ID_MPEG4 && | |
| 484 | + s->codec_id != CODEC_ID_MPEG1VIDEO && | |
| 485 | + s->codec_id != CODEC_ID_MPEG2VIDEO) { | |
| 419 | 486 | av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); |
| 420 | 487 | return -1; |
| 421 | 488 | } |
| 422 | 489 | |
| 423 | − if ((s->codec_id == CODEC_ID_MPEG4 || s->codec_id == CODEC_ID_H263 || | |
| 490 | + if ((s->codec_id == CODEC_ID_MPEG4 || | |
| 491 | + s->codec_id == CODEC_ID_H263 || | |
| 424 | 492 | s->codec_id == CODEC_ID_H263P) && |
| 425 | − (avctx->sample_aspect_ratio.num > 255 || avctx->sample_aspect_ratio.den > 255)) { | |
| 426 | − av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i, limit is 255/255\n", | |
| 493 | + (avctx->sample_aspect_ratio.num > 255 || | |
| 494 | + avctx->sample_aspect_ratio.den > 255)) { | |
| 495 | + av_log(avctx, AV_LOG_ERROR, | |
| 496 | + "Invalid pixel aspect ratio %i/%i, limit is 255/255\n", | |
| 427 | 497 | avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); |
| 428 | 498 | return -1; |
| 429 | 499 | } |
| 430 | 500 | |
| 431 | − if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) | |
| 432 | − && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 501 | + if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME | | |
| 502 | + CODEC_FLAG_ALT_SCAN)) && | |
| 503 | + s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO) { | |
| 433 | 504 | av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); |
| 434 | 505 | return -1; |
| 435 | 506 | } |
| 436 | 507 | |
| 437 | − if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too | |
| 438 | − av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n"); | |
| 508 | + // FIXME mpeg2 uses that too | |
| 509 | + if (s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4) { | |
| 510 | + av_log(avctx, AV_LOG_ERROR, | |
| 511 | + "mpeg2 style quantization not supported by codec\n"); | |
| 439 | 512 | return -1; |
| 440 | 513 | } |
| 441 | 514 | |
| 442 | − if((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis){ | |
| 515 | + if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) { | |
| 443 | 516 | av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); |
| 444 | 517 | return -1; |
| 445 | 518 | } |
| 446 | 519 | |
| 447 | − if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ | |
| 520 | + if ((s->flags & CODEC_FLAG_QP_RD) && | |
| 521 | + s->avctx->mb_decision != FF_MB_DECISION_RD) { | |
| 448 | 522 | av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); |
| 449 | 523 | return -1; |
| 450 | 524 | } |
| 451 | 525 | |
| 452 | − if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ | |
| 453 | − av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection are not supported yet, set threshold to 1000000000\n"); | |
| 526 | + if (s->avctx->scenechange_threshold < 1000000000 && | |
| 527 | + (s->flags & CODEC_FLAG_CLOSED_GOP)) { | |
| 528 | + av_log(avctx, AV_LOG_ERROR, | |
| 529 | + "closed gop with scene change detection are not supported yet, " | |
| 530 | + "set threshold to 1000000000\n"); | |
| 454 | 531 | return -1; |
| 455 | 532 | } |
| 456 | 533 | |
| 457 | − if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 458 | − av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n"); | |
| 534 | + if ((s->flags2 & CODEC_FLAG2_INTRA_VLC) && | |
| 535 | + s->codec_id != CODEC_ID_MPEG2VIDEO) { | |
| 536 | + av_log(avctx, AV_LOG_ERROR, | |
| 537 | + "intra vlc table not supported by codec\n"); | |
| 459 | 538 | return -1; |
| 460 | 539 | } |
| 461 | 540 | |
| 462 | − if(s->flags & CODEC_FLAG_LOW_DELAY){ | |
| 463 | − if (s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 464 | − av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg2\n"); | |
| 541 | + if (s->flags & CODEC_FLAG_LOW_DELAY) { | |
| 542 | + if (s->codec_id != CODEC_ID_MPEG2VIDEO) { | |
| 543 | + av_log(avctx, AV_LOG_ERROR, | |
| 544 | + "low delay forcing is only available for mpeg2\n"); | |
| 465 | 545 | return -1; |
| 466 | 546 | } |
| 467 | − if (s->max_b_frames != 0){ | |
| 468 | − av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n"); | |
| 547 | + if (s->max_b_frames != 0) { | |
| 548 | + av_log(avctx, AV_LOG_ERROR, | |
| 549 | + "b frames cannot be used with low delay\n"); | |
| 469 | 550 | return -1; |
| 470 | 551 | } |
| 471 | 552 | } |
| 472 | 553 | |
| 473 | − if(s->q_scale_type == 1){ | |
| 554 | + if (s->q_scale_type == 1) { | |
| 474 | 555 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 475 | − if(s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 476 | − av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n"); | |
| 556 | + if (s->codec_id != CODEC_ID_MPEG2VIDEO) { | |
| 557 | + av_log(avctx, AV_LOG_ERROR, | |
| 558 | + "non linear quant is only available for mpeg2\n"); | |
| 477 | 559 | return -1; |
| 478 | 560 | } |
| 479 | 561 | #endif |
| 480 | − if(avctx->qmax > 12){ | |
| 481 | − av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n"); | |
| 562 | + if (avctx->qmax > 12) { | |
| 563 | + av_log(avctx, AV_LOG_ERROR, | |
| 564 | + "non linear quant only supports qmax <= 12 currently\n"); | |
| 482 | 565 | return -1; |
| 483 | 566 | } |
| 484 | 567 | } |
| 485 | 568 | |
| 486 | − if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 | |
| 487 | − && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO | |
| 488 | − && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ | |
| 489 | − av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); | |
| 569 | + if (s->avctx->thread_count > 1 && | |
| 570 | + s->codec_id != CODEC_ID_MPEG4 && | |
| 571 | + s->codec_id != CODEC_ID_MPEG1VIDEO && | |
| 572 | + s->codec_id != CODEC_ID_MPEG2VIDEO && | |
| 573 | + (s->codec_id != CODEC_ID_H263P || | |
| 574 | + !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))) { | |
| 575 | + av_log(avctx, AV_LOG_ERROR, | |
| 576 | + "multi threaded encoding not supported by codec\n"); | |
| 490 | 577 | return -1; |
| 491 | 578 | } |
| 492 | 579 | |
| 493 | − if(s->avctx->thread_count < 1){ | |
| 494 | − av_log(avctx, AV_LOG_ERROR, "automatic thread number detection not supported by codec, patch welcome\n"); | |
| 580 | + if (s->avctx->thread_count < 1) { | |
| 581 | + av_log(avctx, AV_LOG_ERROR, | |
| 582 | + "automatic thread number detection not supported by codec," | |
| 583 | + "patch welcome\n"); | |
| 495 | 584 | return -1; |
| 496 | 585 | } |
| 497 | 586 | |
| 498 | − if(s->avctx->thread_count > 1) | |
| 499 | − s->rtp_mode= 1; | |
| 587 | + if (s->avctx->thread_count > 1) | |
| 588 | + s->rtp_mode = 1; | |
| 500 | 589 | |
| 501 | − if(!avctx->time_base.den || !avctx->time_base.num){ | |
| 590 | + if (!avctx->time_base.den || !avctx->time_base.num) { | |
| 502 | 591 | av_log(avctx, AV_LOG_ERROR, "framerate not set\n"); |
| 503 | 592 | return -1; |
| 504 | 593 | } |
| 505 | 594 | |
| 506 | − i= (INT_MAX/2+128)>>8; | |
| 507 | − if(avctx->me_threshold >= i){ | |
| 508 | − av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1); | |
| 595 | + i = (INT_MAX / 2 + 128) >> 8; | |
| 596 | + if (avctx->me_threshold >= i) { | |
| 597 | + av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", | |
| 598 | + i - 1); | |
| 509 | 599 | return -1; |
| 510 | 600 | } |
| 511 | − if(avctx->mb_threshold >= i){ | |
| 512 | − av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1); | |
| 601 | + if (avctx->mb_threshold >= i) { | |
| 602 | + av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", | |
| 603 | + i - 1); | |
| 513 | 604 | return -1; |
| 514 | 605 | } |
| 515 | 606 | |
| 516 | − if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){ | |
| 517 | − av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); | |
| 607 | + if (avctx->b_frame_strategy && (avctx->flags & CODEC_FLAG_PASS2)) { | |
| 608 | + av_log(avctx, AV_LOG_INFO, | |
| 609 | + "notice: b_frame_strategy only affects the first pass\n"); | |
| 518 | 610 | avctx->b_frame_strategy = 0; |
| 519 | 611 | } |
| 520 | 612 | |
| 521 | − i= av_gcd(avctx->time_base.den, avctx->time_base.num); | |
| 522 | − if(i > 1){ | |
| 613 | + i = av_gcd(avctx->time_base.den, avctx->time_base.num); | |
| 614 | + if (i > 1) { | |
| 523 | 615 | av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); |
| 524 | 616 | avctx->time_base.den /= i; |
| 525 | 617 | avctx->time_base.num /= i; |
| 526 | −// return -1; | |
| 527 | − } | |
| 528 | − | |
| 529 | − if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){ | |
| 530 | − s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x | |
| 531 | − s->inter_quant_bias= 0; | |
| 532 | − }else{ | |
| 533 | − s->intra_quant_bias=0; | |
| 534 | − s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x | |
| 618 | + //return -1; | |
| 535 | 619 | } |
| 536 | 620 | |
| 537 | − if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 538 | − s->intra_quant_bias= avctx->intra_quant_bias; | |
| 539 | − if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 540 | − s->inter_quant_bias= avctx->inter_quant_bias; | |
| 541 | − | |
| 542 | − avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); | |
| 543 | − | |
| 544 | − if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ | |
| 545 | − av_log(avctx, AV_LOG_ERROR, "timebase %d/%d not supported by MPEG 4 standard, " | |
| 546 | − "the maximum admitted value for the timebase denominator is %d\n", | |
| 547 | − s->avctx->time_base.num, s->avctx->time_base.den, (1<<16)-1); | |
| 621 | + if (s->mpeg_quant || s->codec_id == CODEC_ID_MPEG1VIDEO || | |
| 622 | + s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG) { | |
| 623 | + // (a + x * 3 / 8) / x | |
| 624 | + s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3); | |
| 625 | + s->inter_quant_bias = 0; | |
| 626 | + } else { | |
| 627 | + s->intra_quant_bias = 0; | |
| 628 | + // (a - x / 4) / x | |
| 629 | + s->inter_quant_bias = -(1 << (QUANT_BIAS_SHIFT - 2)); | |
| 630 | + } | |
| 631 | + | |
| 632 | + if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 633 | + s->intra_quant_bias = avctx->intra_quant_bias; | |
| 634 | + if (avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 635 | + s->inter_quant_bias = avctx->inter_quant_bias; | |
| 636 | + | |
| 637 | + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, | |
| 638 | + &chroma_v_shift); | |
| 639 | + | |
| 640 | + if (avctx->codec_id == CODEC_ID_MPEG4 && | |
| 641 | + s->avctx->time_base.den > (1 << 16) - 1) { | |
| 642 | + av_log(avctx, AV_LOG_ERROR, | |
| 643 | + "timebase %d/%d not supported by MPEG 4 standard, " | |
| 644 | + "the maximum admitted value for the timebase denominator " | |
| 645 | + "is %d\n", s->avctx->time_base.num, s->avctx->time_base.den, | |
| 646 | + (1 << 16) - 1); | |
| 548 | 647 | return -1; |
| 549 | 648 | } |
| 550 | 649 | s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; |
| 551 | 650 | |
| 552 | − switch(avctx->codec->id) { | |
| 651 | + switch (avctx->codec->id) { | |
| 553 | 652 | case CODEC_ID_MPEG1VIDEO: |
| 554 | 653 | s->out_format = FMT_MPEG1; |
| 555 | − s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); | |
| 556 | − avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 654 | + s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY); | |
| 655 | + avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 557 | 656 | break; |
| 558 | 657 | case CODEC_ID_MPEG2VIDEO: |
| 559 | 658 | s->out_format = FMT_MPEG1; |
| 560 | − s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); | |
| 561 | − avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 562 | − s->rtp_mode= 1; | |
| 659 | + s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY); | |
| 660 | + avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 661 | + s->rtp_mode = 1; | |
| 563 | 662 | break; |
| 564 | 663 | case CODEC_ID_LJPEG: |
| 565 | 664 | case CODEC_ID_MJPEG: |
| 566 | 665 | s->out_format = FMT_MJPEG; |
| 567 | 666 | s->intra_only = 1; /* force intra only for jpeg */ |
| 568 | − if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){ | |
| 667 | + if (avctx->codec->id == CODEC_ID_LJPEG && | |
| 668 | + avctx->pix_fmt == PIX_FMT_BGRA) { | |
| 569 | 669 | s->mjpeg_vsample[0] = s->mjpeg_hsample[0] = |
| 570 | 670 | s->mjpeg_vsample[1] = s->mjpeg_hsample[1] = |
| 571 | 671 | s->mjpeg_vsample[2] = s->mjpeg_hsample[2] = 1; |
| 572 | − }else{ | |
| 672 | + } else { | |
| 573 | 673 | s->mjpeg_vsample[0] = 2; |
| 574 | − s->mjpeg_vsample[1] = 2>>chroma_v_shift; | |
| 575 | − s->mjpeg_vsample[2] = 2>>chroma_v_shift; | |
| 674 | + s->mjpeg_vsample[1] = 2 >> chroma_v_shift; | |
| 675 | + s->mjpeg_vsample[2] = 2 >> chroma_v_shift; | |
| 576 | 676 | s->mjpeg_hsample[0] = 2; |
| 577 | − s->mjpeg_hsample[1] = 2>>chroma_h_shift; | |
| 578 | − s->mjpeg_hsample[2] = 2>>chroma_h_shift; | |
| 677 | + s->mjpeg_hsample[1] = 2 >> chroma_h_shift; | |
| 678 | + s->mjpeg_hsample[2] = 2 >> chroma_h_shift; | |
| 579 | 679 | } |
| 580 | − if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) | |
| 581 | − || ff_mjpeg_encode_init(s) < 0) | |
| 680 | + if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) || | |
| 681 | + ff_mjpeg_encode_init(s) < 0) | |
| 582 | 682 | return -1; |
| 583 | − avctx->delay=0; | |
| 584 | − s->low_delay=1; | |
| 683 | + avctx->delay = 0; | |
| 684 | + s->low_delay = 1; | |
| 585 | 685 | break; |
| 586 | 686 | case CODEC_ID_H261: |
| 587 | − if (!CONFIG_H261_ENCODER) return -1; | |
| 687 | + if (!CONFIG_H261_ENCODER) | |
| 688 | + return -1; | |
| 588 | 689 | if (ff_h261_get_picture_format(s->width, s->height) < 0) { |
| 589 | − av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height); | |
| 690 | + av_log(avctx, AV_LOG_ERROR, | |
| 691 | + "The specified picture size of %dx%d is not valid for the " | |
| 692 | + "H.261 codec.\nValid sizes are 176x144, 352x288\n", | |
| 693 | + s->width, s->height); | |
| 590 | 694 | return -1; |
| 591 | 695 | } |
| 592 | 696 | s->out_format = FMT_H261; |
| 593 | − avctx->delay=0; | |
| 594 | − s->low_delay=1; | |
| 697 | + avctx->delay = 0; | |
| 698 | + s->low_delay = 1; | |
| 595 | 699 | break; |
| 596 | 700 | case CODEC_ID_H263: |
| 597 | − if (!CONFIG_H263_ENCODER) return -1; | |
| 598 | − if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 8) { | |
| 599 | − av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height); | |
| 701 | + if (!CONFIG_H263_ENCODER) | |
| 702 | + return -1; | |
| 703 | + if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), | |
| 704 | + s->width, s->height) == 8) { | |
| 705 | + av_log(avctx, AV_LOG_INFO, | |
| 706 | + "The specified picture size of %dx%d is not valid for " | |
| 707 | + "the H.263 codec.\nValid sizes are 128x96, 176x144, " | |
| 708 | + "352x288, 704x576, and 1408x1152." | |
| 709 | + "Try H.263+.\n", s->width, s->height); | |
| 600 | 710 | return -1; |
| 601 | 711 | } |
| 602 | 712 | s->out_format = FMT_H263; |
| 603 | − avctx->delay=0; | |
| 604 | − s->low_delay=1; | |
| 713 | + avctx->delay = 0; | |
| 714 | + s->low_delay = 1; | |
| 605 | 715 | break; |
| 606 | 716 | case CODEC_ID_H263P: |
| 607 | 717 | s->out_format = FMT_H263; |
| 608 | − s->h263_plus = 1; | |
| 718 | + s->h263_plus = 1; | |
| 609 | 719 | /* Fx */ |
| 610 | 720 | #if FF_API_MPEGVIDEO_GLOBAL_OPTS |
| 611 | 721 | if (avctx->flags & CODEC_FLAG_H263P_UMV) |
| @@ -615,108 +725,110 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 3 unmodified lines | ||
| 615 | 725 | if (avctx->flags & CODEC_FLAG_H263P_SLICE_STRUCT) |
| 616 | 726 | s->h263_slice_structured = 1; |
| 617 | 727 | #endif |
| 618 | − s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0; | |
| 619 | − s->modified_quant= s->h263_aic; | |
| 620 | − s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; | |
| 621 | − s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; | |
| 728 | + s->h263_aic = (avctx->flags & CODEC_FLAG_AC_PRED) ? 1 : 0; | |
| 729 | + s->modified_quant = s->h263_aic; | |
| 730 | + s->loop_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1 : 0; | |
| 731 | + s->unrestricted_mv = s->obmc || s->loop_filter || s->umvplus; | |
| 622 | 732 | |
| 623 | 733 | /* /Fx */ |
| 624 | 734 | /* These are just to be sure */ |
| 625 | − avctx->delay=0; | |
| 626 | − s->low_delay=1; | |
| 735 | + avctx->delay = 0; | |
| 736 | + s->low_delay = 1; | |
| 627 | 737 | break; |
| 628 | 738 | case CODEC_ID_FLV1: |
| 629 | − s->out_format = FMT_H263; | |
| 630 | − s->h263_flv = 2; /* format = 1; 11-bit codes */ | |
| 739 | + s->out_format = FMT_H263; | |
| 740 | + s->h263_flv = 2; /* format = 1; 11-bit codes */ | |
| 631 | 741 | s->unrestricted_mv = 1; |
| 632 | − s->rtp_mode=0; /* don't allow GOB */ | |
| 633 | − avctx->delay=0; | |
| 634 | − s->low_delay=1; | |
| 742 | + s->rtp_mode = 0; /* don't allow GOB */ | |
| 743 | + avctx->delay = 0; | |
| 744 | + s->low_delay = 1; | |
| 635 | 745 | break; |
| 636 | 746 | case CODEC_ID_RV10: |
| 637 | 747 | s->out_format = FMT_H263; |
| 638 | − avctx->delay=0; | |
| 639 | − s->low_delay=1; | |
| 748 | + avctx->delay = 0; | |
| 749 | + s->low_delay = 1; | |
| 640 | 750 | break; |
| 641 | 751 | case CODEC_ID_RV20: |
| 642 | − s->out_format = FMT_H263; | |
| 643 | − avctx->delay=0; | |
| 644 | − s->low_delay=1; | |
| 645 | − s->modified_quant=1; | |
| 646 | − s->h263_aic=1; | |
| 647 | − s->h263_plus=1; | |
| 648 | − s->loop_filter=1; | |
| 649 | − s->unrestricted_mv= 0; | |
| 752 | + s->out_format = FMT_H263; | |
| 753 | + avctx->delay = 0; | |
| 754 | + s->low_delay = 1; | |
| 755 | + s->modified_quant = 1; | |
| 756 | + s->h263_aic = 1; | |
| 757 | + s->h263_plus = 1; | |
| 758 | + s->loop_filter = 1; | |
| 759 | + s->unrestricted_mv = 0; | |
| 650 | 760 | break; |
| 651 | 761 | case CODEC_ID_MPEG4: |
| 652 | − s->out_format = FMT_H263; | |
| 653 | − s->h263_pred = 1; | |
| 762 | + s->out_format = FMT_H263; | |
| 763 | + s->h263_pred = 1; | |
| 654 | 764 | s->unrestricted_mv = 1; |
| 655 | − s->low_delay= s->max_b_frames ? 0 : 1; | |
| 656 | − avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 765 | + s->low_delay = s->max_b_frames ? 0 : 1; | |
| 766 | + avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 657 | 767 | break; |
| 658 | 768 | case CODEC_ID_MSMPEG4V2: |
| 659 | − s->out_format = FMT_H263; | |
| 660 | − s->h263_pred = 1; | |
| 769 | + s->out_format = FMT_H263; | |
| 770 | + s->h263_pred = 1; | |
| 661 | 771 | s->unrestricted_mv = 1; |
| 662 | − s->msmpeg4_version= 2; | |
| 663 | − avctx->delay=0; | |
| 664 | − s->low_delay=1; | |
| 772 | + s->msmpeg4_version = 2; | |
| 773 | + avctx->delay = 0; | |
| 774 | + s->low_delay = 1; | |
| 665 | 775 | break; |
| 666 | 776 | case CODEC_ID_MSMPEG4V3: |
| 667 | − s->out_format = FMT_H263; | |
| 668 | − s->h263_pred = 1; | |
| 669 | − s->unrestricted_mv = 1; | |
| 670 | − s->msmpeg4_version= 3; | |
| 671 | − s->flipflop_rounding=1; | |
| 672 | − avctx->delay=0; | |
| 673 | − s->low_delay=1; | |
| 777 | + s->out_format = FMT_H263; | |
| 778 | + s->h263_pred = 1; | |
| 779 | + s->unrestricted_mv = 1; | |
| 780 | + s->msmpeg4_version = 3; | |
| 781 | + s->flipflop_rounding = 1; | |
| 782 | + avctx->delay = 0; | |
| 783 | + s->low_delay = 1; | |
| 674 | 784 | break; |
| 675 | 785 | case CODEC_ID_WMV1: |
| 676 | − s->out_format = FMT_H263; | |
| 677 | − s->h263_pred = 1; | |
| 678 | − s->unrestricted_mv = 1; | |
| 679 | − s->msmpeg4_version= 4; | |
| 680 | − s->flipflop_rounding=1; | |
| 681 | − avctx->delay=0; | |
| 682 | − s->low_delay=1; | |
| 786 | + s->out_format = FMT_H263; | |
| 787 | + s->h263_pred = 1; | |
| 788 | + s->unrestricted_mv = 1; | |
| 789 | + s->msmpeg4_version = 4; | |
| 790 | + s->flipflop_rounding = 1; | |
| 791 | + avctx->delay = 0; | |
| 792 | + s->low_delay = 1; | |
| 683 | 793 | break; |
| 684 | 794 | case CODEC_ID_WMV2: |
| 685 | − s->out_format = FMT_H263; | |
| 686 | − s->h263_pred = 1; | |
| 687 | − s->unrestricted_mv = 1; | |
| 688 | − s->msmpeg4_version= 5; | |
| 689 | − s->flipflop_rounding=1; | |
| 690 | − avctx->delay=0; | |
| 691 | − s->low_delay=1; | |
| 795 | + s->out_format = FMT_H263; | |
| 796 | + s->h263_pred = 1; | |
| 797 | + s->unrestricted_mv = 1; | |
| 798 | + s->msmpeg4_version = 5; | |
| 799 | + s->flipflop_rounding = 1; | |
| 800 | + avctx->delay = 0; | |
| 801 | + s->low_delay = 1; | |
| 692 | 802 | break; |
| 693 | 803 | default: |
| 694 | 804 | return -1; |
| 695 | 805 | } |
| 696 | 806 | |
| 697 | − avctx->has_b_frames= !s->low_delay; | |
| 807 | + avctx->has_b_frames = !s->low_delay; | |
| 698 | 808 | |
| 699 | 809 | s->encoding = 1; |
| 700 | 810 | |
| 701 | − s->progressive_frame= | |
| 702 | − s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)); | |
| 811 | + s->progressive_frame = | |
| 812 | + s->progressive_sequence = !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT | | |
| 813 | + CODEC_FLAG_INTERLACED_ME | | |
| 814 | + CODEC_FLAG_ALT_SCAN)); | |
| 703 | 815 | |
| 704 | 816 | /* init */ |
| 705 | 817 | if (MPV_common_init(s) < 0) |
| 706 | 818 | return -1; |
| 707 | 819 | |
| 708 | − if(!s->dct_quantize) | |
| 820 | + if (!s->dct_quantize) | |
| 709 | 821 | s->dct_quantize = dct_quantize_c; |
| 710 | − if(!s->denoise_dct) | |
| 711 | − s->denoise_dct = denoise_dct_c; | |
| 822 | + if (!s->denoise_dct) | |
| 823 | + s->denoise_dct = denoise_dct_c; | |
| 712 | 824 | s->fast_dct_quantize = s->dct_quantize; |
| 713 | − if(avctx->trellis) | |
| 714 | − s->dct_quantize = dct_quantize_trellis_c; | |
| 825 | + if (avctx->trellis) | |
| 826 | + s->dct_quantize = dct_quantize_trellis_c; | |
| 715 | 827 | |
| 716 | − if((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant) | |
| 717 | − s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
| 828 | + if ((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant) | |
| 829 | + s->chroma_qscale_table = ff_h263_chroma_qscale_table; | |
| 718 | 830 | |
| 719 | − s->quant_precision=5; | |
| 831 | + s->quant_precision = 5; | |
| 720 | 832 | |
| 721 | 833 | ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); |
| 722 | 834 | ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); |
| @@ -732,22 +844,23 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 9 unmodified lines | ||
| 732 | 844 | ff_mpeg1_encode_init(s); |
| 733 | 845 | |
| 734 | 846 | /* init q matrix */ |
| 735 | − for(i=0;i<64;i++) { | |
| 736 | − int j= s->dsp.idct_permutation[i]; | |
| 737 | − if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ | |
| 847 | + for (i = 0; i < 64; i++) { | |
| 848 | + int j = s->dsp.idct_permutation[i]; | |
| 849 | + if (CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4 && | |
| 850 | + s->mpeg_quant) { | |
| 738 | 851 | s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; |
| 739 | 852 | s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; |
| 740 | − }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ | |
| 853 | + } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { | |
| 741 | 854 | s->intra_matrix[j] = |
| 742 | 855 | s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
| 743 | − }else | |
| 744 | − { /* mpeg1/2 */ | |
| 856 | + } else { | |
| 857 | + /* mpeg1/2 */ | |
| 745 | 858 | s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; |
| 746 | 859 | s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
| 747 | 860 | } |
| 748 | − if(s->avctx->intra_matrix) | |
| 861 | + if (s->avctx->intra_matrix) | |
| 749 | 862 | s->intra_matrix[j] = s->avctx->intra_matrix[i]; |
| 750 | − if(s->avctx->inter_matrix) | |
| 863 | + if (s->avctx->inter_matrix) | |
| 751 | 864 | s->inter_matrix[j] = s->avctx->inter_matrix[i]; |
| 752 | 865 | } |
| 753 | 866 | |
| @@ -755,12 +868,14 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 1 unmodified line | ||
| 755 | 868 | /* for mjpeg, we do include qscale in the matrix */ |
| 756 | 869 | if (s->out_format != FMT_MJPEG) { |
| 757 | 870 | ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
| 758 | − s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); | |
| 871 | + s->intra_matrix, s->intra_quant_bias, avctx->qmin, | |
| 872 | + 31, 1); | |
| 759 | 873 | ff_convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, |
| 760 | − s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); | |
| 874 | + s->inter_matrix, s->inter_quant_bias, avctx->qmin, | |
| 875 | + 31, 0); | |
| 761 | 876 | } |
| 762 | 877 | |
| 763 | − if(ff_rate_control_init(s) < 0) | |
| 878 | + if (ff_rate_control_init(s) < 0) | |
| 764 | 879 | return -1; |
| 765 | 880 | |
| 766 | 881 | return 0; |
| @@ -773,7 +888,8 @@ av_cold int MPV_encode_end(AVCodecContext *avctx) · 6 unmodified lines | ||
| 773 | 888 | ff_rate_control_uninit(s); |
| 774 | 889 | |
| 775 | 890 | MPV_common_end(s); |
| 776 | − if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && s->out_format == FMT_MJPEG) | |
| 891 | + if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && | |
| 892 | + s->out_format == FMT_MJPEG) | |
| 777 | 893 | ff_mjpeg_encode_close(s); |
| 778 | 894 | |
| 779 | 895 | av_freep(&avctx->extradata); |
| @@ -781,133 +897,148 @@ av_cold int MPV_encode_end(AVCodecContext *avctx) · 1 unmodified line | ||
| 781 | 897 | return 0; |
| 782 | 898 | } |
| 783 | 899 | |
| 784 | −static int get_sae(uint8_t *src, int ref, int stride){ | |
| 900 | +static int get_sae(uint8_t *src, int ref, int stride) | |
| 901 | +{ | |
| 785 | 902 | int x,y; |
| 786 | − int acc=0; | |
| 903 | + int acc = 0; | |
| 787 | 904 | |
| 788 | − for(y=0; y<16; y++){ | |
| 789 | − for(x=0; x<16; x++){ | |
| 790 | − acc+= FFABS(src[x+y*stride] - ref); | |
| 905 | + for (y = 0; y < 16; y++) { | |
| 906 | + for (x = 0; x < 16; x++) { | |
| 907 | + acc += FFABS(src[x + y * stride] - ref); | |
| 791 | 908 | } |
| 792 | 909 | } |
| 793 | 910 | |
| 794 | 911 | return acc; |
| 795 | 912 | } |
| 796 | 913 | |
| 797 | −static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ | |
| 914 | +static int get_intra_count(MpegEncContext *s, uint8_t *src, | |
| 915 | + uint8_t *ref, int stride) | |
| 916 | +{ | |
| 798 | 917 | int x, y, w, h; |
| 799 | − int acc=0; | |
| 918 | + int acc = 0; | |
| 800 | 919 | |
| 801 | − w= s->width &~15; | |
| 802 | − h= s->height&~15; | |
| 920 | + w = s->width & ~15; | |
| 921 | + h = s->height & ~15; | |
| 803 | 922 | |
| 804 | − for(y=0; y<h; y+=16){ | |
| 805 | − for(x=0; x<w; x+=16){ | |
| 806 | − int offset= x + y*stride; | |
| 807 | − int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16); | |
| 808 | − int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; | |
| 809 | − int sae = get_sae(src + offset, mean, stride); | |
| 923 | + for (y = 0; y < h; y += 16) { | |
| 924 | + for (x = 0; x < w; x += 16) { | |
| 925 | + int offset = x + y * stride; | |
| 926 | + int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, | |
| 927 | + 16); | |
| 928 | + int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8; | |
| 929 | + int sae = get_sae(src + offset, mean, stride); | |
| 810 | 930 | |
| 811 | − acc+= sae + 500 < sad; | |
| 931 | + acc += sae + 500 < sad; | |
| 812 | 932 | } |
| 813 | 933 | } |
| 814 | 934 | return acc; |
| 815 | 935 | } |
| 816 | 936 | |
| 817 | 937 | |
| 818 | −static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ | |
| 819 | − AVFrame *pic=NULL; | |
| 938 | +static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) | |
| 939 | +{ | |
| 940 | + AVFrame *pic = NULL; | |
| 820 | 941 | int64_t pts; |
| 821 | 942 | int i; |
| 822 | − const int encoding_delay= s->max_b_frames; | |
| 823 | − int direct=1; | |
| 824 | − | |
| 825 | − if(pic_arg){ | |
| 826 | − pts= pic_arg->pts; | |
| 827 | − pic_arg->display_picture_number= s->input_picture_number++; | |
| 828 | − | |
| 829 | − if(pts != AV_NOPTS_VALUE){ | |
| 830 | − if(s->user_specified_pts != AV_NOPTS_VALUE){ | |
| 831 | − int64_t time= pts; | |
| 832 | − int64_t last= s->user_specified_pts; | |
| 833 | − | |
| 834 | − if(time <= last){ | |
| 835 | − av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts); | |
| 943 | + const int encoding_delay = s->max_b_frames; | |
| 944 | + int direct = 1; | |
| 945 | + | |
| 946 | + if (pic_arg) { | |
| 947 | + pts = pic_arg->pts; | |
| 948 | + pic_arg->display_picture_number = s->input_picture_number++; | |
| 949 | + | |
| 950 | + if (pts != AV_NOPTS_VALUE) { | |
| 951 | + if (s->user_specified_pts != AV_NOPTS_VALUE) { | |
| 952 | + int64_t time = pts; | |
| 953 | + int64_t last = s->user_specified_pts; | |
| 954 | + | |
| 955 | + if (time <= last) { | |
| 956 | + av_log(s->avctx, AV_LOG_ERROR, | |
| 957 | + "Error, Invalid timestamp=%"PRId64", " | |
| 958 | + "last=%"PRId64"\n", pts, s->user_specified_pts); | |
| 836 | 959 | return -1; |
| 837 | 960 | } |
| 838 | 961 | } |
| 839 | − s->user_specified_pts= pts; | |
| 840 | − }else{ | |
| 841 | − if(s->user_specified_pts != AV_NOPTS_VALUE){ | |
| 842 | − s->user_specified_pts= | |
| 843 | − pts= s->user_specified_pts + 1; | |
| 844 | − av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); | |
| 845 | − }else{ | |
| 846 | − pts= pic_arg->display_picture_number; | |
| 962 | + s->user_specified_pts = pts; | |
| 963 | + } else { | |
| 964 | + if (s->user_specified_pts != AV_NOPTS_VALUE) { | |
| 965 | + s->user_specified_pts = | |
| 966 | + pts = s->user_specified_pts + 1; | |
| 967 | + av_log(s->avctx, AV_LOG_INFO, | |
| 968 | + "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", | |
| 969 | + pts); | |
| 970 | + } else { | |
| 971 | + pts = pic_arg->display_picture_number; | |
| 847 | 972 | } |
| 848 | 973 | } |
| 849 | 974 | } |
| 850 | 975 | |
| 851 | − if(pic_arg){ | |
| 852 | − if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; | |
| 853 | − if(pic_arg->linesize[0] != s->linesize) direct=0; | |
| 854 | − if(pic_arg->linesize[1] != s->uvlinesize) direct=0; | |
| 855 | − if(pic_arg->linesize[2] != s->uvlinesize) direct=0; | |
| 976 | + if (pic_arg) { | |
| 977 | + if (encoding_delay && !(s->flags & CODEC_FLAG_INPUT_PRESERVED)) | |
| 978 | + direct = 0; | |
| 979 | + if (pic_arg->linesize[0] != s->linesize) | |
| 980 | + direct = 0; | |
| 981 | + if (pic_arg->linesize[1] != s->uvlinesize) | |
| 982 | + direct = 0; | |
| 983 | + if (pic_arg->linesize[2] != s->uvlinesize) | |
| 984 | + direct = 0; | |
| 856 | 985 | |
| 857 | −// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); | |
| 986 | + //av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], | |
| 987 | + // pic_arg->linesize[1], s->linesize, s->uvlinesize); | |
| 858 | 988 | |
| 859 | − if(direct){ | |
| 860 | − i= ff_find_unused_picture(s, 1); | |
| 989 | + if (direct) { | |
| 990 | + i = ff_find_unused_picture(s, 1); | |
| 861 | 991 | if (i < 0) |
| 862 | 992 | return i; |
| 863 | 993 | |
| 864 | − pic= (AVFrame*)&s->picture[i]; | |
| 865 | − pic->reference= 3; | |
| 994 | + pic = (AVFrame *) &s->picture[i]; | |
| 995 | + pic->reference = 3; | |
| 866 | 996 | |
| 867 | − for(i=0; i<4; i++){ | |
| 868 | − pic->data[i]= pic_arg->data[i]; | |
| 869 | − pic->linesize[i]= pic_arg->linesize[i]; | |
| 997 | + for (i = 0; i < 4; i++) { | |
| 998 | + pic->data[i] = pic_arg->data[i]; | |
| 999 | + pic->linesize[i] = pic_arg->linesize[i]; | |
| 870 | 1000 | } |
| 871 | − if(ff_alloc_picture(s, (Picture*)pic, 1) < 0){ | |
| 1001 | + if (ff_alloc_picture(s, (Picture *) pic, 1) < 0) { | |
| 872 | 1002 | return -1; |
| 873 | 1003 | } |
| 874 | − }else{ | |
| 875 | − i= ff_find_unused_picture(s, 0); | |
| 1004 | + } else { | |
| 1005 | + i = ff_find_unused_picture(s, 0); | |
| 876 | 1006 | if (i < 0) |
| 877 | 1007 | return i; |
| 878 | 1008 | |
| 879 | − pic= (AVFrame*)&s->picture[i]; | |
| 880 | − pic->reference= 3; | |
| 1009 | + pic = (AVFrame *) &s->picture[i]; | |
| 1010 | + pic->reference = 3; | |
| 881 | 1011 | |
| 882 | − if(ff_alloc_picture(s, (Picture*)pic, 0) < 0){ | |
| 1012 | + if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) { | |
| 883 | 1013 | return -1; |
| 884 | 1014 | } |
| 885 | 1015 | |
| 886 | − if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] | |
| 887 | − && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] | |
| 888 | − && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ | |
| 889 | − // empty | |
| 890 | − }else{ | |
| 1016 | + if (pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] && | |
| 1017 | + pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] && | |
| 1018 | + pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]) { | |
| 1019 | + // empty | |
| 1020 | + } else { | |
| 891 | 1021 | int h_chroma_shift, v_chroma_shift; |
| 892 | − avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
| 893 | − | |
| 894 | − for(i=0; i<3; i++){ | |
| 895 | − int src_stride= pic_arg->linesize[i]; | |
| 896 | − int dst_stride= i ? s->uvlinesize : s->linesize; | |
| 897 | − int h_shift= i ? h_chroma_shift : 0; | |
| 898 | − int v_shift= i ? v_chroma_shift : 0; | |
| 899 | − int w= s->width >>h_shift; | |
| 900 | − int h= s->height>>v_shift; | |
| 901 | − uint8_t *src= pic_arg->data[i]; | |
| 902 | − uint8_t *dst= pic->data[i]; | |
| 903 | − | |
| 904 | − if(!s->avctx->rc_buffer_size) | |
| 905 | − dst +=INPLACE_OFFSET; | |
| 906 | − | |
| 907 | − if(src_stride==dst_stride) | |
| 908 | − memcpy(dst, src, src_stride*h); | |
| 909 | − else{ | |
| 910 | − while(h--){ | |
| 1022 | + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, | |
| 1023 | + &v_chroma_shift); | |
| 1024 | + | |
| 1025 | + for (i = 0; i < 3; i++) { | |
| 1026 | + int src_stride = pic_arg->linesize[i]; | |
| 1027 | + int dst_stride = i ? s->uvlinesize : s->linesize; | |
| 1028 | + int h_shift = i ? h_chroma_shift : 0; | |
| 1029 | + int v_shift = i ? v_chroma_shift : 0; | |
| 1030 | + int w = s->width >> h_shift; | |
| 1031 | + int h = s->height >> v_shift; | |
| 1032 | + uint8_t *src = pic_arg->data[i]; | |
| 1033 | + uint8_t *dst = pic->data[i]; | |
| 1034 | + | |
| 1035 | + if (!s->avctx->rc_buffer_size) | |
| 1036 | + dst += INPLACE_OFFSET; | |
| 1037 | + | |
| 1038 | + if (src_stride == dst_stride) | |
| 1039 | + memcpy(dst, src, src_stride * h); | |
| 1040 | + else { | |
| 1041 | + while (h--) { | |
| 911 | 1042 | memcpy(dst, src, w); |
| 912 | 1043 | dst += dst_stride; |
| 913 | 1044 | src += src_stride; |
| @@ -917,81 +1048,91 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ · 3 unmodified lines | ||
| 917 | 1048 | } |
| 918 | 1049 | } |
| 919 | 1050 | copy_picture_attributes(s, pic, pic_arg); |
| 920 | − pic->pts= pts; //we set this here to avoid modifiying pic_arg | |
| 1051 | + pic->pts = pts; // we set this here to avoid modifiying pic_arg | |
| 921 | 1052 | } |
| 922 | 1053 | |
| 923 | 1054 | /* shift buffer entries */ |
| 924 | − for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++) | |
| 925 | − s->input_picture[i-1]= s->input_picture[i]; | |
| 1055 | + for (i = 1; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++) | |
| 1056 | + s->input_picture[i - 1] = s->input_picture[i]; | |
| 926 | 1057 | |
| 927 | − s->input_picture[encoding_delay]= (Picture*)pic; | |
| 1058 | + s->input_picture[encoding_delay] = (Picture*) pic; | |
| 928 | 1059 | |
| 929 | 1060 | return 0; |
| 930 | 1061 | } |
| 931 | 1062 | |
| 932 | −static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ | |
| 1063 | +static int skip_check(MpegEncContext *s, Picture *p, Picture *ref) | |
| 1064 | +{ | |
| 933 | 1065 | int x, y, plane; |
| 934 | − int score=0; | |
| 935 | − int64_t score64=0; | |
| 1066 | + int score = 0; | |
| 1067 | + int64_t score64 = 0; | |
| 936 | 1068 | |
| 937 | − for(plane=0; plane<3; plane++){ | |
| 1069 | + for (plane = 0; plane < 3; plane++) { | |
| 938 | 1070 | const int stride = p->f.linesize[plane]; |
| 939 | − const int bw= plane ? 1 : 2; | |
| 940 | − for(y=0; y<s->mb_height*bw; y++){ | |
| 941 | − for(x=0; x<s->mb_width*bw; x++){ | |
| 942 | − int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0: 16; | |
| 943 | − int v = s->dsp.frame_skip_cmp[1](s, p->f.data[plane] + 8*(x + y*stride)+off, ref->f.data[plane] + 8*(x + y*stride), stride, 8); | |
| 944 | − | |
| 945 | − switch(s->avctx->frame_skip_exp){ | |
| 946 | − case 0: score= FFMAX(score, v); break; | |
| 947 | − case 1: score+= FFABS(v);break; | |
| 948 | − case 2: score+= v*v;break; | |
| 949 | − case 3: score64+= FFABS(v*v*(int64_t)v);break; | |
| 950 | − case 4: score64+= v*v*(int64_t)(v*v);break; | |
| 1071 | + const int bw = plane ? 1 : 2; | |
| 1072 | + for (y = 0; y < s->mb_height * bw; y++) { | |
| 1073 | + for (x = 0; x < s->mb_width * bw; x++) { | |
| 1074 | + int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0 : 16; | |
| 1075 | + uint8_t *dptr = p->f.data[plane] + 8 * (x + y * stride) + off; | |
| 1076 | + uint8_t *rptr = ref->f.data[plane] + 8 * (x + y * stride); | |
| 1077 | + int v = s->dsp.frame_skip_cmp[1](s, dptr, rptr, stride, 8); | |
| 1078 | + | |
| 1079 | + switch (s->avctx->frame_skip_exp) { | |
| 1080 | + case 0: score = FFMAX(score, v); break; | |
| 1081 | + case 1: score += FFABS(v); break; | |
| 1082 | + case 2: score += v * v; break; | |
| 1083 | + case 3: score64 += FFABS(v * v * (int64_t)v); break; | |
| 1084 | + case 4: score64 += v * v * (int64_t)(v * v); break; | |
| 951 | 1085 | } |
| 952 | 1086 | } |
| 953 | 1087 | } |
| 954 | 1088 | } |
| 955 | 1089 | |
| 956 | − if(score) score64= score; | |
| 1090 | + if (score) | |
| 1091 | + score64 = score; | |
| 957 | 1092 | |
| 958 | − if(score64 < s->avctx->frame_skip_threshold) | |
| 1093 | + if (score64 < s->avctx->frame_skip_threshold) | |
| 959 | 1094 | return 1; |
| 960 | − if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) | |
| 1095 | + if (score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda) >> 8)) | |
| 961 | 1096 | return 1; |
| 962 | 1097 | return 0; |
| 963 | 1098 | } |
| 964 | 1099 | |
| 965 | −static int estimate_best_b_count(MpegEncContext *s){ | |
| 966 | − AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); | |
| 1100 | +static int estimate_best_b_count(MpegEncContext *s) | |
| 1101 | +{ | |
| 1102 | + AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id); | |
| 967 | 1103 | AVCodecContext *c = avcodec_alloc_context3(NULL); |
| 968 | − AVFrame input[FF_MAX_B_FRAMES+2]; | |
| 969 | − const int scale= s->avctx->brd_scale; | |
| 1104 | + AVFrame input[FF_MAX_B_FRAMES + 2]; | |
| 1105 | + const int scale = s->avctx->brd_scale; | |
| 970 | 1106 | int i, j, out_size, p_lambda, b_lambda, lambda2; |
| 971 | − int outbuf_size= s->width * s->height; //FIXME | |
| 972 | − uint8_t *outbuf= av_malloc(outbuf_size); | |
| 973 | − int64_t best_rd= INT64_MAX; | |
| 974 | − int best_b_count= -1; | |
| 975 | − | |
| 976 | − assert(scale>=0 && scale <=3); | |
| 977 | − | |
| 978 | −// emms_c(); | |
| 979 | − p_lambda= s->last_lambda_for[AV_PICTURE_TYPE_P]; //s->next_picture_ptr->quality; | |
| 980 | − b_lambda= s->last_lambda_for[AV_PICTURE_TYPE_B]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; | |
| 981 | − if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else | |
| 982 | − lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT; | |
| 983 | − | |
| 984 | − c->width = s->width >> scale; | |
| 985 | − c->height= s->height>> scale; | |
| 986 | − c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; | |
| 987 | − c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; | |
| 988 | − c->mb_decision= s->avctx->mb_decision; | |
| 989 | − c->me_cmp= s->avctx->me_cmp; | |
| 990 | − c->mb_cmp= s->avctx->mb_cmp; | |
| 991 | − c->me_sub_cmp= s->avctx->me_sub_cmp; | |
| 992 | − c->pix_fmt = PIX_FMT_YUV420P; | |
| 993 | − c->time_base= s->avctx->time_base; | |
| 994 | − c->max_b_frames= s->max_b_frames; | |
| 1107 | + int outbuf_size = s->width * s->height; // FIXME | |
| 1108 | + uint8_t *outbuf = av_malloc(outbuf_size); | |
| 1109 | + int64_t best_rd = INT64_MAX; | |
| 1110 | + int best_b_count = -1; | |
| 1111 | + | |
| 1112 | + assert(scale >= 0 && scale <= 3); | |
| 1113 | + | |
| 1114 | + //emms_c(); | |
| 1115 | + //s->next_picture_ptr->quality; | |
| 1116 | + p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; | |
| 1117 | + //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; | |
| 1118 | + b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B]; | |
| 1119 | + if (!b_lambda) // FIXME we should do this somewhere else | |
| 1120 | + b_lambda = p_lambda; | |
| 1121 | + lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >> | |
| 1122 | + FF_LAMBDA_SHIFT; | |
| 1123 | + | |
| 1124 | + c->width = s->width >> scale; | |
| 1125 | + c->height = s->height >> scale; | |
| 1126 | + c->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | | |
| 1127 | + CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; | |
| 1128 | + c->flags |= s->avctx->flags & CODEC_FLAG_QPEL; | |
| 1129 | + c->mb_decision = s->avctx->mb_decision; | |
| 1130 | + c->me_cmp = s->avctx->me_cmp; | |
| 1131 | + c->mb_cmp = s->avctx->mb_cmp; | |
| 1132 | + c->me_sub_cmp = s->avctx->me_sub_cmp; | |
| 1133 | + c->pix_fmt = PIX_FMT_YUV420P; | |
| 1134 | + c->time_base = s->avctx->time_base; | |
| 1135 | + c->max_b_frames = s->max_b_frames; | |
| 995 | 1136 | |
| 996 | 1137 | if (avcodec_open2(c, codec, NULL) < 0) |
| 997 | 1138 | return -1; |