[FFmpeg-cvslog] libopenjpegenc: allow changing encoding parameters

Paul B Mahol git at videolan.org
Mon Mar 26 05:45:01 CEST 2012


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Mar 25 23:33:53 2012 +0000| [67d5fcc989a0ee3cc3b3a89e643ee7f099ca6229] | committer: Michael Niedermayer

libopenjpegenc: allow changing encoding parameters

Signed-off-by: Paul B Mahol <onemda at gmail.com>
Reviewed-by: Michael Bradshaw <mbradshaw at sorensonmedia.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=67d5fcc989a0ee3cc3b3a89e643ee7f099ca6229
---

 libavcodec/libopenjpegenc.c |   61 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 8eba40d..806209a 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -24,6 +24,7 @@
 * JPEG 2000 encoder using libopenjpeg
 */
 
+#include "libavutil/opt.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/avassert.h"
 #include "avcodec.h"
@@ -33,10 +34,20 @@
 #include <openjpeg.h>
 
 typedef struct {
+    AVClass *avclass;
     opj_image_t *image;
     opj_cparameters_t enc_params;
     opj_cinfo_t *compress;
     opj_event_mgr_t event_mgr;
+    int format;
+    int profile;
+    int cinema_mode;
+    int prog_order;
+    int numresolution;
+    int numlayers;
+    int disto_alloc;
+    int fixed_alloc;
+    int fixed_quality;
 } LibOpenJPEGContext;
 
 static void error_callback(const char *msg, void *data)
@@ -124,11 +135,19 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
     LibOpenJPEGContext *ctx = avctx->priv_data;
 
     opj_set_default_encoder_parameters(&ctx->enc_params);
-    ctx->enc_params.tcp_numlayers = 1;
+    ctx->enc_params.cp_rsiz = ctx->profile;
+    ctx->enc_params.mode = !!avctx->global_quality;
+    ctx->enc_params.cp_cinema = ctx->cinema_mode;
+    ctx->enc_params.prog_order = ctx->prog_order;
+    ctx->enc_params.numresolution = ctx->numresolution;
+    ctx->enc_params.cp_disto_alloc = ctx->disto_alloc;
+    ctx->enc_params.cp_fixed_alloc = ctx->fixed_alloc;
+    ctx->enc_params.cp_fixed_quality = ctx->fixed_quality;
+    ctx->enc_params.tcp_numlayers = ctx->numlayers;
     ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2;
     ctx->enc_params.cp_disto_alloc = 1;
 
-    ctx->compress = opj_create_compress(CODEC_J2K);
+    ctx->compress = opj_create_compress(ctx->format);
     if (!ctx->compress) {
         av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n");
         return AVERROR(ENOMEM);
@@ -381,6 +400,41 @@ static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
     return 0 ;
 }
 
+#define OFFSET(x) offsetof(LibOpenJPEGContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "format",        "Codec Format",      OFFSET(format),        AV_OPT_TYPE_INT,   { CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE, "format"      },
+    { "j2k",           NULL,                0,                     AV_OPT_TYPE_CONST, { CODEC_J2K   }, 0,         0,           VE, "format"      },
+    { "jp2",           NULL,                0,                     AV_OPT_TYPE_CONST, { CODEC_JP2   }, 0,         0,           VE, "format"      },
+    { "profile",       NULL,                OFFSET(profile),       AV_OPT_TYPE_INT,   { STD_RSIZ    }, STD_RSIZ,  CINEMA4K,    VE, "profile"     },
+    { "jpeg2000",      NULL,                0,                     AV_OPT_TYPE_CONST, { STD_RSIZ    }, 0,         0,           VE, "profile"     },
+    { "cinema2k",      NULL,                0,                     AV_OPT_TYPE_CONST, { CINEMA2K    }, 0,         0,           VE, "profile"     },
+    { "cinema4k",      NULL,                0,                     AV_OPT_TYPE_CONST, { CINEMA4K    }, 0,         0,           VE, "profile"     },
+    { "cinema_mode",   "Digital Cinema",    OFFSET(cinema_mode),   AV_OPT_TYPE_INT,   { OFF         }, OFF,       CINEMA4K_24, VE, "cinema_mode" },
+    { "off",           NULL,                0,                     AV_OPT_TYPE_CONST, { OFF         }, 0,         0,           VE, "cinema_mode" },
+    { "2k_24",         NULL,                0,                     AV_OPT_TYPE_CONST, { CINEMA2K_24 }, 0,         0,           VE, "cinema_mode" },
+    { "2k_48",         NULL,                0,                     AV_OPT_TYPE_CONST, { CINEMA2K_48 }, 0,         0,           VE, "cinema_mode" },
+    { "4k_24",         NULL,                0,                     AV_OPT_TYPE_CONST, { CINEMA4K_24 }, 0,         0,           VE, "cinema_mode" },
+    { "prog_order",    "Progression Order", OFFSET(prog_order),    AV_OPT_TYPE_INT,   { LRCP        }, LRCP,      CPRL,        VE, "prog_order"  },
+    { "lrcp",          NULL,                0,                     AV_OPT_TYPE_CONST, { LRCP        }, 0,         0,           VE, "prog_order"  },
+    { "rlcp",          NULL,                0,                     AV_OPT_TYPE_CONST, { RLCP        }, 0,         0,           VE, "prog_order"  },
+    { "rpcl",          NULL,                0,                     AV_OPT_TYPE_CONST, { RPCL        }, 0,         0,           VE, "prog_order"  },
+    { "pcrl",          NULL,                0,                     AV_OPT_TYPE_CONST, { PCRL        }, 0,         0,           VE, "prog_order"  },
+    { "cprl",          NULL,                0,                     AV_OPT_TYPE_CONST, { CPRL        }, 0,         0,           VE, "prog_order"  },
+    { "numresolution", NULL,                OFFSET(numresolution), AV_OPT_TYPE_INT,   { 6           }, 1,         10,          VE                },
+    { "numlayers",     NULL,                OFFSET(numlayers),     AV_OPT_TYPE_INT,   { 1           }, 1,         10,          VE                },
+    { "disto_alloc",   NULL,                OFFSET(disto_alloc),   AV_OPT_TYPE_INT,   { 1           }, 0,         1,           VE                },
+    { "fixed_alloc",   NULL,                OFFSET(fixed_alloc),   AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE                },
+    { "fixed_quality", NULL,                OFFSET(fixed_quality), AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE                },
+    { NULL },
+};
+
+static const AVClass class = {
+    .class_name = "libopenjpeg",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
 
 AVCodec ff_libopenjpeg_encoder = {
     .name           = "libopenjpeg",
@@ -400,4 +454,5 @@ AVCodec ff_libopenjpeg_encoder = {
                                            PIX_FMT_YUV420P16,PIX_FMT_YUV422P16,PIX_FMT_YUV444P16,
                                            PIX_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"),
-} ;
+    .priv_class     = &class,
+};



More information about the ffmpeg-cvslog mailing list