Skip to content

Commit 73db61f

Browse files
committed
burn-timestamps: preserve input timing
1 parent 9494a4e commit 73db61f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

media-utils/burn-timestamps/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ font-drawing.workspace = true
2222
frame-source = { workspace = true, features = ["openh264"] }
2323
env-tracing-logger.workspace = true
2424
strand-datetime-conversion.workspace = true
25-
ffmpeg-writer.workspace = true
25+
ffmpeg-rewriter.workspace = true

media-utils/burn-timestamps/src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn main() -> Result<()> {
106106
}
107107

108108
let mut ffmpeg_wtr =
109-
ffmpeg_writer::FfmpegWriter::new(cli.output.as_str(), Default::default(), None)?;
109+
ffmpeg_rewriter::FfmpegReWriter::new(cli.output.as_str(), Default::default(), None, None)?;
110110

111111
let mut pb: Option<ProgressBar> = if !cli.no_progress {
112112
let (lower_bound, _upper_bound) = src.iter().size_hint();
@@ -133,24 +133,25 @@ fn main() -> Result<()> {
133133
eyre::bail!("Frame {idx} has no decoded image data.",);
134134
};
135135

136-
let text = match frame.timestamp() {
137-
frame_source::Timestamp::Duration(dur) => {
138-
format!(
139-
"{}",
140-
(t0 + dur).to_rfc3339_opts(chrono::format::SecondsFormat::Millis, true)
141-
)
142-
}
143-
frame_source::Timestamp::Fraction(frac) => {
144-
format!("{:2.1}%", frac * 100.0)
136+
let dur = match frame.timestamp() {
137+
frame_source::Timestamp::Duration(dur) => dur,
138+
_ => {
139+
eyre::bail!("Expected duration timestamp");
145140
}
146141
};
142+
let ts = t0 + dur;
143+
144+
let text = format!(
145+
"{}",
146+
ts.to_rfc3339_opts(chrono::format::SecondsFormat::Millis, true)
147+
);
147148

148149
let mut frame_rgb8 = im.into_pixel_format()?.owned();
149150
stamp_frame(&mut frame_rgb8, &font, &text)?;
150151

151152
let dy_im = strand_dynamic_frame::DynamicFrame::from_static_ref(&frame_rgb8);
152153

153-
ffmpeg_wtr.write_dynamic_frame(&dy_im)?;
154+
ffmpeg_wtr.write_dynamic_frame(&dy_im, ts)?;
154155
}
155156

156157
ffmpeg_wtr.close()?;

0 commit comments

Comments
 (0)