Urgent.News

What's breaking now, across thousands of outlets.

Tech

I wrote an SRT-to-WebVTT converter in ~35 lines because players lie about subtitle support

i'm building RKMovies , a 0.91 MB Android media client. the streams come with subtitle files, and the internet almost always hands you SRT. the problem: the <video> element only renders WebVTT properly, and SRT is not WebVTT. the differences that actually bite: timestamps. SRT uses 00:00:01,000 . WebVTT demands 00:00:01.000 . one comma and the whole cue silently disappears. cue indexes. SRT…

I constructed an SRT-to-WebVTT converter in approximately 35 lines of code for a 0.91 MB Android media player. Most streams provide subtitle files in the SRT format, which is not compatible with the WebVTT format used by the video element. The key differences between SRT and WebVTT lie in timestamps and cue indexing. SRT uses a colon and milliseconds, while WebVTT requires a period and milliseconds.

Additionally, SRT files start with a numeric counter line, which WebVTT treats as a cue ID. The converter, named captionVtt(), handles various issues such as BOM, line endings, cue counter, timing format, and text cleaning. It strips the BOM and Windows line endings, splits the file into blocks, removes the cue counter line, converts commas to periods in the timing line, and cleans the text lines by removing tags and entities.

Despite the complexity, the converter is surprisingly concise at about 35 lines. However, the parsing process is more robust than accurate due to the inconsistencies in SRT files. Developers are advised to always use WebVTT when embedding subtitles and validate them using a real <track> element in the browser, as devtools may not warn about comma errors.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Ask the Circuit and Exact Dicke State Preparation at DuQuantum

This is a submission for the MLH x DEV Writing Challenge What I Built At DuQuantum, Duke’s quantum computing hackathon, my team had 24 hours to solve a deceptively simple problem.

  • Team at DuQuantum created efficient circuit for exact Dicke state preparation
  • Dicke state evenly distributes 3 excitations across 20 bitstrings for 6-qubit system
  • Circuit created using CZ and single qubit gates, evaluated with hardware calibration data

Italian Game for Beginners: What If Black Plays ...d5?

By ChessStep editorial team You have developed your knight and bishop. Castling is next on the plan. Then Black pushes a pawn to d5.

  • White's bishop on c4 is attacked by Black's knight on f6.
  • Correct response is to capture Black's pawn on d5 with exd5.
  • After exd5, Black can capture the pawn with Nxd5.

OpenGalvoCal

OpenGalvoCal: Next-Generation F-Theta Lens & Galvo Distortion Calibration System Complete Problem Analysis, Mathematical Foundations, and Modern Software Architecture Specification 1.

More from Saturday 31 October →