Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Image compression for network transmission  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

Bernhard

  • Newbie
  • *
  • Posts: 3
    • View Profile
Image compression for network transmission
« on: July 16, 2015, 04:55:26 pm »
Hello,

I'm using SFML's Image class to hold some graphics data. It's in an uncompressed format, just raw bytes when I create an Image with it. I need to figure out a way to send a lot of these images quite rapidly over a network connection (I was thinking of using SFML's TcpSocket class). Is anyone familiar with any good tools for compression/encoding of images and ways to transport them in a smaller format over a network connection? I need to transmit about 50 images per second, each one is about 4MB uncompressed.

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10988
    • View Profile
    • development blog
    • Email
Re: Image compression for network transmission
« Reply #1 on: July 16, 2015, 06:04:53 pm »
You first should think about whether something like this is feasible with your connection and the fact that data transfer is never fully error free.

An uncompressed image of 4 MiB has about a resolution of 360x360. Taking a random image (from Pioneers) I just had lying around and compress it loss-less as PNG I get 202 KiB, so your connection must be able to upload (and download) 202 KiB * 50/s = 9.9 MiB/s (100 Mbit/s connection).
If I use lossy JPG with 70% quality rating I get 26 KiB, so your connection must be able to upload (and download) 26 KiB * 50/s = 1.3 MiB/s. But obviously the quality of a 70% JPG is quite bad (see below).

Do you have such an upload and download speed? If not then it's not even worth thinking on this further.
If yes, well send over the compressed file and not the raw image and I'm sure there will be many more obstacles, like TCP up-spin or resending packets, etc.

What you probably want is a proper video compression and only go with 50 frames per second if you really have to. What are you trying to achieve anyways?
« Last Edit: July 16, 2015, 06:06:38 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Bernhard

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Image compression for network transmission
« Reply #2 on: July 16, 2015, 08:06:09 pm »
Thanks. It's being transferred between computers on a gigabit LAN, so the bandwidth is substantial.

System Layout:
- 4 client computers, each one captures every rendered frame from an application running on them as a byte array (about 15hz each)
- 1 server, which needs to receive all of the frames from each of the 4 client computers and then do some image processing stuff with them

I know it's a strange setup, but it's a very strange and specific application where a change to the architecture is not possible. Some sort of video streaming solution with built-in compression/encoding would be nice, and have a stream from each client to the server. The server could then have a thread for each video stream it receives.

For each image frame, there's also some non-image metadata that needs to be sent with it.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Image compression for network transmission
« Reply #3 on: July 16, 2015, 10:48:10 pm »
If you need something that runs fast per frame and provides decent compression for images, then try LZO.
I've used it in the past for doing image compression for real-time streaming and it performed pretty well. It doesn't give as high compression ratios as other algorithms (like zlib, bzip2, lzma, etc) but it compresses reasonably well and does so in a fraction of the time of the competition (which is important when you stream real-time).

 

anything