TechQA.

How do I color cues on webvtt?

901 views Asked by Sumadithya At 2020-09-26T18:42:52+00:00 26 September 2020 at 18:42 2025-12-24T18:11:51+00:00

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 answers

2
Carson Carson On 2023-07-13T08:27:00+00:00 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

  • (in promise) TypeError: NetworkError when attempting to fetch resource
  • Optimizing Selenium script for faster execution
  • Apply Firefox policies.json only to Firefox but not to Nightly
  • Difficulty Accessing HTTP URLs/IP Addresses Due to Browser Redirecting to HTTPS: Seeking Solutions
  • How do I separate emails (from 1 alias) in Thunderbird from invasive websites on Firefox with file browsing scripts? Should I worry?
  • Gecko chrome @supports function for strings and numbers
  • some CSS property working on chrome's console but not on firefox
  • Playwright - Firefox tests time out, but Chromium tests don't
  • Notification.permission always return 'denied' on firefox
  • Useless horizontal scrollbar in Firefox with absolute positioned div with fixed height
  • Why is it impossible to definitively know if your website is running as a PWA or as a website?
  • WebRTC from Firefox to Android crashes
  • Firefox CSS: Set a variable based on properties of another element
  • Getting Negative Time Duration in Sender-to-Client Application using Date.now() api
  • Prevent users accessing Firefox menu items

Related Questions in HTML5-VIDEO

  • <video> tag with downloaded path in ionic ios not loads the video
  • Google Ads does not show on website when video is full screen
  • sourceBuffer.appendBuffer successfully but the h5 video player stuck
  • video.audioTracks is not working as expected for large video
  • HTML5 and CSS - Responsive Video Pop Up Not working according to design
  • Video lazy load - background
  • Reimplement HTML Media Tag Fetching without a tag using Media Source API
  • Flask Streaming mp4 video works perfectly on windows but not mobile phone
  • Pause the animation of all html cards when the video popup is opened or when the play button on the video is clicked
  • HTML5 sourcebuffer stalls in firefox
  • Full screen in Electron js adds a blank space at the bottom
  • What is the largest size limit (in Mb) for html video tag on iOS mobile devices
  • Client side H.264 (MP4) video compression/encoding
  • video Enters Fullscreen "Live Broadcast" Mode on iOS Despite playsinline Attribute in Standalone PWA
  • How to process each frames exactly only once using MediaStreamTrackProcessor

Related Questions in CHROMIUM

  • Why is it impossible to definitively know if your website is running as a PWA or as a website?
  • Is it possible to save MHTML with scripts included?
  • Chrome PDF print image aspect ratio incorrect - very apparent with small images - is there a workaround?
  • How to turn off login pop-up on stackoverflow
  • "Inconsistent WhatsApp Web Integration: Error with Manifest File Null Value Reading"
  • Possible scroll bug with usage of overflow-hidden on body along with "sr-only" elements?
  • How to solve Missing X server or $DISPLAY when trying to change the loaded website in Chromium
  • Google Chrome for AWS Lambda as a layer
  • Does Chromium pass URLs along with JS to V8?
  • Chromium version on Puppeteer build
  • Change the blue background of chrome devtool like before
  • Native Messaging "Specified native messaging host not found" debugging
  • PDF-documents not loading inside iframe in Chrome and Edge
  • ReferenceError: ReadableStream is not defined using Puppeteer's page.pdf() on AWS
  • Why is MediaQuery.of(context).size.height in Flutter detecting a larger height in Android chromium-based browsers?

Related Questions in SUBTITLE

  • Use `ffprobe` to display subtitle content like the `cat` command
  • How to extract video embedded subtitle from a video URL and show in a text widget in flutter?
  • SubtitleOctopus how to use octopus subtiles in m3u8 files
  • How to show embedded subtitles in ExoPlayer?
  • How to adjust subtitle font size in Swift macOS?
  • Why doesn't video-conferencing with subtitles exist?
  • Adding SRT subtitle to multiple MP4
  • How to shift subtitle time in an SRT (SubRip) file in C#?
  • getting 2 video streams in output.mkv?
  • The principle behind Youglish for searching YouTube videos
  • tesseract: Specifying (German) language reduces accuracy - what am I missing?
  • SRT Subtitle Processing Using Autosub & Python: Trying to remove blank subtitle entries
  • Extracting subtitle from a teachable/hotmart video
  • Which atom (box) has subtitle data in MP4 (ISOBMFF)
  • Trying to strip tags from extracted subs file

Related Questions in WEBVTT

  • WEBVTT into HLS does not work anymore on last iOS version
  • Read chapters from an mp4 file?
  • WEBVTT subtitle issue on ROKU and LG TV using Dash stream on HTML5 player
  • How to fix unsafe attempt error and show the caption?
  • WebVTT to JSON using `jq`
  • Dash JS player x Cloudflare displaying adaptation ID for CC options
  • How do I convert .vtt subtitle file into segments (.m3u8)?
  • Fill formula down to same level in adjacent column does not work when combined with other working code
  • plyr.io captions dont load nextjs typescript
  • How to convert srt file to vtt then append video
  • Can I make use charset-normalizer 3.0.0 instead of 3.2.0 in build.gradle so that I do not get aiohttp related library error in android studio?
  • Vertical text from left to right with NSTextView
  • Serving Vtt files from AWS Cloudfront with signed cookies
  • Keep .vtt as string object vs write to file - OpenAI Whisper
  • HTML Video won't play vtt subtitles

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?

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)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Aftereffectstemplates
  • Jogjafile