}
}
-static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst,
- const AVFrame *src)
-{
- dst->pict_type = src->pict_type;
- dst->quality = src->quality;
- dst->coded_picture_number = src->coded_picture_number;
- dst->display_picture_number = src->display_picture_number;
- //dst->reference = src->reference;
- dst->pts = src->pts;
- dst->interlaced_frame = src->interlaced_frame;
- dst->top_field_first = src->top_field_first;
-}
-
static void update_duplicate_context_after_me(MpegEncContext *dst,
MpegEncContext *src)
{
av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
- int i;
+ int i, ret;
int chroma_h_shift, chroma_v_shift;
MPV_encode_defaults(s);
s->avctx = avctx;
s->flags = avctx->flags;
s->flags2 = avctx->flags2;
+ if (avctx->max_b_frames > MAX_B_FRAMES) {
+ av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum "
+ "is %d.\n", MAX_B_FRAMES);
+ }
s->max_b_frames = avctx->max_b_frames;
s->codec_id = avctx->codec->id;
s->strict_std_compliance = avctx->strict_std_compliance;
if (ARCH_X86)
ff_MPV_encode_init_x86(s);
+ ff_h263dsp_init(&s->h263dsp);
if (!s->dct_quantize)
s->dct_quantize = ff_dct_quantize_c;
if (!s->denoise_dct)
if (ff_rate_control_init(s) < 0)
return -1;
+#if FF_API_ERROR_RATE
+ FF_DISABLE_DEPRECATION_WARNINGS
+ if (avctx->error_rate)
+ s->error_rate = avctx->error_rate;
+ FF_ENABLE_DEPRECATION_WARNINGS;
+#endif
+
+ if (avctx->b_frame_strategy == 2) {
+ for (i = 0; i < s->max_b_frames + 2; i++) {
+ s->tmp_frames[i] = av_frame_alloc();
+ if (!s->tmp_frames[i])
+ return AVERROR(ENOMEM);
+
+ s->tmp_frames[i]->format = AV_PIX_FMT_YUV420P;
+ s->tmp_frames[i]->width = s->width >> avctx->brd_scale;
+ s->tmp_frames[i]->height = s->height >> avctx->brd_scale;
+
+ ret = av_frame_get_buffer(s->tmp_frames[i], 32);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
return 0;
}
av_cold int ff_MPV_encode_end(AVCodecContext *avctx)
{
MpegEncContext *s = avctx->priv_data;
+ int i;
ff_rate_control_uninit(s);
av_freep(&avctx->extradata);
+ for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
+ av_frame_free(&s->tmp_frames[i]);
+
return 0;
}
if (pic_arg->linesize[2] != s->uvlinesize)
direct = 0;
- av_dlog(s->avctx, "%d %d %d %d\n", pic_arg->linesize[0],
+ av_dlog(s->avctx, "%d %d %td %td\n", pic_arg->linesize[0],
pic_arg->linesize[1], s->linesize, s->uvlinesize);
if (direct) {
}
}
}
- copy_picture_attributes(s, &pic->f, pic_arg);
+ ret = av_frame_copy_props(&pic->f, pic_arg);
+ if (ret < 0)
+ return ret;
+
pic->f.display_picture_number = display_picture_number;
pic->f.pts = pts; // we set this here to avoid modifiying pic_arg
}
{
AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
AVCodecContext *c = avcodec_alloc_context3(NULL);
- AVFrame input[FF_MAX_B_FRAMES + 2];
const int scale = s->avctx->brd_scale;
int i, j, out_size, p_lambda, b_lambda, lambda2;
int64_t best_rd = INT64_MAX;
return -1;
for (i = 0; i < s->max_b_frames + 2; i++) {
- int ysize = c->width * c->height;
- int csize = (c->width / 2) * (c->height / 2);
Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
s->next_picture_ptr;
- avcodec_get_frame_defaults(&input[i]);
- input[i].data[0] = av_malloc(ysize + 2 * csize);
- input[i].data[1] = input[i].data[0] + ysize;
- input[i].data[2] = input[i].data[1] + csize;
- input[i].linesize[0] = c->width;
- input[i].linesize[1] =
- input[i].linesize[2] = c->width / 2;
-
if (pre_input_ptr && (!i || s->input_picture[i - 1])) {
pre_input = *pre_input_ptr;
pre_input.f.data[2] += INPLACE_OFFSET;
}
- s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0],
+ s->dsp.shrink[scale](s->tmp_frames[i]->data[0], s->tmp_frames[i]->linesize[0],
pre_input.f.data[0], pre_input.f.linesize[0],
c->width, c->height);
- s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1],
+ s->dsp.shrink[scale](s->tmp_frames[i]->data[1], s->tmp_frames[i]->linesize[1],
pre_input.f.data[1], pre_input.f.linesize[1],
c->width >> 1, c->height >> 1);
- s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2],
+ s->dsp.shrink[scale](s->tmp_frames[i]->data[2], s->tmp_frames[i]->linesize[2],
pre_input.f.data[2], pre_input.f.linesize[2],
c->width >> 1, c->height >> 1);
}
c->error[0] = c->error[1] = c->error[2] = 0;
- input[0].pict_type = AV_PICTURE_TYPE_I;
- input[0].quality = 1 * FF_QP2LAMBDA;
+ s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
+ s->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA;
- out_size = encode_frame(c, &input[0]);
+ out_size = encode_frame(c, s->tmp_frames[0]);
//rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;
for (i = 0; i < s->max_b_frames + 1; i++) {
int is_p = i % (j + 1) == j || i == s->max_b_frames;
- input[i + 1].pict_type = is_p ?
+ s->tmp_frames[i + 1]->pict_type = is_p ?
AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;
- input[i + 1].quality = is_p ? p_lambda : b_lambda;
+ s->tmp_frames[i + 1]->quality = is_p ? p_lambda : b_lambda;
- out_size = encode_frame(c, &input[i + 1]);
+ out_size = encode_frame(c, s->tmp_frames[i + 1]);
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
}
avcodec_close(c);
av_freep(&c);
- for (i = 0; i < s->max_b_frames + 2; i++) {
- av_freep(&input[i].data[0]);
- }
-
return best_b_count;
}
return -1;
}
- copy_picture_attributes(s, &pic->f,
- &s->reordered_input_picture[0]->f);
+ ret = av_frame_copy_props(&pic->f, &s->reordered_input_picture[0]->f);
+ if (ret < 0)
+ return ret;
/* mark us unused / free shared pic */
av_frame_unref(&s->reordered_input_picture[0]->f);
int skip_dct[8];
int dct_offset = s->linesize * 8; // default for progressive frames
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int wrap_y, wrap_c;
+ ptrdiff_t wrap_y, wrap_c;
for (i = 0; i < mb_block_count; i++)
skip_dct[i] = s->skipdct;
if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {
uint8_t *ebuf = s->edge_emu_buffer + 32;
- s->vdsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,
- mb_y * 16, s->width, s->height);
+ s->vdsp.emulated_edge_mc(ebuf, ptr_y,
+ wrap_y, wrap_y,
+ 16, 16, mb_x * 16, mb_y * 16,
+ s->width, s->height);
ptr_y = ebuf;
- s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,
- mb_block_height, mb_x * 8, mb_y * 8,
+ s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb,
+ wrap_c, wrap_c,
+ 8, mb_block_height, mb_x * 8, mb_y * 8,
s->width >> 1, s->height >> 1);
ptr_cb = ebuf + 18 * wrap_y;
- s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,
- mb_block_height, mb_x * 8, mb_y * 8,
+ s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr,
+ wrap_c, wrap_c,
+ 8, mb_block_height, mb_x * 8, mb_y * 8,
s->width >> 1, s->height >> 1);
ptr_cr = ebuf + 18 * wrap_y + 8;
}
assert((put_bits_count(&s->pb)&7) == 0);
current_packet_size= put_bits_ptr(&s->pb) - s->ptr_lastgob;
- if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){
+ if (s->error_rate && s->resync_mb_x + s->resync_mb_y > 0) {
int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y;
- int d= 100 / s->avctx->error_rate;
+ int d = 100 / s->error_rate;
if(r % d == 0){
current_packet_size=0;
s->pb.buf_ptr= s->ptr_lastgob;
AVCodec ff_h263_encoder = {
.name = "h263",
+ .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H263,
.priv_data_size = sizeof(MpegEncContext),
.encode2 = ff_MPV_encode_picture,
.close = ff_MPV_encode_end,
.pix_fmts= (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE},
- .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"),
.priv_class = &h263_class,
};
AVCodec ff_h263p_encoder = {
.name = "h263p",
+ .long_name = NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H263P,
.priv_data_size = sizeof(MpegEncContext),
.close = ff_MPV_encode_end,
.capabilities = CODEC_CAP_SLICE_THREADS,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
- .long_name = NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"),
.priv_class = &h263p_class,
};
AVCodec ff_msmpeg4v2_encoder = {
.name = "msmpeg4v2",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MSMPEG4V2,
.priv_data_size = sizeof(MpegEncContext),
.encode2 = ff_MPV_encode_picture,
.close = ff_MPV_encode_end,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
.priv_class = &msmpeg4v2_class,
};
AVCodec ff_msmpeg4v3_encoder = {
.name = "msmpeg4",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MSMPEG4V3,
.priv_data_size = sizeof(MpegEncContext),
.encode2 = ff_MPV_encode_picture,
.close = ff_MPV_encode_end,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
.priv_class = &msmpeg4v3_class,
};
AVCodec ff_wmv1_encoder = {
.name = "wmv1",
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV1,
.priv_data_size = sizeof(MpegEncContext),
.encode2 = ff_MPV_encode_picture,
.close = ff_MPV_encode_end,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
.priv_class = &wmv1_class,
};