29ff7e80baeb3f5550f28b674122121f230d381a
[dcpomatic.git] / src / lib / ffmpeg_content.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "ffmpeg_content.h"
22 #include "video_content.h"
23 #include "audio_content.h"
24 #include "ffmpeg_examiner.h"
25 #include "ffmpeg_subtitle_stream.h"
26 #include "ffmpeg_audio_stream.h"
27 #include "compose.hpp"
28 #include "job.h"
29 #include "util.h"
30 #include "filter.h"
31 #include "film.h"
32 #include "log.h"
33 #include "exceptions.h"
34 #include "frame_rate_change.h"
35 #include "text_content.h"
36 #include <dcp/raw_convert.h>
37 #include <libcxml/cxml.h>
38 extern "C" {
39 #include <libavformat/avformat.h>
40 #include <libavutil/pixdesc.h>
41 }
42 #include <libxml++/libxml++.h>
43 #include <boost/foreach.hpp>
44 #include <iostream>
45
46 #include "i18n.h"
47
48 using std::string;
49 using std::vector;
50 using std::list;
51 using std::cout;
52 using std::pair;
53 using std::make_pair;
54 using std::max;
55 using boost::shared_ptr;
56 using boost::dynamic_pointer_cast;
57 using boost::optional;
58 using dcp::raw_convert;
59 using namespace dcpomatic;
60
61 int const FFmpegContentProperty::SUBTITLE_STREAMS = 100;
62 int const FFmpegContentProperty::SUBTITLE_STREAM = 101;
63 int const FFmpegContentProperty::FILTERS = 102;
64 int const FFmpegContentProperty::KDM = 103;
65
66 FFmpegContent::FFmpegContent (boost::filesystem::path p)
67         : Content (p)
68 #ifdef DCPOMATIC_VARIANT_SWAROOP
69         , _encrypted (false)
70 #endif
71 {
72
73 }
74
75 template <class T>
76 optional<T>
77 get_optional_enum (cxml::ConstNodePtr node, string name)
78 {
79         optional<int> const v = node->optional_number_child<int>(name);
80         if (!v) {
81                 return optional<T>();
82         }
83         return static_cast<T>(*v);
84 }
85
86 FFmpegContent::FFmpegContent (cxml::ConstNodePtr node, int version, list<string>& notes)
87         : Content (node)
88 {
89         video = VideoContent::from_xml (this, node, version);
90         audio = AudioContent::from_xml (this, node, version);
91         text = TextContent::from_xml (this, node, version);
92
93         list<cxml::NodePtr> c = node->node_children ("SubtitleStream");
94         for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
95                 _subtitle_streams.push_back (shared_ptr<FFmpegSubtitleStream> (new FFmpegSubtitleStream (*i, version)));
96                 if ((*i)->optional_number_child<int> ("Selected")) {
97                         _subtitle_stream = _subtitle_streams.back ();
98                 }
99         }
100
101         c = node->node_children ("AudioStream");
102         for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
103                 shared_ptr<FFmpegAudioStream> as (new FFmpegAudioStream (*i, version));
104                 audio->add_stream (as);
105                 if (version < 11 && !(*i)->optional_node_child ("Selected")) {
106                         /* This is an old file and this stream is not selected, so un-map it */
107                         as->set_mapping (AudioMapping (as->channels (), MAX_DCP_AUDIO_CHANNELS));
108                 }
109         }
110
111         c = node->node_children ("Filter");
112         for (list<cxml::NodePtr>::iterator i = c.begin(); i != c.end(); ++i) {
113                 Filter const * f = Filter::from_id ((*i)->content ());
114                 if (f) {
115                         _filters.push_back (f);
116                 } else {
117                         notes.push_back (String::compose (_("DCP-o-matic no longer supports the `%1' filter, so it has been turned off."), (*i)->content()));
118                 }
119         }
120
121         optional<ContentTime::Type> const f = node->optional_number_child<ContentTime::Type> ("FirstVideo");
122         if (f) {
123                 _first_video = ContentTime (f.get ());
124         }
125
126         _color_range = get_optional_enum<AVColorRange>(node, "ColorRange");
127         _color_primaries = get_optional_enum<AVColorPrimaries>(node, "ColorPrimaries");
128         _color_trc = get_optional_enum<AVColorTransferCharacteristic>(node, "ColorTransferCharacteristic");
129         _colorspace = get_optional_enum<AVColorSpace>(node, "Colorspace");
130         _bits_per_pixel = node->optional_number_child<int> ("BitsPerPixel");
131 #ifdef DCPOMATIC_VARIANT_SWAROOP
132         _encrypted = node->optional_bool_child("Encrypted").get_value_or(false);
133 #endif
134 }
135
136 FFmpegContent::FFmpegContent (vector<shared_ptr<Content> > c)
137         : Content (c)
138 {
139         vector<shared_ptr<Content> >::const_iterator i = c.begin ();
140
141         bool need_video = false;
142         bool need_audio = false;
143         bool need_text = false;
144
145         if (i != c.end ()) {
146                 need_video = static_cast<bool> ((*i)->video);
147                 need_audio = static_cast<bool> ((*i)->audio);
148                 need_text = !(*i)->text.empty();
149         }
150
151         while (i != c.end ()) {
152                 if (need_video != static_cast<bool> ((*i)->video)) {
153                         throw JoinError (_("Content to be joined must all have or not have video"));
154                 }
155                 if (need_audio != static_cast<bool> ((*i)->audio)) {
156                         throw JoinError (_("Content to be joined must all have or not have audio"));
157                 }
158                 if (need_text != !(*i)->text.empty()) {
159                         throw JoinError (_("Content to be joined must all have or not have subtitles or captions"));
160                 }
161                 ++i;
162         }
163
164         if (need_video) {
165                 video.reset (new VideoContent (this, c));
166         }
167         if (need_audio) {
168                 audio.reset (new AudioContent (this, c));
169         }
170         if (need_text) {
171                 text.push_back (shared_ptr<TextContent> (new TextContent (this, c)));
172         }
173
174         shared_ptr<FFmpegContent> ref = dynamic_pointer_cast<FFmpegContent> (c[0]);
175         DCPOMATIC_ASSERT (ref);
176
177         for (size_t i = 0; i < c.size(); ++i) {
178                 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c[i]);
179                 if (fc->only_text() && fc->only_text()->use() && *(fc->_subtitle_stream.get()) != *(ref->_subtitle_stream.get())) {
180                         throw JoinError (_("Content to be joined must use the same subtitle stream."));
181                 }
182         }
183
184         /* XXX: should probably check that more of the stuff below is the same in *this and ref */
185
186         _subtitle_streams = ref->subtitle_streams ();
187         _subtitle_stream = ref->subtitle_stream ();
188         _first_video = ref->_first_video;
189         _filters = ref->_filters;
190         _color_range = ref->_color_range;
191         _color_primaries = ref->_color_primaries;
192         _color_trc = ref->_color_trc;
193         _colorspace = ref->_colorspace;
194         _bits_per_pixel = ref->_bits_per_pixel;
195 #ifdef DCPOMATIC_VARIANT_SWAROOP
196         _encrypted = ref->_encrypted;
197 #endif
198 }
199
200 void
201 FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const
202 {
203         node->add_child("Type")->add_child_text ("FFmpeg");
204         Content::as_xml (node, with_paths);
205
206         if (video) {
207                 video->as_xml (node);
208         }
209
210         if (audio) {
211                 audio->as_xml (node);
212
213                 BOOST_FOREACH (AudioStreamPtr i, audio->streams ()) {
214                         shared_ptr<FFmpegAudioStream> f = dynamic_pointer_cast<FFmpegAudioStream> (i);
215                         DCPOMATIC_ASSERT (f);
216                         f->as_xml (node->add_child("AudioStream"));
217                 }
218         }
219
220         if (only_text()) {
221                 only_text()->as_xml (node);
222         }
223
224         boost::mutex::scoped_lock lm (_mutex);
225
226         for (vector<shared_ptr<FFmpegSubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
227                 xmlpp::Node* t = node->add_child("SubtitleStream");
228                 if (_subtitle_stream && *i == _subtitle_stream) {
229                         t->add_child("Selected")->add_child_text("1");
230                 }
231                 (*i)->as_xml (t);
232         }
233
234         for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
235                 node->add_child("Filter")->add_child_text ((*i)->id ());
236         }
237
238         if (_first_video) {
239                 node->add_child("FirstVideo")->add_child_text (raw_convert<string> (_first_video.get().get()));
240         }
241
242         if (_color_range) {
243                 node->add_child("ColorRange")->add_child_text (raw_convert<string> (static_cast<int> (*_color_range)));
244         }
245         if (_color_primaries) {
246                 node->add_child("ColorPrimaries")->add_child_text (raw_convert<string> (static_cast<int> (*_color_primaries)));
247         }
248         if (_color_trc) {
249                 node->add_child("ColorTransferCharacteristic")->add_child_text (raw_convert<string> (static_cast<int> (*_color_trc)));
250         }
251         if (_colorspace) {
252                 node->add_child("Colorspace")->add_child_text (raw_convert<string> (static_cast<int> (*_colorspace)));
253         }
254         if (_bits_per_pixel) {
255                 node->add_child("BitsPerPixel")->add_child_text (raw_convert<string> (*_bits_per_pixel));
256         }
257 #ifdef DCPOMATIC_VARIANT_SWAROOP
258         if (_encrypted) {
259                 node->add_child("Encypted")->add_child_text ("1");
260         }
261 #endif
262 }
263
264 void
265 FFmpegContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
266 {
267         ChangeSignaller<Content> cc1 (this, FFmpegContentProperty::SUBTITLE_STREAMS);
268         ChangeSignaller<Content> cc2 (this, FFmpegContentProperty::SUBTITLE_STREAM);
269
270         if (job) {
271                 job->set_progress_unknown ();
272         }
273
274         Content::examine (film, job);
275
276         shared_ptr<FFmpegExaminer> examiner (new FFmpegExaminer (shared_from_this (), job));
277
278         if (examiner->has_video ()) {
279                 video.reset (new VideoContent (this));
280                 video->take_from_examiner (examiner);
281         }
282
283         boost::filesystem::path first_path = path (0);
284
285         {
286                 boost::mutex::scoped_lock lm (_mutex);
287
288                 if (examiner->has_video ()) {
289                         _first_video = examiner->first_video ();
290                         _color_range = examiner->color_range ();
291                         _color_primaries = examiner->color_primaries ();
292                         _color_trc = examiner->color_trc ();
293                         _colorspace = examiner->colorspace ();
294                         _bits_per_pixel = examiner->bits_per_pixel ();
295
296                         if (examiner->rotation()) {
297                                 double rot = *examiner->rotation ();
298                                 if (fabs (rot - 180) < 1.0) {
299                                         _filters.push_back (Filter::from_id ("vflip"));
300                                         _filters.push_back (Filter::from_id ("hflip"));
301                                 } else if (fabs (rot - 90) < 1.0) {
302                                         _filters.push_back (Filter::from_id ("90clock"));
303                                 } else if (fabs (rot - 270) < 1.0) {
304                                         _filters.push_back (Filter::from_id ("90anticlock"));
305                                 }
306                         }
307                 }
308
309                 if (!examiner->audio_streams().empty ()) {
310                         audio.reset (new AudioContent (this));
311
312                         BOOST_FOREACH (shared_ptr<FFmpegAudioStream> i, examiner->audio_streams ()) {
313                                 audio->add_stream (i);
314                         }
315
316                         AudioStreamPtr as = audio->streams().front();
317                         AudioMapping m = as->mapping ();
318                         m.make_default (film ? film->audio_processor() : 0, first_path);
319                         as->set_mapping (m);
320                 }
321
322                 _subtitle_streams = examiner->subtitle_streams ();
323                 if (!_subtitle_streams.empty ()) {
324                         text.clear ();
325                         text.push_back (shared_ptr<TextContent> (new TextContent (this, TEXT_OPEN_SUBTITLE, TEXT_UNKNOWN)));
326                         _subtitle_stream = _subtitle_streams.front ();
327                 }
328
329 #ifdef DCPOMATIC_VARIANT_SWAROOP
330                 _encrypted = first_path.extension() == ".ecinema";
331 #endif
332         }
333
334         if (examiner->has_video ()) {
335                 set_default_colour_conversion ();
336         }
337
338 #ifdef DCPOMATIC_VARIANT_SWAROOP
339         _id = examiner->id ();
340 #endif
341 }
342
343 string
344 FFmpegContent::summary () const
345 {
346         if (video && audio) {
347                 return String::compose (_("%1 [movie]"), path_summary ());
348         } else if (video) {
349                 return String::compose (_("%1 [video]"), path_summary ());
350         } else if (audio) {
351                 return String::compose (_("%1 [audio]"), path_summary ());
352         }
353
354         return path_summary ();
355 }
356
357 string
358 FFmpegContent::technical_summary () const
359 {
360         string as = "";
361         BOOST_FOREACH (shared_ptr<FFmpegAudioStream> i, ffmpeg_audio_streams ()) {
362                 as += i->technical_summary () + " " ;
363         }
364
365         if (as.empty ()) {
366                 as = "none";
367         }
368
369         string ss = "none";
370         if (_subtitle_stream) {
371                 ss = _subtitle_stream->technical_summary ();
372         }
373
374         string filt = Filter::ffmpeg_string (_filters);
375
376         string s = Content::technical_summary ();
377
378         if (video) {
379                 s += " - " + video->technical_summary ();
380         }
381
382         if (audio) {
383                 s += " - " + audio->technical_summary ();
384         }
385
386         return s + String::compose (
387                 "ffmpeg: audio %1 subtitle %2 filters %3", as, ss, filt
388                 );
389 }
390
391 void
392 FFmpegContent::set_subtitle_stream (shared_ptr<FFmpegSubtitleStream> s)
393 {
394         ChangeSignaller<Content> cc (this, FFmpegContentProperty::SUBTITLE_STREAM);
395
396         {
397                 boost::mutex::scoped_lock lm (_mutex);
398                 _subtitle_stream = s;
399         }
400 }
401
402 bool
403 operator== (FFmpegStream const & a, FFmpegStream const & b)
404 {
405         return a._id == b._id;
406 }
407
408 bool
409 operator!= (FFmpegStream const & a, FFmpegStream const & b)
410 {
411         return a._id != b._id;
412 }
413
414 DCPTime
415 FFmpegContent::full_length (shared_ptr<const Film> film) const
416 {
417         FrameRateChange const frc (film, shared_from_this());
418         if (video) {
419                 return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
420         }
421
422         if (audio) {
423                 DCPTime longest;
424                 BOOST_FOREACH (AudioStreamPtr i, audio->streams()) {
425                         longest = max (longest, DCPTime::from_frames(llrint(i->length() / frc.speed_up), i->frame_rate()));
426                 }
427                 return longest;
428         }
429
430         /* XXX: subtitle content? */
431
432         return DCPTime();
433 }
434
435 DCPTime
436 FFmpegContent::approximate_length () const
437 {
438         if (video) {
439                 return DCPTime::from_frames (video->length_after_3d_combine(), 24);
440         }
441
442         DCPOMATIC_ASSERT (audio);
443
444         Frame longest = 0;
445         BOOST_FOREACH (AudioStreamPtr i, audio->streams ()) {
446                 longest = max (longest, Frame(llrint(i->length())));
447         }
448
449         return DCPTime::from_frames (longest, 24);
450 }
451
452 void
453 FFmpegContent::set_filters (vector<Filter const *> const & filters)
454 {
455         ChangeSignaller<Content> cc (this, FFmpegContentProperty::FILTERS);
456
457         {
458                 boost::mutex::scoped_lock lm (_mutex);
459                 _filters = filters;
460         }
461 }
462
463 string
464 FFmpegContent::identifier () const
465 {
466         string s = Content::identifier();
467
468         if (video) {
469                 s += "_" + video->identifier();
470         }
471
472         if (only_text() && only_text()->use() && only_text()->burn()) {
473                 s += "_" + only_text()->identifier();
474         }
475
476         boost::mutex::scoped_lock lm (_mutex);
477
478         if (_subtitle_stream) {
479                 s += "_" + _subtitle_stream->identifier ();
480         }
481
482         for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
483                 s += "_" + (*i)->id ();
484         }
485
486         return s;
487 }
488
489 void
490 FFmpegContent::set_default_colour_conversion ()
491 {
492         DCPOMATIC_ASSERT (video);
493
494         dcp::Size const s = video->size ();
495
496         boost::mutex::scoped_lock lm (_mutex);
497
498         switch (_colorspace.get_value_or(AVCOL_SPC_UNSPECIFIED)) {
499         case AVCOL_SPC_RGB:
500                 video->set_colour_conversion (PresetColourConversion::from_id ("srgb").conversion);
501                 break;
502         case AVCOL_SPC_BT709:
503                 video->set_colour_conversion (PresetColourConversion::from_id ("rec709").conversion);
504                 break;
505         case AVCOL_SPC_BT470BG:
506         case AVCOL_SPC_SMPTE170M:
507         case AVCOL_SPC_SMPTE240M:
508                 video->set_colour_conversion (PresetColourConversion::from_id ("rec601").conversion);
509                 break;
510         case AVCOL_SPC_BT2020_CL:
511         case AVCOL_SPC_BT2020_NCL:
512                 video->set_colour_conversion (PresetColourConversion::from_id ("rec2020").conversion);
513                 break;
514         default:
515                 if (s.width < 1080) {
516                         video->set_colour_conversion (PresetColourConversion::from_id ("rec601").conversion);
517                 } else {
518                         video->set_colour_conversion (PresetColourConversion::from_id ("rec709").conversion);
519                 }
520                 break;
521         }
522 }
523
524 void
525 FFmpegContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
526 {
527         Content::add_properties (film, p);
528
529         if (video) {
530                 video->add_properties (p);
531
532                 if (_bits_per_pixel) {
533                         int const sub = 219 * pow (2, _bits_per_pixel.get() - 8);
534                         int const total = pow (2, _bits_per_pixel.get());
535
536                         switch (_color_range.get_value_or(AVCOL_RANGE_UNSPECIFIED)) {
537                         case AVCOL_RANGE_UNSPECIFIED:
538                                 /// TRANSLATORS: this means that the range of pixel values used in this
539                                 /// file is unknown (not specified in the file).
540                                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Unspecified")));
541                                 break;
542                         case AVCOL_RANGE_MPEG:
543                                 /// TRANSLATORS: this means that the range of pixel values used in this
544                                 /// file is limited, so that not all possible values are valid.
545                                 p.push_back (
546                                         UserProperty (
547                                                 UserProperty::VIDEO, _("Colour range"), String::compose (_("Limited (%1-%2)"), (total - sub) / 2, (total + sub) / 2)
548                                                 )
549                                         );
550                                 break;
551                         case AVCOL_RANGE_JPEG:
552                                 /// TRANSLATORS: this means that the range of pixel values used in this
553                                 /// file is full, so that all possible pixel values are valid.
554                                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), String::compose (_("Full (0-%1)"), total)));
555                                 break;
556                         default:
557                                 DCPOMATIC_ASSERT (false);
558                         }
559                 } else {
560                         switch (_color_range.get_value_or(AVCOL_RANGE_UNSPECIFIED)) {
561                         case AVCOL_RANGE_UNSPECIFIED:
562                                 /// TRANSLATORS: this means that the range of pixel values used in this
563                                 /// file is unknown (not specified in the file).
564                                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Unspecified")));
565                                 break;
566                         case AVCOL_RANGE_MPEG:
567                                 /// TRANSLATORS: this means that the range of pixel values used in this
568                                 /// file is limited, so that not all possible values are valid.
569                                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Limited")));
570                                 break;
571                         case AVCOL_RANGE_JPEG:
572                                 /// TRANSLATORS: this means that the range of pixel values used in this
573                                 /// file is full, so that all possible pixel values are valid.
574                                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Full")));
575                                 break;
576                         default:
577                                 DCPOMATIC_ASSERT (false);
578                         }
579                 }
580
581                 char const * primaries[] = {
582                         _("Unspecified"),
583                         _("BT709"),
584                         _("Unspecified"),
585                         _("Unspecified"),
586                         _("BT470M"),
587                         _("BT470BG"),
588                         _("SMPTE 170M (BT601)"),
589                         _("SMPTE 240M"),
590                         _("Film"),
591                         _("BT2020"),
592                         _("SMPTE ST 428-1 (CIE 1931 XYZ)"),
593                         _("SMPTE ST 431-2 (2011)"),
594                         _("SMPTE ST 432-1 D65 (2010)"), // 12
595                         "", // 13
596                         "", // 14
597                         "", // 15
598                         "", // 16
599                         "", // 17
600                         "", // 18
601                         "", // 19
602                         "", // 20
603                         "", // 21
604                         _("JEDEC P22")
605                 };
606
607                 DCPOMATIC_ASSERT (AVCOL_PRI_NB <= 23);
608                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour primaries"), primaries[_color_primaries.get_value_or(AVCOL_PRI_UNSPECIFIED)]));
609
610                 char const * transfers[] = {
611                         _("Unspecified"),
612                         _("BT709"),
613                         _("Unspecified"),
614                         _("Unspecified"),
615                         _("Gamma 22 (BT470M)"),
616                         _("Gamma 28 (BT470BG)"),
617                         _("SMPTE 170M (BT601)"),
618                         _("SMPTE 240M"),
619                         _("Linear"),
620                         _("Logarithmic (100:1 range)"),
621                         _("Logarithmic (316:1 range)"),
622                         _("IEC61966-2-4"),
623                         _("BT1361 extended colour gamut"),
624                         _("IEC61966-2-1 (sRGB or sYCC)"),
625                         _("BT2020 for a 10-bit system"),
626                         _("BT2020 for a 12-bit system"),
627                         _("SMPTE ST 2084 for 10, 12, 14 and 16 bit systems"),
628                         _("SMPTE ST 428-1"),
629                         _("ARIB STD-B67 ('Hybrid log-gamma')")
630                 };
631
632                 DCPOMATIC_ASSERT (AVCOL_TRC_NB <= 19);
633                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colour transfer characteristic"), transfers[_color_trc.get_value_or(AVCOL_TRC_UNSPECIFIED)]));
634
635                 char const * spaces[] = {
636                         _("RGB / sRGB (IEC61966-2-1)"),
637                         _("BT709"),
638                         _("Unspecified"),
639                         _("Unspecified"),
640                         _("FCC"),
641                         _("BT470BG (BT601-6)"),
642                         _("SMPTE 170M (BT601-6)"),
643                         _("SMPTE 240M"),
644                         _("YCOCG"),
645                         _("BT2020 non-constant luminance"),
646                         _("BT2020 constant luminance"),
647                         _("SMPTE 2085, Y'D'zD'x"),
648                         _("Chroma-derived non-constant luminance"),
649                         _("Chroma-derived constant luminance"),
650                         _("BT2100")
651                 };
652
653                 DCPOMATIC_ASSERT (AVCOL_SPC_NB == 15);
654                 p.push_back (UserProperty (UserProperty::VIDEO, _("Colourspace"), spaces[_colorspace.get_value_or(AVCOL_SPC_UNSPECIFIED)]));
655
656                 if (_bits_per_pixel) {
657                         p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), *_bits_per_pixel));
658                 }
659         }
660
661         if (audio) {
662                 audio->add_properties (film, p);
663         }
664 }
665
666 /** Our subtitle streams have colour maps, which can be changed, but
667  *  they have no way of signalling that change.  As a hack, we have this
668  *  method which callers can use when they've modified one of our subtitle
669  *  streams.
670  */
671 void
672 FFmpegContent::signal_subtitle_stream_changed ()
673 {
674         /* XXX: this is too late; really it should be before the change */
675         ChangeSignaller<Content> cc (this, FFmpegContentProperty::SUBTITLE_STREAM);
676 }
677
678 vector<shared_ptr<FFmpegAudioStream> >
679 FFmpegContent::ffmpeg_audio_streams () const
680 {
681         vector<shared_ptr<FFmpegAudioStream> > fa;
682
683         if (audio) {
684                 BOOST_FOREACH (AudioStreamPtr i, audio->streams()) {
685                         fa.push_back (dynamic_pointer_cast<FFmpegAudioStream> (i));
686                 }
687         }
688
689         return fa;
690 }
691
692 void
693 FFmpegContent::take_settings_from (shared_ptr<const Content> c)
694 {
695         shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (c);
696         if (!fc) {
697                 return;
698                 }
699
700         Content::take_settings_from (c);
701         _filters = fc->_filters;
702 }
703
704 #ifdef DCPOMATIC_VARIANT_SWAROOP
705 void
706 FFmpegContent::add_kdm (EncryptedECinemaKDM kdm)
707 {
708         ChangeSignaller<Content> cc (this, FFmpegContentProperty::KDM);
709         boost::mutex::scoped_lock lm (_mutex);
710         _kdm = kdm;
711
712 }
713 #endif