This article provides a comprehensive guide on implementing video streaming and segmentation using Node.js and React.js, including setting up a React application with a video player and creating an Express.js server to handle video streaming in chunks and segmented video (m3u8).
Abstract
The article delves into the process of streaming video content over the web using Node.js and React.js technologies. It covers the creation of a React.js front-end application that interacts with a Node.js server to stream video in different manners: as a continuous stream and as segmented video using the m3u8 format. The author guides the reader through setting up the project structure, implementing back-end functionalities with Express.js, and using libraries such as fluent-ffmpeg for video segmentation. The article also touches on deploying the application on platforms like Netlify and provides access to a GitHub repository with the complete code example.
Opinions
The author emphasizes the practicality of using Node.js for video streaming, showcasing both Express.js and native Node.js streaming capabilities.
There is a clear preference for using fluent-ffmpeg to abstract the complexity of ffmpeg command-line tools for video segmentation.
The article suggests that developers can benefit from using the provided project template and GitHub repository to expedite their development process.
The author values the ease of use of the vime-js player for React applications and recommends it for handling video playback.
There is an opinion that deploying such applications on services like Netlify can be straightforward, even for beginners.
The author encourages readers to explore their other articles for additional learning and development resources.
Node.js. Video streaming, and segmentation in Examples
In this article we will take a look at how we can send a video as a stream (in chunks), and as a segmented video (m3u8). Additionaly we will create a React.js app with “vime-js” (not vimeo) player.
What we will be implementing
This is how our React.js page will look like fetching data from our Node.js server:
/segments/:segment → will return a file002.ts (as example) from assets/segments folder
React application
At first, add vime player to your dependencies:
yarn add @vime/react
Next, update App.ts file with this code:
Basically, we have three Players:
Chunks and File players requesting a video file from a server in a “simple” way → fetch video file by a link;
Segments players work a bit differently → it fetches m3u8 list with the segment file names and timecodes at first and then file by one at a specific time
⚠️ NOTE: You can check my other article, if want to know how to deploy this app on Netlify: