diff options
author | Seungha Yang <seungha@centricular.com> | 2022-09-28 16:55:11 +0300 |
---|---|---|
committer | Seungha Yang <seungha@centricular.com> | 2022-09-29 17:02:38 +0300 |
commit | 9740140798f7333f234858cf5d489d7db4c7be7c (patch) | |
tree | ed82a3f450881609cf5a64a4f37f52ca6b76439f /video | |
parent | b63627025e0dc334d6052aefff564d792d8079f9 (diff) |
jsontovtt: Don't push zero-duration cue data
It will likely confuse players. We can drop corresponding
cue since the text line will be included in the next cue
Diffstat (limited to 'video')
-rw-r--r-- | video/closedcaption/src/jsontovtt/imp.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/video/closedcaption/src/jsontovtt/imp.rs b/video/closedcaption/src/jsontovtt/imp.rs index b0eea521..199e4269 100644 --- a/video/closedcaption/src/jsontovtt/imp.rs +++ b/video/closedcaption/src/jsontovtt/imp.rs @@ -121,8 +121,8 @@ impl State { fn create_vtt_buffer( timestamp: gst::ClockTime, duration: gst::ClockTime, - text: String, - ) -> gst::Buffer { + text: &str, + ) -> Option<gst::Buffer> { use std::fmt::Write; let mut data = String::new(); @@ -130,6 +130,13 @@ impl State { let (h1, m1, s1, ms1) = Self::split_time(timestamp); let (h2, m2, s2, ms2) = Self::split_time(timestamp + duration); + // Rounding up to the millisecond and clamping to fragment duration + // might result in zero-duration cues, which we skip as some players + // interpret those in a special way + if h1 == h2 && m1 == m2 && s1 == s2 && ms1 == ms2 { + return None; + } + writeln!( &mut data, "{:02}:{:02}:{:02}.{:03} --> {:02}:{:02}:{:02}.{:03}", @@ -146,7 +153,7 @@ impl State { buffer.set_flags(gst::BufferFlags::DELTA_UNIT); } - buffer + Some(buffer) } fn check_initial_header(&mut self, pts: gst::ClockTime) -> Option<gst::Buffer> { @@ -223,11 +230,18 @@ impl State { // No need to output an explicit cue for eg clear buffers if !output_text.is_empty() { - buffers.push(Self::create_vtt_buffer( - lines.pts, - lines.duration, - output_text, - )); + let mut buf = Self::create_vtt_buffer(lines.pts, lines.duration, &output_text); + + if let Some(buf) = buf.take() { + buffers.push(buf); + } else { + gst::debug!( + CAT, + "Dropping empty duration cue, pts: {}, text: {}", + lines.pts, + output_text + ); + } } } |