diff --git a/src/ffmpeg.imageio/ffmpeginput.cpp b/src/ffmpeg.imageio/ffmpeginput.cpp index ae1be13b7d..257dace628 100644 --- a/src/ffmpeg.imageio/ffmpeginput.cpp +++ b/src/ffmpeg.imageio/ffmpeginput.cpp @@ -30,6 +30,7 @@ extern "C" { // ffmpeg is a C api #endif #include +#include } @@ -528,8 +529,19 @@ FFmpegInput::open(const std::string& name, ImageSpec& spec) m_spec.attribute("FramesPerSecond", TypeRational, &rat); m_spec.attribute("oiio:Movie", true); m_spec.attribute("oiio:subimages", int(m_frames)); - m_spec.attribute("oiio:BitsPerSample", - m_codec_context->bits_per_raw_sample); + if (m_codec_context->bits_per_raw_sample) { + m_spec.attribute("oiio:BitsPerSample", + m_codec_context->bits_per_raw_sample); + } else { + // If bits_per_raw_sample is not provided, the bit depth of the + // luma channel is the closest equivalent to a single bit depth. + const AVPixFmtDescriptor* pix_format_desc = av_pix_fmt_desc_get( + src_pix_format); + if (pix_format_desc && pix_format_desc->nb_components > 0) { + m_spec.attribute("oiio:BitsPerSample", + pix_format_desc->comp[0].depth); + } + } m_spec.attribute("ffmpeg:codec_name", m_codec_context->codec->long_name); /* The ffmpeg enums are documented to match CICP values, except the color range. */ const int cicp[4] diff --git a/testsuite/ffmpeg/ref/out-ffmpeg-6.1.txt b/testsuite/ffmpeg/ref/out-ffmpeg6.1.txt similarity index 93% rename from testsuite/ffmpeg/ref/out-ffmpeg-6.1.txt rename to testsuite/ffmpeg/ref/out-ffmpeg6.1.txt index 82b00b1a10..1553a20790 100644 --- a/testsuite/ffmpeg/ref/out-ffmpeg-6.1.txt +++ b/testsuite/ffmpeg/ref/out-ffmpeg6.1.txt @@ -10,7 +10,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 1: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -22,7 +22,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 2: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -34,7 +34,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 3: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -46,7 +46,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 4: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -58,7 +58,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 5: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -70,7 +70,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 6: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -82,6 +82,6 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 diff --git a/testsuite/ffmpeg/ref/out-ffmpeg8.0.txt b/testsuite/ffmpeg/ref/out-ffmpeg8.0.txt index 988ef28210..082a0797f2 100644 --- a/testsuite/ffmpeg/ref/out-ffmpeg8.0.txt +++ b/testsuite/ffmpeg/ref/out-ffmpeg8.0.txt @@ -10,7 +10,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 1: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -22,7 +22,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 2: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -34,7 +34,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 3: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -46,7 +46,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 4: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -58,7 +58,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 5: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -70,7 +70,7 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7 subimage 6: 192 x 108, 3 channel, uint8 FFmpeg movie @@ -82,6 +82,6 @@ ref/vp9_display_p3.mkv : 192 x 108, 3 channel, uint8 FFmpeg movie FramesPerSecond: 24/1 (24) SCENE: "Scene" ffmpeg:codec_name: "Google VP9" - oiio:BitsPerSample: 0 + oiio:BitsPerSample: 8 oiio:Movie: 1 oiio:subimages: 7