【问题标题】:Send a subtitle file (.VTT) with the mp4 from Node/Express to Angular将带有 mp4 的字幕文件 (.VTT) 从 Node/Express 发送到 Angular
【发布时间】:2021-02-24 13:42:37
【问题描述】:

我正在使用 Node/Express 将 mp4 视频发送到我使用 angular 的前端。视频发送顺利,一切正常。现在,我想发送包含字幕的 VTT 文件以及 mp4。我不知道该怎么做?我试过搜索,但找不到任何帮助。这是我的代码:

节点/快递

router.get('/playVideo', (req, res) => {

const path = "videos/testVideo.mp4";
const pathSubtitle = "videos/testsub.vtt";

const stat = fs.statSync(path);
const fileSize = stat.size;

const head = {
  'Content-Length': fileSize,
  'Accept-Ranges' : 'bytes',
  'Content-Type': 'video/mp4'
}

res.writeHead(200, head);
fs.createReadStream(path).pipe(res);
});

角度

<div class="container-fluid">
<br>
<div class="jumbotron-fluid">

  <video id = "videoPlayer" controls preload = "metadata" style = "width: 
      65%; position: fixed; border: 2px solid #7c2c6c;">
      <source src="http://localhost:3000/playVideo" autoplay type = 
      "video/mp4">
  </video>
  
</div>
</div>

如何在视频回复中附加字幕文件?或者,链接到任何其他详细解释的文档?

【问题讨论】:

  • 在角度部分你使用视频标签吗?前端部分长什么样子?
  • @ste-xx,我已经编辑了代码。
  • 只需为字幕创建一个类似的入口点并将添加到

标签: node.js angular express


【解决方案1】:

在不同的 url 上提供 vtt 文件(例如 /playVideo.vtt),然后使用 track 元素显示它:*

<video id = "videoPlayer" controls preload = "metadata" style = "width: 
      65%; position: fixed; border: 2px solid #7c2c6c;">
    <source src="http://localhost:3000/playVideo" autoplay type = 
      "video/mp4">
    <track default src="http://localhost:3000/playVideo.vtt">
</video>

您可以在此处阅读更多信息:https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API#within_site_css 和此处:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track

*代码尚未测试

【讨论】:

  • 这不是问题。我不知道如何从后端发送文件。我是否必须从单独的端点将其作为 blob 发送?我不能使用单个端点做同样的事情吗?
  • 据我所知,没有办法在同一个端点上为它们提供服务,因此您需要 2 个端点。
猜你喜欢
  • 2014-07-13
  • 2019-08-24
  • 2017-10-30
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-24
相关资源
最近更新 更多