summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-07-02 22:32:12 +0100
committerCarl Hetherington <cth@carlh.net>2015-07-02 22:32:12 +0100
commit02478f9f6af48b6209a8e87401025237b7461986 (patch)
treeeb21f4a36bf2b665c8f41b3fcb3417862dcd7084 /src
parentd42225fe5b857fc78979fdb7c980ede67b008785 (diff)
Add bits per pixel to video content properties.
Diffstat (limited to 'src')
-rw-r--r--src/lib/ffmpeg_content.cc34
-rw-r--r--src/lib/ffmpeg_content.h1
-rw-r--r--src/lib/ffmpeg_examiner.cc8
-rw-r--r--src/lib/ffmpeg_examiner.h2
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<const Film> film, cxml::ConstNodePtr no
_first_video = node->optional_number_child<double> ("FirstVideo");
-
_color_range = static_cast<AVColorRange> (node->optional_number_child<int>("ColorRange").get_value_or (AVCOL_RANGE_UNSPECIFIED));
_color_primaries = static_cast<AVColorPrimaries> (node->optional_number_child<int>("ColorPrimaries").get_value_or (AVCOL_PRI_UNSPECIFIED));
_color_trc = static_cast<AVColorTransferCharacteristic> (
node->optional_number_child<int>("ColorTransferCharacteristic").get_value_or (AVCOL_TRC_UNSPECIFIED)
);
_colorspace = static_cast<AVColorSpace> (node->optional_number_child<int>("Colorspace").get_value_or (AVCOL_SPC_UNSPECIFIED));
+ _bits_per_pixel = static_cast<int> (node->number_child<int> ("BitsPerPixel"));
}
@@ -166,6 +166,7 @@ FFmpegContent::as_xml (xmlpp::Node* node) const
node->add_child("ColorPrimaries")->add_child_text (raw_convert<string> (_color_primaries));
node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert<string> (_color_trc));
node->add_child("Colorspace")->add_child_text (raw_convert<string> (_colorspace));
+ node->add_child("BitsPerPixel")->add_child_text (raw_convert<string> (_bits_per_pixel));
}
void
@@ -203,6 +204,7 @@ FFmpegContent::examine (shared_ptr<Job> 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<pair<string, string> >& 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<pair<string, string> >& 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<string> (_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 <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#include <libavutil/pixfmt.h>
+#include <libavutil/pixdesc.h>
}
#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<FFmpegAudioStream>);