diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2010-02-07 22:18:00 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2010-02-07 22:18:00 +0300 |
commit | a8a99a628f6f3bc8ddefec8dfae8a7aa27b8f863 (patch) | |
tree | cd635f8d5cec45c5c8eeb330396b05f05a492f52 /source/gameengine/VideoTexture/VideoFFmpeg.cpp | |
parent | 064345ad8c72d0af21b31c3da47bad6ceb3a7023 (diff) |
BGE: add audio/video synchronization capability to VideoTexture
Add optional parameter to VideoTexture.Texture refresh() method
to specify timestamp (in seconds from start of movie) of the frame
to be loaded. This value is passed down to image source and for
VideoFFmpeg source, it is used instead of current time to load
the frame from the video file.
When combined with an audio actuator, it can be used to synchronize
the sound and the image: specify the same video file in the sound
actuator and use the KX_SoundActuator time attribute as timestamp
to refresh: the frame corresponding to the sound will be loaded:
GameLogic.video.refresh(True, soundAct.time)
Diffstat (limited to 'source/gameengine/VideoTexture/VideoFFmpeg.cpp')
-rw-r--r-- | source/gameengine/VideoTexture/VideoFFmpeg.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp index f21555a95c9..9136e619288 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp +++ b/source/gameengine/VideoTexture/VideoFFmpeg.cpp @@ -54,7 +54,7 @@ VideoFFmpeg::VideoFFmpeg (HRESULT * hRslt) : VideoBase(), m_codec(NULL), m_formatCtx(NULL), m_codecCtx(NULL), m_frame(NULL), m_frameDeinterlaced(NULL), m_frameRGB(NULL), m_imgConvertCtx(NULL), m_deinterlace(false), m_preseek(0), m_videoStream(-1), m_baseFrameRate(25.0), -m_lastFrame(-1), m_eof(false), m_curPosition(-1), m_startTime(0), +m_lastFrame(-1), m_eof(false), m_externTime(false), m_curPosition(-1), m_startTime(0), m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false), m_isThreaded(false), m_stopThread(false), m_cacheStarted(false) { @@ -723,22 +723,37 @@ void VideoFFmpeg::setFrameRate (float rate) // image calculation -void VideoFFmpeg::calcImage (unsigned int texId) +void VideoFFmpeg::calcImage (unsigned int texId, double ts) { - loadFrame(); + loadFrame(ts); } // load frame from video -void VideoFFmpeg::loadFrame (void) +void VideoFFmpeg::loadFrame (double ts) { if (m_status == SourcePlaying) { // get actual time double startTime = PIL_check_seconds_timer(); - if (m_lastFrame == -1 && !m_isFile) - m_startTime = startTime; - double actTime = startTime - m_startTime; + double actTime; + if (m_isFile && ts >= 0.0) + { + // allow setting timestamp only when not streaming + actTime = ts; + if (m_eof && actTime * actFrameRate() < m_lastFrame) + { + // user is asking to rewind while the playback is already finished in the cache. + // we must clean the cache otherwise the eof condition will prevent any further reading. + stopCache(); + } + } + else + { + if (m_lastFrame == -1 && !m_isFile) + m_startTime = startTime; + actTime = startTime - m_startTime; + } // if video has ended if (m_isFile && actTime * m_frameRate >= m_range[1]) { |