mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-20 14:46:24 +00:00
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
This commit is contained in:
parent
b63627025e
commit
9740140798
1 changed files with 22 additions and 8 deletions
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue