illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.95k stars 1.52k forks source link

How to seek a transcoded video file from fluent-ffmpeg stream? #330

Open lucafaggianelli opened 4 years ago

lucafaggianelli commented 4 years ago

Hi there,

I'm working on a media center project (kind of Plex/personal Netflix), where, basically, I serve video files to a browser or to a Chromecast, though some videos are not supported thus I use fluent-ffmpeg for transcoding audio and/or video streams.

Everything works fine, but the videos aren't seekable and haven't the right duration, of course, this is normal due to HTTP protocol, Range headers, etc... Question is, do you think I can use Node-Media-Server to stream the transcoded video with some protocols like HLS or others? Moreover, I need to use Node-Media-Server programmatically, not from CLI.

This is the repo: https://github.com/lucafaggianelli/couch-buddy

and this is where the transcoding happens (I'm using Koa library): https://github.com/lucafaggianelli/couch-buddy/blob/master/server/routes/streaming.js

    videoStream = require('stream').PassThrough()

    ffmpeg(path)
      .withVideoCodec(isSupported.video ? 'copy' : 'libx264')
      .withAudioCodec(isSupported.audio ? 'copy' : 'aac')
      .format('mp4')
      .on('error', (err) => {
        console.log('FFMPEG error:', err)
      })
      .addOption('-movflags', 'frag_keyframe+empty_moov')
      .pipe(videoStream, { end: true })

  ctx.body = videoStream
chrisspiegl commented 4 years ago

I think this is not necessarily a good request for an issue in the repository, since it is not an issue with the software or a feature request. That said…

Probably you can do something with NMS to use for your application to stream video files programmatically and on that note, also transcode on the fly. Please have a look at the readme of this project about transcoders where you can read about how you can use FFMPEG to transcode on the fly.

Please close this issue.