Giter Club home page Giter Club logo

wsd1 / node-tcp-streaming-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kmoskwiak/node-tcp-streaming-server

0.0 0.0 0.0 4 KB

很好的测试项目:nodejs构造了一个express服务器,支持websocket,同时还打开了9090端口,通过tcp可以接收ffmpeg注入的vp8流。视频转发到websocket的客户端浏览器上,并被播放出来。这是一个简单而又全面的前后端视频应用的测试项目。Experimental TCP video streaming server written in node.js. Streaming over TCP and redistributing using WebSockets.

JavaScript 78.02% CSS 5.22% HTML 16.76%

node-tcp-streaming-server's Introduction

Streaming Video over TCP and WebSockets with node.js

This is experimental streaming server in node.js. Ingest stream is sent over TCP to server then it is redistributed to all clients over WebSockets.

Ingest stream

FFMPEG can be used to ingest stream. In this example I use v4l2 to caputre camera on linux.

-f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0

VP8 (using libvpx)

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0  -vcodec libvpx -b:v 3500k -r 25 -crf 10 -quality realtime -speed 16 -threads 8 -an -g 25 -f webm tcp://localhost:9090

H.264 (using libx264)

To stream MP4 it needs to be ISO BMFF compatible, so -movflags is set to empty_moov+default_base_moof.

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0  -vcodec libx264 -profile:v main -g 25 -r 25 -b:v 500k -keyint_min 250 -strict experimental -pix_fmt yuv420p -movflags empty_moov+default_base_moof -an -preset ultrafast -f mp4 tcp://localhost:9090

Stream flow

FFMPEG ---TCP---> NODE.JS Server -- WebSockets --> [client 0] MediaSource Video
                                |-- WebSockets --> [client 1] MediaSource Video
                                |-- WebSockets --> [client 2] MediaSource Video

Ingest stream is sent over TCP to node.js server. Every packet of stream is sent to clients using WebSockets.

MediaSource is used to retrive video stream.

How to use

Install

npm install

Start application

gulp 

In browser go to localhost:8080

Stream video to tcp://localhost:9090

ffmpeg (...) tcp://localhost:9090

According to video codec set codecString in client/js/app.js line 9 to right value.

You can customize ports in server\app.js lines 12 and 13.

'First packet' hack :)

There is little hack in lines 41-44 and 68-76. Server stores beginning of stream in array which is sent to every new client. Every client will receive couple of start frames.

Without that hack video won't start for users who start watching in the middle of stream. Perhaps there is solution in better ffmpeg setting.

node-tcp-streaming-server's People

Contributors

kmoskwiak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.