Re: [FFmpeg-devel] [PATCH] JPEG2000 encoding with variable codeblock size

2017-08-04 Thread Francesco, Cuzzocrea
The standard ISO/IEC FCD15444-1 specify limits for the exponent values 
and their sum. That is codeblock


size xcb and ycb are defined as:

xcb = 2^(xvalue+2)  and ycb = 2^(yvalue+2)

with values that ranges from a minimum of 2 and a maximum of 10. Moreover

the sum should be less or equal to 12 ( xvalue + yvalue <=12). So 64x128 
are allowed because


xvalue = 4 and yvalue = 5.



On 03/08/2017 19.24, Aaron Boxer wrote:

On Aug 3, 2017 9:58 AM,  wrote:

From: Francesco Cuzzocrea 

Hi to all
I've made some simple changes tha allow encoding with variable codeblock
size.  Default value are the same as previous (16X16) but now setting them
to 64x128 make generated codestream compatible with Analog Devices ADV212
video codec.


Interesting - as far as I  aware, part 1 of standard only allows codeblock
of max size 4096, so 64x128 would not be legal.



---
  libavcodec/j2kenc.c | 22 +-
  1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index c8d3861..1bd4fbd 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1178,17 +1178,21 @@ static int j2kenc_destroy(AVCodecContext *avctx)
  // taken from the libopenjpeg wraper so it matches

  #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
+#define OFFSET1(x) offsetof(Jpeg2000CodingStyle, 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,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE,
"format"  },
-{ "j2k",   NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0, 0,   VE,
"format"  },
-{ "jp2",   NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0, 0,   VE,
"format"  },
-{ "tile_width","Tile Width",OFFSET(tile_width),
AV_OPT_TYPE_INT,   { .i64 = 256 }, 1, 1<<30,   VE, },
-{ "tile_height",   "Tile Height",   OFFSET(tile_height),
  AV_OPT_TYPE_INT,   { .i64 = 256 }, 1, 1<<30,   VE, },
-{ "pred",  "DWT Type",  OFFSET(pred),
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0, 1,   VE,
"pred"},
-{ "dwt97int",  NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN, INT_MAX,   VE,
"pred"},
-{ "dwt53", NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN, INT_MAX,   VE,
"pred"},
-
+{ "format",   "Codec Format",   OFFSET(format),
AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, CODEC_J2K,
CODEC_JP2,   VE, "format"  },
+{ "j2k",   NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,
  0,   VE, "format"  },
+{ "jp2",   NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,
  0,   VE, "format"  },
+{ "tile_width","Tile Width",OFFSET(tile_width),
AV_OPT_TYPE_INT,   { .i64 = 256 }, 1,
  1<<30,   VE, },
+{ "tile_height",   "Tile Height",   OFFSET(tile_height),
 AV_OPT_TYPE_INT,   { .i64 = 256 }, 1,
  1<<30,   VE, },
+{ "pred",  "DWT Type",  OFFSET(pred),
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0,
  1,   VE, "pred"},
+{ "dwt97int",  NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN,
INT_MAX,   VE, "pred"},
+{ "dwt53", NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN,
INT_MAX,   VE, "pred"},
+{ "log2_cblk_width",   "Codeblock Width",
  (OFFSET(codsty)+OFFSET1(log2_cblk_width)),AV_OPT_TYPE_INT,   { .i64 =
4   }, 1, 1<<30,   VE, },
+{ "log2_cblk_height",  "Codeblock Height",
(OFFSET(codsty)+OFFSET1(log2_cblk_height)),   AV_OPT_TYPE_INT,   { .i64 =
4   }, 1, 1<<30,   VE, },
  { NULL }
  };

--
2.1.4

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


--
/***

Re: [FFmpeg-devel] [PATCH] JPEG2000 encoding with variable codeblock size

2017-08-04 Thread Francesco, Cuzzocrea

Sorry. I intend 32x128


On 04/08/2017 10.21, Francesco, Cuzzocrea wrote:
The standard ISO/IEC FCD15444-1 specify limits for the exponent values 
and their sum. That is codeblock


size xcb and ycb are defined as:

xcb = 2^(xvalue+2)  and ycb = 2^(yvalue+2)

with values that ranges from a minimum of 2 and a maximum of 10. Moreover

the sum should be less or equal to 12 ( xvalue + yvalue <=12). So 
64x128 are allowed because


xvalue = 4 and yvalue = 5.



On 03/08/2017 19.24, Aaron Boxer wrote:

On Aug 3, 2017 9:58 AM,  wrote:

From: Francesco Cuzzocrea 

Hi to all
I've made some simple changes tha allow encoding with variable codeblock
size.  Default value are the same as previous (16X16) but now setting 
them
to 64x128 make generated codestream compatible with Analog Devices 
ADV212

video codec.


Interesting - as far as I  aware, part 1 of standard only allows 
codeblock

of max size 4096, so 64x128 would not be legal.



---
  libavcodec/j2kenc.c | 22 +-
  1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index c8d3861..1bd4fbd 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1178,17 +1178,21 @@ static int j2kenc_destroy(AVCodecContext *avctx)
  // taken from the libopenjpeg wraper so it matches

  #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
+#define OFFSET1(x) offsetof(Jpeg2000CodingStyle, 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,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE,
"format"  },
-{ "j2k",   NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0, 0,   VE,
"format"  },
-{ "jp2",   NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0, 0,   VE,
"format"  },
-{ "tile_width","Tile Width",OFFSET(tile_width),
AV_OPT_TYPE_INT,   { .i64 = 256 }, 1, 1<<30,   VE, },
-{ "tile_height",   "Tile Height", OFFSET(tile_height),
  AV_OPT_TYPE_INT,   { .i64 = 256 }, 1, 1<<30,   VE, },
-{ "pred",  "DWT Type",  OFFSET(pred),
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0, 1,   VE,
"pred"},
-{ "dwt97int",  NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN, INT_MAX,   VE,
"pred"},
-{ "dwt53", NULL,0,
  AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN, INT_MAX,   VE,
"pred"},
-
+{ "format",   "Codec Format",   OFFSET(format),
AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, 
CODEC_J2K,

CODEC_JP2,   VE, "format"  },
+{ "j2k",   NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,
  0,   VE, "format"  },
+{ "jp2",   NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,
  0,   VE, "format"  },
+{ "tile_width","Tile Width", OFFSET(tile_width),
AV_OPT_TYPE_INT,   { .i64 = 256 }, 1,
  1<<30,   VE, },
+{ "tile_height",   "Tile Height", OFFSET(tile_height),
 AV_OPT_TYPE_INT,   { .i64 = 256 }, 1,
  1<<30,   VE, },
+{ "pred",  "DWT Type",  OFFSET(pred),
AV_OPT_TYPE_INT,   { .i64 = 0   }, 0,
  1,   VE, "pred"},
+{ "dwt97int",  NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN,
INT_MAX,   VE, "pred"},
+{ "dwt53", NULL,0,
 AV_OPT_TYPE_CONST, { .i64 = 0   }, INT_MIN,
INT_MAX,   VE, "pred"},
+{ "log2_cblk_width",   "Codeblock Width",
  (OFFSET(codsty)+OFFSET1(log2_cblk_width)), AV_OPT_TYPE_INT,   { .i64 =
4   }, 1, 1<<30,   VE, },
+{ "log2_cblk_height",  "Codeblock Height",
(OFFSET(codsty)+OFFSET1(log2_cblk_height)),   AV_OPT_TYPE_INT, { .i64 =
4   }, 1, 1<<30,   VE, },
  { NULL }
  };

--
2.1.4

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

Re: [FFmpeg-devel] [PATCH] JPEG200 encoding : added option for changing default codeblock size

2017-08-30 Thread Francesco, Cuzzocrea

Hi Moritz
I check the code and it seems the error born from a previous version of 
ISO/IEC15444-1 I have
(I used a final draft not the final document and the definition was 
quite fuzzy).  Checking final

document I found that you are right.
According to this specification (Table A-18 Width or Height exponent of 
the code-blocks for the SPcod
and SPcoc parameters) code-block exponent width  xcb and height ycb are 
defined as:


xcb = value + 2   and  ycb = value+2

so xcb+ycb <=12 is the correct check. I will correct the patch.

Francesco


On 15/08/2017 23.57, Moritz Barsnick wrote:

On Mon, Aug 07, 2017 at 10:26:21 +0200, france...@bltitalia.com wrote:

Subject: [FFmpeg-devel] [PATCH] JPEG200 encoding : added option for changing 
default codeblock size

Is this your commit message? It's 2000, not 200. ;-) Actually, this
should read:
libavcodec/j2kenc: add option for changing codeblock size


+i = codsty->log2_cblk_width + codsty->log2_cblk_height -4;
+if ( i > 12 )
+{
+  av_log(avctx, AV_LOG_ERROR, "Invalid values for codeblocks size\n");
+  return -1;
+}

Bracket placement, indentation and whitespace all do not correspond to
ffmpeg style.

Apart from that: Isn't that a quite complicated way of saying
if (codsty->log2_cblk_width + codsty->log2_cblk_height > 16)
??


+{ "log2_cblk_width",   "Codeblock Width",   OFFSET(codsty.log2_cblk_width),
AV_OPT_TYPE_INT,   { .i64 = 4   }, 0, 1<<10,   VE, },
+{ "log2_cblk_height",  "Codeblock Height",  OFFSET(codsty.log2_cblk_height),   
AV_OPT_TYPE_INT,   { .i64 = 4   }, 0, 1<<10,   VE, },

I would suggest to drop the capital letters in the option descriptions,
but it appears to follow the style of the other options, so fine by me.

And what's with the upper limits? They don't seem sane. If you choose
either option at one of those limits, the check above will fail
(1<<10 + 0 - 4 is wy larger than 12).

Looking at the spec, you are mixing exponent and value. I read
"Dimension of the code-blocks is always a power of 2 with the minimum
height and width being 4 and and maximum height and width being 1024."
Furthermore the sum of the exponents needs to be less than or equal to
12.

So, the variable being log2, the limits are obviously 2 and 10, the
default 4 (as before). And your check actually needs to read
if (codsty->log2_cblk_width + codsty->log2_cblk_height > 12)
.

Or am I missing something?


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


--
/***\
*Ing. Francesco  Cuzzocrea
*company:BLT Italia srlweb:  http://www.blt.it
*address:via Rosselli, 91 city:  Lido di CAMAIORE
*country:ITALY zip:  55043-i
*  Tel. :+39 0584 904788   Fax:  +39 0584 904789
* e-mail:   france...@bltitalia.com
\***/
-- BLT will be at IBC (15~19 September 2017) - Hall 8, Stand 8.A69 --

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


[FFmpeg-devel] Stream description

2018-02-21 Thread Francesco, Cuzzocrea

Hi to all

I'm writing a module for ffmpeg that demuxes custom file format. Up to 
now audio is ok but I haven't figured out how


to describe video.  Our format is jpeg2000 4:2:2 stored on file as per 
field, that is there is filed0 codestream and field 1


codestream for each frame. This is the description I made for video stream:

    // Add video stream
    v_st = avformat_new_stream(cblt->fc, NULL);
    if (!v_st) {
    av_log(cblt->fc, AV_LOG_ERROR, "could not allocate video 
stream\n");

    ret = AVERROR(ENOMEM);
    goto fail_and_free;
    }

    v_st->index = 0;    v_st->id = 0;

   v_st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
    v_st->codecpar->width = 1920;

   v_st->codecpar->codec_id = AV_CODEC_ID_JPEG2000;
    v_st->codecpar->format = AV_PIX_FMT_YUV422P;
    v_st->codecpar->height = 540; /* Field height, not frame height */
    v_st->codecpar->field_order = AV_FIELD_TB;
    v_st->time_base.num = 1; v_st->time_base.den = 25;
    v_st->avg_frame_rate.num = 25; v_st->avg_frame_rate.den = 1;

    v_st->duration = 75 ; // Clip is of 3 seconds => 75 frames
    v_st->start_time = 0;
    v_st->nb_frames = 75;
    v_st->sample_aspect_ratio.num = 4; v_st->sample_aspect_ratio.den = 3;

With this description only field 0 is decoded.  If in the 
blt_read_packet function


I insert field 0 codestream and field 1 codestream, in the Packet data 
buffer, I receive an error.


How can I describe my stream as per field ?

regards

--
/***\
*Ing. Francesco  Cuzzocrea
*company:BLT Italia srlweb:  http://www.blt.it
*address:via Rosselli, 91 city:  Lido di CAMAIORE
*country:ITALY zip:  55043-i
*  Tel. :+39 0584 904788   Fax:  +39 0584 904789
* e-mail:   france...@bltitalia.com
\***/
--  BLT will be at BVE2018 (27 Feb ~ 1 Mar 2018)  -  Booth  H18   --

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