I am experimenting with a video streaming project. I am writing an IPTV stream in mp4 to disk using ffmpeg. The problem is that the file is live and I need it up to date, so it’s impossible to transfer to the player. At the moment, when I go to localhost: 3000 I get a video that plays from the beginning, if I rewind to the end with my hands, the playback stops

Here is the code:

var http = require("http"); var fs= require("fs"); http.createServer(function (req,res){ res.writeHead(200,{'Content-Type': 'video/mp4'}); var rs= fs.createReadStream("3.mp4"); rs.pipe(res); }).listen(3000); 

First: how to always give the current file?

Second: how to start giving the file not from the beginning?

  • one
    I think it is worth putting Nginx, and not torturing NodeJS. For the most streaming it. And rewinding is also possible. Google "nginx + ffmpeg = rtmp" - Total Pusher 1:21 pm

2 answers 2

First: You always give the actual file using stream , which in turn creates a stream of data that is read on the client, in the order of data receipt and in the case when the meta information about the video has already been received and the timeline video is shown, this does not mean that the video is loaded. Therefore, when you rewind a video for a time, the data for which has not yet been loaded, an error occurs.

Second: As far as I know, no.

    The task was to translate a file to a live one. The ffmpeg library handled it.