diff --git a/CHANGELOG.md b/CHANGELOG.md index ae04c325..b62d4724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Probe completion uses reliable processed media time as well as wall-clock + runtime, with successful FFmpeg exit and usable measurements required for + accelerated probes. Profiles expose **Minimum Probe Completion (%)** under + **Settings -> Profiles -> Edit profile -> Stream Checking**, defaulting to + 80%. Setting 0 disables only the duration rule; probe errors and enabled + blank/freeze checks still apply. Suggested by + [@teffi71](https://github.com/teffi71) in + [#544](https://github.com/krinkuto11/streamflow/issues/544). + - Single-channel changelog entries show the channel name in the card heading and open their full stream measurements in one click. This also applies to historical and manual checks; Teamarr Preflight keeps its reuse summary and diff --git a/backend/apps/automation/automation_config_manager.py b/backend/apps/automation/automation_config_manager.py index ffd93f9e..334870be 100644 --- a/backend/apps/automation/automation_config_manager.py +++ b/backend/apps/automation/automation_config_manager.py @@ -298,8 +298,12 @@ def _normalize_profile_settings(self, extra_settings: Any) -> Dict[str, Any]: extra = dict(self._normalize_extra_settings(extra_settings)) checking = extra.get('stream_checking') if isinstance(checking, dict): + from apps.core.probe_completion import normalize_minimum_probe_completion_percent extra['stream_checking'] = { **checking, + 'minimum_probe_completion_percent': normalize_minimum_probe_completion_percent( + checking.get('minimum_probe_completion_percent', 80), + ), 'provider_stream_limit': self._coerce_non_negative_int( checking.get('provider_stream_limit', 0), ), diff --git a/backend/apps/core/probe_completion.py b/backend/apps/core/probe_completion.py new file mode 100644 index 00000000..933c11d3 --- /dev/null +++ b/backend/apps/core/probe_completion.py @@ -0,0 +1,89 @@ +"""Shared duration policy for probe retries and final stream classification.""" + +import math + +DEFAULT_MINIMUM_PROBE_COMPLETION_PERCENT = 80 + + +def _finite(value): + if isinstance(value, bool): + return None + try: + number = float(value) + except (TypeError, ValueError, OverflowError): + return None + return number if math.isfinite(number) else None + + +def normalize_minimum_probe_completion_percent(value): + number = _finite(value) + if number is None or not 0 <= number <= 100: + return DEFAULT_MINIMUM_PROBE_COMPLETION_PERCENT + return number + + +def media_window_seconds(progress_times, requested_seconds): + """Accept bounded, continuous output progress, not an isolated timestamp. + + Large initial offsets, jumps, backwards time and implausible overruns cannot + prove media coverage. Such inputs retain the wall-clock duration fallback. + """ + expected = _finite(requested_seconds) + times = [_finite(value) for value in progress_times] + if expected is None or expected <= 0 or len(times) < 2 or None in times: + return None + if times[0] < 0 or times[0] > min(5, expected * 0.2): + return None + if times[-1] > expected + max(2, expected * 0.1): + return None + for previous, current in zip(times, times[1:]): + if current < previous or current - previous > max(5, expected * 0.25): + return None + span = times[-1] - times[0] + return span if span > 0 else None + + +def probe_exit_failed(data): + code = data.get('ffmpeg_exit_code') + return data.get('ffmpeg_error_detected') is True or ( + code is not None and _finite(code) != 0 + ) + + +def probe_window_completion(data, minimum_percent=None): + """Return (complete, basis); missing legacy timing keeps its old behavior.""" + if probe_exit_failed(data) or str(data.get('status') or '').lower() in { + 'error', 'failed', 'timeout', 'stream_timeout', 'probe_timeout', + }: + return False, 'ffmpeg_error' + if minimum_percent is None: + minimum_percent = data.get('minimum_probe_completion_percent', 80) + percent = normalize_minimum_probe_completion_percent(minimum_percent) + if percent == 0: + return True, 'duration_check_disabled' + + expected_raw = data.get('ffmpeg_duration', data.get('ffmpeg_duration_seconds')) + elapsed_raw = data.get('elapsed_time') + if expected_raw is None or elapsed_raw is None: + return True, 'legacy_without_timing' + expected, elapsed = _finite(expected_raw), _finite(elapsed_raw) + if expected is None or elapsed is None or elapsed < 0: + return False, 'invalid_timing' + if expected <= 0: + return True, 'legacy_without_timing' + required = expected * percent / 100 + if elapsed >= required: + return True, 'wall_clock' + + media = _finite(data.get('probe_media_seconds')) + # Media-time acceptance requires an explicitly successful FFmpeg process + # plus usable measurements; metadata from failed/partial probes cannot win. + width, _, height = str(data.get('resolution') or '').partition('x') + metrics = [_finite(value) for value in ( + width, height, data.get('fps'), data.get('bitrate_kbps'), + )] + if (data.get('ffmpeg_exit_code') == 0 and media is not None + and required <= media <= expected + max(2, expected * 0.1) + and all(value is not None and value > 0 for value in metrics)): + return True, 'media_time' + return False, 'incomplete_window' diff --git a/backend/apps/core/stream_stats_utils.py b/backend/apps/core/stream_stats_utils.py index fb22da0e..af5b0269 100644 --- a/backend/apps/core/stream_stats_utils.py +++ b/backend/apps/core/stream_stats_utils.py @@ -547,20 +547,27 @@ def is_stream_dead(stream_data: Dict[str, Any], config: Dict[str, Any] = None) - _analysis_failure_context(stream_data), ) - EARLY_EXIT_THRESHOLD = 0.8 - elapsed = stream_data.get('elapsed_time') - expected = stream_data.get('ffmpeg_duration') - if ( - elapsed is not None - and expected is not None - and expected > 0 - and elapsed < expected * EARLY_EXIT_THRESHOLD - ): + from apps.core.probe_completion import probe_exit_failed, probe_window_completion + if probe_exit_failed(stream_data): + return DeadStreamResult(True, 'offline', 'error', _analysis_failure_context(stream_data)) + completed, basis = probe_window_completion( + stream_data, (config or {}).get('minimum_probe_completion_percent'), + ) + if not completed: return DeadStreamResult( True, 'unstable', 'probe_exited_early', - {'actual_seconds': elapsed, 'expected_seconds': expected}, + { + 'actual_seconds': stream_data.get('elapsed_time'), + 'expected_seconds': stream_data.get('ffmpeg_duration'), + 'media_seconds': stream_data.get('probe_media_seconds'), + 'minimum_completion_percent': (config or {}).get( + 'minimum_probe_completion_percent', + stream_data.get('minimum_probe_completion_percent', 80), + ), + 'completion_basis': basis, + }, ) stream_stats = stream_data.get('stream_stats') diff --git a/backend/apps/stream/checker/bitrate_progress.py b/backend/apps/stream/checker/bitrate_progress.py index fc46ce7b..6e1654bc 100644 --- a/backend/apps/stream/checker/bitrate_progress.py +++ b/backend/apps/stream/checker/bitrate_progress.py @@ -55,6 +55,9 @@ def recheck_bitrate_stream(stream, _initial): capacity_transition_lock=stream_statuses_lock, probe_slots=getattr(self, '_preflight_probe_slots', None), ffmpeg_duration=analysis_params.get('ffmpeg_duration', 30), + minimum_probe_completion_percent=_threshold_config.get( + 'minimum_probe_completion_percent', 80, + ), timeout=analysis_params.get('timeout', 30), retries=0, retry_delay=0, diff --git a/backend/apps/stream/checker/classification.py b/backend/apps/stream/checker/classification.py index d3eb7eb5..fb264a8b 100644 --- a/backend/apps/stream/checker/classification.py +++ b/backend/apps/stream/checker/classification.py @@ -27,6 +27,10 @@ def _build_threshold_config_from_profile(self, stream_checking: Dict[str, Any]) second argument. Only non-zero thresholds are included. """ config: Dict[str, Any] = {} + from apps.core.probe_completion import normalize_minimum_probe_completion_percent + config['minimum_probe_completion_percent'] = normalize_minimum_probe_completion_percent( + stream_checking.get('minimum_probe_completion_percent', 80), + ) min_res = stream_checking.get('min_resolution', 'any') if min_res in ('2160p', '4k'): config['min_resolution_width'], config['min_resolution_height'] = 3840, 2160 @@ -101,6 +105,11 @@ def _is_stream_dead(self, stream_data: Dict[str, Any], channel_id: Optional[int] if profile: stream_checking = profile.get('stream_checking', {}) if stream_checking.get('enabled', False): + profile_config['minimum_probe_completion_percent'] = ( + self._build_threshold_config_from_profile(stream_checking)[ + 'minimum_probe_completion_percent' + ] + ) # Construct config from profile settings # Convert min_res string (e.g., '1080p') to dimensions min_res = stream_checking.get('min_resolution', '0x0') diff --git a/backend/apps/stream/checker/concurrent_channel.py b/backend/apps/stream/checker/concurrent_channel.py index 6c902ab1..18b1b178 100644 --- a/backend/apps/stream/checker/concurrent_channel.py +++ b/backend/apps/stream/checker/concurrent_channel.py @@ -730,6 +730,9 @@ def inspection_result(analyzed, ordered_ids=None, dead_ids=()): capacity_transition_lock=stream_statuses_lock, probe_slots=getattr(self, '_preflight_probe_slots', None), ffmpeg_duration=analysis_params.get('ffmpeg_duration', 30), + minimum_probe_completion_percent=_threshold_config.get( + 'minimum_probe_completion_percent', 80, + ), timeout=analysis_params.get('timeout', 30), retries=analysis_params.get('retries', 1), retry_delay=analysis_params.get('retry_delay', 10), diff --git a/backend/apps/stream/checker/sequential_channel.py b/backend/apps/stream/checker/sequential_channel.py index 8ca08a6e..dfea013b 100644 --- a/backend/apps/stream/checker/sequential_channel.py +++ b/backend/apps/stream/checker/sequential_channel.py @@ -534,6 +534,9 @@ def _check_channel_sequential( stream_id=stream['id'], stream_name=stream.get('name', 'Unknown'), ffmpeg_duration=analysis_params.get('ffmpeg_duration', 20), + minimum_probe_completion_percent=_threshold_config.get( + 'minimum_probe_completion_percent', 80, + ), timeout=analysis_params.get('timeout', 30), retries=analysis_params.get('retries', 1), retry_delay=analysis_params.get('retry_delay', 10), @@ -570,6 +573,9 @@ def recheck_sequential_bitrate(_stream, _initial): stream_id=stream['id'], stream_name=stream.get('name', 'Unknown'), ffmpeg_duration=analysis_params.get('ffmpeg_duration', 20), + minimum_probe_completion_percent=_threshold_config.get( + 'minimum_probe_completion_percent', 80, + ), timeout=analysis_params.get('timeout', 30), retries=0, retry_delay=0, @@ -874,6 +880,9 @@ def sequential_recheck_started(initial, recheck_index, recheck_total): stream_id=stream['id'], stream_name=stream.get('name', 'Unknown'), ffmpeg_duration=analysis_params.get('ffmpeg_duration', 20), + minimum_probe_completion_percent=_threshold_config.get( + 'minimum_probe_completion_percent', 80, + ), timeout=analysis_params.get('timeout', 30), retries=analysis_params.get('retries', 1), retry_delay=analysis_params.get('retry_delay', 10), diff --git a/backend/apps/stream/stream_check_utils.py b/backend/apps/stream/stream_check_utils.py index f82a206c..0e0cc8f8 100644 --- a/backend/apps/stream/stream_check_utils.py +++ b/backend/apps/stream/stream_check_utils.py @@ -59,6 +59,10 @@ from apps.core.logging_config import setup_logging from apps.core.log_sanitizer import audit_ref as _audit_ref, scrub_urls, stream_ref, url_ref from apps.core.stream_protocols import effective_stream_startup_buffer, has_supported_stream_protocol +from apps.core.probe_completion import ( + media_window_seconds, normalize_minimum_probe_completion_percent, + probe_window_completion, +) logger = setup_logging(__name__) @@ -95,7 +99,7 @@ 'cannot open', 'unknown hwaccel', ) -EARLY_EXIT_THRESHOLD = 0.8 # Consider ffmpeg exited early if elapsed < 80% of expected duration +EARLY_EXIT_THRESHOLD = 0.8 # Default for diagnostic/bitrate fallback timing MAX_ERROR_LINES_TO_LOG = 5 # Maximum number of error lines to log from ffmpeg output MAX_DEBUG_LINES_TO_LOG = 10 # Maximum number of debug lines to log from ffmpeg output @@ -2008,6 +2012,13 @@ def apply_visual_probe() -> None: progress_bitrate = None last_stats_line = None # keeps updating; final line is the most stable average last_media_time = 0.0 + media_progress_times = [] + result_data['ffmpeg_exit_code'] = result.returncode + result_data['ffmpeg_error_detected'] = bool(re.search( + r'Input/output error|Connection reset by peer|Connection timed out|' + r'Error opening input|Error during demuxing|Server returned [45]\d\d', + output or '', re.IGNORECASE, + )) # Track Input vs Output sections so we only parse input stream codecs, # not decoded output formats (e.g. pcm_s16le instead of aac) @@ -2017,6 +2028,7 @@ def apply_visual_probe() -> None: progress_time = _parse_ffmpeg_progress_time(line) if progress_time is not None: last_media_time = max(last_media_time, progress_time) + media_progress_times.append(progress_time) # ── Section tracking ───────────────────────────────────────────── if 'Input #' in line: @@ -2228,6 +2240,9 @@ def apply_visual_probe() -> None: ] _log_ffmpeg_errors(output, logger, error_patterns) + result_data['probe_media_seconds'] = media_window_seconds(media_progress_times, duration) + if result.returncode != 0 or result_data['ffmpeg_error_detected']: + result_data['status'] = 'Error' apply_visual_probe() logger.debug(f" Analysis completed in {elapsed:.2f}s") @@ -2829,6 +2844,7 @@ def analyze_stream( preempt_check: Optional[Callable[[], bool]] = None, defer_missing_bitrate_retry: bool = False, retry_missing_bitrate: bool = True, + minimum_probe_completion_percent: float = 80, ) -> Dict[str, Any]: """ Perform complete stream analysis including codec, resolution, FPS, bitrate, and audio. @@ -3018,6 +3034,12 @@ def analyze_stream( 'audio_bitrate': result_data['audio_bitrate'], 'status': result_data['status'], 'elapsed_time': result_data.get('elapsed_time', 0), + 'ffmpeg_exit_code': result_data.get('ffmpeg_exit_code'), + 'ffmpeg_error_detected': result_data.get('ffmpeg_error_detected', False), + 'probe_media_seconds': result_data.get('probe_media_seconds'), + 'minimum_probe_completion_percent': normalize_minimum_probe_completion_percent( + minimum_probe_completion_percent, + ), 'ffmpeg_duration': ffmpeg_duration, 'ffmpeg_duration_seconds': result_data.get('ffmpeg_duration_seconds', ffmpeg_duration), 'timeout_seconds': result_data.get( @@ -3145,7 +3167,7 @@ def analyze_stream( # data that is not representative of sustained delivery. # Give it another attempt rather than accepting the result. elapsed = result_data.get('elapsed_time', ffmpeg_duration) - completed = elapsed >= ffmpeg_duration * EARLY_EXIT_THRESHOLD + completed, result['probe_completion_basis'] = probe_window_completion(result) missing_bitrate = result.get('bitrate_kbps') is None if completed and missing_bitrate and not retry_missing_bitrate: logger.info( diff --git a/backend/apps/stream/stream_stats_writer.py b/backend/apps/stream/stream_stats_writer.py index 3b7f63e9..6bd2a9e0 100644 --- a/backend/apps/stream/stream_stats_writer.py +++ b/backend/apps/stream/stream_stats_writer.py @@ -43,6 +43,13 @@ def _update_stream_stats(self, stream_data: Dict) -> bool: "ffmpeg_output_bitrate": bitrate_value, "bitrate_source": stream_data.get("bitrate_source"), "quality_score": stream_data.get("score"), + "probe_completion_basis": stream_data.get("probe_completion_basis"), + "probe_media_seconds": stream_data.get("probe_media_seconds"), + "probe_elapsed_seconds": stream_data.get("elapsed_time"), + "probe_expected_seconds": stream_data.get("ffmpeg_duration"), + "minimum_probe_completion_percent": stream_data.get("minimum_probe_completion_percent"), + "ffmpeg_exit_code": stream_data.get("ffmpeg_exit_code"), + "ffmpeg_error_detected": stream_data.get("ffmpeg_error_detected"), "quality_reason": stream_data.get("quality_reason"), "quality_reason_detail": stream_data.get("quality_reason_detail"), "quality_reason_context": stream_data.get("quality_reason_context"), @@ -165,6 +172,13 @@ def _prepare_stream_stats_for_batch(self, stream_data: Dict) -> Optional[Dict[st "ffmpeg_output_bitrate": bitrate_value, "bitrate_source": stream_data.get("bitrate_source"), "quality_score": stream_data.get("score"), + "probe_completion_basis": stream_data.get("probe_completion_basis"), + "probe_media_seconds": stream_data.get("probe_media_seconds"), + "probe_elapsed_seconds": stream_data.get("elapsed_time"), + "probe_expected_seconds": stream_data.get("ffmpeg_duration"), + "minimum_probe_completion_percent": stream_data.get("minimum_probe_completion_percent"), + "ffmpeg_exit_code": stream_data.get("ffmpeg_exit_code"), + "ffmpeg_error_detected": stream_data.get("ffmpeg_error_detected"), "quality_reason": stream_data.get("quality_reason"), "quality_reason_detail": stream_data.get("quality_reason_detail"), "quality_reason_context": stream_data.get("quality_reason_context"), diff --git a/backend/tests/test_probe_completion.py b/backend/tests/test_probe_completion.py new file mode 100644 index 00000000..e5393032 --- /dev/null +++ b/backend/tests/test_probe_completion.py @@ -0,0 +1,129 @@ +"""Regression coverage for accelerated probes and per-profile sample windows.""" + +import sys +import subprocess +from pathlib import Path +from unittest.mock import patch + +import pytest + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from apps.core.probe_completion import ( + media_window_seconds, normalize_minimum_probe_completion_percent, + probe_window_completion, +) +from apps.core.stream_stats_utils import is_stream_dead +from apps.stream import stream_check_utils + + +def measured(**changes): + return { + 'video_codec': 'hevc', 'audio_codec': 'aac', 'resolution': '3840x2160', + 'fps': 50, 'bitrate_kbps': 12000, 'hdr_format': 'HLG', + 'pixel_format': None, 'audio_sample_rate': None, 'audio_channels': None, + 'channel_layout': None, 'audio_bitrate': None, 'status': 'OK', + 'elapsed_time': 20, 'ffmpeg_duration': 30, 'ffmpeg_exit_code': 0, + 'probe_media_seconds': None, + **changes, + } + + +def test_full_media_window_is_accepted_below_wall_clock_threshold(): + row = measured(probe_media_seconds=media_window_seconds(range(31), 30)) + assert probe_window_completion(row) == (True, 'media_time') + assert is_stream_dead(row) == (False, 'none') + + +@pytest.mark.parametrize('times', [ + [30], [20, 21, 30], [0, 1, 30], [0, 5, 4, 30], + [0, 5, float('nan')], [0, 5, float('inf')], [-2, 0, 5], [0, 5, 300], +]) +def test_bad_timestamps_retain_wall_clock_fallback(times): + row = measured(probe_media_seconds=media_window_seconds(times, 30)) + assert row['probe_media_seconds'] is None + assert is_stream_dead(row) == (True, 'unstable') + + +@pytest.mark.parametrize('percent, expected_calls, dead', [(80, 2, True), (60, 1, False), (0, 1, False)]) +def test_profile_threshold_controls_retries_and_final_verdict_consistently(percent, expected_calls, dead): + with patch.object(stream_check_utils, 'get_stream_info_and_bitrate', return_value=measured()) as probe: + result = stream_check_utils.analyze_stream( + 'http://fixture.test/live.ts', 1, 'UHD fixture', ffmpeg_duration=30, + retries=1, retry_delay=0, minimum_probe_completion_percent=percent, + ) + assert probe.call_count == expected_calls + assert is_stream_dead(result)[0] is dead + assert result['minimum_probe_completion_percent'] == percent + + +@pytest.mark.parametrize('failure', [ + {'ffmpeg_exit_code': 1}, {'ffmpeg_error_detected': True}, {'status': 'Error'}, {'status': 'Timeout'}, +]) +def test_relaxed_duration_never_accepts_probe_errors(failure): + row = measured(probe_media_seconds=30, **failure) + assert not probe_window_completion(row, 0)[0] + assert is_stream_dead(row, {'minimum_probe_completion_percent': 0}) == (True, 'offline') + + +@pytest.mark.parametrize('flag, reason', [('blank', 'blank'), ('freeze', 'freeze')]) +def test_duration_disabled_keeps_enabled_visual_failures(flag, reason): + row = measured(**{flag + '_detected': True, flag + '_probe_ran': True}) + config = {'minimum_probe_completion_percent': 0, 'treat_' + flag + '_as_dead': True} + assert is_stream_dead(row, config) == (True, reason) + + +def test_media_time_requires_successful_exit_and_usable_measurements(): + for change in [{'ffmpeg_exit_code': None}, {'bitrate_kbps': None}, {'fps': 0}, {'resolution': '0x0'}]: + assert not probe_window_completion(measured(probe_media_seconds=30, **change))[0] + + +@pytest.mark.parametrize('bad', [None, True, False, 'bad', 'nan', float('inf'), -1, 101]) +def test_invalid_profile_values_use_safe_default(bad): + assert normalize_minimum_probe_completion_percent(bad) == 80 + + +def test_legacy_cached_metrics_without_timing_remain_usable(): + row = measured() + del row['elapsed_time'] + del row['ffmpeg_duration'] + del row['ffmpeg_exit_code'] + assert is_stream_dead(row) == (False, 'none') + + +def test_profile_serialization_preserves_zero_and_normalizes_legacy_values(): + from apps.automation.automation_config_manager import AutomationConfigManager + manager = object.__new__(AutomationConfigManager) + for configured, expected in [(0, 0), (60, 60), ('70', 70), ('invalid', 80)]: + result = manager._normalize_profile_settings({ + 'stream_checking': {'minimum_probe_completion_percent': configured}, + }) + assert result['stream_checking']['minimum_probe_completion_percent'] == expected + assert manager._normalize_profile_settings({'stream_checking': {}})[ + 'stream_checking']['minimum_probe_completion_percent'] == 80 + + +@pytest.mark.parametrize('exit_code, trailing_error', [(0, ''), (1, ''), (0, 'Error during demuxing: Input/output error')]) +def test_analyzer_carries_real_progress_evidence_and_rejects_ffmpeg_failures(exit_code, trailing_error): + output = '\n'.join([ + 'Input #0, mpegts, from fixture:', + ' Stream #0:0: Video: hevc (Main 10), yuv420p10le, 3840x2160, 50 fps, 50 tbr', + ' Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, 128 kb/s', + 'Output #0, mpegts, to pipe:1:', + *[f'frame= {i * 50} fps=75 size=1000kB time=00:00:{i:05.2f} bitrate=12000.0kbits/s speed=1.5x' + for i in range(31)], trailing_error, + ]) + completed = subprocess.CompletedProcess([], exit_code, stderr=output) + with patch.object(stream_check_utils, '_run_ffmpeg_with_optional_fallback', return_value=completed), \ + patch.object(stream_check_utils.time, 'monotonic', side_effect=[100, 120]): + result = stream_check_utils.get_stream_info_and_bitrate('http://fixture.test/live.ts', duration=30) + assert result['probe_media_seconds'] == 30 + assert result['resolution'] == '3840x2160' + assert result['fps'] == 50 + assert result['bitrate_kbps'] == 12000 + result['ffmpeg_duration'] = 30 + if exit_code or trailing_error: + assert result['status'] == 'Error' + assert is_stream_dead(result, {'minimum_probe_completion_percent': 0}) == (True, 'offline') + else: + assert probe_window_completion(result) == (True, 'media_time') + assert is_stream_dead(result) == (False, 'none') diff --git a/docs/probe-completion.md b/docs/probe-completion.md new file mode 100644 index 00000000..6c904904 --- /dev/null +++ b/docs/probe-completion.md @@ -0,0 +1,33 @@ +# Probe completion + +**Where:** Settings -> Profiles tab -> Edit profile -> Stream Checking -> +Minimum Probe Completion (%). + +The advanced profile setting accepts 0 to 100, with 80 as the default for new +and existing profiles. It controls the minimum accepted portion of the requested +FFmpeg analysis duration. For example, an 80% setting with a 30-second probe +requires at least 24 seconds of evidence. Lower values accept shorter samples. +Zero disables this duration criterion. FFmpeg errors, missing video, other +quality thresholds and enabled blank/freeze checks still apply. + +Set the requested analysis duration separately under Stream Checker -> Stream +Checker Configuration -> Edit -> Stream Analysis -> FFmpeg Duration (seconds). +Changing the profile percentage changes the completion rule, not that duration. +One-off stream checks without a channel profile retain the 80% default. + +A successful probe can cover enough video while finishing faster than real +time. StreamFlow accepts processed media time only with a successful FFmpeg exit, +usable resolution/FPS/bitrate measurements and plausible continuous progress. +Isolated timestamps, large initial offsets, jumps, backwards time and implausible +overruns cannot establish media coverage. They fall back to wall-clock timing. +Probe retries and the final unstable verdict use the same completion policy. + +The resolved profile controls parallel/sequential channel checks and their +bitrate rechecks, including explicitly selected profiles. Existing preflight +reuse is invalidated when the profile policy changes. Invalid saved percentages +fall back to 80%. + +Stored stream statistics include the effective percentage, wall-clock/media +seconds, FFmpeg exit/error indicators and completion basis where available. +These are diagnostic fields; existing cached measurements without timing keep +their legacy handling. No credentials or raw FFmpeg output are stored in them. diff --git a/frontend/public/help/minimum-probe-completion-dark.jpg b/frontend/public/help/minimum-probe-completion-dark.jpg new file mode 100644 index 00000000..ee2955b3 Binary files /dev/null and b/frontend/public/help/minimum-probe-completion-dark.jpg differ diff --git a/frontend/src/lib/operator-help-content.js b/frontend/src/lib/operator-help-content.js index 7b8c84e8..3f536e25 100644 --- a/frontend/src/lib/operator-help-content.js +++ b/frontend/src/lib/operator-help-content.js @@ -229,6 +229,23 @@ export const operatorHelpDetailTopics = [ useWhen: 'Enable for maintenance and event-preflight profiles that should score or protect streams.', risk: 'Disabling it skips stream analysis and leaves quality state unchanged.', }, + { + name: 'Minimum Probe Completion (%)', + controlType: 'Visible UI setting', + defaultValue: '80%', + location: 'Settings -> Profiles tab -> Edit profile -> Stream Checking -> Minimum Probe Completion (%)', + effect: 'Sets the minimum portion of the requested FFmpeg duration needed for a completed probe. Successful probes with reliable output media timing and usable measurements may complete faster than wall-clock time.', + useWhen: 'Use the advanced per-profile control when a provider needs a different minimum sample window. One-off stream checks use the default 80%.', + risk: 'Lower percentages accept shorter samples. 0 disables only the duration rule; probe errors and enabled blank/freeze checks still apply.', + reference: { + imageSrc: '/help/minimum-probe-completion-dark.jpg', + triggerLabel: 'UI Screenshot', + alt: 'Dark mode crop of the Minimum Probe Completion profile setting.', + caption: 'Minimum Probe Completion is in the profile editor under Stream Checking. The default is 80%; 0 disables only the duration rule.', + width: 407, + height: 132, + }, + }, { name: 'Provider Stream Cap', controlType: 'Visible UI setting', diff --git a/frontend/src/lib/operator-help-content.test.js b/frontend/src/lib/operator-help-content.test.js index f0311ce5..cc13d5e9 100644 --- a/frontend/src/lib/operator-help-content.test.js +++ b/frontend/src/lib/operator-help-content.test.js @@ -368,6 +368,7 @@ describe('operatorHelpSections', () => { ) expect(references.map(reference => `${reference.topicId}:${reference.settingName}`)).toEqual([ + 'automation-periods:Minimum Probe Completion (%)', 'automation-periods:Provider Stream Cap', 'automation-periods:Run all due periods', 'automation-periods:Catch-up cap', diff --git a/frontend/src/pages/AutomationProfileEditor.jsx b/frontend/src/pages/AutomationProfileEditor.jsx index d9a5c07d..b9f61716 100644 --- a/frontend/src/pages/AutomationProfileEditor.jsx +++ b/frontend/src/pages/AutomationProfileEditor.jsx @@ -40,6 +40,7 @@ const DEFAULT_PROFILE = { freeze_check_enabled: false, stream_limit: 0, provider_stream_limit: 0, + minimum_probe_completion_percent: 80, min_resolution: 'any', min_fps: 0, min_bitrate: 0, @@ -569,6 +570,22 @@ export default function AutomationProfileEditor() {
++ Advanced. Default: 80%. Minimum portion of the requested FFmpeg duration required before a probe is considered complete. Successful probes with reliable media timing and valid measurements can complete faster than real time. 0 disables only this duration check; errors and enabled blank/freeze checks still apply. Lower values can accept shorter samples. +
+