You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
coordinate video playback with audio frame number
This commit is contained in:
@@ -112,6 +112,8 @@ namespace openshot
|
||||
|
||||
const ReaderInfo & getReaderInfo() const { return reader->info; }
|
||||
tr1::shared_ptr<Frame> getFrame() const { return frame; }
|
||||
int getFramePosition() const { return frame_position; }
|
||||
int getEstimatedFrame() const { return int(estimated_frame); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@ namespace openshot
|
||||
return tr1::shared_ptr<Frame>();
|
||||
}
|
||||
|
||||
int AudioPlaybackThread::getCurrentFramePosition()
|
||||
{
|
||||
return source ? source->getEstimatedFrame() : 0;
|
||||
}
|
||||
|
||||
void AudioPlaybackThread::run()
|
||||
{
|
||||
// Init audio device
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace openshot
|
||||
|
||||
void setReader(ReaderBase *reader);
|
||||
tr1::shared_ptr<Frame> getFrame();
|
||||
int getCurrentFramePosition();
|
||||
|
||||
void run();
|
||||
|
||||
|
||||
@@ -72,15 +72,23 @@ namespace openshot
|
||||
|
||||
videoPlayback->frame = frame;
|
||||
videoPlayback->render.signal();
|
||||
position = audioPlayback->getCurrentFramePosition();
|
||||
frame = getFrame();
|
||||
videoPlayback->rendered.wait();
|
||||
|
||||
int fd = position - audioPlayback->getCurrentFramePosition();
|
||||
|
||||
const Time t2 = Time::getCurrentTime();
|
||||
double ft = (1000.0 / reader->info.fps.ToDouble());
|
||||
int64 d = t2.toMilliseconds() - t1.toMilliseconds();
|
||||
int st = int(ft - d + 0.5);
|
||||
if (0 < ft - d) sleep(st);
|
||||
|
||||
st += fd * reader->info.fps.ToDouble();
|
||||
|
||||
if (0 < st) sleep(st);
|
||||
|
||||
//std::cout << "frametime: " << ft << " - " << d << " = " << st << std::endl;
|
||||
std::cout << "drift: " << fd << std::endl;
|
||||
}
|
||||
|
||||
if (videoPlayback->isThreadRunning()) videoPlayback->stopThread(-1);
|
||||
|
||||
Reference in New Issue
Block a user