WIP: VP9 encoder.
[dcpomatic.git] / src / lib / dcp_encoder.cc
index 186ec59c2a9d5e49bd5c2d60cf60e29ab0292776..fc59452356d455c37c36cfa414cc4de3ec48b589 100644 (file)
@@ -83,6 +83,8 @@ DCPEncoder::DCPEncoder (shared_ptr<const Film> film, weak_ptr<Job> job)
                        }
                }
        }
+
+       _sign_language = contains_sign_language(film->content());
 }
 
 DCPEncoder::~DCPEncoder ()
@@ -126,13 +128,39 @@ DCPEncoder::video (shared_ptr<PlayerVideo> data, DCPTime time)
 {
        if (data->type() == VideoType::MAIN) {
                _j2k_encoder.encode(data, time);
+       } else {
+               _vp9_encoder.encode(data->image(boost::bind(&PlayerVideo::force, AV_PIX_FMT_YUV420P), VideoRange::VIDEO, false), time);
+       }
+}
+
+
+void
+DCPEncoder::write_pending_audio()
+{
+       if (_pending_audio.empty()) {
+               return;
+       }
+
+       auto const last_pending_audio = _pending_audio.back();
+       auto const pending_audio_end = last_pending_audio.second + DCPTime::from_frames(last_pending_audio.first->frames(), _film->video_frame_rate());
+       auto const write_until = std::min(pending_audio_end, _vp9_encoder.end());
+       if (write_until == _last_audio_write_to) {
+               return;
        }
+
+       /* XXX: need to mix _pending_audio with the output from vp9_encoder */
 }
 
+
 void
 DCPEncoder::audio (shared_ptr<AudioBuffers> data, DCPTime time)
 {
-       _writer.write(data, time);
+       if (!_sign_language) {
+               _writer.write(data, time);
+       } else {
+               _pending_audio.push_back({data, time});
+               write_pending_audio();
+       }
 
        auto job = _job.lock ();
        DCPOMATIC_ASSERT (job);