How 30ms Audio Fades Prevent Pops at Cut Boundaries in video-use

30ms audio fades eliminate audible pops at cut boundaries by smoothing the waveform transition to silence, implemented in the extract_segment function using FFmpeg's afade filter.

The video-use repository processes video edits as self-contained segments, where abrupt audio truncation can create distracting clicks. By applying deterministic 30ms fade-in and fade-out curves to every extracted segment, the codebase ensures professional-quality audio without manual intervention.

The Acoustic Problem with Hard Cuts

When audio waveforms are truncated instantly at cut points, the discontinuity creates high-frequency artifacts perceived as audible pops. Digital-to-analog converters (DACs) struggle with instantaneous amplitude changes, resulting in transient noise that degrades the listening experience.

Implementation in helpers/render.py

The fade logic resides in helpers/render.py within the extract_segment function (lines 887-890). This implementation treats every segment as an isolated unit requiring smooth audio boundaries to prevent discontinuities.

Calculating Fade Timing

The system computes the fade-out start time using a safeguarded calculation to handle edge cases:

fade_out_start = max(0.0, duration - 0.03)

This ensures the 30ms fade begins exactly 0.03 seconds before the segment ends, preventing negative values on extremely short clips while maintaining consistent fade behavior.

FFmpeg Filter Chain Construction

The code constructs a precise audio filter string combining both fade-in and fade-out operations:

af = f"afade=t=in:st=0:d=0.03,afade=t=out:st={fade_out_start:.3f}:d=0.03"

This filter graph is passed to FFmpeg via the -af option, applying a 30ms fade-in at the start (0 seconds) and a complementary fade-out at the calculated end position. The waveform is smoothly ramped to silence rather than cut abruptly, removing the high-frequency discontinuity that causes pops.

Command-Line and Programmatic Usage

You can trigger this behavior through the standard rendering pipeline or directly via Python.

To process an edit decision list (EDL) with automatic fades:

python helpers/render.py edl.json -o final.mp4

For direct segment extraction with guaranteed fade application:

from pathlib import Path
from helpers.render import extract_segment

source = Path("input.mp4")
seg_start = 12.5
duration = 4.0
grade_filter = ""
out_path = Path("segment_00.mp4")

extract_segment(
    source,
    seg_start,
    duration,
    grade_filter,
    out_path,
    preview=False,
    draft=False,
)

The resulting segment_00.mp4 contains imperceptible 30ms fades at both boundaries, eliminating pops even when the original source contains sharp transients at the cut timestamps.

Why 30ms?

The 30ms duration represents a pragmatic acoustic compromise documented as Rule 3 in the source. It is short enough to remain inaudible as a distinct effect, yet long enough to provide DACs sufficient samples to settle. This deterministic approach ensures every segment extracted by video-use maintains pop-free audio consistency regardless of the source material's transient characteristics.

Summary

  • 30ms fades prevent audible pops by smoothing waveform discontinuities at cut boundaries
  • The logic lives in helpers/render.py inside the extract_segment function at lines 887-890
  • FFmpeg's afade filter applies fade-in at 0 seconds and fade-out at duration - 0.03
  • Both CLI and Python API automatically include these fades in segment extraction
  • The 30ms duration balances imperceptibility with DAC settling requirements

Frequently Asked Questions

Why does cutting audio create popping sounds?

Abrupt amplitude changes create high-frequency discontinuities that DACs reproduce as transient clicks. The instantaneous jump from a non-zero sample value to silence (or vice versa) generates broadband noise audible as a pop.

Can I adjust the fade duration in video-use?

The current implementation hardcodes 30ms (0.03 seconds) in the extract_segment function. To modify this duration, you would need to edit the fade parameters in helpers/render.py at lines 887-890 where the afade filter string is constructed.

Do the fades affect video quality or synchronization?

Audio fades operate independently of the video stream and do not impact visual quality. The 30ms duration is sufficiently brief to maintain tight synchronization between audio and video while eliminating only the transient artifacts at cut points.

Does this work with all audio formats supported by FFmpeg?

Yes, the afade filter works with any audio codec FFmpeg supports. Since video-use passes the filter string directly to FFmpeg's -af option, the fades apply universally to PCM, AAC, MP3, and other encoded audio streams during the extraction process.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →