Online video website based on IPFS video storage

Video online playback website based on IPFS distributed storage network

Project code cloud address: https://gitee.com/baldness_and_coldness/ipfs_streaming

1. Introduction to IPFS

IPFS is a brand-new hypermedia text transfer protocol. The target is Http hypertext transfer protocol. However, unlike the Http protocol, the IPFS protocol is a decentralized protocol.

What is decentralization?

Centralization and decentralization

Centralization : All data is stored in the central server, and all clients need to request services from the central server.

Advantages : high data security, easy to implement functions

Disadvantages : highly dependent on the central server, prone to single point of failure, performance bottlenecks

Decentralization : Any node that joins the network is both a client and a server, and all nodes have equal status

Advantages : The network phase is more stable and the performance is better

Disadvantage : complex communication protocol design

2. Project introduction

Use the IPFS distributed storage network to store video data, and realize the functions of video upload and online playback through the browser.

3. Project structure

architecture diagram
It mainly includes three parts: browser page , Node.js server and IPFS network .

4. Project installation

1. Install ffmpeg
(refer to https://blog.csdn.net/chy466071353/article/details/54949221 )
2. Install ipfs
(refer to https://blog.csdn.net/lhx0525/article/details/103528680 )
3. Initialize ipfs and run ipfs daemon to start the daemon process
4. npm install installs related dependency packages
5. npm start runs the project
6. Browser URL: http://localhost:3000/
Effect picture 1Effect picture 2

5. Project process

upload video

Since the uploaded video needs to be played online more smoothly, the video is sliced ​​and processed according to the HLS protocol, and the specific implementation is completed by the ffmpeg toolkit.

1: The browser uploads the video to the server
2: The server divides the uploaded data into blocks, and then sends it to the IPFS network
3: After the IPFS network completes the data storage, it returns the corresponding unique Hash code to the server, and the server persists it to generate the corresponding m3u8 file.
IPFS data

(The relevant code for uploading videos is in the server.js of the project)
play video

1. The browser initiates a request to the server, and finds the response index file .m3u8 through the video name
2. The server returns the index file
3. The browser requests the corresponding file in .m3u8 from the IPFS system
4. IPFS returns TS data

(Related codes for online video playback are in the project's play.js and app.js)

The core of the project is:

1. Use ffmpeg to split and play video

2. Through the js toolkit ipfs-api, use the js code to operate the IPFS network.

Due to limited resources, no independent database is introduced, and the m3u8 file can only be persisted on the Node.js server.

If possible, you should build an independent database, save all m3u8 files and ts files to the IPFS network, and save the access connection of the m3u8 files to mysql.

This can greatly speed up the access speed, and at the same time, it is easier to implement functions such as sorting by clicks and hot list

Guess you like

Origin blog.csdn.net/awsl_6699/article/details/123505190