2

I've made an API with NodeJS + Express, which is supposed to send a video stream when we call the /videos/stream/{id} route. Here is the code:

    router.get('/stream/:id', function(req, res) {

      fs.readFile(app.get('path') + '/videos/' + req.params.id + '/video.mp4', function (err,data) {
        if (err) { ... }
        res.writeHead(200, {
            'Content-type' : 'application/octet-stream',
            'Content-Length' : data.length
        });
        res.end(data);
    });
});

This code is working because when I put the whole URI in my browser, I can either open the stream with VLC or save it.

The problem is that I can't see the video stream with the Videogular framework. When I copy/paste the "How to start" code into my AngularJS app, like this:

sources: [
    {src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.mp4"), type: "video/mp4"},
    {src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.webm"), type: "video/webm"},
    {src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.ogg"), type: "video/ogg"}
],

This works, I can see the video into the player, but when I replace the URI with my API's one:

sources: [
    {src: $sce.trustAsResourceUrl("http://localhost:3000/api/videos/stream/556747d8f657a9b81c7f3543"), type: "application/octet-stream"}
],

The player remains black and no video is playing, I don't know why.

4

1 回答 1

1

我找到了解决方案,但这对于我的 API 的工作方式非常具体。在 API 上上传视频时,它会自动转换为 MP4。

所以这是我的配置:

    $scope.config = {
      sources: [
        {src: $sce.trustAsResourceUrl("http://localhost:3000/api/videos/stream/" + data.video._id), type: "video/mp4"}
      ],
      tracks: [{ ... }],
      theme: "bower_components/videogular-themes-default/videogular.css",
      plugins: {
        poster: "http://www.videogular.com/assets/images/videogular.png"
      }
    };

请注意,type : "video/mp4"而不是type : "application/octet-stream"因为我的 API 将所有内容都转换为 MP4。

当上传的视频是 MP4 时,此代码完美运行。否则,当在 API 上上传和转换非 MP4 视频时,我无法将其流式传输到 Videogular 的播放器中。

TL;博士

我的 API 没有正确转换视频,这就是 Videogular 不能流式传输的原因。

于 2015-06-03T14:14:39.260 回答