Skip to content

Commit

Permalink
[cli] Cleanup some config defaults and ensure cut format is always set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Breakthrough committed Jan 29, 2024
1 parent d5f8126 commit 0e7d16a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 5 additions & 2 deletions scenedetect/_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ def format(self, timecode: FrameTimecode) -> str:

_CONFIG_FILE_NAME: AnyStr = 'scenedetect.cfg'
_CONFIG_FILE_DIR: AnyStr = user_config_dir("PySceneDetect", False)
_PLACEHOLDER = 0 # Placeholder for image quality default, as the value depends on output format

CONFIG_FILE_PATH: AnyStr = os.path.join(_CONFIG_FILE_DIR, _CONFIG_FILE_NAME)
DEFAULT_JPG_QUALITY = 95
DEFAULT_WEBP_QUALITY = 100

# TODO(v0.7): Remove [detect-adaptive] min-delta-hsv
CONFIG_MAP: ConfigDict = {
'backend-opencv': {
'max-decode-attempts': 5,
Expand All @@ -257,7 +261,6 @@ def format(self, timecode: FrameTimecode) -> str:
'min-scene-len': TimecodeValue(0),
'threshold': RangeValue(3.0, min_val=0.0, max_val=255.0),
'weights': ScoreWeightsValue(ContentDetector.DEFAULT_COMPONENT_WEIGHTS),
# TODO(v0.7): Remove `min-delta-hsv``.
'min-delta-hsv': RangeValue(15.0, min_val=0.0, max_val=255.0),
},
'detect-content': {
Expand Down Expand Up @@ -312,7 +315,7 @@ def format(self, timecode: FrameTimecode) -> str:
'height': 0,
'num-images': 3,
'output': '',
'quality': RangeValue(0, min_val=0, max_val=100), # Default depends on format
'quality': RangeValue(_PLACEHOLDER, min_val=0, max_val=100),
'scale': 1.0,
'scale-method': 'linear',
'width': 0,
Expand Down
21 changes: 11 additions & 10 deletions scenedetect/_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from scenedetect.stats_manager import StatsManager
from scenedetect.scene_manager import SceneManager, Interpolation

from scenedetect._cli.config import ConfigRegistry, ConfigLoadFailure, TimecodeFormat, CHOICE_MAP
from scenedetect._cli.config import (ConfigRegistry, ConfigLoadFailure, TimecodeFormat, CHOICE_MAP,
DEFAULT_JPG_QUALITY, DEFAULT_WEBP_QUALITY)

logger = logging.getLogger('pyscenedetect')

Expand Down Expand Up @@ -152,14 +153,14 @@ def __init__(self):

# `list-scenes` Command Options
self.list_scenes: bool = False
self.list_scenes_quiet: bool = None # list-scenes -q/--quiet
self.scene_list_dir: str = None # list-scenes -o/--output
self.scene_list_name_format: str = None # list-scenes -f/--filename
self.scene_list_output: bool = None # list-scenes -n/--no-output
self.skip_cuts: bool = None # list-scenes -s/--skip-cuts
self.display_cuts: bool = True # [list-scenes] display-cuts
self.display_scenes: bool = True # [list-scenes] display-scenes
self.cut_format: TimecodeFormat = None # [list-scenes] cut-format
self.list_scenes_quiet: bool = None # list-scenes -q/--quiet
self.scene_list_dir: str = None # list-scenes -o/--output
self.scene_list_name_format: str = None # list-scenes -f/--filename
self.scene_list_output: bool = None # list-scenes -n/--no-output
self.skip_cuts: bool = None # list-scenes -s/--skip-cuts
self.display_cuts: bool = False # [list-scenes] display-cuts
self.display_scenes: bool = True # [list-scenes] display-scenes
self.cut_format: TimecodeFormat = TimecodeFormat.TIMECODE # [list-scenes] cut-format

# `export-html` Command Options
self.export_html: bool = False
Expand Down Expand Up @@ -637,7 +638,7 @@ def handle_save_images(
self.scale_method = Interpolation[self.config.get_value('save-images',
'scale-method').upper()]

default_quality = 100 if webp else 95
default_quality = DEFAULT_WEBP_QUALITY if webp else DEFAULT_JPG_QUALITY
quality = (
default_quality if self.config.is_default('save-images', 'quality') else
self.config.get_value('save-images', 'quality'))
Expand Down

0 comments on commit 0e7d16a

Please sign in to comment.