0

I am currently using Socket.io to sort of "stream" video from a Java game application to a ReactJS website. It's pretty slow, and a little janky, but it works.

The programs work by taking a screenshot of the game with Java, compressing it to JPEG, then sending the compressed, Base64 string over Socket.io to the server. The server then sends this Base64 string to the web client (ReactJS), which then renders the Base64 string as an image using CSS.

This method works. I can control the framerate (to an extent...it runs my CPU through the roof if I use 60 FPS or higher), and I can definitely control the compression of the JPEG (the quality of the image).

It does have its limitations though, and I'm still convinced there's a better way of going about this. I've looked on google for a way to stream video from one application to another, but I haven't found one.

What is the best approach to streaming a game, in a Java client, to a website, in ReactJS?

Jeff smith
  • 147
  • 7

1 Answers1

0

This is not a way to go!

Streaming codecs are much more effective than JPEG screenshots. For example, any movie compression alghorithm adjusts itself based on available bandwidth and does not keep all the frames. In your case you're rendering all the frames for your game, which kills your machine performance (JPEG rendering is much more power-hungry than rendering a proper video).

Another thing - you should just stream the content as it is, by sending stream of data instead of using base-64, providing a constant stream of video footage.

So, final solution would look somewhat like that:

  1. Capture the view, using FFMPEG library
  2. Create stream out of captured footage
  3. Expose stream via socket
  4. Get binary output on the other side of the network
  5. Probably, just use HTML5 player that should support all the popular encoding/streaming formats.

These links may be helpful to start with:

And something in this thread: Stream video in Java

SzybkiSasza
  • 1,591
  • 12
  • 27
  • Not sure why anyone downvoted you, this answer is absolutely correct. – Brad Dec 08 '17 at 04:22
  • I'm looking for a solution that doesn't use any 3rd party systems, like ffmpeg. My program will be shipped by itself, and I don't want to make the users have to download ffmpeg to even let the program run. Any other solutions you can think of? Xuggler doesn't work, the videos it produced for me were unreadable, even after using their example class, I still got a blank video output. – Jeff smith Dec 11 '17 at 04:32