Skip to content

Commit

Permalink
Small tweak to playback logic, to refresh frame anytime Player::Seek(…
Browse files Browse the repository at this point in the history
…) is called - which allows for changing keyframes during playback (i.e. shaking a clip during playback)
  • Loading branch information
jonoomph committed Oct 23, 2022
1 parent 389bf33 commit d46efe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Qt/PlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace openshot
// Constructor
PlayerPrivate::PlayerPrivate(openshot::RendererBase *rb)
: renderer(rb), Thread("player"), video_position(1), audio_position(0),
speed(1), reader(NULL), last_video_position(1), max_sleep_ms(125000), playback_frames(0)
speed(1), reader(NULL), last_video_position(1), max_sleep_ms(125000), playback_frames(0), is_dirty(true)
{
videoCache = new openshot::VideoCacheThread();
audioPlayback = new openshot::AudioPlaybackThread(videoCache);
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace openshot
// - If pre-roll is not ready (This should allow scrubbing of the timeline without waiting on pre-roll)
if ((speed == 0 && video_position == last_video_position) ||
(speed != 0 && last_speed != speed) ||
(speed != 0 && !videoCache->isReady()))
(speed != 0 && !is_dirty && !videoCache->isReady()))
{
// Sleep for a fraction of frame duration
std::this_thread::sleep_for(frame_duration / 4);
Expand Down Expand Up @@ -124,6 +124,9 @@ namespace openshot
std::shared_ptr<openshot::Frame> PlayerPrivate::getFrame()
{
try {
// Getting new frame, so clear this flag
is_dirty = false;

// Get the next frame (based on speed)
if (video_position + speed >= 1 && video_position + speed <= reader->info.video_length) {
video_position = video_position + speed;
Expand Down Expand Up @@ -167,6 +170,7 @@ namespace openshot
{
video_position = new_position;
last_video_position = 0;
is_dirty = true;
}

// Start video/audio playback
Expand Down
1 change: 1 addition & 0 deletions src/Qt/PlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace openshot
openshot::RendererBase *renderer;
int64_t last_video_position; /// The last frame actually displayed
int max_sleep_ms; /// The max milliseconds to sleep (when syncing audio and video)
bool is_dirty; /// Detect if a frame needs to be refreshed (calls to Seek() set this to true)

/// Constructor
PlayerPrivate(openshot::RendererBase *rb);
Expand Down

0 comments on commit d46efe8

Please sign in to comment.