Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPEG XS essence support #48

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
59 changes: 53 additions & 6 deletions apps/raw2bmx/raw2bmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <bmx/essence_parser/J2CEssenceParser.h>
#include <bmx/essence_parser/VC3EssenceParser.h>
#include <bmx/essence_parser/VC2EssenceParser.h>
#include <bmx/essence_parser/JXSEssenceParser.h>
#include <bmx/essence_parser/RawEssenceReader.h>
#include <bmx/essence_parser/FileEssenceSource.h>
#include <bmx/essence_parser/KLVEssenceSource.h>
Expand Down Expand Up @@ -102,6 +103,7 @@ typedef enum
D10_ESSENCE_GROUP,
AVCI_ESSENCE_GROUP,
AVC_ESSENCE_GROUP,
JXS_ESSENCE_GROUP,
} EssenceTypeGroup;


Expand Down Expand Up @@ -780,6 +782,10 @@ static void usage(const char *cmd)
printf(" --j2c_rgba <name|j2cpattern> Raw JPEG 2000 (ISO/IEC 15444-1) codestream representing components (e.g. RGB) described by a MXF RGBA descriptor\n");
printf(" If a '%%' is in the value then it is assumed to be a <j2cpattern> for a sequence of files, each containing a single frame\n");
printf(" See Notes below for a detailed description of <j2cpattern>\n");
printf(" --jxs_cdci <name|jxspattern> Raw JPEG XS codestream representing components (e.g. YCbCr) described by a MXF CDCI descriptor\n");
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
printf(" If a '%%' is in the value then it is assumed to be a <jxspattern> for a sequence of files, each containing a single frame\n");
printf(" --jxs_rgba <name|jxspattern> Raw JPEG XS codestream representing components (e.g. RGB) described by a MXF RGBA descriptor\n");
printf(" If a '%%' is in the value then it is assumed to be a <jxspattern> for a sequence of files, each containing a single frame\n");
printf(" --vc2 <name> Raw VC2 input file\n");
printf(" --vc3 <name> Raw VC3/DNxHD input file\n");
printf(" --vc3_1080p_1235 <name> Raw VC3/DNxHD 1920x1080p 220/185/175 Mbps 10bit input file\n");
Expand Down Expand Up @@ -3537,6 +3543,38 @@ int main(int argc, const char** argv)
inputs.push_back(input);
cmdln_index++;
}
else if (strcmp(argv[cmdln_index], "--jxs_rgba") == 0)
{
if (cmdln_index + 1 >= argc)
{
usage(argv[0]);
fprintf(stderr, "Missing argument for input '%s'\n", argv[cmdln_index]);
return 1;
}
input.essence_type = JPEGXS_RGBA;
if (strchr(argv[cmdln_index + 1], '%') != 0)
input.file_pattern = argv[cmdln_index + 1];
else
input.filename = argv[cmdln_index + 1];
inputs.push_back(input);
cmdln_index++;
}
else if (strcmp(argv[cmdln_index], "--jxs_cdci") == 0)
{
if (cmdln_index + 1 >= argc)
{
usage(argv[0]);
fprintf(stderr, "Missing argument for input '%s'\n", argv[cmdln_index]);
return 1;
}
input.essence_type = JPEGXS_CDCI;
if (strchr(argv[cmdln_index + 1], '%') != 0)
input.file_pattern = argv[cmdln_index + 1];
else
input.filename = argv[cmdln_index + 1];
inputs.push_back(input);
cmdln_index++;
}
else if (strcmp(argv[cmdln_index], "--rdd36_422_proxy") == 0)
{
if (cmdln_index + 1 >= argc)
Expand Down Expand Up @@ -3641,9 +3679,9 @@ int main(int argc, const char** argv)
}
input.essence_type = JPEG2000_RGBA;
if (strchr(argv[cmdln_index + 1], '%') != 0)
input.file_pattern = argv[cmdln_index + 1];
input.file_pattern = argv[cmdln_index + 1];
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
else
input.filename = argv[cmdln_index + 1];
input.filename = argv[cmdln_index + 1];
inputs.push_back(input);
cmdln_index++;
}
Expand Down Expand Up @@ -4137,7 +4175,6 @@ int main(int argc, const char** argv)

if (!open_raw_reader(input))
throw false;

philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
if (input->essence_type_group == DV_ESSENCE_GROUP ||
input->essence_type == IEC_DV25 ||
input->essence_type == DVBASED_DV25 ||
Expand Down Expand Up @@ -4848,7 +4885,6 @@ int main(int argc, const char** argv)
log_info("Output filename set to '%s'\n", complete_output_name.c_str());
}


philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
// create clip

int flavour = 0;
Expand Down Expand Up @@ -4925,8 +4961,6 @@ int main(int argc, const char** argv)
BMX_ASSERT(false);
break;
}


philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
// initialize clip properties

SourcePackage *physical_package = 0;
Expand Down Expand Up @@ -5396,6 +5430,12 @@ int main(int argc, const char** argv)
if (BMX_OPT_PROP_IS_SET(input->afd))
clip_track->SetAFD(input->afd);
break;
case JPEGXS_CDCI:
case JPEGXS_RGBA:
clip_track->SetAspectRatio(input->aspect_ratio);
if (BMX_OPT_PROP_IS_SET(input->afd))
clip_track->SetAFD(input->afd);
break;
case VC2:
clip_track->SetAspectRatio(input->aspect_ratio);
if (BMX_OPT_PROP_IS_SET(input->afd))
Expand Down Expand Up @@ -5648,6 +5688,13 @@ int main(int argc, const char** argv)
input->raw_reader->SetEssenceParser(new J2CEssenceParser());
input->raw_reader->SetCheckMaxSampleSize(100000000);
break;
case JPEGXS_CDCI:
case JPEGXS_RGBA:
input->sample_sequence[0] = 1;
input->sample_sequence_size = 1;
input->raw_reader->SetEssenceParser(new JXSEssenceParser());
input->raw_reader->SetCheckMaxSampleSize(100000000);
break;
case VC2:
input->sample_sequence[0] = 1;
input->sample_sequence_size = 1;
Expand Down
73 changes: 70 additions & 3 deletions deps/libMXF/mxf/mxf_baseline_data_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -2059,9 +2059,76 @@ MXF_SET_DEFINITION(SubDescriptor, JPEG2000SubDescriptor,
0
);

MXF_SET_DEFINITION(SubDescriptor, ContainerConstraintsSubDescriptor,
MXF_LABEL(0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x67,0x00)
);
MXF_SET_DEFINITION(SubDescriptor, ContainerConstraintsSubDescriptor,
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
MXF_LABEL(0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x67,0x00)
);

MXF_SET_DEFINITION(SubDescriptor, JPEGXSSubDescriptor,
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x81, 0x02)
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSPpih,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x01, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSPlev,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x02, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSWf,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x03, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSHf,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x04, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSNc,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x05, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT8_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSComponentTable,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x06, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT8ARRAY_TYPE,
1
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSCw,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x07, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
0
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSHsl,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x08, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT16_TYPE,
0
);

MXF_ITEM_DEFINITION(JPEGXSSubDescriptor, JPEGXSMaximumBitRate,
MXF_LABEL(0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x0e, 0x04, 0x01, 0x06, 0x0b, 0x09, 0x00, 0x00, 0x00),
0x0000,
MXF_UINT32_TYPE,
0
);


#if !defined(KEEP_DATA_MODEL_DEFS)
Expand Down
37 changes: 37 additions & 0 deletions deps/libMXF/mxf/mxf_header_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,43 @@ int mxf_alloc_array_item_elements(MXFMetadataSet *set, const mxfKey *itemKey, ui
return 0;
}

int mxf_alloc_jxs_array(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen,
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
uint32_t count, uint8_t **elements)
{
MXFMetadataItem *newItem = NULL;
uint8_t *buffer = NULL;

assert(set->headerMetadata != NULL);

if (count == 0)
{
int result = mxf_set_empty_array_item(set, itemKey, elementLen);
if (result)
{
*elements = NULL;
}
return result;
}

CHK_OFAIL(count * elementLen < 65536);

CHK_ORET(get_or_create_set_item(set->headerMetadata, set, itemKey, &newItem));

CHK_MALLOC_ARRAY_ORET(buffer, uint8_t, count * elementLen);
//mxf_set_array_header(count, elementLen, buffer);
memset(&buffer[0], 0, elementLen * count);

CHK_OFAIL(mxf_set_item_value(newItem, buffer, (uint16_t)(count * elementLen)));
*elements = &newItem->value[0];

SAFE_FREE(buffer);
return 1;

fail:
SAFE_FREE(buffer);
return 0;
}

int mxf_grow_array_item(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen,
uint32_t count, uint8_t **newElements)
{
Expand Down
2 changes: 2 additions & 0 deletions deps/libMXF/mxf/mxf_header_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ int mxf_set_video_line_map_item(MXFMetadataSet *set, const mxfKey *itemKey, cons

int mxf_alloc_array_item_elements(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen,
uint32_t count, uint8_t **elements);
int mxf_alloc_jxs_array(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen,
uint32_t count, uint8_t **elements);
int mxf_grow_array_item(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen,
uint32_t count, uint8_t **newElements);
int mxf_set_empty_array_item(MXFMetadataSet *set, const mxfKey *itemKey, uint32_t elementLen);
Expand Down
6 changes: 6 additions & 0 deletions deps/libMXF/mxf/mxf_labels_and_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ int mxf_is_jpeg2000_ec(const mxfUL *label)
label->octet13 == 0x0c;
}

int mxf_is_jpegxs_ec(const mxfUL *label)
{
return mxf_is_generic_container_label(label) &&
label->octet13 == 0x21;
}


void mxf_complete_essence_element_key(mxfKey *key, uint8_t count, uint8_t type, uint8_t num)
{
Expand Down
42 changes: 42 additions & 0 deletions deps/libMXF/mxf/mxf_labels_and_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ static const mxfUL MXF_CMDEF_L(JPEG2000_HTJ2K_GENERIC) = MXF_JPEG2000_CMDEV_L(MX
void mxf_get_jpeg2000_coding_label(uint16_t profile, uint8_t main_level, uint8_t sub_level, mxfUL *label);


/* JPEG XS */

#define MXF_JPEGXS_CMDEV_L(profile) \
{0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x0d, 0x04, 0x01, 0x02, 0x02, 0x03, 0x08, profile, 0x00}

static const mxfUL MXF_CMDEF_L(JPEGXSPictureCodingSchemes) = MXF_JPEGXS_CMDEV_L(0x00);
static const mxfUL MXF_CMDEF_L(JPEGXSUnrestrictedCodestream) = MXF_JPEGXS_CMDEV_L(0x01);
static const mxfUL MXF_CMDEF_L(JPEGXSMain422_10Profile) = MXF_JPEGXS_CMDEV_L(0x02);
static const mxfUL MXF_CMDEF_L(JPEGXSMain444_12Profile) = MXF_JPEGXS_CMDEV_L(0x03);
static const mxfUL MXF_CMDEF_L(JPEGXSMain4444_12Profile) = MXF_JPEGXS_CMDEV_L(0x04);
static const mxfUL MXF_CMDEF_L(JPEGXSLight422_10Profile) = MXF_JPEGXS_CMDEV_L(0x05);
static const mxfUL MXF_CMDEF_L(JPEGXSLight444_12Profile) = MXF_JPEGXS_CMDEV_L(0x06);
static const mxfUL MXF_CMDEF_L(JPEGXSLightSubline422_10Profile) = MXF_JPEGXS_CMDEV_L(0x07);
static const mxfUL MXF_CMDEF_L(JPEGXSHigh444_12Profile) = MXF_JPEGXS_CMDEV_L(0x08);
static const mxfUL MXF_CMDEF_L(JPEGXSHigh4444_12Profile) = MXF_JPEGXS_CMDEV_L(0x09);

//void mxf_get_jpegxs_coding_label(mxfUL *label);
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved

/* uncompressed picture coding */

/* fourcc 2vuy */
Expand Down Expand Up @@ -564,6 +582,18 @@ static const mxfUL MXF_EC_L(JPEG2000P1Wrapped) = MXF_JPEG2000_EC_L(0x0d, 0x06);

int mxf_is_jpeg2000_ec(const mxfUL *label);

/* JPEG XS */

#define MXF_JPEGXS_EC_L(byte15) \
MXF_GENERIC_CONTAINER_LABEL(0x0d, 0x21, byte15, 0x00)

static const mxfUL MXF_EC_L(MXFGCJPEGXSPictures) = MXF_JPEGXS_EC_L(0x00);
static const mxfUL MXF_EC_L(MXFGCFrameWrappedProgressiveJPEGXSPictures) = MXF_JPEGXS_EC_L(0x01);
static const mxfUL MXF_EC_L(MXFGCFrameWrappedInterlacedJPEGXSPictures) = MXF_JPEGXS_EC_L(0x02);
static const mxfUL MXF_EC_L(MXFGCClipWrappedJPEGXSPictures) = MXF_JPEGXS_EC_L(0x03);

int mxf_is_jpegxs_ec(const mxfUL *label);


/* Data */

Expand Down Expand Up @@ -885,6 +915,18 @@ static const mxfKey MXF_EE_K(SDTI_CP_System_Pack) =
#define MXF_JPEG2000_CLIP_WRAPPED_EE_TYPE 0x09


/* JPEG XS */

#define MXF_JPEGXS_EE_K(elecount, eletype, elenum) \
MXF_GENERIC_CONTAINER_ELEMENT_KEY(0x01, 0x15, elecount, eletype, elenum)

#define MXF_JPEGXS_TRACK_NUM(elecount, eletype, elenum) \
MXF_TRACK_NUM(0x15, elecount, eletype, elenum)

#define MXF_JPEGXS_FRAME_WRAPPED_EE_TYPE 0x1A
#define MXF_JPEGXS_CLIP_WRAPPED_EE_TYPE 0x1B


/* Data mappings */

static const mxfUL MXF_EE_K(VBIData) = MXF_GENERIC_CONTAINER_ELEMENT_KEY(0x01, 0x17, 0x01, 0x01, 0x01);
Expand Down
1 change: 1 addition & 0 deletions deps/libMXFpp/libMXF++/HeaderMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ void HeaderMetadata::initialiseObjectFactory()
REGISTER_CLASS(DCTimedTextDescriptor);
REGISTER_CLASS(DCTimedTextResourceSubDescriptor);
REGISTER_CLASS(JPEG2000SubDescriptor);
REGISTER_CLASS(JPEGXSSubDescriptor);
REGISTER_CLASS(ContainerConstraintsSubDescriptor);

// Add new classes here
Expand Down
12 changes: 12 additions & 0 deletions deps/libMXFpp/libMXF++/MetadataSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,18 @@ void MetadataSet::setUInt8ArrayItem(const mxfKey *itemKey, const vector<uint8_t>
}
}

void MetadataSet::setUInt8JxsArray(const mxfKey *itemKey, const vector<uint8_t> &value)
philipnbbc marked this conversation as resolved.
Show resolved Hide resolved
{
size_t i;
uint8_t *data = 0;
MXFPP_CHECK(mxf_alloc_jxs_array(_cMetadataSet, itemKey, 1, (uint32_t)value.size(), &data));
for (i = 0; i < value.size(); i++)
{
mxf_set_uint8(value.at(i), data);
data += 1;
}
}

void MetadataSet::setUInt16ArrayItem(const mxfKey *itemKey, const vector<uint16_t> &value)
{
size_t i;
Expand Down
1 change: 1 addition & 0 deletions deps/libMXFpp/libMXF++/MetadataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class MetadataSet
void setStrongRefItem(const mxfKey *itemKey, MetadataSet *value);
void setWeakRefItem(const mxfKey *itemKey, MetadataSet *value);

void setUInt8JxsArray(const mxfKey *itemKey, const std::vector<uint8_t> &value);
void setUInt8ArrayItem(const mxfKey *itemKey, const std::vector<uint8_t> &value);
void setUInt16ArrayItem(const mxfKey *itemKey, const std::vector<uint16_t> &value);
void setUInt32ArrayItem(const mxfKey *itemKey, const std::vector<uint32_t> &value);
Expand Down
2 changes: 2 additions & 0 deletions deps/libMXFpp/libMXF++/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ list(APPEND MXFpp_sources
metadata/Identification.cpp
metadata/InterchangeObject.cpp
metadata/JPEG2000SubDescriptor.cpp
metadata/JPEGXSSubDescriptor.cpp
metadata/Locator.cpp
metadata/MCALabelSubDescriptor.cpp
metadata/MPEGVideoDescriptor.cpp
Expand Down Expand Up @@ -81,6 +82,7 @@ list(APPEND MXFpp_headers
metadata/Identification.h
metadata/InterchangeObject.h
metadata/JPEG2000SubDescriptor.h
metadata/JPEGXSSubDescriptor.h
metadata/Locator.h
metadata/MCALabelSubDescriptor.h
metadata/MPEGVideoDescriptor.h
Expand Down
Loading