From 4d574975cc7fd0c0ad57aad6d171258bbf59cbfa Mon Sep 17 00:00:00 2001 From: jaybinks Date: Tue, 19 Feb 2008 12:45:54 +0000 Subject: first steps towards loopable videos. ( http://trac2.assembla.com/usdx/ticket/5 ) Currently videos specified in the song, will loop if they are shorter than the mp3. this should become selectable, however at the moment it will always loop if the video is shorter. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@863 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVideo.pas | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Game/Code/Classes/UVideo.pas b/Game/Code/Classes/UVideo.pas index 66c0c8e6..1eab5d91 100644 --- a/Game/Code/Classes/UVideo.pas +++ b/Game/Code/Classes/UVideo.pas @@ -89,7 +89,7 @@ type ScaledVideoWidth, ScaledVideoHeight: Real; VideoAspect: Real; VideoTextureU, VideoTextureV: Real; - VideoTimeBase, VideoTime, LastFrameTime, TimeDifference: Extended; + VideoTimeBase, VideoTime, LastFrameTime, TimeDifference, flooptime: Extended; WantedAudioCodecContext, @@ -212,7 +212,7 @@ begin if fVideoPaused then Exit; - myTime := Time + fVideoSkipTime; + myTime := ( Time - flooptime ) + fVideoSkipTime; TimeDifference := myTime - VideoTime; DropFrame := False; @@ -267,7 +267,23 @@ begin while ( FrameFinished = 0 ) do begin if ( av_read_frame(VideoFormatContext, AVPacket) < 0 ) then + begin + // Record the Time we looped, this is used to keep the loops, in time. otherwise they speed + flooptime := time; + + // Dont use SetPosition() it dosnt let us go back to frame 0... can we / should we fix this ?? + fVideoSkipTime := 0; + VideoTime := 0; + + // Free the packet we just got from av_read_frame + av_free_packet( @AVPacket ); + + // Seek to frame 0 in the video stream + av_seek_frame(VideoFormatContext,VideoStreamIndex,0,AVSEEK_FLAG_ANY); break; + end; + + // if we got a packet from the video stream, then decode it if (AVPacket.stream_index=VideoStreamIndex) then begin -- cgit v1.2.3