X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilm_state.cc;h=3cd7091ca69ebdb62a8706c652dc7113d63f8779;hb=d7801f3fe5a5ac46aa2c512bcd00be2bee39ed17;hp=739eeac3c7a89dc9a1b05f55c870ff11ce33254f;hpb=d4168894a231253d2625a7c1f7b4df68c9c8557c;p=dcpomatic.git diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index 739eeac3c..3cd7091ca 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -35,6 +35,7 @@ #include "format.h" #include "dcp_content_type.h" #include "util.h" +#include "exceptions.h" using namespace std; using namespace boost; @@ -251,10 +252,13 @@ ContentType FilmState::content_type () const { #if BOOST_FILESYSTEM_VERSION == 3 - string const ext = filesystem::path(content).extension().string(); + string ext = filesystem::path(content).extension().string(); #else - string const ext = filesystem::path(content).extension(); + string ext = filesystem::path(content).extension(); #endif + + transform (ext.begin(), ext.end(), ext.begin(), ::tolower); + if (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png") { return STILL; } @@ -275,3 +279,35 @@ FilmState::bytes_per_sample () const return 0; } + +int +FilmState::target_sample_rate () const +{ + double t = dcp_audio_sample_rate (audio_sample_rate); + if (rint (frames_per_second) != frames_per_second) { + if (fabs (frames_per_second - 23.976) < 1e-6 || (fabs (frames_per_second - 29.97) < 1e-6)) { + /* 24fps or 30fps drop-frame ie {24,30} * 1000 / 1001 frames per second; + hence we need to resample the audio to dcp_audio_sample_rate * 1000 / 1001 + so that when we play it back at dcp_audio_sample_rate it is sped up + by the same amount that the video is + */ + t *= double(1000) / 1001; + } else { + throw EncodeError ("unknown fractional frame rate"); + } + } + + return rint (t); +} + +int +FilmState::dcp_length () const +{ + if (dcp_frames) { + return dcp_frames; + } + + return length; +} + +