DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

How do I color cues on webvtt?

900 Views Asked by Sumadithya At 26 September 2020 at 18:42 2025-12-21T07:32:50.169000

HTML

<!DOCTYPE HTML>
<html>
  <head>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <video controls autoplay>
      <source src="./test.mp4" type="video/mp4"/>
      <track default kind="captions" srclang="en" label="English" src="./test.vtt"/>
    </video>
  </body>
</html>

CSS

.yellowish {
  background-color: blue;
  color: yellow;
}
.redcolor {
  background-color: white;
  color: red;
}

VTT

WEBVTT

00:00:00.000 --> 00:00:03.000
<c.yellowish>This text should be yellow.</c> This text will be the default color.

00:00:03.000 --> 00:00:06.000
<c.redcolor>This text should be red.</c> This text will be the default color.

I hosted them on a simple http server with node.js and tried it on chromium and Firefox. They did not show colors. I tried including styles in the vtt file, it did not work either. Size and colors seems to be not working in Firefox and chromium. Alignment doesn't work in chromium. All other webvtt features work perfectly. Am I supposed to use any front-end frameworks for this? It works on YouTube perfectly.(1:30 to 1:40)

firefox html5-video chromium subtitle webvtt
Original Q&A
1

There are 1 best solutions below

2
Carson Carson On 13 July 2023 at 08:27 BEST ANSWER

Changing the CSS as below will work.

/* .yellowish { */
video::cue(.yellowish) {
  background-color: blue;
  color: yellow;
}
/* .redcolor { */
video::cue(.redcolor ) {
  background-color: white;
  color: red;
}

Example

<style>
  video::cue(.yellowish) {
    background-color: blue;
    color: yellow;
  }
  video::cue(.redcolor ) {
    background-color: white;
    color: red;
  }
</style>

<script>
  const vttTxt = `WEBVTT
00:00:00.000 --> 00:00:03.000
<c.yellowish>This text should be yellow.</c> This text will be the default color.

00:00:03.000 --> 00:09:56.000
<c.redcolor>This text should be red.</c> This text will be the default color.
`
  const blobVTT = new Blob([vttTxt], {"type": "text/plain"})
  const trackUrl = URL.createObjectURL(blobVTT)
  const frag = document.createRange().createContextualFragment(`
          <video width="400" height="200" controls>
  <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
  <track src="${trackUrl}" kind="captions" srclang="en" label="English" default >
  </video>
          `)
  document.body.append(frag)
</script>


The following content is a suggestion, I do not recommend putting foreground and background colors together. According to the documentation.#default-classes, you can define attributes for individual colors separately, which will provide more flexibility when using them. Here is an example:

<style>
  /* color */
  video::cue(.yellow) {
    color: yellow;
  }
  video::cue(.bg_yellow) {
    background-color: yellow;
  }
  video::cue(.red) {
    color: red;
  }
  video::cue(.bg_red) {
    background-color: red;
  }

  /* font-size */
  video::cue(.big) {
    font-size: 2rem;
  }
</style>
00:00:00.000 --> 00:00:03.000
<c.yellow.bg_red>This text should be yellow.</c> This text will be the default color.

00:00:03.000 --> 00:09:56.000
<c.big.red.bg_yello>This text should be red.</c> This text will be the default color.

Example2

<style>
  video::cue(.yellow) {
    color: yellow;
  }
  video::cue(.bg_yellow) {
    background-color: yellow;
  }
  video::cue(.red) {
    color: red;
  }
  video::cue(.bg_red) {
    background-color: red;
  }
  video::cue(.big) {
    font-size: 2rem;
  }
</style>

<script>
const vttTxt = `WEBVTT
00:00:00.000 --> 00:00:03.000
<c.yellow.bg_red>This text should be yellow.</c> This text will be the default color.

00:00:03.000 --> 00:09:56.000
<c.big.red.bg_yellow>This text should be red.</c> This text will be the default color.
`
const blobVTT = new Blob([vttTxt], {"type": "text/plain"})
const trackUrl = URL.createObjectURL(blobVTT)
const frag = document.createRange().createContextualFragment(`
          <video width="400" height="200" controls>
  <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
  <track src="${trackUrl}" kind="captions" srclang="en" label="English" default >
  </video>
          `)
document.body.append(frag)
</script>

Related Questions in FIREFOX

  • Firefox 37 throwing error when trying to add microphone volume control for WebRTC audio context
  • Polymer 1.0 on Firefox, Safari /deep/ selector not working
  • Firefox Windows / Linux inconstancies
  • Firefox SDK Add-on - How to start
  • PlayN and Firefox issues
  • Copy to clipboard from Firefox add-on content script
  • SVG data image not working as a background-image in a pseudo element
  • Selenium Firefox webdriver does not adopt profile
  • how can i use require(""); in javascript
  • Skewed border won't display properly in FiFO on MacOs
  • Optimize website to show reader view in Firefox
  • Remove the black line from the bottom and right side of Firefox select boxes
  • Onclick doesn't work in Firefox, but in Chrome - yes
  • How do you close the DOM Properties window in Firefox Developer Edition?
  • Cannot click on Angular-JS button with selenium web-driver: ElementNotVisibleException

Related Questions in HTML5-VIDEO

  • Video tags play audio but not video
  • Does video tag html5 slow my webpage or is it heavy if I have many videos in video tags?
  • How can I use javascript to get the thumbnail of an html5 video?
  • Want to hide scrollbar when a absolute div already has a 100% height
  • Html5 videos not displaying
  • If section has class than start playing video
  • Load Html5Video 100% then show Page
  • html crops height video to height 100vh, video to fullscreen
  • Fully preload html5 video from CDN in Safari
  • How to create a Javascript video overlay with VAST VPAID?
  • Getting video metadata from a Youtube video
  • How to add video background over a section?
  • Ignore HTML5 on mobile devices
  • video, form then video in html
  • Add a preload image that disappears after video is loaded

Related Questions in CHROMIUM

  • Implementing a custom header bar for chromiumembedded
  • what does "Failed to load resource: net::ERR_CERT_DATABASE_CHANGED" mean
  • Crosswalk Chomium API : Blank View on Wear
  • Building QtWebEngine for Raspberry Pi2 using Yocto Poky - vcos_platform_types.h: No such file or directory
  • How to use the <webview> methods in Electron
  • Mapping own keyboard input using chrome extension which able directly edit in google docs
  • Brackets can't find Chromium in Windows
  • How to save console log from chrome in local file without any third party tool?
  • Bug in Chromium with rendering css transformation transition
  • Get Bytebuffer from JavaFX Browser
  • How to compile chromium with debugging flag?
  • SKIA Rendering on Windows(SkCanvas from HDC)
  • Command line chrome extension loading and testing
  • Unknown chromium error: 0
  • Server has a weak ephemeral Diffie-Hellman public key. How to by-pass it?

Related Questions in SUBTITLE

  • Exoplayer - InvalidResponseCodeException (404) while file exists
  • Subtitle TableView Cell
  • HTML5 track subtitles and property cue and ActiveCue is empty in IE (internet explorer)
  • Android CollapsingToolbarLayout subtitle
  • Chromecast add subtitle while playing video
  • How to compile libass to iOS platform?
  • Change subitem backcolor of a listview next item
  • FFMPEG encode audio and forced subtitles at same time?
  • ffmpeg set subtitles track as default
  • Does HTML5 Video support srt textTrack?
  • Extracting chinese subtitle from video
  • How to add subtitles to a QuickTime movie
  • Is it possible for HTML5 video to play subtitles embedded in mp4 file as a track?
  • Subtext in Listview
  • Rendering pixel perfect subtitles for small videos

Related Questions in WEBVTT

  • HTML5 track cues empty
  • Is it possible for podcast audio stream to have script/text?
  • Is it possible to move an HTML5 video CC under the video?
  • Using Javascript to convert .srt to .webvtt
  • Does HTML5 Video support srt textTrack?
  • Is it possible for HTML5 video to play subtitles embedded in mp4 file as a track?
  • How do I color cues on webvtt?
  • Node JS Promise.all to async update properties in array of JSON objects
  • track element in html5 video player
  • Dash JS player x Cloudflare displaying adaptation ID for CC options
  • WebVTT to JSON using `jq`
  • How to fix unsafe attempt error and show the caption?
  • FFMPEG multiple styles in .srt file
  • Styling VTT cues - ::cue(#id) selector does not work
  • Giving VTT subtitles a fading out effect

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?
.

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates