Skip to content

Commit f24fa3c

Browse files
brechtvlzachlewis
authored andcommitted
feat(ffmpeg): Read CICP metadata, and add test (AcademySoftwareFoundation#4882)
The actual CICP reading code is trivial. Also recognize mkv (Matroska) extension for the test. Add test using Matroska + VP9, to maximize the chance of an ffmpeg build supporting them. They are royalty free, built into ffmpeg and relatively old. Signed-off-by: Brecht Van Lommel <brecht@blender.org> Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
1 parent 6ef30fb commit f24fa3c

File tree

7 files changed

+199
-3
lines changed

7 files changed

+199
-3
lines changed

src/cmake/testing.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ macro (oiio_add_all_tests)
250250
ENABLEVAR ENABLE_FITS
251251
IMAGEDIR fits-images
252252
URL http://www.cv.nrao.edu/fits/data/tests/)
253+
oiio_add_tests (ffmpeg
254+
ENABLEVAR ENABLE_FFMPEG
255+
FOUNDVAR FFmpeg_FOUND)
253256
oiio_add_tests (gif
254257
FOUNDVAR GIF_FOUND ENABLEVAR ENABLE_GIF
255258
IMAGEDIR oiio-images/gif URL "Recent checkout of OpenImageIO-images")

src/doc/builtinplugins.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,9 @@ Some special attributes are used for movie files:
14331433
* - ``ffmpeg:TimeCode``
14341434
- string
14351435
- Start time timecode
1436+
* - ``CICP``
1437+
- int[4]
1438+
- Coding-independent code points to describe the color profile.
14361439

14371440

14381441

src/ffmpeg.imageio/ffmpeginput.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ ffmpeg_input_imageio_create()
180180
// QuickTime / MOV
181181
// raw MPEG-4 video
182182
// MPEG-1 Systems / MPEG program stream
183-
OIIO_EXPORT const char* ffmpeg_input_extensions[] = {
184-
"avi", "mov", "qt", "mp4", "m4a", "3gp", "3g2", "mj2", "m4v", "mpg", nullptr
185-
};
183+
OIIO_EXPORT const char* ffmpeg_input_extensions[]
184+
= { "avi", "mov", "qt", "mp4", "m4a", "3gp",
185+
"3g2", "mj2", "m4v", "mpg", "mkv", nullptr };
186186

187187

188188
OIIO_PLUGIN_EXPORTS_END
@@ -531,6 +531,12 @@ FFmpegInput::open(const std::string& name, ImageSpec& spec)
531531
m_spec.attribute("oiio:BitsPerSample",
532532
m_codec_context->bits_per_raw_sample);
533533
m_spec.attribute("ffmpeg:codec_name", m_codec_context->codec->long_name);
534+
/* The ffmpeg enums are documented to match CICP values, except the color range. */
535+
const int cicp[4]
536+
= { m_codec_context->color_primaries, m_codec_context->color_trc,
537+
m_codec_context->colorspace,
538+
m_codec_context->color_range == AVCOL_RANGE_MPEG ? 0 : 1 };
539+
m_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp);
534540
m_nsubimages = m_frames;
535541
spec = m_spec;
536542
m_filename = name;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Reading ref/vp9_display_p3.mkv
2+
ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie
3+
7 subimages: 192x108 [u8,u8,u8]
4+
subimage 0: 192 x 108, 3 channel, uint8 FFmpeg movie
5+
SHA-1: E65FAFBDA14543571188F8A84F75E1567E13148C
6+
channel list: R, G, B
7+
CICP: 12, 1, 1, 1
8+
DATE: "2025/09/13 21:58:33"
9+
ENCODER: "Lavf61.7.100"
10+
FramesPerSecond: 24/1 (24)
11+
SCENE: "Scene"
12+
ffmpeg:codec_name: "Google VP9"
13+
oiio:BitsPerSample: 0
14+
oiio:Movie: 1
15+
oiio:subimages: 7
16+
subimage 1: 192 x 108, 3 channel, uint8 FFmpeg movie
17+
SHA-1: 8D54A542C4E6A47A4F8829993001786BA62288DF
18+
channel list: R, G, B
19+
CICP: 12, 1, 1, 1
20+
DATE: "2025/09/13 21:58:33"
21+
ENCODER: "Lavf61.7.100"
22+
FramesPerSecond: 24/1 (24)
23+
SCENE: "Scene"
24+
ffmpeg:codec_name: "Google VP9"
25+
oiio:BitsPerSample: 0
26+
oiio:Movie: 1
27+
oiio:subimages: 7
28+
subimage 2: 192 x 108, 3 channel, uint8 FFmpeg movie
29+
SHA-1: 8D54A542C4E6A47A4F8829993001786BA62288DF
30+
channel list: R, G, B
31+
CICP: 12, 1, 1, 1
32+
DATE: "2025/09/13 21:58:33"
33+
ENCODER: "Lavf61.7.100"
34+
FramesPerSecond: 24/1 (24)
35+
SCENE: "Scene"
36+
ffmpeg:codec_name: "Google VP9"
37+
oiio:BitsPerSample: 0
38+
oiio:Movie: 1
39+
oiio:subimages: 7
40+
subimage 3: 192 x 108, 3 channel, uint8 FFmpeg movie
41+
SHA-1: 8D54A542C4E6A47A4F8829993001786BA62288DF
42+
channel list: R, G, B
43+
CICP: 12, 1, 1, 1
44+
DATE: "2025/09/13 21:58:33"
45+
ENCODER: "Lavf61.7.100"
46+
FramesPerSecond: 24/1 (24)
47+
SCENE: "Scene"
48+
ffmpeg:codec_name: "Google VP9"
49+
oiio:BitsPerSample: 0
50+
oiio:Movie: 1
51+
oiio:subimages: 7
52+
subimage 4: 192 x 108, 3 channel, uint8 FFmpeg movie
53+
SHA-1: D9B0B8782048AEE24C4DF767E2B0969EBAB9D36B
54+
channel list: R, G, B
55+
CICP: 12, 1, 1, 1
56+
DATE: "2025/09/13 21:58:33"
57+
ENCODER: "Lavf61.7.100"
58+
FramesPerSecond: 24/1 (24)
59+
SCENE: "Scene"
60+
ffmpeg:codec_name: "Google VP9"
61+
oiio:BitsPerSample: 0
62+
oiio:Movie: 1
63+
oiio:subimages: 7
64+
subimage 5: 192 x 108, 3 channel, uint8 FFmpeg movie
65+
SHA-1: C6B5666BB0A937A59762B8FE846BF50FED40889E
66+
channel list: R, G, B
67+
CICP: 12, 1, 1, 1
68+
DATE: "2025/09/13 21:58:33"
69+
ENCODER: "Lavf61.7.100"
70+
FramesPerSecond: 24/1 (24)
71+
SCENE: "Scene"
72+
ffmpeg:codec_name: "Google VP9"
73+
oiio:BitsPerSample: 0
74+
oiio:Movie: 1
75+
oiio:subimages: 7
76+
subimage 6: 192 x 108, 3 channel, uint8 FFmpeg movie
77+
SHA-1: 63516D95A1BB56E9E9483F9BCFC4305851A8BC54
78+
channel list: R, G, B
79+
CICP: 12, 1, 1, 1
80+
DATE: "2025/09/13 21:58:33"
81+
ENCODER: "Lavf61.7.100"
82+
FramesPerSecond: 24/1 (24)
83+
SCENE: "Scene"
84+
ffmpeg:codec_name: "Google VP9"
85+
oiio:BitsPerSample: 0
86+
oiio:Movie: 1
87+
oiio:subimages: 7
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Reading ref/vp9_display_p3.mkv
2+
ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie
3+
7 subimages: 192x108 [u8,u8,u8]
4+
subimage 0: 192 x 108, 3 channel, uint8 FFmpeg movie
5+
SHA-1: C882152FF48CB068931C2710175659A9D0493C08
6+
channel list: R, G, B
7+
CICP: 12, 1, 1, 1
8+
DATE: "2025/09/13 21:58:33"
9+
ENCODER: "Lavf61.7.100"
10+
FramesPerSecond: 24/1 (24)
11+
SCENE: "Scene"
12+
ffmpeg:codec_name: "Google VP9"
13+
oiio:BitsPerSample: 0
14+
oiio:Movie: 1
15+
oiio:subimages: 7
16+
subimage 1: 192 x 108, 3 channel, uint8 FFmpeg movie
17+
SHA-1: 1E2EB62F7BDD2DAC5C6FBDE582EE19978DC7C290
18+
channel list: R, G, B
19+
CICP: 12, 1, 1, 1
20+
DATE: "2025/09/13 21:58:33"
21+
ENCODER: "Lavf61.7.100"
22+
FramesPerSecond: 24/1 (24)
23+
SCENE: "Scene"
24+
ffmpeg:codec_name: "Google VP9"
25+
oiio:BitsPerSample: 0
26+
oiio:Movie: 1
27+
oiio:subimages: 7
28+
subimage 2: 192 x 108, 3 channel, uint8 FFmpeg movie
29+
SHA-1: 1E2EB62F7BDD2DAC5C6FBDE582EE19978DC7C290
30+
channel list: R, G, B
31+
CICP: 12, 1, 1, 1
32+
DATE: "2025/09/13 21:58:33"
33+
ENCODER: "Lavf61.7.100"
34+
FramesPerSecond: 24/1 (24)
35+
SCENE: "Scene"
36+
ffmpeg:codec_name: "Google VP9"
37+
oiio:BitsPerSample: 0
38+
oiio:Movie: 1
39+
oiio:subimages: 7
40+
subimage 3: 192 x 108, 3 channel, uint8 FFmpeg movie
41+
SHA-1: 1E2EB62F7BDD2DAC5C6FBDE582EE19978DC7C290
42+
channel list: R, G, B
43+
CICP: 12, 1, 1, 1
44+
DATE: "2025/09/13 21:58:33"
45+
ENCODER: "Lavf61.7.100"
46+
FramesPerSecond: 24/1 (24)
47+
SCENE: "Scene"
48+
ffmpeg:codec_name: "Google VP9"
49+
oiio:BitsPerSample: 0
50+
oiio:Movie: 1
51+
oiio:subimages: 7
52+
subimage 4: 192 x 108, 3 channel, uint8 FFmpeg movie
53+
SHA-1: 35565DB895AB1CA413192B7F25A1890718CFC0F5
54+
channel list: R, G, B
55+
CICP: 12, 1, 1, 1
56+
DATE: "2025/09/13 21:58:33"
57+
ENCODER: "Lavf61.7.100"
58+
FramesPerSecond: 24/1 (24)
59+
SCENE: "Scene"
60+
ffmpeg:codec_name: "Google VP9"
61+
oiio:BitsPerSample: 0
62+
oiio:Movie: 1
63+
oiio:subimages: 7
64+
subimage 5: 192 x 108, 3 channel, uint8 FFmpeg movie
65+
SHA-1: 338C9A82B74CE3B291DAD6564AE7C060AE6D9267
66+
channel list: R, G, B
67+
CICP: 12, 1, 1, 1
68+
DATE: "2025/09/13 21:58:33"
69+
ENCODER: "Lavf61.7.100"
70+
FramesPerSecond: 24/1 (24)
71+
SCENE: "Scene"
72+
ffmpeg:codec_name: "Google VP9"
73+
oiio:BitsPerSample: 0
74+
oiio:Movie: 1
75+
oiio:subimages: 7
76+
subimage 6: 192 x 108, 3 channel, uint8 FFmpeg movie
77+
SHA-1: 90BC91EAA745A9C897EEDEC0D34BAAF1D40B1C7C
78+
channel list: R, G, B
79+
CICP: 12, 1, 1, 1
80+
DATE: "2025/09/13 21:58:33"
81+
ENCODER: "Lavf61.7.100"
82+
FramesPerSecond: 24/1 (24)
83+
SCENE: "Scene"
84+
ffmpeg:codec_name: "Google VP9"
85+
oiio:BitsPerSample: 0
86+
oiio:Movie: 1
87+
oiio:subimages: 7
5.33 KB
Binary file not shown.

testsuite/ffmpeg/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
imagedir = "ref/"
8+
files = [ "vp9_display_p3.mkv" ]
9+
for f in files:
10+
command = command + info_command (os.path.join(imagedir, f))

0 commit comments

Comments
 (0)