From 02478f9f6af48b6209a8e87401025237b7461986 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 2 Jul 2015 22:32:12 +0100 Subject: [PATCH] Add bits per pixel to video content properties. --- src/lib/ffmpeg_content.cc | 34 +++++++++++++++++++++------------- src/lib/ffmpeg_content.h | 1 + src/lib/ffmpeg_examiner.cc | 8 ++++++++ src/lib/ffmpeg_examiner.h | 2 ++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 9d3a79e81..384b10233 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -99,13 +99,13 @@ FFmpegContent::FFmpegContent (shared_ptr film, cxml::ConstNodePtr no _first_video = node->optional_number_child ("FirstVideo"); - _color_range = static_cast (node->optional_number_child("ColorRange").get_value_or (AVCOL_RANGE_UNSPECIFIED)); _color_primaries = static_cast (node->optional_number_child("ColorPrimaries").get_value_or (AVCOL_PRI_UNSPECIFIED)); _color_trc = static_cast ( node->optional_number_child("ColorTransferCharacteristic").get_value_or (AVCOL_TRC_UNSPECIFIED) ); _colorspace = static_cast (node->optional_number_child("Colorspace").get_value_or (AVCOL_SPC_UNSPECIFIED)); + _bits_per_pixel = static_cast (node->number_child ("BitsPerPixel")); } @@ -166,6 +166,7 @@ FFmpegContent::as_xml (xmlpp::Node* node) const node->add_child("ColorPrimaries")->add_child_text (raw_convert (_color_primaries)); node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert (_color_trc)); node->add_child("Colorspace")->add_child_text (raw_convert (_colorspace)); + node->add_child("BitsPerPixel")->add_child_text (raw_convert (_bits_per_pixel)); } void @@ -203,6 +204,7 @@ FFmpegContent::examine (shared_ptr job) _color_primaries = examiner->color_primaries (); _color_trc = examiner->color_trc (); _colorspace = examiner->colorspace (); + _bits_per_pixel = examiner->bits_per_pixel (); } signal_changed (FFmpegContentProperty::SUBTITLE_STREAMS); @@ -360,18 +362,22 @@ FFmpegContent::add_properties (list >& p) const { VideoContent::add_properties (p); - /* I tried av_*_name for these but they are not the most - nicely formatted. - */ - - char const * ranges[] = { - _("Unspecified"), - _("MPEG (0-219 or equivalent)"), - _("JPEG (0-255 or equivalent)") - }; - - DCPOMATIC_ASSERT (AVCOL_RANGE_NB == 3); - p.push_back (make_pair (_("Colour range"), ranges[_color_range])); + int const sub = 219 * pow (2, _bits_per_pixel - 8); + int const total = pow (2, _bits_per_pixel); + + switch (_color_range) { + case AVCOL_RANGE_UNSPECIFIED: + p.push_back (make_pair (_("Colour range"), _("Unspecified"))); + break; + case AVCOL_RANGE_MPEG: + p.push_back (make_pair (_("Colour range"), String::compose ("Limited (%1-%2)", (total - sub) / 2, (total + sub) / 2))); + break; + case AVCOL_RANGE_JPEG: + p.push_back (make_pair (_("Colour range"), String::compose ("Full (0-total)", (total - sub) / 2, (total + sub) / 2))); + break; + default: + DCPOMATIC_ASSERT (false); + } char const * primaries[] = { _("Unspecified"), @@ -427,4 +433,6 @@ FFmpegContent::add_properties (list >& p) const DCPOMATIC_ASSERT (AVCOL_SPC_NB == 11); p.push_back (make_pair (_("Colourspace"), spaces[_colorspace])); + + p.push_back (make_pair (_("Bits per pixel"), raw_convert (_bits_per_pixel))); } diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index 05f6cebb6..b2a492e68 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -122,6 +122,7 @@ private: AVColorPrimaries _color_primaries; AVColorTransferCharacteristic _color_trc; AVColorSpace _colorspace; + int _bits_per_pixel; }; #endif diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index 16a89faa7..f4b650eee 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -20,6 +20,8 @@ extern "C" { #include #include +#include +#include } #include "ffmpeg_examiner.h" #include "ffmpeg_content.h" @@ -275,3 +277,9 @@ FFmpegExaminer::stream_name (AVStream* s) const return n.str (); } + +int +FFmpegExaminer::bits_per_pixel () const +{ + return av_get_bits_per_pixel (av_pix_fmt_desc_get (video_codec_context()->pix_fmt)); +} diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h index f5ee95acf..795a9c6ff 100644 --- a/src/lib/ffmpeg_examiner.h +++ b/src/lib/ffmpeg_examiner.h @@ -64,6 +64,8 @@ public: return video_codec_context()->colorspace; } + int bits_per_pixel () const; + private: void video_packet (AVCodecContext *); void audio_packet (AVCodecContext *, boost::shared_ptr); -- 2.30.2