WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 130fe16

Browse files
committed
Track last frame timestamp in SegmentedAudioEncoder
1 parent 85ef4a1 commit 130fe16

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/enc-ffmpeg/src/mux/segmented_audio.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct SegmentedAudioEncoder {
1212
current_index: u32,
1313
segment_duration: Duration,
1414
segment_start_time: Option<Duration>,
15+
last_frame_timestamp: Option<Duration>,
1516

1617
completed_segments: Vec<SegmentInfo>,
1718
}
@@ -87,6 +88,7 @@ impl SegmentedAudioEncoder {
8788
current_index: 0,
8889
segment_duration,
8990
segment_start_time: None,
91+
last_frame_timestamp: None,
9092
completed_segments: Vec::new(),
9193
})
9294
}
@@ -125,6 +127,8 @@ impl SegmentedAudioEncoder {
125127
self.segment_start_time = Some(timestamp);
126128
}
127129

130+
self.last_frame_timestamp = Some(timestamp);
131+
128132
let segment_elapsed =
129133
timestamp.saturating_sub(self.segment_start_time.unwrap_or(Duration::ZERO));
130134

@@ -205,15 +209,15 @@ impl SegmentedAudioEncoder {
205209
if let Some(mut encoder) = self.current_encoder.take() {
206210
if encoder.has_frames {
207211
if let Some(segment_start) = self.segment_start_time {
208-
let final_duration = Duration::from_secs(5);
212+
let final_duration = self
213+
.last_frame_timestamp
214+
.unwrap_or(segment_start)
215+
.saturating_sub(segment_start);
209216

210217
self.completed_segments.push(SegmentInfo {
211218
path: self.current_segment_path(),
212219
index: self.current_index,
213-
duration: final_duration.saturating_sub(
214-
final_duration
215-
.saturating_sub(segment_start.saturating_sub(segment_start)),
216-
),
220+
duration: final_duration,
217221
});
218222
}
219223

crates/enc-ffmpeg/src/remux.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ pub fn probe_video_can_decode(path: &Path) -> Result<bool, String> {
290290
.map_err(|e| format!("Failed to create video decoder: {e}"))?;
291291

292292
let stream_index = input_stream.index();
293-
drop(input_stream);
294293

295294
let mut input = avformat::input(path).map_err(|e| format!("Failed to reopen file: {e}"))?;
296295

0 commit comments

Comments
 (0)