syntax is: 20,10,2
 this adds 3 layers, the first with a 20x, the second with 10x and
 a third with 2x compression.

 Layers define the progression by image quality within the code stream and,
 although not defined by the JPEG 2000 standard, in general codecs try to
 build layers in such a way that the image quality will increase monotonically
 with each layer.

Signed-off-by: Jean First <jeanfi...@gmail.com>
---

 it remove the numlayers parameter, but i'm not sure it ever worked. 
Unfortunately
 the j2k_dump provided by openjpeg won't show the individual rates per layer - I
 also tried the files provided in 
http://samples.ffmpeg.org/jpeg2000/fdis_j2kp4files.zip
 and the rates shown are always 0.0

 TODO: Write the libopenjpegenc documentation

 libavcodec/libopenjpegenc.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index bbf6190..b9a8bac 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -56,6 +56,8 @@ typedef struct {
     int disto_alloc;
     int fixed_alloc;
     int fixed_quality;
+    char *layerrates;
+    float tcp_rates[100]; /** User specified rate stored in case of cinema 
option */
 } LibOpenJPEGContext;
 
 static void error_callback(const char *msg, void *data)
@@ -224,8 +226,21 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
*avctx)
     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.tcp_numlayers = 0;
+
+    char *s = ctx->layerrates;
+    while (sscanf(s, "%f", &ctx->tcp_rates[ctx->enc_params.tcp_numlayers]) == 
1) {
+        ctx->enc_params.tcp_numlayers++;
+        while (*s && *s != ',')
+            s++;
+        if (!*s)
+            break;
+        s++;
+    }
+    if (ctx->enc_params.tcp_numlayers < 1){
+        ctx->enc_params.tcp_numlayers = 1;
+        ctx->tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2;
+    }
 
     if (ctx->cinema_mode > 0) {
         cinema_parameters(&ctx->enc_params);
@@ -629,7 +644,7 @@ static const AVOption options[] = {
     { "pcrl",          NULL,                0,                     
AV_OPT_TYPE_CONST, { .i64 = PCRL        }, 0,         0,           VE, 
"prog_order"  },
     { "cprl",          NULL,                0,                     
AV_OPT_TYPE_CONST, { .i64 = CPRL        }, 0,         0,           VE, 
"prog_order"  },
     { "numresolution", NULL,                OFFSET(numresolution), 
AV_OPT_TYPE_INT,   { .i64 = 6           }, 1,         INT_MAX,     VE           
     },
-    { "numlayers",     NULL,                OFFSET(numlayers),     
AV_OPT_TYPE_INT,   { .i64 = 1           }, 1,         10,          VE           
     },
+    { "layerrates",    "Layer compression rates", OFFSET(layerrates), 
AV_OPT_TYPE_STRING, { .str = "auto"  }, 0,         0,           VE              
  },
     { "disto_alloc",   NULL,                OFFSET(disto_alloc),   
AV_OPT_TYPE_INT,   { .i64 = 1           }, 0,         1,           VE           
     },
     { "fixed_alloc",   NULL,                OFFSET(fixed_alloc),   
AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,           VE           
     },
     { "fixed_quality", NULL,                OFFSET(fixed_quality), 
AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,           VE           
     },
-- 
2.2.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to