Video Source File Path from .txt file

onairmitflo

Member
Thanks very much, will try later when back home. Just a thought, is there a simple solution so as to be able to 'play' image files (.png or .jpeg) using an Image source rather then a Media source? Perhaps not in this script, but I have tried just changing working scripts on text Sources to call the image Source name (flag):
local source = obs.obs_get_source_by_name(flag)
and then the Settings to:
obs.obs_data_set_string(settings, "image_file", "C:\Users\MyPC\Documents\OBS\mdt\Temp\gbr.png"), etc.,
this seems not to work for an Image Source though?
I think that the answer is not specialized to their question. I asked him via direct message the question if on command individual videos from a folder can be played randomly. Not whether you can display images.

I think it would be smarter if they would open a single thread in the OBS forum that relates only to their question.

Best regards
 

khaver

Member
Oops, there was an error in the new code. Please trash it and use the attached one instead.
 

Attachments

  • MediaFromTXT4a.zip
    2.2 KB · Views: 54

khaver

Member
Florian, I'm still having a problem. Don't use either version until you've clarified the following and I fix the code.
I need to see all combinations of the text written in the mAirList text file.
1) Music video file with video and no starting offset (X:\Music\Video.mp4)
2) Music video file with video and a starting offset (X:\Music\Video.mp4;3,0
3) Music video file with no video and no starting offset (?)
4) Music video file with no video and a starting offset (X:\Music\Video.mp4;3,0;true)
I'll need to make changes depending on the format for #3.
 

khaver

Member
Okay, I think I figured out for all combinations now. for combination #3 it will catch all:
X:\Music\Video.mp4;true
X:\Music\Video.mp4;0;true
X:\Music\Video.mp4;;true
Try the attached version and let me know if it's working okay.
 

Attachments

  • MediaFromTXT4b.zip
    2.3 KB · Views: 39

andy5211d

New Member
Andy, my post above is for the original author of this thread.
Thanks. I'll move my question to another thread as can't seem to change the image file location in Lua. However this conversation has enabled me to work around my problem by using a media file rather than an image file (image converted into a 2sec video)! So thanks team.
 

onairmitflo

Member
Okay, I think I figured out for all combinations now. for combination #3 it will catch all:
X:\Music\Video.mp4;true
X:\Music\Video.mp4;0;true
X:\Music\Video.mp4;;true
Try the attached version and let me know if it's working okay.
I will sit down tomorrow (Thursday) to give this a try.

Thanks already, for your effort! This I appreciate.
 

onairmitflo

Member
I will sit down tomorrow (Thursday) to give this a try.

Thanks already, for your effort! This I appreciate.
Evening Together. I come with the first results. I have noticed that it already selects and plays random videos, but as soon as these are over, the video simply stops and no new random video is played - as actually wanted.

Tomorrow I will create a proof video, which will show the behavior of OBS maybe a bit better.

Best regards
 

khaver

Member
Did you set the Media Source in each scene to loop? If one of the random videos selected is shorter than the audio only music video file, the random video will need to loop. The script can only select a new random video file when the current scene transitions to the other scene when the mAirList text file is changed.

If you mean that once all the random videos have been played, the script doesn't start over with all the videos again? If that's the case, it's a bug and I'll have to look into it.

Update: You're right, it won't reload the random video files once they've all been played. I'm looking into it now.
 

khaver

Member
I found the problem. In Lua, you can't just copy an array from one variable to another using ARRAY2 = ARRAY1. You have to copy the contents over one at a time with a for next loop. Use the attached new version. Fingers crossed!
 

Attachments

  • MediaFromTXT4c.zip
    2.3 KB · Views: 44

onairmitflo

Member
All clear. I now it works. Only unfortunately not quite as intended as I imagined.

Problem 1:
It picks a random video, but plays it endlessly. My wish was that as soon as the video is over, the next random is played directly.

Problem 2:
It does not hide the random media source after mAirList plays a track with video again.

Problem 3:
The script changes scenes somehow comically. As soon as mAirList plays the next track it makes a transition from VIDEO B to VIDEO A. But not vice versa. From VIDEO A to VIDEO B I had to do the transition manually, but the video is put into the source. Cursed devil

Question: I have added Random A & Random B in both scenes. Correct?

Here screens:
22.04_ilj6TMDjgp.png


This picture shows if the track should not be crossfaded from Random A or B. Unfortunately mAirList does not give false, but only "true" and nothing.

22.04_euhJmwylul.png


Best regards
 

khaver

Member
Regarding your question, no, only Random A should be in scene VIDEO A, and Random B in Video B (see my picture a few posts back).

Problem 1: Yeah, I was hoping all your random videos were longer than any of the music videos so they wouldn't have to loop. I'll look into finding a way to start a new random video if the current one ends before the music video ends. Do you need to transition between the next video or is it okay to just start the next as soon as the current one ends?

Problem 2: I think this one will be fixed once you make the fix in my answer to your question above (only Random A in VIDEO A and Random B in VIDEO B).

Problem 3: Again this should be fixed with the fix to your question.

Until I find a solution to Problem 1, you should either have random videos that you know are longer than any of the music videos, or pick videos that are okay to loop.
 

onairmitflo

Member
To answer on the whole to all: Yes, unfortunately, we can not avoid short random clips. Sorry.

In between there should be a seamless cut when the next random video is played.
 

khaver

Member
Florian, here's my latest version. It should do what you want (Show randomly selected silent video clips over the music video clips whenever the mAirList text file has "true" at the end. It will also choose other random clips if the current one ends before the music video ends.).
Here are instructions and the new script.

Create four scenes, with names something like:
SCENE A
SCENE B
SCENE AR
SCENE BR

In SCENE A, add a Browser Source, with a name like MV A with the following parameters:
Uncheck "Local file"
Set "Width" and "Height" to your OBS base canvas size
Uncheck "Use custom frame rate"
Check "Control audio via OBS"
In "Custom CSS" type:
video::-webkit-media-controls {
display:none;
}

Uncheck "Shutdown source when not visible"
Uncheck "Refresh browser when scene becomes active"
Leave remaining settings at default
02-Browser_Source_MV_A_Settings.jpg


In SCENE B, add a Browser Source, with a name like MV B with the same parameters.
03-Scene_B.jpg


In SCENE AR, add a browser source and select "Add Existing" and choose MV A.
05-Scene_AR_add_existing.jpg

04-Scene_AR.jpg


Add a Media Source with a name like Random A with the following parameters:
Check "Local File"
Navigate to the folder where your random videos are and select one.
Uncheck "Loop"
Check "Restart playback when source becaomes active"
Check "Use hardware decoding when available"
Uncheck "Show nothing when playback ends"
Uncheck "Close file when inactive"
Leave other settings at default.
After clicking "OK" for the settings, you should now size the source window so it matches your OBS base canvas size.
(Note, all your random videos will need to be the same resolution)
06-Scene_AR_add_media.jpg


Add another Media Source to SCENE AR with a name like Random B, using the same parameters.
Make sure the order of the sources, from top to bottom, is Random A, Random B then MV A.
Turn off Random A and Random B

In SCENE BR, add a Browser Source and select "Add Existing" and choose MV B.
Add a Media Source and select "Add Existing" and choose Random A.
Add another Media Source, selecting "Add Existing" and choose Random B.
Make sure the order of the sources, from top to bottom, is Random A, Random B then MV A.
Turn off Random A and Random B

Go to the OBS Scripts tool and unload the current "MediaFromTXT4.lua" from the list.
Add "MediaFromTXT5.lua".
In "mAirList txt File" browse to and select the mAirList text file.
In "Random video folder", browse to and select the folder where your random videos are stored.
In the "Scene A" dropdown, select your SCENE A scene.
In the "Scene A Source" dropdown, select your MV A source.
In "Scene B" select your SCENE B scene.
In "Scene B Source" select your MV B source.
In "Random Scene A" select your "SCENE AR" scene.
In "Random Scene B" select your "SCENE BR" scene.
In "Random A Source" select your "Random A" source.
In "Random B Source" select your "Random B" source.
08-Load_script.jpg


Check "Enable script".
Close OBS and re-start it.
It should start working.
 

Attachments

  • 06-Scene_AR_add_media.jpg
    06-Scene_AR_add_media.jpg
    42.6 KB · Views: 37
  • 04-Scene_AR.jpg
    04-Scene_AR.jpg
    21.8 KB · Views: 36
  • MediaFromTXT5.zip
    2.8 KB · Views: 59

khaver

Member
The OP hasn't been on the forum since May, so I'm assuming it's either working for him or he went another route.

This project was never meant to be added to the forum resources page. It was just a solution for his original post.
 

bcoyle

Member
The OP hasn't been on the forum since May, so I'm assuming it's either working for him or he went another route.

This project was never meant to be added to the forum resources page. It was just a solution for his original post.
Thank you for your kind answer. I was interested in the video scrub problem and whether they solved it.
 
Last edited:

bcoyle

Member
Hi - Ran into this problem myself. To scrub forward, the media needs to be visible and then "always" starts playing from the beginning. You can't scrub without it being visible. My solution is before switching to the scene, make opacity = 0% using a filter setting. Then after you scrub, change opacity back to 100%. This works perfectly.
 
Top