简体   繁体   English

如何播放带有html5内置字幕的视频?

[英]how to play video w/ built in subtitle in html5?

I have mp4 and mkv files with built in subtitle that I want to play in html5 and show the built in subtitle, I have try this 我有要在html5中播放的带有内置字幕的mp4和mkv文件,并显示内置字幕,我已经尝试过

<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>

but it doesn't work 但这不起作用

media players like WindowsMediaPlayer, etc use the subtitle file in the same folder as video file to show subtitles on the screen. 诸如WindowsMediaPlayer之类的媒体播放器将字幕文件与视频文件放在同一文件夹中,以在屏幕上显示字幕。 If that is what you are trying to do, you will need to add a track tag nested within the video tag. 如果这是您要尝试的操作,则需要添加嵌套在视频标签内的跟踪标签。 Look at this 这个

The browser would need to support this, but to the best of my knowledge no major browser supports this for progressive video. 浏览器需要支持此功能,但据我所知,没有主要的浏览器支持渐进式视频。 You should consider extracting the subtitles and sideload them. 您应该考虑提取字幕并将其侧载。 There are several tools for extracting subtitles, eg CCextractor or MP4Box . 有几种提取字幕的工具,例如CCextractorMP4Box

You can add them as tracks to the video element as described in the Mozilla Developer Network : 您可以按照Mozilla开发人员网络中的说明将它们作为轨道添加到video元素:

<video id="video" controls preload="metadata">
  <source src="video/sintel-short.mp4" type="video/mp4">
  <source src="video/sintel-short.webm" type="video/webm">

  <track label="English" kind="subtitles" srclang="en" src="captions/vtt/sintel-en.vtt" default>
  <track label="Deutsch" kind="subtitles" srclang="de" src="captions/vtt/sintel-de.vtt">
  <track label="Español" kind="subtitles" srclang="es" src="captions/vtt/sintel-es.vtt">
</video>

However, this only works for VTT files and there might be cross-browser issues as well. 但是,这仅适用于VTT文件,并且也可能存在跨浏览器的问题。 There are several web players out there which also support different subtitle formats, JWPlayer or the Bitmovin Player . 有几种支持不同字幕格式的Web播放器 ,即JWPlayer或Bitmovin Player

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM