Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

streaming - How to stream .avi film files with node.JS? (File opens download screen instead of streamed)

I'm using vid-streamer https://github.com/meloncholy/vid-streamer.

  1. To install just create a folder on your pc
  2. open terminal and do CD to folder
  3. execute npm init
  4. give the app a name like 'MyVidStreamer'
  5. a package.json will be created
  6. npm install express
  7. create a server.js on the same folder of package.json
  8. write this and save

    var app = require("express");
    var app = app();
    var vidStreamer = require("vid-streamer");
    app.get("/videos/:type", vidStreamer); //{folder}/{videoName.extension}
    app.listen(3000);
    
  9. update the vid-streamer configuration: open node_modules/vid-streamer/config/ and edit the json file vidStreamer-sample.json:

    {
    "mode": "development",
    "forceDownload": false,
    "random": false,
    "rootFolder": "",   <----
    "rootPath": "",  <-------
    "server": "VidStreamer.js/0.1.4",
    "maxAge": "3600",
    "throttle": false
    }
    
  10. create a folder named videos at the same level of our server.js
  11. add a avi file inside of it
  12. on the terminal make cd followed by path to the folder where we have our server.js
  13. run node server.js
  14. open browse and type 'localhost:3000/videos/{name_of_your_vid_File.extension}

I'm able to stream mp4 files and ogg, but not avi files. so the question is how can i fix this in order to stream avi files

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First of all, you should know that browsers are not video players so you can not expect that a browser can play any format of videos !

In addition, not all video formats are suitable for the web for many reasons, so try always to take this point on consideration when you want stream videos, and think how to make your video suitable for the web and not how to make web suitable to your video ( like your question ;) ).

Recent browsers can support natively some video formats like MP4, WEBM and OGG which will be played using the HTML5 <video> element, in the case where a video format is not natively supported, the browser will try to play it with a plugin like VLC Web Plugin, QuickTime, Osmozilla - GPAC Plugin, ... otherwise ( there are no suitable plugin ), the browser will simply download the file (or open it with the associated application after asking user).

So to "resolve your problem", I think that you have 2 choices :

  • Convert your videos to natively supported formats.
  • Force users to get the suitable plugins for your videos, which is technically impossible.

For more informations about all that and more, you can take a look on these links :

Of course here I tried just to give you a short "answer" to your question about playing video directly in the browser ( without HTML ), and I think after this, you will surely think to play your videos in HTML pages, you can also find an answer for that in the links above.

Hope all that can help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...