Code Monkey home page Code Monkey logo

obs-random-videos's Introduction

OBS Random Video Player

Play videos in random order!

Perfect for BRB screens!

Notice: the VLC Source now supports "Shuffle playlist" option.

Instructions

  1. Download the latest executable for your system from above
  2. Place the executable into the folder where your video/audio files you want to use are located
  3. Run the file and follow the prompts for your settings
  4. A new file called obs-random-videos.html will be created in the same folder
  5. Add a new Browser Source to OBS
    1. Check "Local File" and select the new obs-random-videos.html you just created.
    2. Copy this path
    3. Uncheck "Local file" and set the url to file://<paste the path you copied>
      1. Windows example: file://C:/obs-videos-folder/obs-random-videos.html
      2. Mac/Linux example: file:///obs-videos-folder/obs-random-videos.html (note the /// instead of //)
    4. Set the width and height to your full canvas resolution
    5. Check "Shutdown source when not visible"
    6. If you want a new shuffle each time: check "Refresh browser when scene becomes active"
    7. Leave "Page permissions" set to "Read access to OBS status information"
  6. Rerun the executable when you add or remove videos or want to change any settings

Supported files

Video

  • mp4
  • m4v
  • webm
  • mpeg4

Audio

  • mp3
  • ogg
  • aac

Notes

  • VLC Source now supports "Shuffle playlist"
    • This may be a more stable alternative to this project
    • Mac's with M1 chip: Install the Intel version of VLC to use the VLC plugin
  • Set Refresh browser when scene becomes active
  • Video resolutions should match your canvas aspect ratio
  • Autoplay only works in OBS!
    • To test in your browser you must hit the Play button first
  • Pro tip: webm videos support transparency (convert mov to webm to save on file size)

Stuck? Or nothing happening?

  1. Try hitting Refresh cache of current page in OBS
  2. In OBS go to Scene Collection then New
    1. Add only your random video browser source and see if this works
    2. If it works, then theres an external issue. I have no idea what is causing this so, if you have any info on this us know in the discussions
  3. Enable remote debugging and open the page for the browser source
    1. Open Chrome Dev tools
    2. Application tab
    3. Make sure Local and session storage box is CHECKED
    4. Click Clear site data
  4. If issues persist: use GitHub Discussions or join the Discord server

TODO

  • Audio-only or video-only modes
  • Option for cross-fading between videos
  • Option to HTML background color
    • Good for videos with weird aspect ratio
    • Good for audio files
  • Switch to Bubble Tea instead of promptui

obs-random-videos's People

Contributors

jaredcat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obs-random-videos's Issues

No longer functioning after most recent OBS update

Hi! I've been using this to run a BRB clipshow for about six months with no issues, but it no longer appears to be compatible after the most recent OBS update. My suspicion is that a change to the browser source is preventing autoplay, but I don't have the knowledge-base to really dig in a find out for sure

Repeat?

Hey,

thanks for this script.
Do you think you could add a repeat feature?

Best
Tom

MAC Version Doesn't Generate HTML

Hey,

I've been using obs-ramdom-videos on Windows - including the latest version - fine for the past year or so, but can't get it to work on my Mac.

I've tested in a couple of different ways - including only using one video and changing directories - but the Mac version doesn't ever generate an HTML file.

Running Monterrey 12.6 on a MBP 16" M1 Max.

Happy to provide further information if needed.

Thank you

3.3.0 Checks more than just sub directories for files

In my setup I have several folders next to each other for different scenes such as Background Clips and BRB Clips, with their own generated html files. Seems its reading directories outside of the one it is in and not just sub directories.

[Feature request] Starting each video at random time

Hi, sorry to bother, just wanted to ask if it would be possible in the future to add a feature to start the videos at a random time. I often use timelapses of >1hr, and I'd be great if I could also shuffle the starting position of each video. No urgency of any kind, just wanted to ask if it could be added to the project.

Transition video between random files?

Hey,

I'm wondering if it'spossible to have a video file working as transition between the random files?
That would give us a nice cutting effect.

Example:

randomvid53
transvid
randomvi34
transvid
randomvid0459
transvid
randomvid349

Loop not smooth

I have a few videos and have them set to randomly loop 1 of the videos when I switch to the scene in OBS however I've noticed the videos don't loop smoothly, when the videos end I can see a split second stutter which isn't there if I add the videos using OBS's media option. Is this just a issue with html or is there a way of making the loop smooth when it loops?

Looping Introduces Black Frames Between Loops

First off, love the idea of this plugin! Thanks for creating it! I'm trying to use several video loops to make my starting soon scene unique every time. I've looped the files back to back in my video editing software and gone through frame by frame - there's zero noticeable gap when looped. However, when using this in OBS, there's a few frames of black that are introduced between the loops, making it very distracting and obvious when a loop occurs.

Any idea what might be causing this or ways to fix it? I've tried using both mp4 and mov file types - both have the same issue.

Nothing is working, blank white page in Chrome, nothing shown in OBS

Well Title pretty much says everything.

I hit yes for the 1st question and changed nothing in the code.

File Path:
const initMediaFiles = /** @type {string[]} */ (["D:\\ART\\000. OBS Recordings\\RENDER from VEGAS\\01. CAT GIRL - 2022-05-29 14-59-50.mp4", "D:\\ART\\000. OBS Recordings\\RENDER from VEGAS\\02. Girl With a GUN - 2022-06-08 20-09-40.mp4"]);

Not randomizing at all

It only randomizes when I reload quick enough. If i do it after the vid ended it will just play the first one over and over

Running 2 instances

Hi, I was just starting to use your script and was using in multiple scenes in OBS for different things. From what I can see it doesn't seem to support having it be used more in more then one spot due to the way it uses localstorage??

I made it work by manually adding

function getPlaylist() {
let playlist = [];
localStorage.clear(); // THIS IS THE LINE I ADDED
try {

Have you tried this or is it a known issue? I haven't dug into the code yet but I will probably download it and fix the issue. I can do a merge request if you like to have the fix to put into your code. You might want to fix it yourself of course. Or perhaps I am doing something wrong??

Thanks!

Not working on 27.2.3

Tried the latest release but it still has the same issue as the previous one for me.
Program properly detects all the videos and generates proper filepaths but the source is blank in OBS.

Keep Track of Recently Played Videos

Does the software have any algorithm to not repeat videos if one of the last 4-5 videos played? Like a list of what's recently been played that keeps cycling through what's in the list.

Nothing happens when executing exe file

Everything is in the title.

Btw, windows 10 pro here. I put exe in folder with all videos. When executing .exe the only thing that happens is the brief lost of focus on the exlorer window.

Audio jitter one source startup (Changing scenes)

I'm getting some really bad audio stuttering whenever the source actives. same when I change to my scene that has the source (I'm using it as a background music shuffler in my chatting screen). Not sure if it's because it's audio only and not for videos. Any help would be greatly welcome.

OBS Latest Update, MP3's don't play.

I used this to play random MP3s in the Intro and Outro on my stream and as per the title, with the latest OBS update this no longer works at all. Please let me know if you need anything else to help diagnose.

Getting error when playing in browser, and video freezes half way when playing in OBS

This has been working fine all along, but it stopped working this week. The videos would play halfway then freeze in OBS. And when I tried to play them through the browser, one plays then i get "Error loading: UNKNOWN SOURCE FILE ERROR"

I hadnt changed anything, so i deleted the app and downloaded the latest version and ran it again, same issue occurs.

Question: How good is the randomness?

Hey, thanks for this, it allows for really flexible ways to setup my stream!

The only thing I'd like to understand is regarding how effective the randomization actually is. I get the sense that my video order is fairly consistent across multiple refreshes. In my case I have a folder with 179 videos - I'd think that would be plenty for the algorithm to be effective. I took a look at the html source but I'm not math-savvy enough to make sense of the randomization formula running the show.

Could you offer some insight please? Thank you.

Small black screen when reloading video

Hey! I really love this, it's been a great help for my stream!

One tiny little thing - I have it to randomly select one video and loop it. However, when it loops, it cuts to a black screen for a second, then restarts the video. Is there a way to get rid of this cut so that it loops seamlessly?

Blank Screen only

Working fine in chrome but showing blank in OBS plz fix asap

<script> // @ts-check const mediaFolder = /** @type {string} */ ("C:\\Users\\shaik\\Desktop\\video\\"); const initMediaFiles = /** @type {string[]} */ (["Parrot - 21309.mp4", "Titmouse - 30486.mp4", "romantic_-_103946 (Original).mp4", "swans_-_3109 (Original).mp4", "tit_-_32959 (Original).mp4"]); const transitionVideo = /** @type {string} */(""); const playOnlyOne = /** @type {boolean} */ (false); const loopFirstVideo = /** @type {boolean} */ (false); const transitionVideoPath = /** @type {string} */ (`${mediaFolder}${transitionVideo}`);

let isTransition = true;

/**

  • shuffleArr takes in an array and returns a new array in random order
  • @param {any[]} a any array to be shuffled
  • @return {any[]} shuffled array
    */
    function shuffleArr(a) {
    var j, x, i;
    for (i = a.length - 1; i > 0; i--) {
    j = Math.floor(Math.random() * (i + 1));
    x = a[i];
    a[i] = a[j];
    a[j] = x;
    }
    return a;
    }

/**

  • prependFolderToFiles simply adds a folder path to a list of files and returns
  • the new array
  • @param {string} folder folder path, must end with a trailing slash
  • @param {string[]} files array of file names
  • @returns {string[]} new array with full path to files
    */
    function prependFolderToFiles(folder, files) {
    return files.map((file) => ${folder}${file});
    }

/**

  • storePlaylistState takes in a playlist and stores it into localstorage
  • @param {string[]} state
  • @returns {void}
    */
    function storePlaylistState(state) {
    localStorage.setItem('playlist', JSON.stringify(state));
    }

/**

  • getNewPlaylist creates a newly randomize list of files and stores it in
  • localstorage
  • @returns {string[]} a new playlist
    */
    function getNewPlaylist() {
    const playlist = prependFolderToFiles(
    mediaFolder,
    shuffleArr(initMediaFiles),
    );
    storePlaylistState(playlist);
    return playlist;
    }

/**

  • getPlaylist will get the playlist state form localstorage or create a new one
  • @returns {string[]} current playlist state
    */
    function getPlaylist() {
    let playlist = [];
    try {
    playlist = JSON.parse(localStorage.getItem('playlist'));
    } catch {
    console.log('playlist empty!');
    }
    if (!playlist || playlist.length === 0) {
    playlist = getNewPlaylist();
    }
    return playlist;
    }

/**

  • progressPlaylistState removes the last item from the playlist and stores the
  • updated version in localstorage
  • @returns {void}
    */
    function progressPlaylistState() {
    const playlist = getPlaylist();
    playlist.pop();
    storePlaylistState(playlist);
    }

/**

  • getNextPlaylistItem returns the next item in the playlist unless it matches
  • the last thing played then it moves that item to the end and returns the
  • next item after that
  • @returns {string} the next item in the playlist
    */
    function getNextPlaylistItem() {
    const playlist = getPlaylist();
    let mediaItem = playlist.pop();

// check if we played this mediaItem last run
console.log({ lastPlayed: localStorage.getItem('lastPlayed'), mediaItem });
if (localStorage.getItem('lastPlayed') === mediaItem) {
// moves the repeated item to the end so its not skipped entirely
storePlaylistState([mediaItem].concat(playlist));
mediaItem = getNextPlaylistItem();
}
return mediaItem;
}

/**

  • playNext is the core function of this project and handles the loading and
  • playing of the alternating video players
  • @param {HTMLMediaElement} player currently playing video player
  • @param {HTMLMediaElement} nextPlayer the next video player to be played
  • @returns {void}
    */
    function playNext(player, nextPlayer) {
    const currentMp4Source = player.getElementsByClassName('mp4Source')[0];
    const nextMp4Source = nextPlayer.getElementsByClassName('mp4Source')[0];
    const currentVideo = currentMp4Source.getAttribute('src');
    if (currentVideo !== transitionVideoPath) {
    localStorage.setItem('lastPlayed', currentVideo);
    }

let video = localStorage.getItem('lastPlayed');
if (!loopFirstVideo && (!transitionVideo || !isTransition)) {
video = getNextPlaylistItem();
console.log(next video: ${video});
}

// TODO: we can use this opacity to crossfade between mediaFiles
player.style['z-index'] = 1;
player.style['opacity'] = '1';
nextPlayer.style['z-index'] = 0;
nextPlayer.style['opacity'] = '0';

if (transitionVideo && transitionVideo !== '' && isTransition) {
video = transitionVideoPath;
isTransition = false;
} else {
isTransition = true;
}
nextMp4Source.setAttribute('src', video);
nextPlayer.load();
nextPlayer.pause();

if (playOnlyOne) {
// Remove videos after playing once
player.onended = () => {
currentMp4Source.removeAttribute('src');
nextMp4Source.removeAttribute('src');
player.load();
nextPlayer.load();
};
}

player.play();
}

</script>
<style>
  html,
  body {
    margin: 0;
    padding: 0;
  }
</style>
<script> // @ts-check const player = /** @type {HTMLMediaElement} */ ( document.getElementById('videoPlayer1') );

const player2 = /** @type {HTMLMediaElement} */ (
document.getElementById('videoPlayer2')
);
player.addEventListener(
'ended',
() => {
if (!loopFirstVideo) {
progressPlaylistState();
}
playNext(player2, player);
},
{
passive: true,
},
);
player2.addEventListener(
'ended',
() => {
if (!loopFirstVideo) {
progressPlaylistState();
}
playNext(player, player2);
},
{
passive: true,
},
);

/***** Initial load *****/

const mp4Source = player.getElementsByClassName('mp4Source')[0];
let video = getNextPlaylistItem();
// have to move the state forward after getting the first video
progressPlaylistState();

mp4Source.setAttribute('src', video);
player.load();

playNext(player, player2);

</script>

Not work

OSB version: 28.1.2 (windows x64)
Autoplay doesn't work at all

Issue handling of some special characters (like #)

Proposed solution:
"#" should be converted to %23

Browser error text:
Error loading: file:///X:/Video%20Projects/Uploaded/2022-11-26%2021-38-26%20-%20Maxell%20#1%20-%20Huntington.mp4

Console error:
obs-random-videos.html:240 Error loading: file:///X:/Video%20Projects/Uploaded/2022-11-26%2021-38-26%20-%20Maxell%20#1%20-%20Huntington.mp4 errorFunction @ obs-random-videos.html:240 error (async) (anonymous) @ obs-random-videos.html:219

Screenshot:
Capture

Support additional (or custom) file types

Would it be possible to add support for other file types (namely MKV for video and FLAC for audio) to this tool? Most of my sources are encoded to either of these two formats and I'd like to avoid transcoding them if possible.

Currently I work around this limitation by duplicating my files into a new directory and renaming them (eg. renaming all my FLAC files to OGG) and it works well, but it'd be nice if this was a native feature. Alternatively, perhaps a better solution would be to allow a user to specify an additional custom extension to scan for to prevent any similar situations to this.

Regardless, thank you for this fantastic and incredibly useful tool!

Scan subfolder

Hello,

Given that for hard-drive management purpose we are all driven to sort things in folders, a sub-folders scanning would be highly appreciated.

2022-01-17_18h12m23s_obs-random-videos

Also, the possibility to link to nodes that are outside the actual scope would help to gather different locations that can be scattered around a hard-drive without possibility to be children of the same parent.

Ex :

  • D:\folder1\folder2\folder3
  • E:\folder4\folder5
  • F:\folder6\folder7\folder8\folder9
  • etc...

This would require a CFG to run the project instead of simply copying it in a folder where it's supposed to collect videos from. (and thus, it would be managed as a real program that we could install anywhere, like in C:\Program Files).

Lost and I don't know how

Maybe you could have better luck figuring out why nothing worked for me? I went through all your listed steps and added everything to OBS as noted, but it never so much as played one of these and I'm lost as to why (and yes, the index is in the same folder as my music)

2021-04-21_04-10-53

Little problem of video display

Hi,
First of all, great plugin, even if i have a problem i looked your code and it was nicely done with comments.
It's the only plugin i found to do the work this easily.

Unfortunately, if it seems that i follow your instruction, i'm facing a problem. When i launch the browser source in OBS studio, the plugin seems to be correctly called as i get the sound of the random video. But only the sound is running.

I don't where the issue could come from. I stored only MP4 files, no complicated names (i checked and the names seems to be correctly stored int he HTML file).

Could you help me on that?

If it can help you, my default browser (firefox) seems not to be able to read these videos either.

Thanks in advance for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.