}
void
-FFmpegDecoder::seek (VideoContent::Frame frame)
+FFmpegDecoder::seek (VideoContent::Frame frame, bool accurate)
{
- do_seek (frame, false, false);
-}
-
-void
-FFmpegDecoder::seek_back ()
-{
- if (_video_position == 0) {
- return;
- }
-
- do_seek (_video_position - 1, true, true);
-}
-
-void
-FFmpegDecoder::do_seek (VideoContent::Frame frame, bool backwards, bool accurate)
-{
- int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * av_q2d (_format_context->streams[_video_stream]->time_base));
- av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
+ double const time_base = av_q2d (_format_context->streams[_video_stream]->time_base);
+ int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * time_base);
+ av_seek_frame (_format_context, _video_stream, vt, AVSEEK_FLAG_BACKWARD);
avcodec_flush_buffers (video_codec_context());
if (_subtitle_codec_context) {
int const r = avcodec_decode_video2 (video_codec_context(), _frame, &finished, &_packet);
if (r >= 0 && finished) {
int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
- if (bet > vt) {
- _video_position = (bet * av_q2d (_format_context->streams[_video_stream]->time_base) + _pts_offset)
- * _ffmpeg_content->video_frame_rate();
+ if (bet >= vt) {
+ _video_position = rint (
+ (bet * time_base + _pts_offset) * _ffmpeg_content->video_frame_rate()
+ );
+ av_free_packet (&_packet);
break;
}
}
/* We just did a seek, so disable any attempts to correct for where we
are / should be.
*/
- _video_position = pts * _ffmpeg_content->video_frame_rate ();
+ _video_position = rint (pts * _ffmpeg_content->video_frame_rate ());
_just_sought = false;
}
-
+
double const next = _video_position / _ffmpeg_content->video_frame_rate();
double const one_frame = 1 / _ffmpeg_content->video_frame_rate ();
double delta = pts - next;
~FFmpegDecoder ();
void pass ();
- void seek (VideoContent::Frame);
- void seek_back ();
+ void seek (VideoContent::Frame, bool);
bool done () const;
private:
AVSampleFormat audio_sample_format () const;
int bytes_per_audio_sample () const;
- void do_seek (VideoContent::Frame, bool, bool);
bool decode_video_packet ();
void decode_audio_packet ();
}
void
-ImageMagickDecoder::seek (VideoContent::Frame frame)
+ImageMagickDecoder::seek (VideoContent::Frame frame, bool)
{
_video_position = frame;
}
-void
-ImageMagickDecoder::seek_back ()
-{
- if (_video_position > 0) {
- _video_position--;
- }
-}
-
bool
ImageMagickDecoder::done () const
{
/* Decoder */
void pass ();
- void seek (VideoContent::Frame);
- void seek_back ();
+ void seek (VideoContent::Frame, bool);
bool done () const;
private:
/** @return true on error */
void
-Player::seek (Time t)
+Player::seek (Time t, bool accurate)
{
if (!_have_valid_pieces) {
setup_pieces ();
FrameRateConversion frc (vc->video_frame_rate(), _film->dcp_video_frame_rate());
VideoContent::Frame f = s * _film->dcp_video_frame_rate() / (frc.factor() * TIME_HZ);
- dynamic_pointer_cast<VideoDecoder>((*i)->decoder)->seek (f);
+ dynamic_pointer_cast<VideoDecoder>((*i)->decoder)->seek (f, accurate);
}
/* XXX: don't seek audio because we don't need to... */
}
-
-void
-Player::seek_back ()
-{
-
-}
-
void
Player::setup_pieces ()
{
void disable_audio ();
bool pass ();
- void seek (Time);
- void seek_back ();
+ void seek (Time, bool);
Time video_position () const {
return _video_position;
public:
VideoDecoder (boost::shared_ptr<const Film>);
- virtual void seek (VideoContent::Frame) = 0;
- virtual void seek_back () = 0;
+ virtual void seek (VideoContent::Frame, bool) = 0;
/** Emitted when a video frame is ready.
* First parameter is the video image.
return;
}
- /* This will cause a Player::Changed to be emitted */
- _player->seek (_player->video_position() - _film->video_frames_to_time (1));
+ _player->seek (_player->video_position() - _film->video_frames_to_time (1), false);
fetch_next_frame ();
}
FilmViewer::slider_moved (wxScrollEvent &)
{
if (_film && _player) {
- _player->seek (_slider->GetValue() * _film->length() / 4096);
+ _player->seek (_slider->GetValue() * _film->length() / 4096, false);
fetch_next_frame ();
}
}
if (!_player) {
return;
}
+
+ Time const t = _film->video_frames_to_time (1);
- _player->seek_back ();
+ _player->seek (_player->video_position() - t * 2.5, true);
fetch_next_frame ();
}