source-sdk-2013 icon indicating copy to clipboard operation
source-sdk-2013 copied to clipboard

Unable to loop videos using IVideoServices

Open TotallyMehis opened this issue 10 months ago • 3 comments

Hey, my mod uses a looping video for the main menu background. AFAIK bink video is no longer supported in the x64 build, so videos have to be re-encoded to webm. That's fine, but looping a webm doesn't seem to be possible which worked with bink video.

I have tried creating the video material like this:

m_pVideoMaterial = g_pVideo->CreateVideoMaterial( "VideoMaterial",
                                                  "media/background01.webm",
                                                  "MOD",
                                                  VideoPlaybackFlags::LOOP_VIDEO | VideoPlaybackFlags::NO_AUDIO,
                                                  VideoSystem::SOURCE2_WRAPPER,
                                                  false );
m_pVideoMaterial->SetLooping( true );

The video plays fine, but eventually stops playing when it's finished.

AFAIK webm doesn't have any metadata for looping. Perhaps there's another container format I can try?

Any help would be appreciated 😄

TotallyMehis avatar Feb 24 '25 19:02 TotallyMehis

yes this seems to be a issue with it ending the video regardless and purging said video, this is problematic for looping media

Image

AnthonyPython avatar Mar 08 '25 11:03 AnthonyPython

Any help would be appreciated 😄

Here is a work around example solution found is using the OnThink function and doing an if statement to check current time and total duration. I'm using the loop variable in res file to know if the video should loop from the tf video panel but you can check how ever you please. how ever I might need to make a edge case for when the menu is closed from loading, and opened in game. as OnThink will only do it while visible which means the video needs to be stopped and then started.

void CTFVideoPanel::OnThink()
{
	BaseClass::OnThink();
	if (m_VideoMaterial && m_bLoop)
	{
		if (m_VideoMaterial->Update() == true)
		{
			float cur_vidtime = m_VideoMaterial->GetCurrentVideoTime();
			float dur_vidtime = m_VideoMaterial->GetVideoDuration();
			if ((cur_vidtime + 0.1) >= dur_vidtime)
			{
				m_VideoMaterial->SetTime(0);
			}
			
			
		}

	}

}

AnthonyPython avatar Mar 08 '25 13:03 AnthonyPython

For anyone wanting a more direct fix for this, you can access the source 2 video player interface from the video material and set it to loop, as the player supports looping, it's just not hooked up for some reason.

#ifdef WINDOWS
	IVideoPlayer* player = *reinterpret_cast<IVideoPlayer**>( (intptr_t)(m_VideoMaterial) + 0x128 );
#else
	IVideoPlayer* player = *reinterpret_cast<IVideoPlayer**>( (intptr_t)(m_VideoMaterial) + 0xd8 );
#endif
	player->SetRepeat( true );

The offsets might have changed a little since I'm not on the latest binaries, but you can just step into any of the IVideoMaterial setters like SetVolume or SetPaused with the disassembly view and eyeball it, which is what I did.

nooodles-ahh avatar Jun 22 '25 11:06 nooodles-ahh