Skip to content

refactor: centralize constants and de-duplicate processor.py (#4, #5, #6) - #4

Open
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:refactor/processor-dedup-constants
Open

refactor: centralize constants and de-duplicate processor.py (#4, #5, #6)#4
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:refactor/processor-dedup-constants

Conversation

@rsmxingu

Copy link
Copy Markdown

Three related, behavior-preserving cleanups in processor.py. The generated ffmpeg/auto-editor command and filter strings are byte-for-byte unchanged (verified by the existing tests).

#4 — Speed is no longer hardcoded; defaults are centralized

The 1.2x speedup was a literal in two places and could not be changed without editing code. Added module-level constants and made run() read speed_val from config (default DEFAULT_SPEED), so the value is configurable end-to-end.

DEFAULT_SPEED, DEFAULT_CRF, DEFAULT_PRESET, DEFAULT_MARGIN,
DEFAULT_THRESHOLD, AUDIO_BITRATE, INTRO_OVERLAY_SECONDS, DYNAUDNORM_FILTER

These replace magic numbers/strings that previously had to be edited in several spots (e.g. recent commits that bumped CRF in multiple places).

#5 — De-duplicate clip-speed parsing in build_filtergraph

The "parse speed: effect + resolve target speed" block was copy-pasted three times (duration calc, video clips, audio clips). Extracted _clip_speed() and _target_speed() helpers. Malformed effects now tolerate IndexError in addition to ValueError.

#6 — De-duplicate ffmpeg command construction

The identical H.265 video + AAC audio argument block (two-pass and single-pass) is now built by _append_encode_args(). The two-pass intro-overlay branch no longer repeats the overlay filter string across the boost / no-boost cases.

Tests

  • Added TestClipSpeedHelpers covering _clip_speed / _target_speed (no-effect, explicit speed, malformed effect, speedup-disabled).
  • All existing build_filtergraph / run tests pass unchanged → confirms identical generated strings.
  • python3 -m unittest tests.test_processor14 passed (no tkinter needed for this module).

🤖 Generated with Claude Code

Three related cleanups in the processing pipeline, behavior-preserving (the
generated ffmpeg/auto-editor command strings are unchanged):

rsd#4 — Speed is no longer hardcoded and is read from config
  The 1.2x speedup was a literal in two places (two-pass and single-pass) and
  could not be changed without editing code. Added module-level constants
  (DEFAULT_SPEED, DEFAULT_CRF, DEFAULT_PRESET, DEFAULT_MARGIN, DEFAULT_THRESHOLD,
  AUDIO_BITRATE, INTRO_OVERLAY_SECONDS, DYNAUDNORM_FILTER) and made run() read
  speed_val from config (falling back to DEFAULT_SPEED), so the value is now
  configurable end-to-end. The same constants replace the magic numbers that
  previously had to be edited in several spots (e.g. recent commits that bumped
  CRF in multiple places).

rsd#5 — De-duplicate clip speed parsing in build_filtergraph
  The "parse speed: effect + resolve target speed" block was copy-pasted three
  times (duration calc, video clips, audio clips). Extracted _clip_speed() and
  _target_speed() helpers; malformed effects now also tolerate IndexError, not
  just ValueError.

rsd#6 — De-duplicate ffmpeg command construction
  The identical H.265 video + AAC audio argument block (two-pass and single-pass)
  is now built by _append_encode_args(). The two-pass intro-overlay branch no
  longer repeats the overlay filter string for the boost/no-boost cases.

Tests:
- Add TestClipSpeedHelpers covering _clip_speed / _target_speed (including the
  malformed-effect and speedup-disabled cases).
- Existing build_filtergraph / run tests pass unchanged, confirming the
  generated filter and command strings are identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant