Youtube livestream help

Hello everyone!

I didn’t think this would be possible at all, but it works, for a few seconds…

I would like to play a youtube livestream within processing. I’ve installed the vlcjvideo library, as well as VideoLAN. The “basic” example, works great, but it is not a youtube video. If I enter a youtube video it will play (at low quality) for a few seconds, but then turn into a series of strange horizontal bars. It looks like it’s starting out in low res, but then switching to hires after about five seconds, and maybe processing can’t handle that. This behavior is present when playing within VLCPlayer as well, but that program handles it without a problem. You used to be able to edit the URL to force a resolution from the start, but that doesn’t seem to work anymore. Can anybody get this to work? Thank you very much!

//A basic example

import VLCJVideo.*;

VLCJVideo video;

void setup() {
  size(640, 360);
  video = new VLCJVideo(this);
  video.openAndPlay("https://www.youtube.com/watch?v=DHUnz4dyb54");
}

void draw() {
  background(0);
  image(video, 0, 0, width, height);
}

So, I have not managed to get this to work through processing code alone, but, I did come up with a workaround that works.

The problem certainly is that the youtube feed always starts out at one resolution, and then switches to a higher one (depending on connection speed I think). This resolution change freaks out processing, which I don’t understand because I would think that defining the width and height would preempt any issues, but that not enough apparently.

So, my workaround is to install GStreamer and run OBS in virtual webcam mode. Then I “connect” to that virtual webcam and it plays without issue.

2 Likes

Cool beans!

Answers my question:

Can you provide details on hardware and software versions?

:)

Sure.

Thinkcentre M920q, Windows 11, NVIDIA Quardo 400
Processing 4.3.4
OBS 31.02
GStreamer 1.26.0 (Download GStreamer) (may require restart)

OBS Notes:
install OBS and when prompted, setup as virtual webcam
Add youtube address as a source.
I played with various OBS settings, but nothing that I believe was critical.
Start the virtual Cam and then run the code below:

import processing.video.*;

Capture cam;

void setup() {
  size(800, 600); 

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    cam = new Capture(this, width,height,cameras[0]); //for me, [0] = OBS Virtual Camera
    cam.start();     
  }    
  
  background(0);
  
}//setup

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  
  
  //image(cam, 0, 0);
  // The following does the same, and is faster when just drawing the image
  // without any additional resizing, transformations, or tint.
  set(0, 0, cam);
}
1 Like

And I tried your code. It worked fine for me.

1 Like

That being said, this solution is far from ideal, I’d like to just handle everything within the code.

So, unfortunately, after getting this to finally work, now I cannot play videos with video library (4) installed. I get errors like this even when trying the simple loop example file:

The specified module could not be found.

Native library (win32-x86-64/swresample-3.dll) not found in resource path (C:\Users\vislab\AppData\Local\Temp\processing\Loop_test5861263251825668802temp;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\core.jar;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\gluegen-rt.jar;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\jogl-all.jar;C:\Users\vislab\Documents\Processing\libraries\video\library\gst1-java-core-1.4.0.jar;C:\Users\vislab\Documents\Processing\libraries\video\library\jna.jar;C:\Users\vislab\Documents\Processing\libraries\video\library\video.jar)
Processing video library using system-wide GStreamer 1.26.0

(Processing core video:10760): GStreamer-WARNING **: 10:55:39.714: Failed to load plugin 'C:\Program Files\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstd3d11.dll': The specified module could not be found.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.

When I follow the path to see if the .dll’s are there I do indeed find them there, so I don’t understand what GStreamer’s problem is…

Gstreamer is the problem.

I have installed and reinstalled only the 64bit version several times (and restarted), but based on the errors I last posted it looks like processing thinks that there is a 32 bit version installed and is trying to find files in the wrong path location.

I haven’t figured out how to fix this yet.

Every time I uninstall Gstreamer, those errors go away, and processing will play videos again. But actually need Gstreamer so that I can play videos locally on my hard drive AND streaming from YouTube.

EDIT with possible solution:

MAYBE it’ll be OK now. I tried uninstalling, rebooting, then installing an older version of Gstreamer (1.22), then rebooted again. No change. However, I then redownloaded/reinstalled the video for processing 4 library and now streaming and local video playback works as it should, though there are still some errors that I will add below. If I understand this correctly, I think there are two things here, the separate/dedicated GStreamer .MSI file from the GStreamer website, that will install it on your computer, but there is ALSO a version of GStreamer built into the video for processing 4 library. So, the order that you install them may matter so that processing looks for files where it should. But I could be wrong.

These are most of the errors that still exist:

Native library (win32-x86-64/libfreetype-6.dll) not found in resource path (C:\Users\vislab\AppData\Local\Temp\processing\ERT_2b479082329369542490temp;;C:\Earth in Real Time\ERT_2b\code\video.jar;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\core.jar;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\gluegen-rt.jar;C:\Users\vislab\Downloads\processing-4.3.4-windows-x64\processing-4.3.4\core\library\jogl-all.jar;C:\Users\vislab\Documents\processing\libraries\video\library\gst1-java-core-1.4.0.jar;C:\Users\vislab\Documents\processing\libraries\video\library\jna.jar;C:\Users\vislab\Documents\processing\libraries\video\library\video.jar)
can't load library libtheora-0 (libtheora-0|liblibtheora-0|liblibtheora-0-0) with -Djna.library.path=C:\gstreamer\1.0\msvc_x86_64\bin. Last error:java.lang.UnsatisfiedLinkError: Unable to load library 'libtheora-0':
The specified module could not be found.

The specified module could not be found.

The specified module could not be found.

(Processing core video:2928): GStreamer-WARNING **: 13:45:54.378: Failed to load plugin 'C:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstwebrtc.dll': The specified module could not be found.
This usually means Windows was unable to find a DLL dependency of the plugin. Please check that PATH is correct.
You can run 'dumpbin -dependents' (provided by the Visual Studio developer prompt) to list the DLL deps of any DLL.
There are also some third-party GUIs to list and debug DLL dependencies recursively.
Processing video library using system-wide GStreamer 1.22.12