diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-09-25 04:54:20 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-09-25 06:33:16 +0400 |
commit | f2f28861da6a332712eb632e98010d1a7838f43a (patch) | |
tree | 8f2c99b0e5d260585a623ee8437e6ae9ab764ece /libavcodec | |
parent | ccecab4a0d7f3f4f296551c2e22bbf12af7d14e8 (diff) |
AMV video encoder.
Authors are Vladimir Voroshilov and Dobrica Pavlinušić based on svn blame/log
For full details of authorship see http://code.google.com/p/amv-codec-tools/
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/allcodecs.c | 2 | ||||
-rw-r--r-- | libavcodec/mjpegenc.c | 36 | ||||
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 10 |
3 files changed, 47 insertions, 1 deletions
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 0115240d66..6522127d26 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -71,7 +71,7 @@ void avcodec_register_all(void) REGISTER_ENCODER (A64MULTI, a64multi); REGISTER_ENCODER (A64MULTI5, a64multi5); REGISTER_DECODER (AASC, aasc); - REGISTER_DECODER (AMV, amv); + REGISTER_ENCDEC (AMV, amv); REGISTER_DECODER (ANM, anm); REGISTER_DECODER (ANSI, ansi); REGISTER_ENCDEC (ASV1, asv1); diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index 48b84701b6..91a119e931 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -200,6 +200,9 @@ void ff_mjpeg_encode_picture_header(MpegEncContext *s) put_marker(&s->pb, SOI); + // hack for AMV mjpeg format + if(s->avctx->codec_id == CODEC_ID_AMV) return; + jpeg_put_comments(s); jpeg_table_header(s); @@ -445,6 +448,28 @@ void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]) s->i_tex_bits += get_bits_diff(s); } +// maximum over s->mjpeg_vsample[i] +#define V_MAX 2 +static int amv_encode_picture(AVCodecContext *avctx, + unsigned char *buf, int buf_size, void *data) +{ + + AVFrame* pic=data; + MpegEncContext *s = avctx->priv_data; + int i; + + //CODEC_FLAG_EMU_EDGE have to be cleared + if(s->avctx->flags & CODEC_FLAG_EMU_EDGE) + return -1; + + //picture should be flipped upside-down + for(i=0; i < 3; i++) { + pic->data[i] += (pic->linesize[i] * (s->mjpeg_vsample[i] * (8 * s->mb_height -((s->height/V_MAX)&7)) - 1 )); + pic->linesize[i] *= -1; + } + return MPV_encode_picture(avctx,buf, buf_size, pic); +} + AVCodec ff_mjpeg_encoder = { .name = "mjpeg", .type = AVMEDIA_TYPE_VIDEO, @@ -456,3 +481,14 @@ AVCodec ff_mjpeg_encoder = { .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), }; + +AVCodec ff_amv_encoder = { + "amv", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_AMV, + sizeof(MpegEncContext), + MPV_encode_init, + amv_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, -1}, +}; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 65eff63c2c..c9c67d0e63 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -265,6 +265,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) } break; case CODEC_ID_MJPEG: + case CODEC_ID_AMV: if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); @@ -530,6 +531,11 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){ s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x s->inter_quant_bias= 0; + }else if(s->codec_id==CODEC_ID_AMV){ + s->intra_quant_bias= 0; + s->inter_quant_bias= 0; + s->fixed_qscale = 1; + s->adaptive_quant = 0; }else{ s->intra_quant_bias=0; s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x @@ -540,6 +546,8 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) s->inter_quant_bias= avctx->inter_quant_bias; + av_log(avctx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_quant_bias); + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ @@ -564,6 +572,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_LJPEG: case CODEC_ID_MJPEG: + case CODEC_ID_AMV: s->out_format = FMT_MJPEG; s->intra_only = 1; /* force intra only for jpeg */ if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){ @@ -1788,6 +1797,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, h263_encode_mb(s, s->block, motion_x, motion_y); break; case CODEC_ID_MJPEG: + case CODEC_ID_AMV: if (CONFIG_MJPEG_ENCODER) ff_mjpeg_encode_mb(s, s->block); break; |