All audio content should resample if the output frame rate and content
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index b7551c96af36ed3a85e47671ac6e1237a8d96499..4ea6dbc6ac4c23f9c3f2cefd747848968b8a3749 100644 (file)
@@ -21,6 +21,7 @@ extern "C" {
 #include <libavformat/avformat.h>
 }
 #include <libcxml/cxml.h>
+#include <libdcp/raw_convert.h>
 #include "ffmpeg_content.h"
 #include "ffmpeg_examiner.h"
 #include "compose.hpp"
@@ -33,6 +34,8 @@ extern "C" {
 
 #include "i18n.h"
 
+#define LOG_GENERAL(...) film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
+
 using std::string;
 using std::stringstream;
 using std::vector;
@@ -40,8 +43,8 @@ using std::list;
 using std::cout;
 using std::pair;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using boost::dynamic_pointer_cast;
+using libdcp::raw_convert;
 
 int const FFmpegContentProperty::SUBTITLE_STREAMS = 100;
 int const FFmpegContentProperty::SUBTITLE_STREAM = 101;
@@ -152,7 +155,7 @@ FFmpegContent::as_xml (xmlpp::Node* node) const
        }
 
        if (_first_video) {
-               node->add_child("FirstVideo")->add_child_text (lexical_cast<string> (_first_video.get ()));
+               node->add_child("FirstVideo")->add_child_text (raw_convert<string> (_first_video.get ()));
        }
 }
 
@@ -170,7 +173,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
 
        VideoContent::Frame video_length = 0;
        video_length = examiner->video_length ();
-       film->log()->log (String::compose ("Video length obtained from header as %1 frames", video_length));
+       LOG_GENERAL ("Video length obtained from header as %1 frames", video_length);
 
        {
                boost::mutex::scoped_lock lm (_mutex);
@@ -271,7 +274,7 @@ AudioContent::Frame
 FFmpegContent::audio_length () const
 {
        int const cafr = content_audio_frame_rate ();
-       int const vfr  = video_frame_rate ();
+       float const vfr = video_frame_rate ();
        VideoContent::Frame const vl = video_length_after_3d_combine ();
 
        boost::mutex::scoped_lock lm (_mutex);
@@ -306,30 +309,6 @@ FFmpegContent::content_audio_frame_rate () const
        return _audio_stream->frame_rate;
 }
 
-int
-FFmpegContent::output_audio_frame_rate () const
-{
-       shared_ptr<const Film> film = _film.lock ();
-       assert (film);
-       
-       /* Resample to a DCI-approved sample rate */
-       double t = dcp_audio_frame_rate (content_audio_frame_rate ());
-
-       FrameRateConversion frc (video_frame_rate(), film->video_frame_rate());
-
-       /* Compensate if the DCP is being run at a different frame rate
-          to the source; that is, if the video is run such that it will
-          look different in the DCP compared to the source (slower or faster).
-          skip/repeat doesn't come into effect here.
-       */
-
-       if (frc.change_speed) {
-               t *= video_frame_rate() * frc.factor() / film->video_frame_rate();
-       }
-
-       return rint (t);
-}
-
 bool
 operator== (FFmpegStream const & a, FFmpegStream const & b)
 {
@@ -353,7 +332,7 @@ void
 FFmpegStream::as_xml (xmlpp::Node* root) const
 {
        root->add_child("Name")->add_child_text (name);
-       root->add_child("Id")->add_child_text (lexical_cast<string> (_id));
+       root->add_child("Id")->add_child_text (raw_convert<string> (_id));
 }
 
 FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node, int version)
@@ -369,10 +348,10 @@ void
 FFmpegAudioStream::as_xml (xmlpp::Node* root) const
 {
        FFmpegStream::as_xml (root);
-       root->add_child("FrameRate")->add_child_text (lexical_cast<string> (frame_rate));
-       root->add_child("Channels")->add_child_text (lexical_cast<string> (channels));
+       root->add_child("FrameRate")->add_child_text (raw_convert<string> (frame_rate));
+       root->add_child("Channels")->add_child_text (raw_convert<string> (channels));
        if (first_audio) {
-               root->add_child("FirstAudio")->add_child_text (lexical_cast<string> (first_audio.get ()));
+               root->add_child("FirstAudio")->add_child_text (raw_convert<string> (first_audio.get ()));
        }
        mapping.as_xml (root->add_child("Mapping"));
 }