Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framerate fixes #350

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/Boxes/videobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ VideoBox::VideoBox() : AnimationBox("Video", eBoxType::video),

connect(this, &eBoxOrSound::parentChanged,
mSound.get(), &eBoxOrSound::setParentGroup);
connect(this, &eBoxOrSound::parentChanged, this, &VideoBox::setCorrectFps);
}

void VideoBox::fileHandlerConnector(ConnContext &conn, VideoFileHandler *obj) {
Expand Down
22 changes: 22 additions & 0 deletions src/core/Boxes/videobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unordered_map>
#include "Boxes/animationbox.h"
#include "FileCacheHandlers/videocachehandler.h"
#include "canvas.h"

class eVideoSound;

Expand Down Expand Up @@ -66,6 +67,27 @@ class CORE_EXPORT VideoBox : public AnimationBox {

qsptr<eVideoSound> mSound;
FileHandlerObjRef<VideoFileHandler> mFileHandler;

void setCorrectFps(){
auto const pScene = getParentScene();
if (!pScene) { return; }

auto const dataHandler = mFileHandler->getFrameHandler();
if (!dataHandler) { return; }
qsptr<VideoFrameHandler> vframeHandler;
vframeHandler = enve::make_shared<VideoFrameHandler>(dataHandler);

// Any changes we make to the video in the timeline have to be reflected on the video stream, that's why we have to apply the changes to dataHandler and vframeHandler.
qreal newmod = (pScene->getFps() / dataHandler->getFps());
dataHandler->setFps(dataHandler->getFps() *newmod);
vframeHandler->mVideoStreamsData->fFps = dataHandler->getFps();
dataHandler->setFrameCount(vframeHandler->mVideoStreamsData->fFrameCount*newmod);
vframeHandler->mVideoStreamsData->fFrameCount = vframeHandler->mVideoStreamsData->fFrameCount*newmod;
setAnimationFramesHandler(vframeHandler);
animationDataChanged();
return;
}

};

#endif // VIDEOBOX_H
2 changes: 2 additions & 0 deletions src/core/FileCacheHandlers/videocachehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CORE_EXPORT VideoDataHandler : public FileDataCacheHandler {
qreal mFrameFps = 0;
int mFrameWidth = 0;
int mFrameHeight = 0;
public:
QList<VideoFrameHandler*> mFrameHandlers;
QList<int> mFramesBeingLoaded;
QList<stdsptr<VideoFrameLoader>> mFrameLoaders;
Expand Down Expand Up @@ -103,6 +104,7 @@ class CORE_EXPORT VideoFrameHandler : public AnimationFrameHandler {
std::set<int> mNeededFrames;

VideoDataHandler* const mDataHandler;
public:
stdsptr<VideoStreamsData> mVideoStreamsData;
};
#include "CacheHandlers/soundcachehandler.h"
Expand Down