}
#include "ffmpeg_examiner.h"
#include "ffmpeg_content.h"
+#include "job.h"
#include "ffmpeg_audio_stream.h"
#include "ffmpeg_subtitle_stream.h"
#include "util.h"
using boost::shared_ptr;
using boost::optional;
-FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c)
+/** @param job job that the examiner is operating in, or 0 */
+FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Job> job)
: FFmpeg (c)
+ , _video_length (0)
, _need_video_length (false)
{
/* Find audio and subtitle streams */
/* See if the header has duration information in it */
_need_video_length = _format_context->duration == AV_NOPTS_VALUE;
if (!_need_video_length) {
- _video_length = ContentTime::from_seconds (double (_format_context->duration) / AV_TIME_BASE);
+ _video_length = (double (_format_context->duration) / AV_TIME_BASE) * video_frame_rate().get ();
+ } else if (job) {
+ job->sub (_("Finding length"));
+ job->set_progress_unknown ();
}
/* Run through until we find:
_first_video = frame_time (_format_context->streams[_video_stream]);
}
if (_need_video_length) {
- _video_length = frame_time (_format_context->streams[_video_stream]).get_value_or (ContentTime ());
+ _video_length = frame_time (
+ _format_context->streams[_video_stream]
+ ).get_value_or (ContentTime ()).frames (video_frame_rate().get ());
}
}
}
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;
+ FFmpegSubtitlePeriod const period = subtitle_period (sub);
+ if (sub.num_rects <= 0 && _last_subtitle_start) {
+ stream->add_subtitle (ContentTimePeriod (_last_subtitle_start.get (), period.from));
+ _last_subtitle_start = optional<ContentTime> ();
} else if (sub.num_rects == 1) {
- stream->periods.push_back (period);
+ if (period.to) {
+ stream->add_subtitle (ContentTimePeriod (period.from, period.to.get ()));
+ } else {
+ _last_subtitle_start = period.from;
+ }
}
+ avsubtitle_free (&sub);
}
}
}
/** @return Length according to our content's header */
-ContentTime
+Frame
FFmpegExaminer::video_length () const
{
- ContentTime const length = ContentTime::from_seconds (double (_format_context->duration) / AV_TIME_BASE);
- return ContentTime (max (ContentTime (1), _video_length));
+ return max (Frame (1), _video_length);
}
optional<float>