Importing Live Internet Video in Processing

#1

Hi there, I was just wondering if it is possible to import a live internet video feed from the following weblink into Processing:

Ultimately I wish to manipulate the live video but for now I would just like to import it into the Processing window.

Thanks for you help.

#2

If the direct video link is http you should be able to pass it in where you’d normally pass the file in Processing Video’s Movie class. For some reason the url protocols are restricted. You could also use PraxisLIVE - the video library there doesn’t have that restriction.

#3

Thanks for replying. So you’re saying because the link has some restrictions, there’s no way I can bring it into my Processing sketch?

#4

I have no idea without digging into the source of that webpage and finding the actual link to the video stream.

#5

https://hddn01.skylinewebcams.com/live.m3u8?a=pg04frmj4t7csjlsufthoqsqm1
i could open in VLC

#6

I think it works as http too so you might be in luck. Use a Movie example from the Video library and pass in that link (as http not https) instead of the filename. Does it work?

#7

I’m new to all this, not sure where in the code I should paste the http link. The video library examples all read from an existing video file.

#8

In place of the file name. eg. In the Loop example in place of "launch2.mp4" put "http://<whatever the link is>"

#9

Thanks for replying, I’ve tried that but nothing is playing in my sketch. Here is the code, I don’t know if I’m doing something wrong:

import processing.video.*;
Movie syn;

void setup() {
  fullScreen();

  syn = new Movie(this, "http://www.skylinewebcams.com/en/webcam/ellada/atiki/athina/ermou-street-syntagma-square.html");
  syn.loop();
  syn.read();
}

void draw() {
  image(syn, 0, 0);
}
#10

Not the .html link, the .m3u8 link that was posted earlier.

#11

Just tried it but it still doesn’t work, any idea why?

import processing.video.*;
Movie syn;

void setup() {
  fullScreen();

  syn = new Movie(this, "http://hddn01.skylinewebcams.com/live.m3u8?a=pg04frmj4t7csjlsufthoqsqm1");
  syn.loop();
  syn.read();
}

void draw() {
  image(syn, 0, 0);
}
#12

The link has changed - it’s now https://hddn01.skylinewebcams.com/live.m3u8?a=udnt3mth5bdqbntskbrg6n1o43

The problem you’ll have is finding the link each time. It will probably change every few hours. I used a Linux CLI tool called youtube-dl to extract the link. It’s currently working in PraxisLIVE with GStreamer 1.x so should work with Video Library v2 beta if not v1.

#13

If the page url is stable, and the form of the link is stable – but the subdomain and suffix changes all the time – then you can retrieve the url dynamically at run time using a regex. Something like this:

String[] pageHTML = loadStrings("http://www.skylinewebcams.com/en/webcam/ellada/atiki/athina/ermou-street-syntagma-square.html");
String camURLpattern = "'(https://hddn)(\\d*)(.skylinewebcams.com/live)(.*?)(.m3u8)(.*?)'"; // pg04frmj4t7csjlsufthoqsqm1"
String[] m = match(join(pageHTML, ""), camURLpattern);
String camURL = m[1] + m[2] + m[3] + m[4] + m[5] + m[6];
println(camURL);

As long as the url follows the pattern you specify, the code will pick it up – assuming you can then load the live video directly with processing.video (untested).

#14

Try the IPCapture library that you can install in Processing using the Contribution Manager. Unsure if it will work with your video format but worth checking: https://processing.org/reference/libraries/

Kf

#15

@jeremydouglass that depends on the link being in the HTML source, which as far as I can tell it isn’t or I wouldn’t have needed to use youtube-dl in the first place :smile: It’s a blob uri. I had a quick look and couldn’t find any easy obvious way to extract it in Processing. eg. https://stackoverflow.com/questions/42901942/how-do-we-download-a-blob-url-video

@kfrajer as far as I can tell that library says it’s just for MJPEG? Which would make sense if it’s pure Java. The Video library should be able to play this, GStreamer certainly is fine, but getting the actual link is more “fun”.

@kll How did you get the link when you first posted?

#16

i dig website with inspect ?media? …
but when i call it in browser a download started.
when i click that: vlc started and show the stream
for a few seconds. reloading the same link does not work,
must run program again to get a new “a=xxxxx”

that way can find it, BUT not show it??

again call browser, get download, click VLC works

String theURL = "https://www.skylinewebcams.com/en/webcam/ellada/atiki/athina/ermou-street-syntagma-square.html";
String thestart = "https://hddn01.skylinewebcams.com/live.m3u8";
String theend = "'},";
String[] incoming;
int srcindex, srcend;
String line,picsrc;
PImage found;
boolean foundone = false;

void setup() {
  size(400,400);
  incoming = loadStrings(theURL);
  //printArray(incoming);

  for (int i=0; i<incoming.length; i++) {
    srcindex=0;
    srcend=0;
    line = incoming[i];
    srcindex = line.indexOf(thestart);
    if ( srcindex > 0 )//&& srcend > 0 && srcend > srcindex) 
    {
      picsrc   = line.substring(srcindex);                        // use second part
      srcend   = picsrc.indexOf(theend);                          // search end in that part only
      println("i "+i+" srcindex "+srcindex+" srcend "+srcend);
      picsrc = picsrc.substring(0, srcend);                       // cut of rest
      println(picsrc);
      //found = loadImage(picsrc);
      foundone = true;
    }
  }
}

void draw() {
//  if ( foundone ) image(found,0,0);
}
#17

Maybe I misunderstood. When you run my 5-line sketch above, it loads the skylinewebcams page, finds the latest .m3u8 url with the ?a= suffix, which is in the page, and prints it. This is the one you referred to when you said “The link has changed […] The problem you’ll have is finding the link each time.”

Not familiar with “blob URI” – if the m3u8 url isn’t what is needed, then apologies for the confusion.

#18

Sorry, you’re right. I only inspected the page in the browser and found the blob URL in the video element, which is normally for hiding things. Didn’t realise the .m3u8 URL is in the script element. Lousy hiding, but it fooled me! :smile:

So putting it all together, with Video library v2 beta, replacing the gst1-java-core-0.9.1.jar file with the latest gst1-java-core-0.9.4.jar (there’s a bug), adapting to force a http URL (because https gets filtered in the Video library), and using the system installed GStreamer on Ubuntu 18.04 we can get it to work. :sweat: Whether it works with any other combination remains to be seen.

import processing.video.*;
Movie syn;

void setup() {
  size(640,480);
  String[] pageHTML = loadStrings("http://www.skylinewebcams.com/en/webcam/ellada/atiki/athina/ermou-street-syntagma-square.html");
  String camURLpattern = "'(https://hddn)(\\d*)(.skylinewebcams.com/live)(.*?)(.m3u8)(.*?)'";
  String[] m = match(join(pageHTML, ""), camURLpattern);
  String camURL = "http://hddn" + m[2] + m[3] + m[4] + m[5] + m[6];
  println(camURL);
  syn = new Movie(this, camURL);
  syn.play();
}

void draw() {
  if (syn.available()) {
    syn.read();
  }
  image(syn, 0, 0, width, height);
}

2 Likes