]> git.sesse.net Git - ffmpeg/commitdiff
lavc: add -mpv_flags to mpegvideo_enc-based encoders.
authorAnton Khirnov <anton@khirnov.net>
Mon, 27 Feb 2012 11:12:19 +0000 (12:12 +0100)
committerAnton Khirnov <anton@khirnov.net>
Wed, 29 Feb 2012 06:09:29 +0000 (07:09 +0100)
Deprecate CODEC_FLAG2_SKIP_RD in favor of the corresponding mpv_flags
flag.

libavcodec/avcodec.h
libavcodec/flvenc.c
libavcodec/h261enc.c
libavcodec/mpeg12enc.c
libavcodec/mpeg4videoenc.c
libavcodec/mpegvideo.h
libavcodec/mpegvideo_enc.c
libavcodec/options.c
libavcodec/rv10enc.c
libavcodec/rv20enc.c
libavcodec/version.h

index cd86856d32505ae92d5e92203ccebff37f1fce8d..0623c1cb01418a639bfde099e3a38a20204b3bc9 100644 (file)
@@ -570,7 +570,9 @@ typedef struct RcOverride{
 #define CODEC_FLAG2_STRICT_GOP    0x00000002 ///< Strictly enforce GOP size.
 #define CODEC_FLAG2_NO_OUTPUT     0x00000004 ///< Skip bitstream encoding.
 #define CODEC_FLAG2_LOCAL_HEADER  0x00000008 ///< Place global headers at every keyframe instead of in extradata.
+#if FF_API_MPV_GLOBAL_OPTS
 #define CODEC_FLAG2_SKIP_RD       0x00004000 ///< RD optimal MB level residual skipping
+#endif
 #define CODEC_FLAG2_CHUNKS        0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
 
 /* Unsupported options :
index 332592d62322f0be05026b405ffdd3ea55a4d4be..121aaf548deb30680fa36b463fbb533a2f3fd822 100644 (file)
@@ -84,6 +84,8 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, in
     }
 }
 
+FF_MPV_GENERIC_CLASS(flv)
+
 AVCodec ff_flv_encoder = {
     .name           = "flv",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -94,4 +96,5 @@ AVCodec ff_flv_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
+    .priv_class     = &flv_class,
 };
index 0ae48ca0921754ad175b8f9f4bc508198696848f..1f3cf714f16ec6a2f359ae25cba38584ed03af1b 100644 (file)
@@ -321,6 +321,8 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
     }
 }
 
+FF_MPV_GENERIC_CLASS(h261)
+
 AVCodec ff_h261_encoder = {
     .name           = "h261",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -331,4 +333,5 @@ AVCodec ff_h261_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("H.261"),
+    .priv_class     = &h261_class,
 };
index c53d99b1b50d5b63dfb512d95b9926c14d454a4e..b6cbbbc2d26e51d7358c07c35ba6671109a60a67 100644 (file)
@@ -927,6 +927,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
 
 static const AVOption mpeg1_options[] = {
     COMMON_OPTS
+    FF_MPV_COMMON_OPTS
     { NULL },
 };
 
@@ -934,6 +935,7 @@ static const AVOption mpeg2_options[] = {
     COMMON_OPTS
     { "non_linear_quant",    "Use nonlinear quantizer.",          OFFSET(q_scale_type),         AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
     { "alternate_scan",      "Enable alternate scantable.",       OFFSET(alternate_scan),       AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+    FF_MPV_COMMON_OPTS
     { NULL },
 };
 
index d512daa1fa1a5f5f7dbf8cd06570137a0bc4d8fe..c2d4626dadb44860ab5c4d35b18993512b963b89 100644 (file)
@@ -1320,6 +1320,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
 static const AVOption options[] = {
     { "data_partitioning",       "Use data partitioning.",      OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
     { "alternate_scan",          "Enable alternate scantable.", OFFSET(alternate_scan),    AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+    FF_MPV_COMMON_OPTS
     { NULL },
 };
 
index 9753d1064cd6250903b50bc2c7e371a759297a50..7e157fdfffd5372bcf7572d078e8b0ca27d5863f 100644 (file)
@@ -37,6 +37,8 @@
 #include "mpeg12data.h"
 #include "rl.h"
 
+#include "libavutil/opt.h"
+
 #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
 
 enum OutputFormat {
@@ -687,6 +689,8 @@ typedef struct MpegEncContext {
     int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
     int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
     void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
+
+    int mpv_flags;      ///< flags set by private options
 } MpegEncContext;
 
 #define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
@@ -694,6 +698,25 @@ typedef struct MpegEncContext {
         &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
     : NULL)
 
+/* mpegvideo_enc common options */
+#define FF_MPV_FLAG_SKIP_RD      0x0001
+
+#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
+#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
+#define FF_MPV_COMMON_OPTS \
+{ "mpv_flags",      "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "skip_rd",        "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+
+extern const AVOption ff_mpv_generic_options[];
+
+#define FF_MPV_GENERIC_CLASS(name) \
+static const AVClass name ## _class = {\
+    .class_name = #name " encoder",\
+    .item_name  = av_default_item_name,\
+    .option     = ff_mpv_generic_options,\
+    .version    = LIBAVUTIL_VERSION_INT,\
+};
+
 void ff_MPV_decode_defaults(MpegEncContext *s);
 int ff_MPV_common_init(MpegEncContext *s);
 void ff_MPV_common_end(MpegEncContext *s);
index 6f4df595172087c17e56b51171ff160c1638b7b6..8e502ed62c2725fb7e156c035fe6b300533a6352 100644 (file)
@@ -62,6 +62,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int
 static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
 static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
 
+const AVOption ff_mpv_generic_options[] = {
+    FF_MPV_COMMON_OPTS
+    { NULL },
+};
+
 void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
                        uint16_t (*qmat16)[2][64],
                        const uint16_t *quant_matrix,
@@ -606,6 +611,11 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
     }
     s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
 
+#if FF_API_MPV_GLOBAL_OPTS
+    if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
+        s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
+#endif
+
     switch (avctx->codec->id) {
     case CODEC_ID_MPEG1VIDEO:
         s->out_format = FMT_MPEG1;
@@ -2698,7 +2708,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
                                  &dmin, &next_block, 0, 0);
                 }
-                if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
+                if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {
                     int coded=0;
                     for(i=0; i<6; i++)
                         coded |= s->block_last_index[i];
@@ -4046,6 +4056,7 @@ int ff_dct_quantize_c(MpegEncContext *s,
 static const AVOption h263_options[] = {
     { "obmc",         "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
     { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+    FF_MPV_COMMON_OPTS
     { NULL },
 };
 
@@ -4074,6 +4085,7 @@ static const AVOption h263p_options[] = {
     { "aiv",        "Use alternative inter VLC.",       OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
     { "obmc",       "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
     { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+    FF_MPV_COMMON_OPTS
     { NULL },
 };
 static const AVClass h263p_class = {
@@ -4097,6 +4109,8 @@ AVCodec ff_h263p_encoder = {
     .priv_class     = &h263p_class,
 };
 
+FF_MPV_GENERIC_CLASS(msmpeg4v2)
+
 AVCodec ff_msmpeg4v2_encoder = {
     .name           = "msmpeg4v2",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -4107,8 +4121,11 @@ AVCodec ff_msmpeg4v2_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
+    .priv_class     = &msmpeg4v2_class,
 };
 
+FF_MPV_GENERIC_CLASS(msmpeg4v3)
+
 AVCodec ff_msmpeg4v3_encoder = {
     .name           = "msmpeg4",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -4119,8 +4136,11 @@ AVCodec ff_msmpeg4v3_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
+    .priv_class     = &msmpeg4v3_class,
 };
 
+FF_MPV_GENERIC_CLASS(wmv1)
+
 AVCodec ff_wmv1_encoder = {
     .name           = "wmv1",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -4131,4 +4151,5 @@ AVCodec ff_wmv1_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
+    .priv_class     = &wmv1_class,
 };
index 81e910cb7e7cce4508f144b16e7946e65fcdff7b..fb48030ebc4b791147e93fab2a64d9f9290b10fe 100644 (file)
@@ -361,7 +361,9 @@ static const AVOption options[]={
 {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
 {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
 {"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
-{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#if FF_API_MPV_GLOBAL_OPTS
+{"skiprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#endif
 {"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
 {"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
 {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
index 47fb2225e4aa34755a737b15b92ba0bac67b8281..1b4694c50234369b368a89700c8ee2c6727674eb 100644 (file)
@@ -56,6 +56,8 @@ void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
     put_bits(&s->pb, 3, 0);     /* ignored */
 }
 
+FF_MPV_GENERIC_CLASS(rv10)
+
 AVCodec ff_rv10_encoder = {
     .name           = "rv10",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -66,4 +68,5 @@ AVCodec ff_rv10_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
+    .priv_class     = &rv10_class,
 };
index ace70d180b97780f4ccde0aec1f8ea44c5654984..8b50baf52f94986a7628b14da6095ea0ae78a7d9 100644 (file)
@@ -57,6 +57,8 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){
     }
 }
 
+FF_MPV_GENERIC_CLASS(rv20)
+
 AVCodec ff_rv20_encoder = {
     .name           = "rv20",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -67,4 +69,5 @@ AVCodec ff_rv20_encoder = {
     .close          = ff_MPV_encode_end,
     .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
     .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
+    .priv_class     = &rv20_class,
 };
index bf2848d4b2c822ff7e0f28318e3bc96055a78c75..ffce89588d41dc6caf6c27d1ab18251c3c57207c 100644 (file)
@@ -50,5 +50,8 @@
 #ifndef FF_API_OLD_ENCODE_VIDEO
 #define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55)
 #endif
+#ifndef FF_API_MPV_GLOBAL_OPTS
+#define FF_API_MPV_GLOBAL_OPTS  (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
 
 #endif /* AVCODEC_VERSION_H */