Node Js-Azure视频流非常慢

时间:2019-01-17 16:28:45

标签: javascript node.js azure-storage

我已经使用节点azure-storage插件来从azure存储中流式传输视频。

创建了一个Node控制器,该控制器用于从azure传输流视频并通过管道传输Web视频播放器的数据。

这是蒸的演示代码。

    global.blobService.getBlobProperties(config.azure.container, _transactionId + '.mp4', function (err, blobResult, headers) {
      if (!err) {
        const fileSize = Number(params.contentLength);
        if (range) {
          const parts = range.replace(/bytes=/, "").split("-");
          const start = parseInt(parts[0], 10);
          const end = parts[1]
            ? parseInt(parts[1], 10)
            : fileSize - 1
          const chunksize = (end - start) + 1;
          const stream = global.blobService.createReadStream(config.azure.container, _transactionId + '.mp4', { rangeStart: start, rangeEnd: end, highWaterMark: 256 * 1024 });
          const head = {
            'Content-Range': `bytes ${start}-${end}/${fileSize}`,
            'Accept-Ranges': 'bytes',
            'Content-Length': chunksize,
            'Content-Type': params.contentType,
          }

          res.writeHead(206, head)
          stream.pipe(res)
        } else {
          const head = {
            'Content-Length': fileSize,
            'Content-Type': 'video/mp4',
          }
          res.writeHead(200, head)
          global.blobService.createReadStream(config.azure.container, _transactionId + '.mp4', null).pipe(res);
        }
      }
    });

0 个答案:

没有答案
相关问题