Streaming large video files from the server to the client which might be a web app or mobile apps inefficient manner!
We can’t send the entire video once to a client. because there are conditions like the bandwidth and data restrictions of the user.
Let’s say youtube, the user may watch some part of the video and went away for some reason, if he opened that video again, it should not load the entire video from start.
Here is the part we need some mechanism to handle this situation.
Nodejs stream API comes into picture, its more efficient than reading a file in conventional manner and waiting for the callbacks to resolve.
Created a basic video streaming server to explain it little better.
User visits the site (index.html)
The html5 video component in index.html is pointed to URL of the video that is streaming by server
The video request is handler by the server by processing range header and sends out part of the video as partial content
The flow of the system:
mkdir <project name>
cd <project name>
npm init -y
Open your favourite text editor
Create index.html on that folder (check below html code, use it there)
Create a server.js file(check the js code provided below)
Run the command “node server.js”
Open browser and navigate to “localhost:3000”
Setting up project:
Complete source code:
we will need a index.html file show the video that coming from the server!
Finally we can see the result in the browser
- foreach() loop vs Stream foreach() vs Parallel Stream foreach()
- How to open a PDF files in web browser using PHP?
- Creating a dataframe using Excel files
- Deleting all files from a folder using PHP
- How to include() all PHP files from a directory ?
- Perl | Creating Excel Files
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?
- HTML | DOM Input FileUpload files Property
- How to upload files asynchronously using jQuery?
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Perl | Reading Excel Files
- Minification of CSS files
- How to count files in a directory using PHP?
- Writing CSV files in Python
- SASS | Use variables across multiple files
- How to Select Multiple Files using HTML Input Tag ?
- How to store deployment configuration files in Node.js ?
- How to Import another TypeScript Files ?
- How to keep compiled files in a separate directory ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.