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