Skip to content

Commit

Permalink
Work on colors
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Aug 27, 2024
1 parent 474e661 commit cbf41b5
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 65 deletions.
6 changes: 5 additions & 1 deletion mini_analyser/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@
*/
int main(int argc, char *argv[])
{
// Arguments parsing ///////////////////////////////////////////////////////

std::cout << GREEN "mini_analyser() arguments" RESET << std::endl;

bool cli_enabled = false;
bool cli_details_enabled = false;

QStringList files;

std::cout << GREEN "mini_analyser() arguments" RESET << std::endl;
for (int i = 1; i < argc; i++)
{
if (argv[i])
Expand Down
16 changes: 9 additions & 7 deletions mini_analyser/src/mainwindow_datas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,9 @@ int MainWindow::printAudioDetails()

if (t->stream_size)
{
uint64_t rawsize = t->sampling_rate * t->channel_count * (t->bit_per_sample / 8);
uint64_t rawsize = t->sampling_rate * t->channel_count * (t->bit_per_sample / 8.0);
rawsize *= t->stream_duration_ms;
rawsize /= 1000;
rawsize /= 1000.0;

uint64_t ratio = std::round(static_cast<double>(rawsize) / static_cast<double>(t->stream_size));
ui->label_audio_compression_ratio->setText(QString::number(ratio) + ":1");
Expand Down Expand Up @@ -1104,7 +1104,7 @@ int MainWindow::printVideoDetails()
ui->label_video_par->setVisible(false);
}

if (t->color_space > 0 && t->color_subsampling > 0)
if (t->color_space > 0 && t->chroma_subsampling > 0)
{
ui->label_50->setVisible(true);
ui->label_60->setVisible(true);
Expand All @@ -1126,7 +1126,7 @@ int MainWindow::printVideoDetails()
else
ui->label_video_color_space->setText("YCbCr (best guess)");

ui->label_video_color_subsampling->setText(getChromaSubsamplingQString((ChromaSubSampling_e)t->color_subsampling));
ui->label_video_color_subsampling->setText(getChromaSubsamplingQString((ChromaSubSampling_e)t->chroma_subsampling));
}
else
{
Expand Down Expand Up @@ -1243,10 +1243,12 @@ int MainWindow::printVideoDetails()
// Compression ratio
if (t->stream_size)
{
if (t->color_planes == 0) t->color_planes = 3;
if (t->color_depth == 0) t->color_depth = 8;
unsigned color_planes = t->color_planes;
unsigned color_depth = t->color_depth;
if (color_planes == 0) color_planes = 3;
if (color_depth == 0) color_depth = 8;

uint64_t rawsize = t->width * t->height * (t->color_depth / 8) * t->color_planes;
uint64_t rawsize = t->width * t->height * (color_depth / 8.0) * color_planes;
rawsize *= t->sample_count;

uint64_t ratio = std::round(static_cast<double>(rawsize) / static_cast<double>(t->stream_size));
Expand Down
70 changes: 63 additions & 7 deletions minivideo/src/bitstream_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,22 +571,32 @@ bool computeCodecsSpecifics(MediaFile_t *media)

// Chroma
if (avcC->sps_array[0]->chroma_format_idc == 0)
track->color_subsampling = CHROMA_SS_400;
track->chroma_subsampling = CHROMA_SS_400;
else if (avcC->sps_array[0]->chroma_format_idc == 1)
track->color_subsampling = CHROMA_SS_420;
track->chroma_subsampling = CHROMA_SS_420;
else if (avcC->sps_array[0]->chroma_format_idc == 2)
track->color_subsampling = CHROMA_SS_422;
track->chroma_subsampling = CHROMA_SS_422;
else if (avcC->sps_array[0]->chroma_format_idc == 3)
track->color_subsampling = CHROMA_SS_444;
track->chroma_subsampling = CHROMA_SS_444;
else
track->color_subsampling = CHROMA_SS_420;
track->chroma_subsampling = CHROMA_SS_420;

if (avcC->sps_array[0]->vui)
{
track->color_range = avcC->sps_array[0]->vui->video_full_range_flag;
track->color_primaries = avcC->sps_array[0]->vui->colour_primaries;
track->color_transfer = avcC->sps_array[0]->vui->transfer_characteristics;
track->color_matrix = avcC->sps_array[0]->vui->matrix_coefficients;

if (avcC->sps_array[0]->vui->chroma_loc_info_present_flag)
{
if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 0) track->chroma_location = CHROMA_LOC_LEFT;
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 1) track->chroma_location = CHROMA_LOC_CENTER;
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 2) track->chroma_location = CHROMA_LOC_TOPLEFT;
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 3) track->chroma_location = CHROMA_LOC_TOP;
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 4) track->chroma_location = CHROMA_LOC_BOTTOMLEFT;
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 5) track->chroma_location = CHROMA_LOC_BOTTOM;
}
}

if (avcC->pps_count > 0 && avcC->pps_array[0])
Expand Down Expand Up @@ -634,6 +644,18 @@ bool computeCodecsSpecifics(MediaFile_t *media)
track->color_depth = vpcC->bitDepth;
track->color_range = vpcC->videoFullRangeFlag;

if (vpcC->chromaSubsampling == 0 || vpcC->chromaSubsampling == 1)
track->chroma_subsampling = CHROMA_SS_420;
else if (vpcC->chromaSubsampling == 2)
track->chroma_subsampling = CHROMA_SS_422;
else if (vpcC->chromaSubsampling == 3)
track->chroma_subsampling = CHROMA_SS_444;

if (vpcC->chromaSubsampling == 1)
track->chroma_location = CHROMA_LOC_TOPLEFT;
else
track->chroma_location = CHROMA_LOC_LEFT;

track->color_primaries = vpcC->colourPrimaries;
track->color_transfer = vpcC->transferCharacteristics;
track->color_matrix = vpcC->matrixCoefficients;
Expand Down Expand Up @@ -670,9 +692,43 @@ bool computeCodecsSpecifics(MediaFile_t *media)
else if (av1C->seq_level_idx_0 == 22) track->video_level = 7.2;
else if (av1C->seq_level_idx_0 == 23) track->video_level = 7.3;

if (av1C->high_bitdepth) track->color_depth = 10;
else if (av1C->twelve_bit) track->color_depth = 12;
if (av1C->twelve_bit) track->color_depth = 12;
else if (av1C->high_bitdepth) track->color_depth = 10;
else track->color_depth = 8;

if (av1C->chroma_subsampling_x == 0 && av1C->chroma_subsampling_y == 0 && av1C->monochrome == 0)
track->chroma_subsampling = CHROMA_SS_444;
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 0 && av1C->monochrome == 0)
track->chroma_subsampling = CHROMA_SS_422;
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 1 && av1C->monochrome == 0)
track->chroma_subsampling = CHROMA_SS_420;
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 1 && av1C->monochrome == 1)
track->chroma_subsampling = CHROMA_SS_400;

if (av1C->chroma_sample_position == 1)
track->chroma_location = CHROMA_LOC_LEFT;
else if (av1C->chroma_sample_position == 2)
track->chroma_location = CHROMA_LOC_TOPLEFT;
}

else if (track->stream_codec == CODEC_PRORES_422_PROXY ||
track->stream_codec == CODEC_PRORES_422_LT ||
track->stream_codec == CODEC_PRORES_422 ||
track->stream_codec == CODEC_PRORES_422_HQ)
{
track->chroma_subsampling = CHROMA_SS_422;
}
else if (track->stream_codec == CODEC_PRORES_4444 ||
track->stream_codec == CODEC_PRORES_4444_XQ)
{
track->chroma_subsampling = CHROMA_SS_444;
}
else if (track->stream_codec == CODEC_PRORES_RAW ||
track->stream_codec == CODEC_PRORES_RAW_HQ)
{
// RAW variants are not using YUV pixel subsampling
track->chroma_subsampling = CHROMA_SS_UNKNOWN;
track->color_depth = 16;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions minivideo/src/demuxer/mkv/mkv_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,6 @@ int parse_vpx_private(Bitstream_t *bitstr, mkv_track_t *track, mkv_t *mkv)
TRACE_1(MP4, "> colourPrimaries: %u", track->vpcC->colourPrimaries);
TRACE_1(MP4, "> transferCharacteristics: %u", track->vpcC->transferCharacteristics);
TRACE_1(MP4, "> matrixCoefficients: %u", track->vpcC->matrixCoefficients);

TRACE_1(MP4, "> codecIntializationDataSize: %u", track->vpcC->codecIntializationDataSize);
#endif // ENABLE_DEBUG

// xmlMapper
Expand Down
2 changes: 1 addition & 1 deletion minivideo/src/demuxer/mkv/mkv_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ typedef struct mkv_track_t
std::vector <mkv_sample_t *> sample_vector;

// Video specific parameters
unsigned int color_depth = 8;
unsigned int color_depth = 0;
unsigned int color_range = 0;
unsigned int color_space = 0;
unsigned int color_primaries = 0;
Expand Down
16 changes: 2 additions & 14 deletions minivideo/src/demuxer/mp4/mp4_stsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,8 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
track->vpcC->transferCharacteristics = read_bits(bitstr, 8);
track->vpcC->matrixCoefficients = read_bits(bitstr, 8);

track->vpcC->codecIntializationDataSize = read_bits(bitstr, 16);
if (track->vpcC->codecIntializationDataSize > 0)
int codecIntializationDataSize = read_bits(bitstr, 16);
if (codecIntializationDataSize > 0)
{
// Note: must be 0 for VP8 and VP9
}
Expand All @@ -1634,12 +1634,6 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
TRACE_1(MP4, "> colourPrimaries: %u", track->vpcC->colourPrimaries);
TRACE_1(MP4, "> transferCharacteristics: %u", track->vpcC->transferCharacteristics);
TRACE_1(MP4, "> matrixCoefficients: %u", track->vpcC->matrixCoefficients);

TRACE_1(MP4, "> codecIntializationDataSize: %u", track->vpcC->codecIntializationDataSize);
if (track->vpcC->codecIntializationDataSize)
{
// TODO
}
#endif // ENABLE_DEBUG

// xmlMapper
Expand All @@ -1653,12 +1647,6 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
fprintf(mp4->xml, " <colourPrimaries>%u</colourPrimaries>\n", track->vpcC->colourPrimaries);
fprintf(mp4->xml, " <transferCharacteristics>%u</transferCharacteristics>\n", track->vpcC->transferCharacteristics);
fprintf(mp4->xml, " <matrixCoefficients>%u</matrixCoefficients>\n", track->vpcC->matrixCoefficients);

fprintf(mp4->xml, " <codecIntializationDataSize>%u</codecIntializationDataSize>\n", track->vpcC->codecIntializationDataSize);
if (track->vpcC->codecIntializationDataSize)
{
// TODO
}
fprintf(mp4->xml, " </a>\n");
}

Expand Down
4 changes: 2 additions & 2 deletions minivideo/src/minivideo_avutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ typedef enum ChromaLocation_e
{
CHROMA_LOC_UNKNOWN = 0, //!< Unknown chroma location

CHROMA_LOC_LEFT = 1, //!<
CHROMA_LOC_LEFT = 1, //!< vertical
CHROMA_LOC_CENTER = 2,
CHROMA_LOC_TOPLEFT = 3,
CHROMA_LOC_TOPLEFT = 3, //!< colocated
CHROMA_LOC_TOP = 4,
CHROMA_LOC_BOTTOMLEFT = 5,
CHROMA_LOC_BOTTOM = 6,
Expand Down
26 changes: 0 additions & 26 deletions minivideo/src/minivideo_codecs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,32 +745,6 @@ const char *getCodecString(const StreamType_e type, const Codecs_e codec, const

/* ************************************************************************** */

const char *getPictureString(const Pictures_e picture, const bool long_description)
{
switch (picture)
{
case PICTURE_BMP:
return "BMP";
case PICTURE_JPG:
return "JPG";
case PICTURE_PNG:
return "PNG";
case PICTURE_WEBP:
return "WebP";
case PICTURE_TGA:
return "TGA";
case PICTURE_YUV444:
return "YCbCr 4:4:4";
case PICTURE_YUV420:
return "YCbCr 4:2:0";

default:
return "";
}
}

/* ************************************************************************** */

const char *getCodecProfileString(const CodecProfiles_e profile, const bool long_description)
{
switch (profile)
Expand Down
2 changes: 0 additions & 2 deletions minivideo/src/minivideo_codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,6 @@ CodecProfiles_e getH266CodecProfile(const unsigned profil_idc);
minivideo_EXPORT const char *getCodecString(const StreamType_e type, const Codecs_e codec, const bool long_description = false);
minivideo_EXPORT const char *getCodecProfileString(const CodecProfiles_e profile, const bool long_description = false);

minivideo_EXPORT const char *getPictureString(const Pictures_e picture, const bool long_description = false);

/* ************************************************************************** */

minivideo_EXPORT const char *getScanModeString(const ScanType_e mode);
Expand Down
8 changes: 6 additions & 2 deletions minivideo/src/minivideo_codecs_private_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ typedef struct codecprivate_vvcC_t

/* ************************************************************************** */

/*!
* https://www.webmproject.org/vp9/mp4/
*/
typedef struct codecprivate_vpcC_t
{
uint8_t profile;
Expand All @@ -120,12 +123,13 @@ typedef struct codecprivate_vpcC_t
uint8_t transferCharacteristics;
uint8_t matrixCoefficients;

uint16_t codecIntializationDataSize;

} codecprivate_vpcC_t;

/* ************************************************************************** */

/*!
* https://aomediacodec.github.io/av1-isobmff/
*/
typedef struct codecprivate_av1C_t
{
bool marker;
Expand Down
3 changes: 2 additions & 1 deletion minivideo/src/minivideo_mediastream.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ typedef struct MediaStream_t
FramerateMode_e framerate_mode; //!< Framerate mode

unsigned int color_planes; //!< Number of encoded planes (ex: 1 for monochrome, 3 for YUV or 4 for RGBA)
unsigned int color_subsampling; //!< Chroma sub-sampling
unsigned int color_depth; //!< Color resolution per channel
unsigned int color_range; //!< Colors are in restricted or full range
unsigned int chroma_subsampling; //!< Chroma sub-sampling
unsigned int chroma_location; //!< Chroma location
unsigned int color_space; //!< Internal color encoding
unsigned int color_primaries; //!< Color primaries
unsigned int color_transfer; //!< Color transfer function
Expand Down

0 comments on commit cbf41b5

Please sign in to comment.