Use uchardet to guess encoding of subtitle files and reject non-UTF-8.
[dcpomatic.git] / src / lib / ffmpeg.cc
index 4eee089928480577a12948b52c23497d383bcdba..8fa03fdffb552f3ddbd49042df0d41d084d5d6ed 100644 (file)
 #include "ffmpeg.h"
 #include "ffmpeg_content.h"
 #include "film.h"
-#include "ffmpeg_audio_stream.h"
-#include "ffmpeg_subtitle_stream.h"
 #include "exceptions.h"
 #include "util.h"
 #include "raw_convert.h"
 #include "log.h"
+#include "ffmpeg_subtitle_stream.h"
+#include "compose.hpp"
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 #include <libswscale/swscale.h>
 }
 #include <boost/algorithm/string.hpp>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -246,3 +247,19 @@ FFmpeg::avio_seek (int64_t const pos, int whence)
 
        return _file_group.seek (pos, whence);
 }
+
+FFmpegSubtitlePeriod
+FFmpeg::subtitle_period (AVSubtitle const & sub)
+{
+       ContentTime const packet_time = ContentTime::from_seconds (static_cast<double> (sub.pts) / AV_TIME_BASE);
+
+       if (sub.end_display_time == static_cast<uint32_t> (-1)) {
+               /* End time is not known */
+               return FFmpegSubtitlePeriod (packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3));
+       }
+
+       return FFmpegSubtitlePeriod (
+               packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3),
+               packet_time + ContentTime::from_seconds (sub.end_display_time / 1e3)
+               );
+}