Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Play a video in the browser that is being updated in the background?
New on LowEndTalk? Please Register and read our Community Rules.

Play a video in the browser that is being updated in the background?

sgno1sgno1 Member

Hi there, I hope you all are doing well!

I have a video that's being encoded with some FFmpeg flags applied to it in the MKV format, that's running in the background. I'm working on a type of web panel that would preview the video as it's being encoded from MKV to MKV (with new FFmpeg flags).

I've managed to make a Node.js HTTP Streaming script using the tutorial How to Code a Video Streaming Server using NodeJS.

However, it seems like the video is not updating the new content and stops playing after 1 second or so. I've tried to push in new content through pipes however I had no luck (using watchers such as fs.watchFile and test intervals).

Maybe @yoursunny has a solution? :smile:

Hoping someone can guide me on the right path, thanks!

Thanked by 1yoursunny

Comments

  • Knowing how your stuff is set up would help us a lot here.

    Are you streaming the files as you go with Transfer-Encoding: chunked or similar sending new file parts as and when you detect them with fs.watchFile()?

    Does fs.WatchFile() even emit events on partial writes? I never used it directly, but I know chokidar does so only when files are closed.

  • Why not HLS?
    Ffmpeg can output in HLS format directly.

    Thanked by 1yoursunny
  • sgno1sgno1 Member

    @farsighter said:
    Why not HLS?
    Ffmpeg can output in HLS format directly.

    I am trying this out, but is there a way to keep pushing in new segments? I assume if I write to the master file the player should automatically pick up these changes?

  • @sgno1 said:

    @farsighter said:
    Why not HLS?
    Ffmpeg can output in HLS format directly.

    I am trying this out, but is there a way to keep pushing in new segments? I assume if I write to the master file the player should automatically pick up these changes?

    I'm sure that's easily achievable. Here are 2 working examples from my snippets. I don't remember all the flags (used it for restreaming 2 years ago) take these as a starting point and polish as necessary:

    ffmpeg -re -i input.mp4 -c copy -segment_list_flags +live -hls_time 4 -hls_list_size 6 -hls_wrap 6 -segment_list_type m3u8 -map 0:0 -map 0:1 -segment_time 4 /var/www/hls/index.m3u8

    If you need to pipe into ffmpeg then command should look like this:

    commamd | ffmpeg -re -i pipe: -c copy -segment_list_flags +live -hls_time 4 -hls_list_size 6 -hls_wrap 6 -segment_list_type m3u8 -map 0:0 -map 0:1 -segment_time 4 /var/www/hls/index.m3u8

    ffmpeg can also take a named pipe as input.

    Also found this tutorial in my bookmarks which can help for better understanding:

    https://www.martin-riedl.de/2018/08/24/using-ffmpeg-as-a-hls-streaming-server-part-1/

Sign In or Register to comment.