如何在 chrome 中播放 MPEG-TS

How to play MPEG-TS in chrome

我有一个视频想向用户展示('the' 用户,因为他可以访问 Chrome PC 或 Chrome android)。

如果可能的话,使用 html5 标签会很好,但由于它是 TS,所以不能...

所以,我需要一个更好的建议,告诉我如何播放它们,而不是打开 vlc 并复制并粘贴文件路径。 但这是个糟糕的主意...

我看到 this 库添加了 VLC 协议( vlc:// 链接 ),但我更喜欢使用服务器端解决方案。

我上传了一个示例文件,您可以在其中看到 here

我不想将所有文件都转换成另一种格式。

编辑: 如果将来有人来这里,在听取@szatmary 的建议后,GitHub 上有一些项目是这样做的,但是我不能在不部分转换(以某种方式)的情况下使用它们中的任何一个,因为我使用非常大的文件 (10G+) 和非常弱的计算机(单 1.8 Cpu 核心)我设法只显示音频,不是真正的解决方案,但满足了我的需求。

将文件转换为 mp4。如果 ts 文件是 h.264+aac,您可以在 javascript 中转换为 fmp4 并通过媒体源扩展播放,但这需要大量代码才能正常工作。

你可以直接播放ts文件索引m3u8文件,如果没有你可以制作m3u8文件,它只是ts文件的索引.

有些浏览器比如edge你直接玩ts。参考this answer

<video width="352" height="198" controls>
    <source src="index.m3u8" type="application/x-mpegURL">
</video>

对于 firefox 和 chrome 等其他浏览器,您需要使用 js 将 ts 提供给视频,例如 video.js,

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>videojs-contrib-hls embed</title>

  <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
  <script src="https://unpkg.com/video.js/dist/video.js"></script>
  <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>

</head>
<body>
  <h1>Video.js Example Embed</h1>

  <video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268" 
  data-setup='{}'>
    <source src="index.m3u8" type="application/x-mpegURL">
  </video>

  <script>
  </script>

</body>
</html>

除了播放ts文件外,您还可以将其转换为mp4。

您可以使用pipe these ts files in to ffmpeg并输出mp4文件。

cat *.ts | ffmpeg -i pipe: -c:a copy -c:v copy output.mp4

或者如果你的ts文件名没有顺序,

grep .*.ts index.m3u8 | xargs cat | ffmpeg -i pipe: -c:a copy -c:v copy output.mp4