Repository navigation
fix(silence_cutter): handle negative timestamps and segments without video - #995
Open
Alvaro8317 wants to merge 2 commits into
Open
Alvaro8317 wants to merge 2 commits into
Alvaro8317 wants to merge 2 commits into
Conversation
- tools/video/silence_cutter.py: accept a leading minus sign and exponent notation when parsing silencedetect output, and clamp the start to 0, so a missed first start no longer shifts every later start/end pair - tests/tools/test_silence_timestamp_parsing.py: new regression tests for negative and exponent first timestamps
- tools/video/silence_cutter.py: when the source has video, leave out of the concat any rendered segment without video packets, which happens when the audio outlasts the video and corrupts the output timeline; report the count and exclude it from output_duration. Audio-only sources and cover art keep every segment - tests/tools/test_silence_segments_without_video.py: new native FFmpeg tests for audio longer than video, matching streams, audio-only input and cover art
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two cases where
silence_cutterreturnssuccess: Truewith a wrong result. I found both while cutting a 7m43s narrated screen recording.1. A negative or exponent
silence_startis misread. When a stream starts slightly before 0, FFmpeg printssilence_start: -0.000166667. The pattern[\d.]+does not match it, so that start is lost and every later start is paired with the wrong end. On the original recording, 152 silences produced a single speech segment, so nothing would be cut. Exponent values have a related problem:2.08333e-05was read as2.08333.2. Audio longer than video corrupts the output. If a rendered segment falls past the last video frame, it is audio-only, and concatenating it breaks the output timeline. A 0.11 s audio tail was enough: the output declared 2429.9 s of video instead of about 388.7 s, and decoding reported an error.
Related issue
None. I searched open and closed issues and PRs for
silenceandsilence_cutterand found no duplicate. #898 changed the same tool but covers detection failures.Changes
silencedetectvalues, and clamp the start to 0.removeandspeed_up, only when the source has a real video stream. Audio-only files and cover art keep every segment.dropped_segments_without_videoto the result so the drop is visible, and exclude the dropped time fromoutput_duration.Testing
pytest tests) on Python 3.11, Linux, FFmpeg 6.1.1: 2917 passed before, 2930 passed after, 17 skipped in both.removemode, after the fix: 388.70 s video and 388.70 s audio, no decode errors, one segment dropped.Notes for reviewers
ffprobecall.Checklist
make test-contracts/make test) where applicable.🤖 Generated with Claude Code