Re: [FFmpeg-devel] [PATCH] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-05-02 Thread Cédric Le Barz


Le 27/04/2023 à 14:45, Tomas Hardin a écrit :

  static inline uint16_t rescale_mastering_chroma(AVRational q)
  {
@@ -1260,7 +1305,6 @@ static int64_t
mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
  f1 *= 2;
  }
  
-

Stray deleted line


+/* Image components number */
+mxf_write_local_tag(s, 2, 0x840A);
+avio_wb16(pb, component_count);
+   /* Array of picture components where each component comprises 3

Looks like you missed a space there (:


+/* Extract usefull size infromation from the SIZ marker */
+if (bytestream2_get_be16u(&g) != JPEG2000_SIZ) {
+av_log(s, AV_LOG_ERROR, "SIZ marker not present\n");
+return 0;
+}
+bytestream2_skip(&g, 2); // Skip Lsiz
+sc->j2k_cap = bytestream2_get_be16u(&g);
+sc->j2k_xsiz = bytestream2_get_be32u(&g);
+sc->j2k_ysiz = bytestream2_get_be32u(&g);
+sc->j2k_x0siz = bytestream2_get_be32u(&g);
+sc->j2k_y0siz = bytestream2_get_be32u(&g);
+sc->j2k_xtsiz = bytestream2_get_be32u(&g);
+sc->j2k_ytsiz = bytestream2_get_be32u(&g);
+sc->j2k_xt0siz = bytestream2_get_be32u(&g);
+sc->j2k_yt0siz = bytestream2_get_be32u(&g);
+j2k_ncomponents = bytestream2_get_be16u(&g);
+if (j2k_ncomponents != component_count) {
+av_log(s, AV_LOG_WARNING, "Incoherence about components
image number.\n");

Erroring out here seems more appropriate.

/Tomas


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


I've attached to this mail the new patch taking into account the 3 
remarks above.


Regards

Cédric
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 169 +++-
 2 files changed, 168 insertions(+), 2 deletions(-)

diff --git a/ffmpeg/libavformat/mxf.h b/ffmpeg/libavformat/mxf.h
index 2561605..7dd1681 100644
--- a/ffmpeg/libavformat/mxf.h
+++ b/ffmpeg/libavformat/mxf.h
@@ -55,6 +55,7 @@ enum MXFMetadataSetType {
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
 FFV1SubDescriptor,
+JPEG2000SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index a29d678..909682a 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -48,8 +48,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/time_internal.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/h264.h"
+#include "libavcodec/jpeg2000.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/startcode.h"
 #include "avformat.h"
@@ -102,6 +104,16 @@ typedef struct MXFStreamContext {
 int b_picture_count; ///< maximum number of consecutive b pictures, 
used in mpeg-2 descriptor
 int low_delay;   ///< low delay, used in mpeg-2 descriptor
 int avc_intra;
+uint16_t j2k_cap;///< j2k required decoder capabilities
+uint32_t j2k_xsiz;   ///< j2k widht of the reference grid
+uint32_t j2k_ysiz;   ///< j2k height of the reference grid
+uint32_t j2k_x0siz;  ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the image
+uint32_t j2k_y0siz;  ///< j2k vertical offset from the origin of the 
reference grid to the left side of the image
+uint32_t j2k_xtsiz;  ///< j2k width of one reference tile with respect 
to the reference grid
+uint32_t j2k_ytsiz;  ///< j2k height of one reference tile with 
respect to the reference grid
+uint32_t j2k_xt0siz; ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the first tile
+uint32_t j2k_yt0siz; ///< j2k vertical offset from the origin of the 
reference grid to the left side of the first tile
+uint8_t  j2k_comp_desc[12]; ///< j2k components descriptor
 } MXFStreamContext;
 
 typedef struct MXFContainerEssenceEntry {
@@ -390,6 +402,20 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
 { 0x8302, FF_MXF_MasteringDisplayWhitePointChromaticity },
 { 0x8303, FF_MXF_MasteringDisplayMaximumLuminance },
 { 0x8304, FF_MXF_MasteringDisplayMinimumLuminance },
+// ff_mxf_jpeg2000_local_tags
+{ 0x8400, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}},
 /* Sub Descriptors / Opt Ordered array of strong references to sub descriptor 
sets */
+{ 0x8401, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00}},
 /* An enumerated value that defines the decoder capabilities */
+{ 0x8402, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x02,0x00,0x00,0x00}},
 /* Width of the reference grid */
+{ 0x8403, 
{0x06,0x0e,0x2b,0x34,0x01,0x

Re: [FFmpeg-devel] [PATCH] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-06-01 Thread Cédric Le Barz


Le 09/05/2023 à 16:28, Pierre-Anthony Lemieux a écrit :

Couple of follow-up comments.

- "mxf_parse_jpeg2000_frame" could be moved to one of jpeg2000 source
files, to keep J2K parsing code together. Maybe there is a way to
reuse jpeg2000_read_main_headers() at jpeg2000dec.c?

- when defining the J2K descriptor items, please refer to the symbol
name from the SMPTE registers, it make following/debugging the code a
lot easier:

{ 0x8405,
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x05,0x00,0x0
0,0x00}},
/* Vertical offset from the origin of the reference grid to the left
side of the image area */

becomes

{ 0x8405,
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x05,0x00,0x0
0,0x00}},
/* YOsiz: vertical offset from the origin of the reference grid to the
left side of the image area */
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org  with subject "unsubscribe".



Attach to this mail, is my new patch for adding jpeg2000 sub-descriptor 
in MXF file  taking into account remarks from FFmpeg community (remarks 
from Pierre-Anthony above as well as this from Tomas), i.e. :


1 - When there is a mismatch in components number, this is now process 
as an error.


2 - When defining and using the J2K descriptor items, I now refer to the 
symbol name from the SMPTE registers (X0siz, XT0siz...)


3 - As suggested, I make use of  jpeg2000_read_main_headers() in 
libavcodec. But, I let the parsing function in mxfenc.c file as all 
other parsing functions are in this file (mxf_parse_mpeg2_frame, 
mxf_parse_h264_frame...). The use of jpeg2000_read_main_headers() in 
mxfenc implies some minor modifications in jpeg2000 files :


* rename of Jpeg2000Tile structure to J2kTile in j2kenc.c (to avoid 
redefinition)


* move some structure declarations from jpeg2000dec.c to jpeg2000.h

* make jpeg2000_read_main_headers() function "public"


Regards,


Cédric
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavcodec/j2kenc.c  |  28 +++---
 ffmpeg/libavcodec/jpeg2000.h|  90 +
 ffmpeg/libavcodec/jpeg2000dec.c |  89 +
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 169 +++-
 5 files changed, 273 insertions(+), 104 deletions(-)

diff --git a/ffmpeg/libavcodec/j2kenc.c b/ffmpeg/libavcodec/j2kenc.c
index 6406f90..f5178d7 100644
--- a/ffmpeg/libavcodec/j2kenc.c
+++ b/ffmpeg/libavcodec/j2kenc.c
@@ -106,7 +106,7 @@ static const int dwt_norms[2][4][10] = { // 
[dwt_type][band][rlevel] (multiplied
 typedef struct {
Jpeg2000Component *comp;
double *layer_rates;
-} Jpeg2000Tile;
+} J2kTile;
 
 typedef struct {
 AVClass *class;
@@ -131,7 +131,7 @@ typedef struct {
 Jpeg2000CodingStyle codsty;
 Jpeg2000QuantStyle  qntsty;
 
-Jpeg2000Tile *tile;
+J2kTile *tile;
 int layer_rates[100];
 uint8_t compression_rate_enc; ///< Is compression done using compression 
ratio?
 
@@ -171,7 +171,7 @@ static void dump(Jpeg2000EncoderContext *s, FILE *fd)
 s->width, s->height, s->tile_width, s->tile_height,
 s->numXtiles, s->numYtiles, s->ncomponents);
 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
-Jpeg2000Tile *tile = s->tile + tileno;
+J2kTile *tile = s->tile + tileno;
 nspaces(fd, 2);
 fprintf(fd, "tile %d:\n", tileno);
 for(compno = 0; compno < s->ncomponents; compno++){
@@ -427,7 +427,7 @@ static void compute_rates(Jpeg2000EncoderContext* s)
 int layno, compno;
 for (i = 0; i < s->numYtiles; i++) {
 for (j = 0; j < s->numXtiles; j++) {
-Jpeg2000Tile *tile = &s->tile[s->numXtiles * i + j];
+J2kTile *tile = &s->tile[s->numXtiles * i + j];
 for (compno = 0; compno < s->ncomponents; compno++) {
 int tilew = tile->comp[compno].coord[0][1] - 
tile->comp[compno].coord[0][0];
 int tileh = tile->comp[compno].coord[1][1] - 
tile->comp[compno].coord[1][0];
@@ -460,12 +460,12 @@ static int init_tiles(Jpeg2000EncoderContext *s)
 s->numXtiles = ff_jpeg2000_ceildiv(s->width, s->tile_width);
 s->numYtiles = ff_jpeg2000_ceildiv(s->height, s->tile_height);
 
-s->tile = av_calloc(s->numXtiles, s->numYtiles * sizeof(Jpeg2000Tile));
+s->tile = av_calloc(s->numXtiles, s->numYtiles * sizeof(J2kTile));
 if (!s->tile)
 return AVERROR(ENOMEM);
 for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++)
 for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){
-Jpeg2000Tile *tile = s->tile + tileno;
+J2kTile *tile = s->tile + tileno;
 
 tile->comp = av_calloc(s->ncomponents, sizeof(*tile->comp));
 if (!tile->comp)
@@ -509,7 +509,7 @@ static int init_tiles(Jpeg2000EncoderContext

[FFmpeg-devel] [PATCH] Fix issue when invalid nb_index_entries value is read - SPONSORED BY INA (Institut National de l'Audiovisuel)

2023-03-08 Thread Cédric Le Barz



Fix issue when invalid nb_index_entries value is read : in case of false 
nb_index_entries value, ffmpeg exit. This patch fix this problem.



Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxfdec.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ffmpeg/libavformat/mxfdec.c b/ffmpeg/libavformat/mxfdec.c
index 4530617..ffc8987 100644
--- a/ffmpeg/libavformat/mxfdec.c
+++ b/ffmpeg/libavformat/mxfdec.c
@@ -1221,8 +1221,18 @@ static int mxf_read_index_entry_array(AVIOContext 
*pb, MXFIndexTableSegment *seg

 }
  for (i = 0; i < segment->nb_index_entries; i++) {
-if(avio_feof(pb))
-return AVERROR_INVALIDDATA;
+
+if(avio_feof(pb)) {
+if (i == 0) {
+return AVERROR_INVALIDDATA;
+} else {
+/* To be more robust to invalid nb_index_entries value,
+   fix the index entry number according to read entries */
+segment->nb_index_entries = i;
+return 0;
+}
+}
+
 segment->temporal_offset_entries[i] = avio_r8(pb);
 avio_r8(pb);/* 
KeyFrameOffset */

 segment->flag_entries[i] = avio_r8(pb);
--
2.34.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-04-25 Thread Cédric Le Barz


Le 05/04/2023 à 15:53, Tomas Härdin a écrit :

ons 2023-04-05 klockan 15:05 +0200 skrev Cédric Le Barz:

Le 03/04/2023 à 17:14, Michael Niedermayer a écrit :

On Mon, Apr 03, 2023 at 10:08:25AM +0200, Cédric Le Barz wrote:

Hi,

I've attached the patch to this mail, in order to solve newlines

insertion

issue.

Please make sure each patch also updates the fate tests so
make fate
doesnt fail

I've attached to this mail the new patch. Fate test issue is fixed.


Please avoid top posting.

I was actually about to suggest merging these two patches but I see you
read my mind :)


@@ -1131,9 +1164,9 @@ static const UID mxf_aes3_descriptor_key  =
{ 0x06,0x0E,0x2B,0x34,0x02,0x53,
  static const UID mxf_cdci_descriptor_key  = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x28,0x00 };
  static const UID mxf_rgba_descriptor_key  = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x29,0x00 };
  static const UID mxf_generic_sound_descriptor_key = {
0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0D,0x01,0x01,0x01,0x01,0x01
,0x42,0x00 };
-

Stray line deletion


+mxf_write_local_tag(s, 2, 0x8401);
+avio_wb16(pb, 0x);
+mxf_write_local_tag(s, 4, 0x8402);
+avio_wb32(pb, st->codecpar->width);
+mxf_write_local_tag(s, 4, 0x8403);
+avio_wb32(pb, st->codecpar->height);
+mxf_write_local_tag(s, 4, 0x8404);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8405);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8406);
+avio_wb32(pb, st->codecpar->width);
+mxf_write_local_tag(s, 4, 0x8407);
+avio_wb32(pb, st->codecpar->height);
+mxf_write_local_tag(s, 4, 0x8408);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 4, 0x8409);
+avio_wb32(pb, 0);
+mxf_write_local_tag(s, 2, 0x840A);
+avio_wb16(pb, component_count);

A comment on each of these explaining what they are would be nice.


+{
+char _desc [3][3]= {  {0x09,0x01,0x01} , {0x09,0x02,0x01} ,
{0x09,0x02,0x01} };
+int comp = 0;
+for ( comp = 0; comp< component_count ;comp++ ) {
+avio_write(pb, _desc[comp%3] , 3);
+}
+}

Maybe just a style nit but you could move the char desc[] into the loop
body, int comp to the start of the function and then you can remove the
extra {} around this. Also you could make desc static const.


+{
+char _layout[16] = {  'Y' , '\n', 'U' , '\n', 'V' , '\n',
'F' , 0x02,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
+avio_write(pb, _layout , 16);
+}

Again there is the issue of RGB(A)

/Tomas

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



Please consider this new patch taking into account remarks. For the 
moment, I remove the RGB(A) / YUV code part as it is an optional feature 
for the JPEG2000 subdescriptor.


Regards,

Cédric
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 169 +++-
 2 files changed, 167 insertions(+), 3 deletions(-)

diff --git a/ffmpeg/libavformat/mxf.h b/ffmpeg/libavformat/mxf.h
index 2561605..7dd1681 100644
--- a/ffmpeg/libavformat/mxf.h
+++ b/ffmpeg/libavformat/mxf.h
@@ -55,6 +55,7 @@ enum MXFMetadataSetType {
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
 FFV1SubDescriptor,
+JPEG2000SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index a29d678..7065a7d 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -48,8 +48,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/time_internal.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/h264.h"
+#include "libavcodec/jpeg2000.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/startcode.h"
 #include "avformat.h"
@@ -102,6 +104,16 @@ typedef struct MXFStreamContext {
 int b_picture_count; ///< maximum number of consecutive b pictures, 
used in mpeg-2 descriptor
 int low_delay;   ///< low delay, used in mpeg-2 descriptor
 int avc_intra;
+uint16_t j2k_cap;///< j2k required decoder capabilities
+uint32_t j2k_xsiz;   ///< j2k widht of the reference grid
+uint32_t j2k_ysiz;   ///< j2k height of the reference grid
+uint32_t j2k_x0siz;  ///< j2k horizontal offset from the origin of the 
reference grid to the left side of t

Re: [FFmpeg-devel] [PATCH] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-09-22 Thread Cédric Le Barz


Le 04/06/2023 à 20:24, Tomas Härdin a écrit :

tor 2023-06-01 klockan 17:19 +0200 skrev Cédric Le Barz:

Attach to this mail, is my new patch for adding jpeg2000 sub-
descriptor
in MXF file  taking into account remarks from FFmpeg community
(remarks
from Pierre-Anthony above as well as this from Tomas), i.e. :

1 - When there is a mismatch in components number, this is now
process
as an error.

2 - When defining and using the J2K descriptor items, I now refer to
the
symbol name from the SMPTE registers (X0siz, XT0siz...)

3 - As suggested, I make use of  jpeg2000_read_main_headers() in
libavcodec. But, I let the parsing function in mxfenc.c file as all
other parsing functions are in this file (mxf_parse_mpeg2_frame,
mxf_parse_h264_frame...). The use of jpeg2000_read_main_headers() in
mxfenc implies some minor modifications in jpeg2000 files :

* rename of Jpeg2000Tile structure to J2kTile in j2kenc.c (to avoid
redefinition)

* move some structure declarations from jpeg2000dec.c to jpeg2000.h

* make jpeg2000_read_main_headers() function "public"

For this you need to prefix the name with ff_ and bump libavcodec's
minor version number


+static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream
*st, AVPacket *pkt)
+{
+MXFContext *mxf = s->priv_data;
+MXFStreamContext *sc = st->priv_data;
+int component_count = av_pix_fmt_count_planes(st->codecpar-

format);

+Jpeg2000DecoderContext jpeg2000ctx;

This makes sizeof(Jpeg2000DecoderContext) part of the public API which
is a big no-no. Consider making the fields part of a different smaller
struct instead that is also included in Jpeg2000DecoderContext. The
safest option is to have a function that allocates that struct. The
reason for this is because we might want to read other things from the
headers at a later date. Another possibility is to pass a bunch of
pointers to ints that the parsed values get written to. If at a later
date we need to parse more fields then we can introduce
ff_jpeg2000_read_main_headers_2() and so on. The latter seems easier
API stability wise, if a bit tedious with the number of function
arguments.

/Tomas

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Hi,

I'm facing a problem to get the jpeg2000 information I need to build the 
mxf file.


All the functions to extract jpeg2000 information exist : they are 
located in libavcodec side and used Jpeg2000DecoderContext, which is not 
obviously public and therefore unknown from libavformat side.


Is there a way to get a pointer on the Jpeg2000DecoderContext (at least 
a void*) from libavcodec side ?


Thanks for your help.

Cédric



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] [MXF] - Add jpeg2000 subdescriptor in MXF file.

2023-12-08 Thread Cédric Le Barz

Add jpeg2000 subdescriptor in MXF file.
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 173 +++-
 2 files changed, 173 insertions(+), 1 deletion(-)

diff --git a/ffmpeg/libavformat/mxf.h b/ffmpeg/libavformat/mxf.h
index 2561605..7dd1681 100644
--- a/ffmpeg/libavformat/mxf.h
+++ b/ffmpeg/libavformat/mxf.h
@@ -55,6 +55,7 @@ enum MXFMetadataSetType {
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
 FFV1SubDescriptor,
+JPEG2000SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index 53bd6ae..a06c8af 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -48,8 +48,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/time_internal.h"
 #include "libavcodec/defs.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/h264.h"
+#include "libavcodec/jpeg2000.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/rangecoder.h"
 #include "libavcodec/startcode.h"
@@ -78,6 +80,20 @@ typedef struct MXFIndexEntry {
 uint8_t flags;
 } MXFIndexEntry;
 
+typedef struct j2k_info_t {
+uint16_t j2k_cap;///< j2k required decoder capabilities
+uint16_t j2k_rsiz;   ///< j2k required decoder capabilities (Rsiz)
+uint32_t j2k_xsiz;   ///< j2k width of the reference grid (Xsiz)
+uint32_t j2k_ysiz;   ///< j2k height of the reference grid (Ysiz)
+uint32_t j2k_x0siz;  ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the image (X0siz)
+uint32_t j2k_y0siz;  ///< j2k vertical offset from the origin of the 
reference grid to the left side of the image (Y0siz)
+uint32_t j2k_xtsiz;  ///< j2k width of one reference tile with respect 
to the reference grid (XTsiz)
+uint32_t j2k_ytsiz;  ///< j2k height of one reference tile with 
respect to the reference grid (YTsiz)
+uint32_t j2k_xt0siz; ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the first tile (XT0siz)
+uint32_t j2k_yt0siz; ///< j2k vertical offset from the origin of the 
reference grid to the left side of the first tile (YT0siz)
+uint8_t  j2k_comp_desc[12]; ///< j2k components descriptor (Ssiz(i), 
XRsiz(i), YRsiz(i))
+} j2k_info_t;
+
 typedef struct MXFStreamContext {
 int64_t pkt_cnt; ///< pkt counter for muxed packets
 UID track_essence_element_key;
@@ -104,6 +120,7 @@ typedef struct MXFStreamContext {
 int low_delay;   ///< low delay, used in mpeg-2 descriptor
 int avc_intra;
 int micro_version;   ///< format micro_version, used in ffv1 descriptor
+j2k_info_t j2k_info;
 } MXFStreamContext;
 
 typedef struct MXFContainerEssenceEntry {
@@ -413,6 +430,20 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
 { 0xDFD9, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x06,0x00,0x00,0x00}},
 /* FFV1 Micro-version */
 { 0xDFDA, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x05,0x00,0x00,0x00}},
 /* FFV1 Version */
 { 0xDFDB, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x01,0x00,0x00,0x00}},
 /* FFV1 Initialization Metadata */
+// ff_mxf_jpeg2000_local_tags
+{ 0x8400, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}},
 /* Sub Descriptors / Opt Ordered array of strong references to sub descriptor 
sets */
+{ 0x8401, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00}},
 /* Rsiz: An enumerated value that defines the decoder capabilities */
+{ 0x8402, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x02,0x00,0x00,0x00}},
 /* Xsiz: Width of the reference grid */
+{ 0x8403, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x03,0x00,0x00,0x00}},
 /* Ysiz: Height of the reference grid */
+{ 0x8404, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x04,0x00,0x00,0x00}},
 /* X0siz: Horizontal offset from the origin of the reference grid to the left 
side of the image area */
+{ 0x8405, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x05,0x00,0x00,0x00}},
 /* Y0siz: Vertical offset from the origin of the reference grid to the left 
side of the image area */
+{ 0x8406, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x06,0x00,0x00,0x00}},
 /* XTsiz: Width of one reference tile with respect to the reference grid */
+{ 0x8407, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x07,0x00,0x00,0x00}},
 /* YTsiz: Height of one reference tile with respect to the reference grid */
+{ 0x8408, 
{0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x08,0x00,0x00,0x00}},
 /* XT0siz: Horizontal offset from the origin of the reference grid to the left 
side of th

Re: [FFmpeg-devel] [PATCH] [MXF] - Add jpeg2000 subdescriptor in MXF file (V2).

2023-12-20 Thread Cédric Le Barz

Le 19/12/2023 à 14:36, Tomas Härdin a écrit :

+for ( comp = 0; comp < component_count; comp++ ) {
+avio_write(pb, &sc->j2k_info.j2k_comp_desc[3*comp] , 3);
+}

Looks like this could be simplified to just

   avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*component_count);


+if (j2k_ncomponents != component_count) {
+av_log(s, AV_LOG_ERROR, "Incoherence about components image
number.\n");
+}

I again feel this should be a hard error


+for (comp = 0; comp < j2k_ncomponents; comp++) {
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents] =
bytestream2_get_byteu(&g);   // Bitdepth for each component
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents+1] =
bytestream2_get_byteu(&g); // Horizontal sampling for each component
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents+2] =
bytestream2_get_byteu(&g); // Vertical sampling for each component
+}

Could be simplified to a single avio_read()

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Here is the new version of the patch taken into account your remarks.

Regards,

Cédric Le Barz
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxf.h|   1 +
 ffmpeg/libavformat/mxfenc.c | 169 +++-
 2 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/ffmpeg/libavformat/mxf.h b/ffmpeg/libavformat/mxf.h
index 2561605..7dd1681 100644
--- a/ffmpeg/libavformat/mxf.h
+++ b/ffmpeg/libavformat/mxf.h
@@ -55,6 +55,7 @@ enum MXFMetadataSetType {
 SoundfieldGroupLabelSubDescriptor,
 GroupOfSoundfieldGroupsLabelSubDescriptor,
 FFV1SubDescriptor,
+JPEG2000SubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index 53bd6ae..685c11b 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -48,8 +48,10 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/time_internal.h"
 #include "libavcodec/defs.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/h264.h"
+#include "libavcodec/jpeg2000.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/rangecoder.h"
 #include "libavcodec/startcode.h"
@@ -78,6 +80,20 @@ typedef struct MXFIndexEntry {
 uint8_t flags;
 } MXFIndexEntry;
 
+typedef struct j2k_info_t {
+uint16_t j2k_cap;///< j2k required decoder capabilities
+uint16_t j2k_rsiz;   ///< j2k required decoder capabilities (Rsiz)
+uint32_t j2k_xsiz;   ///< j2k width of the reference grid (Xsiz)
+uint32_t j2k_ysiz;   ///< j2k height of the reference grid (Ysiz)
+uint32_t j2k_x0siz;  ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the image (X0siz)
+uint32_t j2k_y0siz;  ///< j2k vertical offset from the origin of the 
reference grid to the left side of the image (Y0siz)
+uint32_t j2k_xtsiz;  ///< j2k width of one reference tile with respect 
to the reference grid (XTsiz)
+uint32_t j2k_ytsiz;  ///< j2k height of one reference tile with 
respect to the reference grid (YTsiz)
+uint32_t j2k_xt0siz; ///< j2k horizontal offset from the origin of the 
reference grid to the left side of the first tile (XT0siz)
+uint32_t j2k_yt0siz; ///< j2k vertical offset from the origin of the 
reference grid to the left side of the first tile (YT0siz)
+uint8_t  j2k_comp_desc[12]; ///< j2k components descriptor (Ssiz(i), 
XRsiz(i), YRsiz(i))
+} j2k_info_t;
+
 typedef struct MXFStreamContext {
 int64_t pkt_cnt; ///< pkt counter for muxed packets
 UID track_essence_element_key;
@@ -104,6 +120,7 @@ typedef struct MXFStreamContext {
 int low_delay;   ///< low delay, used in mpeg-2 descriptor
 int avc_intra;
 int micro_version;   ///< format micro_version, used in ffv1 descriptor
+j2k_info_t j2k_info;
 } MXFStreamContext;
 
 typedef struct MXFContainerEssenceEntry {
@@ -413,6 +430,20 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
 { 0xDFD9, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x06,0x00,0x00,0x00}},
 /* FFV1 Micro-version */
 { 0xDFDA, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x05,0x00,0x00,0x00}},
 /* FFV1 Version */
 { 0xDFDB, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x0E,0x04,0x01,0x06,0x0C,0x01,0x00,0x00,0x00}},
 /* FFV1 Initialization Metadata */
+// ff_mxf_jpeg2000_local_tags
+{ 0x8400, 
{0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00}},
 /* Sub Descriptors / O

Re: [FFmpeg-devel] [PATCH] [MXF] - Add jpeg2000 subdescriptor in MXF file (V2).

2023-12-22 Thread Cédric Le Barz


Le 21/12/2023 à 12:11, Tomas Härdin a écrit :

ons 2023-12-20 klockan 18:04 +0100 skrev Cédric Le Barz:

Le 19/12/2023 à 14:36, Tomas Härdin a écrit :

+for ( comp = 0; comp < component_count; comp++ ) {
+avio_write(pb, &sc->j2k_info.j2k_comp_desc[3*comp] , 3);
+}

Looks like this could be simplified to just

avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*component_count);


+if (j2k_ncomponents != component_count) {
+av_log(s, AV_LOG_ERROR, "Incoherence about components
image
number.\n");
+}

I again feel this should be a hard error


+for (comp = 0; comp < j2k_ncomponents; comp++) {
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents] =
bytestream2_get_byteu(&g);   // Bitdepth for each component
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents+1] =
bytestream2_get_byteu(&g); // Horizontal sampling for each
component
+sc->j2k_info.j2k_comp_desc[comp*j2k_ncomponents+2] =
bytestream2_get_byteu(&g); // Vertical sampling for each
component
+}

Could be simplified to a single avio_read()

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Here is the new version of the patch taken into account your remarks.

Looks OK. Does this also work with RGB(A)? Seems to not be hardcoded
for YUV at least. Higher bitdepths would also be nice, I've been
working with lossless RGB48 J2K. Doesn't necessarily need to hold up
this patch, just curious.

/Tomas


Any J2K bitdepth can be handled with this patch (up to 31 bits per 
component).


Concerning RGBA, The JPEG 2000 sub-descriptor can be referenced either 
by the CDCI picture essence descriptor or the RGBA picture essence 
descriptor both of which are defined by SMPTE ST 377-1. In this patch it 
is only referenced by the CDCI as the RGBA essence descriptor is not yet 
implemented in FFmpeg.   Nevertheless, I think it should work too with 
CDCI essence descriptor : if you have such data, you can try.


Cédric



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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] [MXF] - Set aspect ratio for jpeg2000 images

2024-01-26 Thread Cédric Le Barz

Set aspect ratio for jpeg2000 images.
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxfenc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index 0f13068..7ea19ca 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -2639,7 +2639,6 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, 
AVStream *st, AVPacket *
 {
 MXFContext *mxf = s->priv_data;
 MXFStreamContext *sc = st->priv_data;
-AVIOContext *pb = s->pb;
 int component_count = av_pix_fmt_count_planes(st->codecpar->format);
 GetByteContext g;
 uint32_t j2k_ncomponents;
@@ -2679,6 +2678,10 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, 
AVStream *st, AVPacket *
 }
 bytestream2_get_bufferu(&g, sc->j2k_info.j2k_comp_desc, 3 * 
j2k_ncomponents);
 
+/* Set aspect ratio */
+av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
+  sc->j2k_info.j2k_xsiz, sc->j2k_info.j2k_ysiz, INT32_MAX);
+
 sc->frame_size = pkt->size;
 
 return 1;
-- 
2.34.1

--- End Message ---
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] [MXF] - Add "footer_with_hmd" option

2024-01-26 Thread Cédric Le Barz
Add "footer_with_hmd" option: this option activates the writing of the 
header metadata in the footer partition.
--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxfenc.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index 0f13068..79c92e1 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -480,6 +480,7 @@ typedef struct MXFContext {
 int cbr_index;   ///< use a constant bitrate index
 uint8_t unused_tags[MXF_NUM_TAGS];  ///< local tags that we know will not 
be used
 MXFStreamContext timecode_track_priv;
+int footer_with_hmd; // Flag to activate header metadata writing in footer 
partition
 } MXFContext;
 
 static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int 
value)
@@ -3420,10 +3421,10 @@ static int mxf_write_footer(AVFormatContext *s)
 mxf_write_klv_fill(s);
 mxf->footer_partition_offset = avio_tell(pb);
 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { // no need to repeat 
index
-if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
+if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 
mxf->footer_with_hmd)) < 0)
 return err;
 } else {
-if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
+if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 
mxf->footer_with_hmd)) < 0)
 return err;
 mxf_write_klv_fill(s);
 mxf_write_index_table_segment(s);
@@ -3567,6 +3568,8 @@ static const AVOption mxf_options[] = {
 MXF_COMMON_OPTIONS
 { "store_user_comments", "",
   offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 
0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+{ "footer_with_hmd", "",
+  offsetof(MXFContext, footer_with_hmd), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 
1, AV_OPT_FLAG_ENCODING_PARAM},
 { NULL },
 };
 
-- 
2.34.1

--- End Message ---
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] [MXF] - Add "footer_with_hmd" option

2024-02-09 Thread Cédric Le Barz
Add "footer_with_hmd" option: this option activates the writing of the 
header metadata in the footer partition.


Cédric


--- Begin Message ---
Signed-off-by: Cedric Le Barz 
---
 ffmpeg/libavformat/mxfenc.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ffmpeg/libavformat/mxfenc.c b/ffmpeg/libavformat/mxfenc.c
index 0f13068..79c92e1 100644
--- a/ffmpeg/libavformat/mxfenc.c
+++ b/ffmpeg/libavformat/mxfenc.c
@@ -480,6 +480,7 @@ typedef struct MXFContext {
 int cbr_index;   ///< use a constant bitrate index
 uint8_t unused_tags[MXF_NUM_TAGS];  ///< local tags that we know will not 
be used
 MXFStreamContext timecode_track_priv;
+int footer_with_hmd; // Flag to activate header metadata writing in footer 
partition
 } MXFContext;
 
 static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int 
value)
@@ -3420,10 +3421,10 @@ static int mxf_write_footer(AVFormatContext *s)
 mxf_write_klv_fill(s);
 mxf->footer_partition_offset = avio_tell(pb);
 if (mxf->edit_unit_byte_count && !IS_OPATOM(s)) { // no need to repeat 
index
-if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)
+if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 
mxf->footer_with_hmd)) < 0)
 return err;
 } else {
-if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
+if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 
mxf->footer_with_hmd)) < 0)
 return err;
 mxf_write_klv_fill(s);
 mxf_write_index_table_segment(s);
@@ -3567,6 +3568,8 @@ static const AVOption mxf_options[] = {
 MXF_COMMON_OPTIONS
 { "store_user_comments", "",
   offsetof(MXFContext, store_user_comments), AV_OPT_TYPE_BOOL, {.i64 = 1}, 
0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+{ "footer_with_hmd", "",
+  offsetof(MXFContext, footer_with_hmd), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 
1, AV_OPT_FLAG_ENCODING_PARAM},
 { NULL },
 };
 
-- 
2.34.1

--- End Message ---
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] [MXF] - Add "footer_with_hmd" option

2024-02-21 Thread Cédric Le Barz


-Message d'origine-
De : ffmpeg-devel  De la part de Tomas Härdin
Envoyé : lundi 19 février 2024 11:40
À : FFmpeg development discussions and patches 
Objet : Re: [FFmpeg-devel] [PATCH] [MXF] - Add "footer_with_hmd" option

fre 2024-02-09 klockan 11:58 +0100 skrev Cédric Le Barz:
> Add "footer_with_hmd" option: this option activates the writing of the 
> header metadata in the footer partition.

Sounds useful for writing MXF to a stream.

Could use a test.

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

To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with 
subject "unsubscribe".




Hi Tomas,

What do you mean by "Could you a test.".
Thanks,

Cédric

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".