Git Product home page Git Product logo

hls-buffer's Introduction

hls-buffer

Preload and buffer http live streams (aka do not lag on crappy networks)

npm install hls-buffer

Usage

hls-buffer takes a m3u8 url from a remote server and preloads and buffers the linked .ts files in memory

var hls = require('hls-buffer');
var buffer = hls('http://my-favorite-stream.com/some/path/index.m3u8');
var http = require('http');

var server = http.createServer(function(request, response) {
	if (request.url === '/index.m3u8') {
		// first return a playlist
		buffer.playlist(function(err, pl) {
			response.setHeader('Content-Type', 'application/vnd.apple.mpegurl');
			response.end(pl);
		});
	} else {
		// else return the linked segment
		var stream = buffer.segment(request.url);
		response.setHeader('Content-Type', 'video/mp2s');
		stream.pipe(response);
	}
});

server.listen(8080);

If you run the above example with your favorite http live streaming service a local preloading proxy will be started on http://localhost:8080/index.m3u8.

Per default up to 10 segments will be buffered in ram. To change this pass {max:number} as the second parameter to the constructor

License

MIT

hls-buffer's People

Contributors

mafintosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hls-buffer's Issues

Stream not getting initialized with any desktop player, unbuffered stream works OK.

Using the provided example code i'm getting:

hls-buffer.js:16
         stream.pipe(response);
                    ^
 TypeError: Cannot call method 'pipe' of null
     at Server.<anonymous> (c:\hlsbuffer\hls-buffer.js:16:16)
     at Server.EventEmitter.emit (events.js:98:17)
     at HTTPParser.parser.onIncoming (http.js:2056:12)
     at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:120:23)
     at Socket.socket.ondata (http.js:1946:22)
     at TCP.onread (net.js:525:27)

Update: the index.m3u8 only contains a reference to chunklist.m3u8. I noticed that the .ts file this buffer creates is actually just a renamed chunklist.m3u8. Here are both the files:

index.m3u8:

    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1717211,CODECS="avc1.77.30, mp4a.40.2",RESOLUTION=1024x576
    chunklist.m3u8?wowzasessionid=594606542

chunklist.m3u8:

    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-ALLOW-CACHE:NO
    #EXT-X-TARGETDURATION:11
    #EXT-X-MEDIA-SEQUENCE:1317
    #EXTINF:9.04,
    media_1317.ts?wowzasessionid=1052438652
    #EXTINF:10.96,
    media_1318.ts?wowzasessionid=1052438652
    #EXTINF:10.0,
    media_1319.ts?wowzasessionid=1052438652

Update 2: replaced references to index.m3u8 with chunklist.m3u8, which looks like this now:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:1443
#EXTINF:10.0,
/5f0cfc1274b39c66437a69464aa6d73b.ts
#EXTINF:10.0,
/2e1ad8c774f6cfe12c502d27ed7d662c.ts
#EXTINF:10.0,
/45fcedc4303515b455730a7086627bfc.ts

But I still get the same error.

Cannot read property 'statusCode' of undefined and Error: connect ENOENT /path.m3u8

Hello, I am getting a strange error.

TypeError: Cannot read property 'statusCode' of undefined`  
    at Request._callback (/node-index-page/node_modules/hls-buffer/index.js:30:17)
    at self.callback (/node-index-page/node_modules/hls-buffer/node_modules/request/request.js:129:22)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at ClientRequest.self.clientErrorHandler (/node-index-page/node_modules/hls-buffer/node_modules/request/request.js:239:10)
    at emitOne (events.js:120:20)
    at ClientRequest.emit (events.js:210:7)
    at Socket.socketErrorListener (_http_client.js:385:9)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Which is caused by this line https://github.com/mafintosh/hls-buffer/blob/master/index.js#L30 because there is no error check. Which I can offer my help. So with a help of a global request logger I have managed to get the actual request and its error which is:

{
    port: 80,                                                                                                                                                        
    path: '/tjktv.m3u8',                                                                                                                                                            
    host: 'tjktv.ercdn.net',                                                                                                                                                        
    href: 'http://tjktv.ercdn.net/tjktv.m3u8',                                                                                                                                      
    method: 'GET',                                                                                                                                                                  
    headers: { host: 'tjktv.ercdn.net' },                                                                                                                                           
    error:  {
      Error: connect ENOENT /tjktv.m3u8                                                                                                                                            
      at Object._errnoException (util.js:1021:11)                                                                                                                                   
      at _exceptionWithHostPort (util.js:1043:20)                                                                                                                                   
      at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1175:14)                                                                                                              
      code: 'ENOENT',                                                                                                                                                              
      errno: 'ENOENT',                                                                                                                                                             
      syscall: 'connect',                                                                                                                                                          
      address: '/tjktv.m3u8'
    }
}

When I curl http://tjktv.ercdn.net/tjktv.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1050000,NAME=576p,RESOLUTION=1024x576
tjktv_576p.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=770000,NAME=480p,RESOLUTION=845x480
tjktv_480p.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=520000,NAME=360P,RESOLUTION=640x360
tjktv_360p.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=260000,NAME=240P,RESOLUTION=426x240
tjktv_240p.m3u8

My initialization code is same as in the README.md

I can offer my help for the first one but I have no idea why the second one is happening. Project is running on node:8.7.0-slim

could not get it to work?

TypeError: Cannot read property 'pipe' of null

Has this code been working ? I am looking for a similar solution...

Thanks

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.