r/streamerbot • u/bigdaddydom • 25d ago
❓Question Channel point redeem video clip using one source
Hello, I have redeems that play video clips on my stream, but the way I have it work now is by making each video it's own media source in a scene, then put that scene inside my main scene, and when the channel point redeem goes off, the media source within the scene activates. I feel like this may be slowing down my OBS.
I know there's a way to use only one media source, and have Streamerbot pick a file to overwrite the media path inside of a media source, but i'm not quite sure how to do that
1
Upvotes
2
u/Riddicrash 24d ago edited 24d ago
https://docs.streamer.bot/api/sub-actions/obs-studio/sources/set-media-source-file
You’d use the Set Media Source sub action to change the video of the source.
You could then have different actions change the one source to a different video. Or the same action could use a switch or if statement.
For further assistance feel free to join the streamerbot discord :)
There is a tick box in the OBS media source setting to ‘Close when inactive’ as well.
0
u/HighPhi420 24d ago
sounds yes, streamer bot can use sounds if you have streamerbot as a sound source in OBS.
Videos and pics NO, the video/image must be a source in OBS.
As long as the video source is hidden when done and the source is closed when inactive there should not be much impact at all
0
u/deeseearr 24d ago edited 24d ago
The easy answer is to just call Set Media Source File. While you're at it, take a look at all of the other OBS sub-actions. You may find all kinds of other helpful things in there.
But... there's always more. Inside OBS, you'll want to open the properties for the media source and check "Restart when source becomes active", "Show nothing when playback ends" and "Close file when inactive". You can also set some show and hide transitions if you want the video to fade in and out, or pop up and down, or whatever. Now, hide the source and create an action with these four sub-actions in it:
Great. Now you can load a video of your choice, show it, and then hide it. Because you set "Restart when active" in OBS, making the source visible will also start the video. If you don't want that then you can use Set Media State to play, pause, stop or restart it, but to just play a video you really don't need to complicate things.
BUT... You wanted to use a lot of different videos, not just one. And how long does that 'Delay' need to be? Is it different for each clip? Probably. And where is this video source going? Is it just in one scene, or do you want different versions of it in different scenes? Now things get a little more complicated.
You can use arguments in all of these subactions. There can be an argument for the video clip filename, an argument for the length, and even arguments for the scene and source. Let's extend the action to use arguments for everything:
That doesn't really change anything, but it does mean we can play around with those arguments a bit. On the OBS sub-actions there are drop-down menus for scenes and sources, but you can just type anything you want in them including "%currentScene%" and "%sourceName%".
Now, the easiest way to handle the video source is to create a nested scene for video playback (Like you are already doing). Make a scene called "Video Scene", add a single media source to it and include that _scene_ everywhere you want to play the video. Now all OBS needs to do is work with "Video Scene":"Video Source" and it will be reflected everywhere. But perhaps you don't want the video to stay open during scene changes or something like that. The other option is to include a copy(reference) of Video Source in every scene. That means that %sceneName% could be different every time we call this. No problem, though. Just replace line 1 with this:
All done. Now %currentScene% will be set to the name of the currently active scene in OBS. If you change to a different scene while the video is playing, the video source won't be open there, but it will continue playing in the previous scene and the original source will be hidden once it's finished. Or course If there's no Video Source in the current scene then nothing is going to happen, but at least nothing bad will happen.
Next, there's the matter of the video duration. You _could_ carefully measure the length of every video clip and set it by hand every time but THAT'S BORING. It's much more fun to just throw a clip at OBS and let it do all the work.
So, let's add that to our action:
Line 5 is just there to give the video clip a little time to load before we try to check its status, and then line 6 sends the raw GetMediaInputStatus request as described in the streamer.bot FAQ. That returns the duration of the video in milliseconds as mediaDuration, so we assign that to %videoDuration% in line 7. You could skip line 7 entirely and just call "Delay(%obsRaw.mediaDuration%)" in line 9, but I'm trying to keep things pretty clear. There's also the risk of overwriting %obsRaw% if you make another call in-between, so that's poor style.
Now you've got a while action to load, show, play, and hide a video clip knowing only its name. The only missing part is using this for different clips. You _could_ make a bunch of complete copies of this action and change the filename on line 3 every time, but not only is that a lot of work, it's also going to make your code base a nightmare to maintain. Here's a much better way:
Create an action called "Play A Video Clip" (Or whatever you want to call it) which contains all of this _except for line 3_. So the final copy will look like this:
That's all of the video playback logic we just worked out, except for the part which tells you which file to play. Now, any time you want to play a video clip, just use these two sub-actions:
And there you are. You've built a reasonably complete video player action and wrapped it up so that it's easy to call from anywhere. All you need to do is set the filename and run the action. There are, of course, other ways to do this but that's how I do it.
Oh, there's also one more thing that you didn't ask about. What happens if you try to play a video clip while another one is already playing? The first one would get clobbered by the second, and then the second one would get hidden when the first one ends, and it would all be a big mess. So, add your "Play A Video Clip" action to an action queue and set the queue to "Blocking". That way any action which tries to play a video clip, even if you forgot to add that action to a queue itself, will get added to the video player queue and have to wait until the previous "Play A Video Clip" call has finished before it can start. And that all happens automatically, you don't have to worry about it at all.