#7604·refine

getWaveformPortion 会损坏音频缓冲区并泄露负开始时间偏移的音频样本

作者: codeCraft-Ritik创建于 2026年9月16日更新于 2026年9月16日
标签bug

描述错误

描述错误 当使用GetWaveform Portion'或可视化AudioWaveform'的音频音轨时,该音轨以相向开头(例如,音频从t = 2.0s'起,可视化窗口从t = 0'起),`GetWaveform Portion'会腐蚀返回的波形缓冲器。

在[`包装/介质-利用/src/get-waveform-portion.ts' (包装/media-utils/src/get-waveform-portion.ts#L69-L83)中:

被夹住的开始 = Math.max(从样板开始, 0); c. 相接端= Math.min(波形.长,端样);

const padStart = 样本在开始前 > 0? 新的Float32Array(样本在开始前). fill (0): 无效; cont supend End = 样本后 > 0? 新的Float32Array(样本后端). fill (0): 无效; cont arrs = [padStart, swaveform.slic (clampedStart, caped End), send End]. filter (NoReact Internals. truthy; ).


当`终样' < 0'(例如`起始样'=-2000',`终样'=-1500'),`被宣布为 " 1500 " 。 在JavaScript中,`Float32Array.protOtype.slice (0, - 1500)'将负数视为从阵列的**端**中抵消。 对于一万个抽样轨道,`slice(0, - 1500)'返回8,500个实际音频数据样本,而不是沉默。 此外,`Samples BeeforeStart ' 和`samples After End ' 使用无限制差异,造成一个超大小的缓冲器,其中包含10,500个样本,当时只要求500个样本沉默。

                                                                                    

                                                                                    
1. 在音频启动前,在负时间内用窗口拨打 " GetWaveform Portion " :

从“@remotion/media-utils” 导入{ get Waveform Portion};

const 部分 = 获得Waveform Portion({)
音频数据 : {
样本数量:1,000,
频道号码: 1,
会期 秒数: 10,
信道Waveforms: [新浮图32Array(1000).fill(0.9)],
{\fn华文楷体\fs16\1cHE0E0E0}
启动 TimeInseconds: 0,
会期 秒数:0.5,
dataOffsetInseconds: 2.0, // 音频起始于 2s, 窗口为 -2s 到 -1.5s
样本数: 50,
* ;
  1. 检查返回的栏杆:其中有振幅0.9'(从音轨上取出)而不是0'。

预期行为

预期行为 当音频音轨开始前请求音频数据时,“GetWaveform Portion”应返回一个完全由“0”振幅固定的阵列,与所要求的确切持续时间相匹配。 被宣布为起点'和被宣布为终点'必须限定为`[0,波形.长]'。

建议的修补 {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你来干什么? -- -- a/packages/media-utils/src/get-waveform-portion.ts 页面存档备份,存于互联网档案馆. b/包装/介质-用途/弧/格-波形-相位.ts +-63,14+63,14 + + 输出 const 得到Waveform Portion=({ 音频Data.sampleRate, (三)

  • 开始前样本=0 -- -- startSample;
  • Const sample After End = endSample-波形.长;
  • Const padStartLength = Math.max (0, Math.min (endSample, 0) - startSample); ; + C.
  • Const被夹住的Sart = Math.max (0, Math.min (waveform.word, startSample)); ; + Const被夹住的Sart = Math.max (0, Math.min (波形.word, startSample)).
  • Const被夹住的 End = Math.max (0, Math.min (waveform.hong, endSample)); ; 2.
  • const sample EndLength = Math.max (0, endSample - Math.max (startSample, waveform.長)); 2.
  • Const被夹住的Sart = Math.max(sartSample, 0); . . . . . . .

内容来源: refinedev/refine