summaryrefslogtreecommitdiff
path: root/src/lib/ffmpeg_examiner.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-22 16:53:38 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-22 16:53:38 +0100
commit24d54ea7fe1ba128cf8d3521d6738fc73a7c623e (patch)
tree7c3674e34b30f81334dc8f35a91d3cbb31b7ff9d /src/lib/ffmpeg_examiner.cc
parentd156fe45ee21fc416ce6b9e43ceed95bf42fde41 (diff)
Basics of noting subtitle times in FFmpegSubtitleStreams.
Diffstat (limited to 'src/lib/ffmpeg_examiner.cc')
-rw-r--r--src/lib/ffmpeg_examiner.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc
index 013799d03..df12830f8 100644
--- a/src/lib/ffmpeg_examiner.cc
+++ b/src/lib/ffmpeg_examiner.cc
@@ -25,6 +25,7 @@ extern "C" {
#include "ffmpeg_content.h"
#include "ffmpeg_audio_stream.h"
#include "ffmpeg_subtitle_stream.h"
+#include "util.h"
#include "i18n.h"
@@ -63,8 +64,15 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c)
}
}
- /* Run through until we find the first audio (for each stream) and video */
-
+ /* Run through until we find:
+ * - the first video.
+ * - the first audio for each stream.
+ * - the subtitle periods for each stream.
+ *
+ * We have to note subtitle periods as otherwise we have no way of knowing
+ * where we should look for subtitles (video and audio are always present,
+ * so they are ok).
+ */
while (1) {
int r = av_read_frame (_format_context, &_packet);
if (r < 0) {
@@ -122,7 +130,17 @@ FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptr<FFmpegAudioStr
void
FFmpegExaminer::subtitle_packet (AVCodecContext* context, shared_ptr<FFmpegSubtitleStream> stream)
{
-
+ int frame_finished;
+ AVSubtitle sub;
+ if (avcodec_decode_subtitle2 (context, &sub, &frame_finished, &_packet) >= 0 && frame_finished) {
+ ContentTimePeriod const period = subtitle_period (sub);
+ if (sub.num_rects == 0 && !stream->periods.empty () && stream->periods.back().to > period.from) {
+ /* Finish the last subtitle */
+ stream->periods.back().to = period.from;
+ } else if (sub.num_rects == 1) {
+ stream->periods.push_back (period);
+ }
+ }
}
optional<ContentTime>