Skip to content

Commit cbf41b5

Browse files
committed
Work on colors
1 parent 474e661 commit cbf41b5

11 files changed

+90
-65
lines changed

mini_analyser/src/main.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@
4646
*/
4747
int main(int argc, char *argv[])
4848
{
49+
// Arguments parsing ///////////////////////////////////////////////////////
50+
51+
std::cout << GREEN "mini_analyser() arguments" RESET << std::endl;
52+
4953
bool cli_enabled = false;
5054
bool cli_details_enabled = false;
55+
5156
QStringList files;
5257

53-
std::cout << GREEN "mini_analyser() arguments" RESET << std::endl;
5458
for (int i = 1; i < argc; i++)
5559
{
5660
if (argv[i])

mini_analyser/src/mainwindow_datas.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,9 @@ int MainWindow::printAudioDetails()
780780

781781
if (t->stream_size)
782782
{
783-
uint64_t rawsize = t->sampling_rate * t->channel_count * (t->bit_per_sample / 8);
783+
uint64_t rawsize = t->sampling_rate * t->channel_count * (t->bit_per_sample / 8.0);
784784
rawsize *= t->stream_duration_ms;
785-
rawsize /= 1000;
785+
rawsize /= 1000.0;
786786

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

1107-
if (t->color_space > 0 && t->color_subsampling > 0)
1107+
if (t->color_space > 0 && t->chroma_subsampling > 0)
11081108
{
11091109
ui->label_50->setVisible(true);
11101110
ui->label_60->setVisible(true);
@@ -1126,7 +1126,7 @@ int MainWindow::printVideoDetails()
11261126
else
11271127
ui->label_video_color_space->setText("YCbCr (best guess)");
11281128

1129-
ui->label_video_color_subsampling->setText(getChromaSubsamplingQString((ChromaSubSampling_e)t->color_subsampling));
1129+
ui->label_video_color_subsampling->setText(getChromaSubsamplingQString((ChromaSubSampling_e)t->chroma_subsampling));
11301130
}
11311131
else
11321132
{
@@ -1243,10 +1243,12 @@ int MainWindow::printVideoDetails()
12431243
// Compression ratio
12441244
if (t->stream_size)
12451245
{
1246-
if (t->color_planes == 0) t->color_planes = 3;
1247-
if (t->color_depth == 0) t->color_depth = 8;
1246+
unsigned color_planes = t->color_planes;
1247+
unsigned color_depth = t->color_depth;
1248+
if (color_planes == 0) color_planes = 3;
1249+
if (color_depth == 0) color_depth = 8;
12481250

1249-
uint64_t rawsize = t->width * t->height * (t->color_depth / 8) * t->color_planes;
1251+
uint64_t rawsize = t->width * t->height * (color_depth / 8.0) * color_planes;
12501252
rawsize *= t->sample_count;
12511253

12521254
uint64_t ratio = std::round(static_cast<double>(rawsize) / static_cast<double>(t->stream_size));

minivideo/src/bitstream_map.cpp

+63-7
Original file line numberDiff line numberDiff line change
@@ -571,22 +571,32 @@ bool computeCodecsSpecifics(MediaFile_t *media)
571571

572572
// Chroma
573573
if (avcC->sps_array[0]->chroma_format_idc == 0)
574-
track->color_subsampling = CHROMA_SS_400;
574+
track->chroma_subsampling = CHROMA_SS_400;
575575
else if (avcC->sps_array[0]->chroma_format_idc == 1)
576-
track->color_subsampling = CHROMA_SS_420;
576+
track->chroma_subsampling = CHROMA_SS_420;
577577
else if (avcC->sps_array[0]->chroma_format_idc == 2)
578-
track->color_subsampling = CHROMA_SS_422;
578+
track->chroma_subsampling = CHROMA_SS_422;
579579
else if (avcC->sps_array[0]->chroma_format_idc == 3)
580-
track->color_subsampling = CHROMA_SS_444;
580+
track->chroma_subsampling = CHROMA_SS_444;
581581
else
582-
track->color_subsampling = CHROMA_SS_420;
582+
track->chroma_subsampling = CHROMA_SS_420;
583583

584584
if (avcC->sps_array[0]->vui)
585585
{
586586
track->color_range = avcC->sps_array[0]->vui->video_full_range_flag;
587587
track->color_primaries = avcC->sps_array[0]->vui->colour_primaries;
588588
track->color_transfer = avcC->sps_array[0]->vui->transfer_characteristics;
589589
track->color_matrix = avcC->sps_array[0]->vui->matrix_coefficients;
590+
591+
if (avcC->sps_array[0]->vui->chroma_loc_info_present_flag)
592+
{
593+
if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 0) track->chroma_location = CHROMA_LOC_LEFT;
594+
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 1) track->chroma_location = CHROMA_LOC_CENTER;
595+
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 2) track->chroma_location = CHROMA_LOC_TOPLEFT;
596+
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 3) track->chroma_location = CHROMA_LOC_TOP;
597+
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 4) track->chroma_location = CHROMA_LOC_BOTTOMLEFT;
598+
else if (avcC->sps_array[0]->vui->chroma_sample_loc_type_top_field == 5) track->chroma_location = CHROMA_LOC_BOTTOM;
599+
}
590600
}
591601

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

647+
if (vpcC->chromaSubsampling == 0 || vpcC->chromaSubsampling == 1)
648+
track->chroma_subsampling = CHROMA_SS_420;
649+
else if (vpcC->chromaSubsampling == 2)
650+
track->chroma_subsampling = CHROMA_SS_422;
651+
else if (vpcC->chromaSubsampling == 3)
652+
track->chroma_subsampling = CHROMA_SS_444;
653+
654+
if (vpcC->chromaSubsampling == 1)
655+
track->chroma_location = CHROMA_LOC_TOPLEFT;
656+
else
657+
track->chroma_location = CHROMA_LOC_LEFT;
658+
637659
track->color_primaries = vpcC->colourPrimaries;
638660
track->color_transfer = vpcC->transferCharacteristics;
639661
track->color_matrix = vpcC->matrixCoefficients;
@@ -670,9 +692,43 @@ bool computeCodecsSpecifics(MediaFile_t *media)
670692
else if (av1C->seq_level_idx_0 == 22) track->video_level = 7.2;
671693
else if (av1C->seq_level_idx_0 == 23) track->video_level = 7.3;
672694

673-
if (av1C->high_bitdepth) track->color_depth = 10;
674-
else if (av1C->twelve_bit) track->color_depth = 12;
695+
if (av1C->twelve_bit) track->color_depth = 12;
696+
else if (av1C->high_bitdepth) track->color_depth = 10;
675697
else track->color_depth = 8;
698+
699+
if (av1C->chroma_subsampling_x == 0 && av1C->chroma_subsampling_y == 0 && av1C->monochrome == 0)
700+
track->chroma_subsampling = CHROMA_SS_444;
701+
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 0 && av1C->monochrome == 0)
702+
track->chroma_subsampling = CHROMA_SS_422;
703+
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 1 && av1C->monochrome == 0)
704+
track->chroma_subsampling = CHROMA_SS_420;
705+
else if (av1C->chroma_subsampling_x == 1 && av1C->chroma_subsampling_y == 1 && av1C->monochrome == 1)
706+
track->chroma_subsampling = CHROMA_SS_400;
707+
708+
if (av1C->chroma_sample_position == 1)
709+
track->chroma_location = CHROMA_LOC_LEFT;
710+
else if (av1C->chroma_sample_position == 2)
711+
track->chroma_location = CHROMA_LOC_TOPLEFT;
712+
}
713+
714+
else if (track->stream_codec == CODEC_PRORES_422_PROXY ||
715+
track->stream_codec == CODEC_PRORES_422_LT ||
716+
track->stream_codec == CODEC_PRORES_422 ||
717+
track->stream_codec == CODEC_PRORES_422_HQ)
718+
{
719+
track->chroma_subsampling = CHROMA_SS_422;
720+
}
721+
else if (track->stream_codec == CODEC_PRORES_4444 ||
722+
track->stream_codec == CODEC_PRORES_4444_XQ)
723+
{
724+
track->chroma_subsampling = CHROMA_SS_444;
725+
}
726+
else if (track->stream_codec == CODEC_PRORES_RAW ||
727+
track->stream_codec == CODEC_PRORES_RAW_HQ)
728+
{
729+
// RAW variants are not using YUV pixel subsampling
730+
track->chroma_subsampling = CHROMA_SS_UNKNOWN;
731+
track->color_depth = 16;
676732
}
677733
}
678734
}

minivideo/src/demuxer/mkv/mkv_codec.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,6 @@ int parse_vpx_private(Bitstream_t *bitstr, mkv_track_t *track, mkv_t *mkv)
797797
TRACE_1(MP4, "> colourPrimaries: %u", track->vpcC->colourPrimaries);
798798
TRACE_1(MP4, "> transferCharacteristics: %u", track->vpcC->transferCharacteristics);
799799
TRACE_1(MP4, "> matrixCoefficients: %u", track->vpcC->matrixCoefficients);
800-
801-
TRACE_1(MP4, "> codecIntializationDataSize: %u", track->vpcC->codecIntializationDataSize);
802800
#endif // ENABLE_DEBUG
803801

804802
// xmlMapper

minivideo/src/demuxer/mkv/mkv_struct.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ typedef struct mkv_track_t
406406
std::vector <mkv_sample_t *> sample_vector;
407407

408408
// Video specific parameters
409-
unsigned int color_depth = 8;
409+
unsigned int color_depth = 0;
410410
unsigned int color_range = 0;
411411
unsigned int color_space = 0;
412412
unsigned int color_primaries = 0;

minivideo/src/demuxer/mp4/mp4_stsd.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,8 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
16191619
track->vpcC->transferCharacteristics = read_bits(bitstr, 8);
16201620
track->vpcC->matrixCoefficients = read_bits(bitstr, 8);
16211621

1622-
track->vpcC->codecIntializationDataSize = read_bits(bitstr, 16);
1623-
if (track->vpcC->codecIntializationDataSize > 0)
1622+
int codecIntializationDataSize = read_bits(bitstr, 16);
1623+
if (codecIntializationDataSize > 0)
16241624
{
16251625
// Note: must be 0 for VP8 and VP9
16261626
}
@@ -1634,12 +1634,6 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
16341634
TRACE_1(MP4, "> colourPrimaries: %u", track->vpcC->colourPrimaries);
16351635
TRACE_1(MP4, "> transferCharacteristics: %u", track->vpcC->transferCharacteristics);
16361636
TRACE_1(MP4, "> matrixCoefficients: %u", track->vpcC->matrixCoefficients);
1637-
1638-
TRACE_1(MP4, "> codecIntializationDataSize: %u", track->vpcC->codecIntializationDataSize);
1639-
if (track->vpcC->codecIntializationDataSize)
1640-
{
1641-
// TODO
1642-
}
16431637
#endif // ENABLE_DEBUG
16441638

16451639
// xmlMapper
@@ -1653,12 +1647,6 @@ int parse_vpcC(Bitstream_t *bitstr, Mp4Box_t *box_header, Mp4Track_t *track, Mp4
16531647
fprintf(mp4->xml, " <colourPrimaries>%u</colourPrimaries>\n", track->vpcC->colourPrimaries);
16541648
fprintf(mp4->xml, " <transferCharacteristics>%u</transferCharacteristics>\n", track->vpcC->transferCharacteristics);
16551649
fprintf(mp4->xml, " <matrixCoefficients>%u</matrixCoefficients>\n", track->vpcC->matrixCoefficients);
1656-
1657-
fprintf(mp4->xml, " <codecIntializationDataSize>%u</codecIntializationDataSize>\n", track->vpcC->codecIntializationDataSize);
1658-
if (track->vpcC->codecIntializationDataSize)
1659-
{
1660-
// TODO
1661-
}
16621650
fprintf(mp4->xml, " </a>\n");
16631651
}
16641652

minivideo/src/minivideo_avutils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ typedef enum ChromaLocation_e
191191
{
192192
CHROMA_LOC_UNKNOWN = 0, //!< Unknown chroma location
193193

194-
CHROMA_LOC_LEFT = 1, //!<
194+
CHROMA_LOC_LEFT = 1, //!< vertical
195195
CHROMA_LOC_CENTER = 2,
196-
CHROMA_LOC_TOPLEFT = 3,
196+
CHROMA_LOC_TOPLEFT = 3, //!< colocated
197197
CHROMA_LOC_TOP = 4,
198198
CHROMA_LOC_BOTTOMLEFT = 5,
199199
CHROMA_LOC_BOTTOM = 6,

minivideo/src/minivideo_codecs.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -745,32 +745,6 @@ const char *getCodecString(const StreamType_e type, const Codecs_e codec, const
745745

746746
/* ************************************************************************** */
747747

748-
const char *getPictureString(const Pictures_e picture, const bool long_description)
749-
{
750-
switch (picture)
751-
{
752-
case PICTURE_BMP:
753-
return "BMP";
754-
case PICTURE_JPG:
755-
return "JPG";
756-
case PICTURE_PNG:
757-
return "PNG";
758-
case PICTURE_WEBP:
759-
return "WebP";
760-
case PICTURE_TGA:
761-
return "TGA";
762-
case PICTURE_YUV444:
763-
return "YCbCr 4:4:4";
764-
case PICTURE_YUV420:
765-
return "YCbCr 4:2:0";
766-
767-
default:
768-
return "";
769-
}
770-
}
771-
772-
/* ************************************************************************** */
773-
774748
const char *getCodecProfileString(const CodecProfiles_e profile, const bool long_description)
775749
{
776750
switch (profile)

minivideo/src/minivideo_codecs.h

-2
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ CodecProfiles_e getH266CodecProfile(const unsigned profil_idc);
430430
minivideo_EXPORT const char *getCodecString(const StreamType_e type, const Codecs_e codec, const bool long_description = false);
431431
minivideo_EXPORT const char *getCodecProfileString(const CodecProfiles_e profile, const bool long_description = false);
432432

433-
minivideo_EXPORT const char *getPictureString(const Pictures_e picture, const bool long_description = false);
434-
435433
/* ************************************************************************** */
436434

437435
minivideo_EXPORT const char *getScanModeString(const ScanType_e mode);

minivideo/src/minivideo_codecs_private_struct.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ typedef struct codecprivate_vvcC_t
109109

110110
/* ************************************************************************** */
111111

112+
/*!
113+
* https://www.webmproject.org/vp9/mp4/
114+
*/
112115
typedef struct codecprivate_vpcC_t
113116
{
114117
uint8_t profile;
@@ -120,12 +123,13 @@ typedef struct codecprivate_vpcC_t
120123
uint8_t transferCharacteristics;
121124
uint8_t matrixCoefficients;
122125

123-
uint16_t codecIntializationDataSize;
124-
125126
} codecprivate_vpcC_t;
126127

127128
/* ************************************************************************** */
128129

130+
/*!
131+
* https://aomediacodec.github.io/av1-isobmff/
132+
*/
129133
typedef struct codecprivate_av1C_t
130134
{
131135
bool marker;

minivideo/src/minivideo_mediastream.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ typedef struct MediaStream_t
105105
FramerateMode_e framerate_mode; //!< Framerate mode
106106

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

0 commit comments

Comments
 (0)