mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-08 20:02:05 +00:00
fix(export): encode WebM audio packets in place instead of draining each from the front
This commit is contained in:
@@ -244,12 +244,14 @@ pub(crate) async fn webm(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut Sta
|
||||
let pad = (fs - pcm_left.len() % fs) % fs + fs;
|
||||
pcm_left.extend(std::iter::repeat_n(0.0, pad));
|
||||
}
|
||||
while pcm_left.len() >= fs {
|
||||
let pkt = enc.encode_float(&pcm_left[..fs]);
|
||||
pcm_left.drain(..fs);
|
||||
// Packets are read in place and the encoded samples dropped once: draining each packet
|
||||
// from the front would shift the rest of the batch's audio every 20 ms.
|
||||
for packet in pcm_left.chunks_exact(fs) {
|
||||
let pkt = enc.encode_float(packet);
|
||||
frames.push(Frame { ms: packets as i64 * 20, track: 2, key: true, prev_ms: None, data: pkt, alpha: None });
|
||||
packets += 1;
|
||||
}
|
||||
pcm_left.drain(..pcm_left.len() / fs * fs);
|
||||
};
|
||||
|
||||
let batch = batch_size();
|
||||
|
||||
@@ -124,12 +124,14 @@ pub(crate) async fn webm_av1(job: &Cx<'_>, comp: &Comp, w: u32, h: u32, st: &mut
|
||||
let pad = (fs - pcm_left.len() % fs) % fs + fs;
|
||||
pcm_left.extend(std::iter::repeat_n(0.0, pad));
|
||||
}
|
||||
while pcm_left.len() >= fs {
|
||||
let pkt = enc.encode_float(&pcm_left[..fs]);
|
||||
pcm_left.drain(..fs);
|
||||
// Packets are read in place and the encoded samples dropped once: draining each packet
|
||||
// from the front would shift the rest of the batch's audio every 20 ms.
|
||||
for packet in pcm_left.chunks_exact(fs) {
|
||||
let pkt = enc.encode_float(packet);
|
||||
blocks.push(Block { ms: packets as i64 * 20, track: 2, key: true, data: pkt });
|
||||
packets += 1;
|
||||
}
|
||||
pcm_left.drain(..pcm_left.len() / fs * fs);
|
||||
};
|
||||
|
||||
let batch = batch_size();
|
||||
|
||||
Reference in New Issue
Block a user