Streaming webm video using lighttpd memory usage - streaming

I have a folder of webm videos on my website and I would like to stream them.
When you go to mysite.com/media/video.webm you get a firefox native webm video player and the video is streaming correctly.
The server only has 512MB memory and while the video is streaming all free memory disappears. (from 300MB to only 16MB of free space)
The video is just read from the file, but I think the entire video gets cached while it is viewed.
How do I stream a video via lighttpd without loosing all my memory?

In lighttpd.conf, use server.network-backend = "sendfile"
If you have a CGI or FastCGI or SCGI backend that is serving the file to lighttpd, then modify those scripts to return X-Sendfile: /path/to/file.webm and configure mod_cgi, mod_fastcgi, or mod_scgi to accept X-Sendfile response header from backends.
In any case, lighttpd 1.4.40 and later put large responses from backends into temporary files, so the server memory usage should remain low, regardless of the size of the files being served.

Related

How would you build a back-end that accepts video .mp4's from an input form on the front-end?

React/Next front-end + Node.js and MongoDB on the back?
How would video storage work?
You can use post requests to send files to your remote server. You backend code should read request data and then store the file onto the disk or any object storage like s3. Most backend web frameworks have many libraries to store files received in an HTTP request directly to s3
Most of the web development frameworks have the capability to guess the mimetype but here since you know it's video/mp4 you can just save it.
I must warn you if you are trying to upload huge files it might be a better idea to use chunked uploads. This gives you ability to pause and resume and is robust to network failures.

Is this video being cached or not?

I'm wanting to ensure that videos I'm serving are being cached by the browser.
I've knocked up this test page : https://itype.online/videoCacheTest
I'm a bit puzzled about why I'm not seeing a 304 status in the Network tab for the video. Instead I see status 206.
Is my file being retrieved from the browser cache or is it coming from the server every time?
Thanks,
Peter
The link you shared appears broken (there are some cloud availability issues at this time so maybe that is the problem) but its possible to test with other videos and similar behaviour will be seen.
Its worth looking at the most common ways of streaming a video:
Simple HTTP streaming of a single video file
streaming via a dedicated streaming protocol like HLS or MPEG DASH
For simple HTTP streaming, the video file is typically downloaded using byte range requests. In theory, so long as the cache can handle range requests then the cache should be ok to cache the responses - from the HTTP caching spec (RFC 2616 Fielding, et al):
A response received with a status code of 200, 203, 206, 300, 301 or 410 MAY be stored by a cache and used in reply to a subsequent request, subject to the expiration mechanism, unless a cache-control directive prohibits caching. However, a cache that does not support the Range and Content-Range headers MUST NOT cache 206 (Partial Content) responses.
In practice, it seems that many browsers still do not cache the 206 responses as you have seen. It is made more difficult to observe the behaviour sometimes as some browsers, to speed up download, may add a first request for the full video initially, which is then cancelled and replaced by range requests when the video length is known.
HLS and DASH introduce a further complexity - with ABR you create multiple bit rate versions of the video on the server, each broken into chunks. The player decides which resolution to download the next chunk of the video from based on a number of factors, typically including network conditions and device display size and capabilities.
So when HLS or DASH is being used, replaying a video will not necessarily download the same chunks every time as network conditions etc may have changed.
You can usually see on the browser inspector if a particular item is downloaded on the network or loaded from memory/cache - for example with Safari web inspector:
And for Chrome:
You could also use Wireshark is you want to be 100% sure - this will show the network traffic to and from your device: https://www.unified-streaming.com/academy

Playing a streamed data from the server on a client software

I'm trying to plan a learning curve for a nodeJS module that streams all my output sounds to a server. Say I have a nodeJS module that forwards all outgoing sounds and music as packets to the server's port 8000. How can I connect some client's mp3 player to playback the streaming audio formats from the server? I mean the buffer that is sent is just raw messy bits, how to make my audio player on the client recognize the format, connect to the stream, forward the packets to the player etc.
You (I) need to open up a file, meaning by that a resource through POST request's answer and transmit to that file chunks of data from your original video resource according to the indices[ranges] the request asks for. So the request asks for data at xyz (just in an additional field) and tries to download resource Z and you constantly fill that resource with data so that it is always full.
This is a rather complex topic but there are many examples and documentation already available.
Just doing a quick search these came out:
node (socket) live audio stream / broadcast
https://www.npmjs.com/package/audio-stream
By the way, I'm not an expert but I think if you want to do audio streaming probably mp3 is not the right choice and you may get some benefit if you convert it to an intermediate streaming format.

Fiddler consumes data even when the streaming tab is closed in the browser

I am new to Fiddler.
But when I developing a tool I noticed a strange thing when Fiddler is running.
I go to a particular steaming link that has a .mp4 file from my web browser and just after viewing a little part of the video (still not whole video is buffered), I close the tab.
But I see that Fiddler process continues to consume some data even though I do not do any thing after that. Seems it downloads whole streaming file although I close it. Consumes more data when the link time is higher.
I can see the bandwidth consumption and data consumption through traffic monitor that fiddler process consumes data.
This does not happen for every streaming site it seems. And it only happens when the fiddler is open for this problematic site.
I get this problem either the streaming button is enable or not (if that has any connection)
Do we have any option to disable this in Fiddler?
Tools > Fiddler Options > Performance. Adjust the Streaming dropdown as desired.

JPG Images as Fallback fom RTMP Live Streaam

I would like to offer a few Live broadcast to users who don't support any of the available Streaming protocols as auto refreshing JPG's.
I got the idea to use ffmpeg (or mjpg_stramer) to extract two frames per second from the RTMP Live Stream base64 ecndoe it and load them by JavaScript at half second interval, but with 5-50 concurrent streams this is a hard job for the Server.
What would be the best way to get from multiple RTMP Live Streams two (or more) images per second as Base64 encoded JPG?