videopython 0.59.0__tar.gz → 0.60.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. {videopython-0.59.0 → videopython-0.60.0}/PKG-INFO +1 -1
  2. {videopython-0.59.0 → videopython-0.60.0}/pyproject.toml +1 -1
  3. videopython-0.60.0/src/videopython/_exceptions.py +63 -0
  4. {videopython-0.59.0/src/videopython/base → videopython-0.60.0/src/videopython}/_ffmpeg.py +49 -18
  5. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/remux.py +2 -2
  6. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/transforms.py +11 -16
  7. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/source_metadata.py +2 -2
  8. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/audio/__init__.py +3 -1
  9. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/audio/audio.py +3 -2
  10. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/__init__.py +10 -18
  11. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/_video_io.py +14 -17
  12. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/video.py +13 -4
  13. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/__init__.py +6 -0
  14. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/audio_ops.py +2 -2
  15. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/effects.py +2 -2
  16. videopython-0.60.0/src/videopython/editing/errors.py +98 -0
  17. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/operation.py +2 -3
  18. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/streaming.py +2 -2
  19. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/transcription_overlay.py +1 -1
  20. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/transforms.py +1 -1
  21. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/video_edit.py +41 -29
  22. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/mcp/server.py +1 -1
  23. videopython-0.59.0/src/videopython/base/exceptions.py +0 -219
  24. {videopython-0.59.0 → videopython-0.60.0}/.gitignore +0 -0
  25. {videopython-0.59.0 → videopython-0.60.0}/LICENSE +0 -0
  26. {videopython-0.59.0 → videopython-0.60.0}/README.md +0 -0
  27. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/__init__.py +0 -0
  28. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/__init__.py +0 -0
  29. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/_device.py +0 -0
  30. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/_ollama.py +0 -0
  31. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/_optional.py +0 -0
  32. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/_predictor.py +0 -0
  33. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/_revisions.py +0 -0
  34. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/__init__.py +0 -0
  35. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/backend.py +0 -0
  36. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/catalog.py +0 -0
  37. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/editor.py +0 -0
  38. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/local.py +0 -0
  39. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/models.py +0 -0
  40. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/auto_edit/resolve.py +0 -0
  41. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/__init__.py +0 -0
  42. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/_tts_backend.py +0 -0
  43. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/audio_ops.py +0 -0
  44. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/config.py +0 -0
  45. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/dubber.py +0 -0
  46. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/models.py +0 -0
  47. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/pipeline.py +0 -0
  48. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/quality.py +0 -0
  49. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/separation.py +0 -0
  50. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/timing.py +0 -0
  51. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/translation.py +0 -0
  52. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/dubbing/voice_sample.py +0 -0
  53. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/effects.py +0 -0
  54. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/errors.py +0 -0
  55. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/generation/__init__.py +0 -0
  56. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/generation/audio.py +0 -0
  57. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/generation/image.py +0 -0
  58. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/generation/video.py +0 -0
  59. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/keyframe.py +0 -0
  60. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/ops.py +0 -0
  61. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/__init__.py +0 -0
  62. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/_detector.py +0 -0
  63. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/audio.py +0 -0
  64. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/classification.py +0 -0
  65. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/faces.py +0 -0
  66. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/image.py +0 -0
  67. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/objects.py +0 -0
  68. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/understanding/temporal.py +0 -0
  69. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/__init__.py +0 -0
  70. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/analyzer.py +0 -0
  71. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/detectors.py +0 -0
  72. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/models.py +0 -0
  73. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/ai/video_analysis/sampling.py +0 -0
  74. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/audio/analysis.py +0 -0
  75. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/_dimensions.py +0 -0
  76. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/description.py +0 -0
  77. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/draw_detections.py +0 -0
  78. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Anton-OFL.txt +0 -0
  79. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Anton-Regular.ttf +0 -0
  80. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/BebasNeue-OFL.txt +0 -0
  81. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/BebasNeue-Regular.ttf +0 -0
  82. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/DejaVuSans.ttf +0 -0
  83. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/LICENSE_DEJAVU +0 -0
  84. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Lato-Bold.ttf +0 -0
  85. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Lato-OFL.txt +0 -0
  86. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Poppins-Bold.ttf +0 -0
  87. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/Poppins-OFL.txt +0 -0
  88. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/fonts/__init__.py +0 -0
  89. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/base/transcription.py +0 -0
  90. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/_ass.py +0 -0
  91. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/_easing.py +0 -0
  92. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/editing/_schema.py +0 -0
  93. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/mcp/__init__.py +0 -0
  94. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/mcp/_models.py +0 -0
  95. {videopython-0.59.0 → videopython-0.60.0}/src/videopython/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: videopython
3
- Version: 0.59.0
3
+ Version: 0.60.0
4
4
  Summary: LLM-friendly Python video editing with JSON plans, local AI, and MCP tools.
5
5
  Project-URL: Homepage, https://videopython.com
6
6
  Project-URL: Repository, https://github.com/bartwojtowicz/videopython/
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "videopython"
3
- version = "0.59.0"
3
+ version = "0.60.0"
4
4
  description = "LLM-friendly Python video editing with JSON plans, local AI, and MCP tools."
5
5
  authors = [
6
6
  { name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
@@ -0,0 +1,63 @@
1
+ """Exception hierarchy shared by the package layers."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class VideoPythonError(Exception):
7
+ """Base exception for all videopython errors."""
8
+
9
+ pass
10
+
11
+
12
+ class FFmpegError(VideoPythonError):
13
+ """Base exception for ffmpeg/ffprobe subprocess failures."""
14
+
15
+ pass
16
+
17
+
18
+ class FFmpegProbeError(FFmpegError):
19
+ """Raised when an ffprobe invocation or its JSON output fails."""
20
+
21
+ pass
22
+
23
+
24
+ class FFmpegRunError(FFmpegError):
25
+ """Raised when a blocking ffmpeg run returns a non-zero exit code."""
26
+
27
+ pass
28
+
29
+
30
+ class VideoError(VideoPythonError):
31
+ """Base exception for video-related errors."""
32
+
33
+ pass
34
+
35
+
36
+ class VideoLoadError(VideoError):
37
+ """Raised when there's an error loading a video file."""
38
+
39
+ pass
40
+
41
+
42
+ class VideoMetadataError(VideoError):
43
+ """Raised when there's an error getting video metadata."""
44
+
45
+ pass
46
+
47
+
48
+ class AudioError(VideoPythonError):
49
+ """Base exception for audio-related errors."""
50
+
51
+ pass
52
+
53
+
54
+ class AudioLoadError(AudioError):
55
+ """Raised when there's an error loading audio."""
56
+
57
+ pass
58
+
59
+
60
+ class TransformError(VideoPythonError):
61
+ """Base exception for transformation errors."""
62
+
63
+ pass
@@ -11,11 +11,17 @@ from __future__ import annotations
11
11
 
12
12
  import json
13
13
  import subprocess
14
+ import tempfile
14
15
  from contextlib import contextmanager
15
16
  from pathlib import Path
16
- from typing import Any, Iterator, Sequence
17
+ from typing import Any, BinaryIO, Iterator, Sequence, cast
17
18
 
18
- from videopython.base.exceptions import FFmpegProbeError, FFmpegRunError
19
+ from videopython._exceptions import FFmpegProbeError, FFmpegRunError
20
+
21
+
22
+ def _strict_decode_command(cmd: Sequence[str]) -> list[str]:
23
+ argv = list(cmd)
24
+ return [argv[0], "-hide_banner", "-loglevel", "error", "-xerror", *argv[1:]]
19
25
 
20
26
 
21
27
  def run(cmd: Sequence[str], *, stdin: bytes | None = None) -> bytes:
@@ -86,13 +92,37 @@ def _terminate(proc: subprocess.Popen[bytes], *, timeout: float = 5) -> None:
86
92
  proc.wait()
87
93
 
88
94
 
95
+ class _DecodeProcess:
96
+ """FFmpeg decode process with diagnostics stored outside the pipe."""
97
+
98
+ def __init__(self, process: subprocess.Popen[bytes], errors: BinaryIO):
99
+ self._process = process
100
+ self._errors = errors
101
+
102
+ @property
103
+ def stdout(self) -> BinaryIO:
104
+ return cast(BinaryIO, self._process.stdout)
105
+
106
+ def communicate(self) -> tuple[bytes, None]:
107
+ stdout, _ = self._process.communicate()
108
+ return stdout, None
109
+
110
+ def check(self) -> None:
111
+ if self._process.wait() == 0:
112
+ return
113
+ self._errors.seek(0)
114
+ detail = self._errors.read().decode(errors="replace")
115
+ raise FFmpegRunError(f"ffmpeg failed (exit {self._process.returncode}): {detail}")
116
+
117
+
89
118
  @contextmanager
90
- def popen_decode(cmd: Sequence[str], *, bufsize: int = -1) -> Iterator[subprocess.Popen[bytes]]:
119
+ def popen_decode(cmd: Sequence[str], *, bufsize: int = -1) -> Iterator[_DecodeProcess]:
91
120
  """Context manager wrapping an ffmpeg decode process.
92
121
 
93
- Yields a Popen with ``stdout=PIPE`` and ``stderr=DEVNULL``. Callers
94
- read raw bytes from ``proc.stdout``. On exit, the process is
95
- terminated (with kill fallback) and stdout is closed.
122
+ Yields a :class:`_DecodeProcess` with ``stdout=PIPE`` and diagnostics
123
+ stored in a temporary file. A caller that drains stdout must call
124
+ :meth:`_DecodeProcess.check`; a caller that stops early can leave the
125
+ context and the process is terminated without a decode error.
96
126
 
97
127
  Args:
98
128
  cmd: Full ffmpeg argv. The output target is typically ``pipe:1``.
@@ -100,18 +130,19 @@ def popen_decode(cmd: Sequence[str], *, bufsize: int = -1) -> Iterator[subproces
100
130
  (e.g. ``10**8``) for batched reads or a frame-sized value
101
131
  for streaming reads.
102
132
  """
103
- proc = subprocess.Popen(
104
- list(cmd),
105
- stdout=subprocess.PIPE,
106
- stderr=subprocess.DEVNULL,
107
- bufsize=bufsize,
108
- )
109
- try:
110
- yield proc
111
- finally:
112
- _terminate(proc)
113
- if proc.stdout is not None and not proc.stdout.closed:
114
- proc.stdout.close()
133
+ with tempfile.TemporaryFile() as errors:
134
+ proc = subprocess.Popen(
135
+ _strict_decode_command(cmd),
136
+ stdout=subprocess.PIPE,
137
+ stderr=errors,
138
+ bufsize=bufsize,
139
+ )
140
+ try:
141
+ yield _DecodeProcess(proc, errors)
142
+ finally:
143
+ _terminate(proc)
144
+ if proc.stdout is not None and not proc.stdout.closed:
145
+ proc.stdout.close()
115
146
 
116
147
 
117
148
  @contextmanager
@@ -10,9 +10,9 @@ from typing import TYPE_CHECKING
10
10
 
11
11
  import numpy as np
12
12
 
13
+ from videopython import _ffmpeg
14
+ from videopython._exceptions import FFmpegRunError
13
15
  from videopython.ai.errors import AiError
14
- from videopython.base import _ffmpeg
15
- from videopython.base.exceptions import FFmpegRunError
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  from videopython.audio import Audio
@@ -10,12 +10,12 @@ from pathlib import Path
10
10
  from typing import ClassVar, Literal
11
11
 
12
12
  import numpy as np
13
- from pydantic import Field
13
+ from pydantic import Field, PositiveInt
14
14
  from tqdm import tqdm
15
15
 
16
+ from videopython._ffmpeg import escape_filter_value
16
17
  from videopython.ai.understanding.faces import FaceSmoothingTracker
17
18
  from videopython.base._dimensions import floor_to_even
18
- from videopython.base._ffmpeg import escape_filter_value
19
19
  from videopython.base.video import FrameIterator, VideoMetadata
20
20
  from videopython.editing.operation import FilterCtx, OpCategory, Operation
21
21
 
@@ -46,30 +46,28 @@ class FaceTrackingCrop(Operation):
46
46
  category: ClassVar[OpCategory] = OpCategory.TRANSFORM
47
47
  compiles_from_source: ClassVar[bool] = True
48
48
 
49
- target_aspect: tuple[int, int] = Field((9, 16), description="Output aspect ratio as (width, height).")
49
+ target_aspect: tuple[PositiveInt, PositiveInt] = Field(
50
+ (9, 16), description="Output aspect ratio as (width, height)."
51
+ )
50
52
  face_selection: Literal["largest", "centered", "index"] = Field(
51
53
  "largest", description="Strategy for selecting which face to track."
52
54
  )
53
55
  face_index: int = Field(0, ge=0, description='Index of face to track when using ``face_selection="index"``.')
54
- padding: float = Field(0.3, ge=0, description="Extra space around face (0.3 = 30% padding on each side).")
55
56
  vertical_offset: float = Field(-0.1, description='Vertical position offset used by ``framing_rule="offset"``.')
56
- framing_rule: Literal["offset", "center", "headroom", "thirds", "dynamic"] = Field(
57
+ framing_rule: Literal["offset", "center", "headroom", "thirds"] = Field(
57
58
  "offset",
58
59
  description=(
59
60
  'Subject framing strategy. "offset": apply ``vertical_offset``; '
60
61
  '"center": keep face centered; "headroom": extra room above the face; '
61
- '"thirds": face near the upper-third line; "dynamic": currently same as "headroom".'
62
+ '"thirds": face near the upper-third line.'
62
63
  ),
63
64
  )
64
65
  headroom: float = Field(0.15, description="Headroom amount for framing rules that use it.")
65
66
  smoothing: float = Field(0.8, ge=0, le=1, description="Position smoothing factor (0-1, higher = smoother).")
66
67
  max_speed: float | None = Field(None, gt=0, description="Optional max camera movement per frame (normalized).")
67
- fallback: Literal["center", "last_position", "full_frame"] = Field(
68
+ fallback: Literal["center", "last_position"] = Field(
68
69
  "last_position",
69
- description=(
70
- 'Behavior when no face detected. "center" and "full_frame" both center the crop '
71
- 'while "last_position" holds the last tracked crop.'
72
- ),
70
+ description='Behavior when no face is detected. "center" centers the crop; "last_position" holds it.',
73
71
  )
74
72
  detection_interval: int = Field(3, ge=1, description="Frames between face detections.")
75
73
 
@@ -80,10 +78,7 @@ class FaceTrackingCrop(Operation):
80
78
  return (face_cx, face_cy)
81
79
  if self.framing_rule == "headroom":
82
80
  return (face_cx, face_cy - self.headroom)
83
- if self.framing_rule == "thirds":
84
- return (face_cx, face_cy - (1 / 3 - 0.5))
85
- # "dynamic" — placeholder until motion/look-direction framing is implemented.
86
- return (face_cx, face_cy - self.headroom)
81
+ return (face_cx, face_cy - (1 / 3 - 0.5))
87
82
 
88
83
  def _resolved_output_dims(self, w: int, h: int) -> tuple[int, int]:
89
84
  """Output ``(width, height)`` -- the fixed crop-window size.
@@ -154,7 +149,7 @@ class FaceTrackingCrop(Operation):
154
149
  positions.append((x, y))
155
150
  elif self.fallback == "last_position":
156
151
  positions.append(last)
157
- else: # "center" / "full_frame"
152
+ else:
158
153
  positions.append(default)
159
154
  return positions
160
155
 
@@ -13,9 +13,9 @@ from datetime import datetime, timezone
13
13
  from pathlib import Path
14
14
  from typing import Callable, TypeVar
15
15
 
16
+ from videopython import _ffmpeg
17
+ from videopython._exceptions import FFmpegProbeError
16
18
  from videopython.ai.video_analysis.models import GeoMetadata
17
- from videopython.base import _ffmpeg
18
- from videopython.base.exceptions import FFmpegProbeError
19
19
 
20
20
  logger = logging.getLogger(__name__)
21
21
 
@@ -1,5 +1,7 @@
1
+ from videopython._exceptions import AudioLoadError
2
+
1
3
  from .analysis import AudioLevels, AudioSegment, AudioSegmentType, SilentSegment
2
- from .audio import Audio, AudioLoadError, AudioMetadata
4
+ from .audio import Audio, AudioMetadata
3
5
 
4
6
  __all__ = [
5
7
  "Audio",
@@ -11,8 +11,8 @@ from typing import TYPE_CHECKING, Any
11
11
  import numpy as np
12
12
  import soxr
13
13
 
14
- from videopython.base import _ffmpeg
15
- from videopython.base.exceptions import AudioLoadError, FFmpegProbeError
14
+ from videopython import _ffmpeg
15
+ from videopython._exceptions import AudioLoadError, FFmpegProbeError
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  from videopython.audio.analysis import AudioLevels, AudioSegment, AudioSegmentType, SilentSegment
@@ -231,6 +231,7 @@ class Audio:
231
231
  # way: one for `BytesIO`, one for `readframes`.
232
232
  cmd = [
233
233
  "ffmpeg",
234
+ "-xerror",
234
235
  "-v",
235
236
  "error",
236
237
  "-i",
@@ -1,3 +1,13 @@
1
+ from videopython._exceptions import (
2
+ AudioError,
3
+ AudioLoadError,
4
+ TransformError,
5
+ VideoError,
6
+ VideoLoadError,
7
+ VideoMetadataError,
8
+ VideoPythonError,
9
+ )
10
+
1
11
  from .description import (
2
12
  AudioClassification,
3
13
  AudioEvent,
@@ -11,19 +21,6 @@ from .description import (
11
21
  SceneDescription,
12
22
  )
13
23
  from .draw_detections import DetectionStyle, class_color, draw_detections
14
- from .exceptions import (
15
- AudioError,
16
- AudioLoadError,
17
- PlanError,
18
- PlanErrorCode,
19
- PlanRepair,
20
- PlanValidationError,
21
- TransformError,
22
- VideoError,
23
- VideoLoadError,
24
- VideoMetadataError,
25
- VideoPythonError,
26
- )
27
24
  from .transcription import Transcription, TranscriptionSegment, TranscriptionWord
28
25
  from .video import FrameIterator, Video, VideoMetadata
29
26
 
@@ -40,11 +37,6 @@ __all__ = [
40
37
  "AudioError",
41
38
  "AudioLoadError",
42
39
  "TransformError",
43
- # Structured plan validation / repair
44
- "PlanError",
45
- "PlanErrorCode",
46
- "PlanValidationError",
47
- "PlanRepair",
48
40
  # Detection overlay renderer (AI-free)
49
41
  "draw_detections",
50
42
  "DetectionStyle",
@@ -20,15 +20,15 @@ from typing import Literal, get_args
20
20
 
21
21
  import numpy as np
22
22
 
23
- from videopython.audio import Audio
24
- from videopython.base import _ffmpeg
25
- from videopython.base._dimensions import require_even
26
- from videopython.base.exceptions import (
23
+ from videopython import _ffmpeg
24
+ from videopython._exceptions import (
27
25
  AudioLoadError,
28
26
  FFmpegRunError,
29
27
  VideoLoadError,
30
28
  VideoMetadataError,
31
29
  )
30
+ from videopython.audio import Audio
31
+ from videopython.base._dimensions import require_even
32
32
 
33
33
  ALLOWED_VIDEO_FORMATS = Literal["mp4", "avi", "mov", "mkv", "webm"]
34
34
  ALLOWED_VIDEO_PRESETS = Literal[
@@ -140,11 +140,17 @@ def decode_video(
140
140
  frames_read = 0
141
141
 
142
142
  with _ffmpeg.popen_decode(ffmpeg_cmd, bufsize=10**8) as process:
143
- while frames_read < estimated_frames:
143
+ while True:
144
144
  remaining_frames = estimated_frames - frames_read
145
- batch_size = min(read_batch_size, remaining_frames)
145
+ if remaining_frames < read_batch_size:
146
+ new_size = max(estimated_frames * 2, frames_read + read_batch_size)
147
+ new_frames = np.empty((new_size, out_height, out_width, 3), dtype=np.uint8)
148
+ new_frames[:frames_read] = frames[:frames_read]
149
+ frames = new_frames
150
+ estimated_frames = new_size
151
+ batch_size = read_batch_size
146
152
 
147
- batch_data = process.stdout.read(frame_size * batch_size) # type: ignore[union-attr]
153
+ batch_data = process.stdout.read(frame_size * batch_size)
148
154
  if not batch_data:
149
155
  break
150
156
 
@@ -156,19 +162,10 @@ def decode_video(
156
162
  complete_data = batch_frames[: complete_frames * out_height * out_width * 3]
157
163
  batch_frames_array = complete_data.reshape(complete_frames, out_height, out_width, 3)
158
164
 
159
- if frames_read + complete_frames > estimated_frames:
160
- new_size = max(estimated_frames * 2, frames_read + complete_frames + 100)
161
- new_frames = np.empty((new_size, out_height, out_width, 3), dtype=np.uint8)
162
- new_frames[:frames_read] = frames[:frames_read]
163
- frames = new_frames
164
- estimated_frames = new_size
165
-
166
165
  end_idx = frames_read + complete_frames
167
166
  frames[frames_read:end_idx] = batch_frames_array
168
167
  frames_read += complete_frames
169
-
170
- if process.returncode not in (0, None) and frames_read == 0:
171
- raise ValueError(f"FFmpeg failed to process video (return code: {process.returncode})")
168
+ process.check()
172
169
 
173
170
  if frames_read == 0:
174
171
  raise ValueError("No frames were read from the video")
@@ -10,10 +10,11 @@ from typing import Any, Generator
10
10
 
11
11
  import numpy as np
12
12
 
13
+ from videopython import _ffmpeg
14
+ from videopython._exceptions import FFmpegProbeError, FFmpegRunError, VideoLoadError, VideoMetadataError
13
15
  from videopython.audio import Audio
14
- from videopython.base import _ffmpeg, _video_io
16
+ from videopython.base import _video_io
15
17
  from videopython.base._video_io import ALLOWED_VIDEO_FORMATS, ALLOWED_VIDEO_PRESETS
16
- from videopython.base.exceptions import FFmpegProbeError, VideoMetadataError
17
18
 
18
19
  __all__ = [
19
20
  "Video",
@@ -298,7 +299,7 @@ class FrameIterator:
298
299
 
299
300
  def _build_ffmpeg_command(self) -> list[str]:
300
301
  """Build ffmpeg command for frame streaming."""
301
- cmd = ["ffmpeg", "-hide_banner", "-loglevel", "error"]
302
+ cmd = ["ffmpeg"]
302
303
 
303
304
  if self.start_second > 0:
304
305
  cmd.extend(["-ss", str(self.start_second)])
@@ -344,7 +345,7 @@ class FrameIterator:
344
345
  with _ffmpeg.popen_decode(cmd, bufsize=self._frame_size * 2) as proc:
345
346
  frame_idx = int(self.start_second * self.output_fps)
346
347
  while True:
347
- raw_frame = proc.stdout.read(self._frame_size) # type: ignore[union-attr]
348
+ raw_frame = proc.stdout.read(self._frame_size)
348
349
  if len(raw_frame) != self._frame_size:
349
350
  break
350
351
  frame = (
@@ -352,6 +353,10 @@ class FrameIterator:
352
353
  )
353
354
  yield frame_idx, frame
354
355
  frame_idx += 1
356
+ try:
357
+ proc.check()
358
+ except FFmpegRunError as e:
359
+ raise VideoLoadError(f"FFmpeg failed: {e}") from e
355
360
 
356
361
  def __enter__(self) -> "FrameIterator":
357
362
  return self
@@ -419,6 +424,10 @@ def extract_frames_at_indices(
419
424
 
420
425
  with _ffmpeg.popen_decode(cmd, bufsize=10**8) as process:
421
426
  raw_data, _ = process.communicate()
427
+ try:
428
+ process.check()
429
+ except FFmpegRunError as e:
430
+ raise VideoLoadError(f"FFmpeg failed: {e}") from e
422
431
 
423
432
  actual_frames = len(raw_data) // frame_size
424
433
  if actual_frames == 0:
@@ -22,6 +22,7 @@ from .effects import (
22
22
  VolumeAdjust,
23
23
  Zoom,
24
24
  )
25
+ from .errors import PlanError, PlanErrorCode, PlanRepair, PlanValidationError
25
26
  from .operation import FilterCtx, OpCategory, Operation, TimeRange
26
27
  from .streaming import OpStreamability, StreamabilityReport, StreamingClass
27
28
  from .transcription_overlay import SubtitleRegion, SubtitleStyle, TranscriptionOverlay
@@ -89,4 +90,9 @@ __all__ = [
89
90
  "StreamabilityReport",
90
91
  "OpStreamability",
91
92
  "StreamingClass",
93
+ # Plan validation
94
+ "PlanError",
95
+ "PlanErrorCode",
96
+ "PlanRepair",
97
+ "PlanValidationError",
92
98
  ]
@@ -25,8 +25,8 @@ from pathlib import Path
25
25
 
26
26
  from pydantic import BaseModel, ConfigDict, Field
27
27
 
28
- from videopython.base import _ffmpeg
29
- from videopython.base.exceptions import PlanError, PlanErrorCode, PlanValidationError
28
+ from videopython import _ffmpeg
29
+ from videopython.editing.errors import PlanError, PlanErrorCode, PlanValidationError
30
30
 
31
31
  __all__ = [
32
32
  "MusicBed",
@@ -25,12 +25,12 @@ import numpy as np
25
25
  from PIL import Image, ImageDraw, ImageFont
26
26
  from pydantic import Field, PrivateAttr, model_validator
27
27
 
28
- from videopython.base._ffmpeg import escape_filter_value
28
+ from videopython._ffmpeg import escape_filter_value
29
29
  from videopython.base.description import BoundingBox
30
- from videopython.base.exceptions import PlanError, PlanErrorCode, PlanValidationError
31
30
  from videopython.base.fonts import load_font
32
31
  from videopython.editing._easing import ease, ease_out
33
32
  from videopython.editing.audio_ops import volume_envelope
33
+ from videopython.editing.errors import PlanError, PlanErrorCode, PlanValidationError
34
34
  from videopython.editing.operation import Effect, FilterCtx
35
35
 
36
36
  if TYPE_CHECKING:
@@ -0,0 +1,98 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from enum import Enum
5
+
6
+
7
+ class PlanErrorCode(str, Enum):
8
+ """Machine-readable edit-plan failure classes."""
9
+
10
+ SEGMENT_END_EXCEEDS_SOURCE = "segment_end_exceeds_source"
11
+ SEGMENT_NEGATIVE = "segment_negative"
12
+ SEGMENT_RANGE = "segment_range"
13
+ EFFECT_WINDOW_EXCEEDS_DURATION = "effect_window_exceeds_duration"
14
+ WINDOW_NEGATIVE = "window_negative"
15
+ WINDOW_ORDER = "window_order"
16
+ CUT_EXCEEDS_DURATION = "cut_exceeds_duration"
17
+ OP_TIMESTAMP_OUT_OF_RANGE = "op_timestamp_out_of_range"
18
+ CROP_EXCEEDS_SOURCE = "crop_exceeds_source"
19
+ DEGENERATE_DURATION = "degenerate_duration"
20
+ SOURCE_UNREADABLE = "source_unreadable"
21
+ OP_PREDICTION_FAILED = "op_prediction_failed"
22
+ UNKNOWN_OP = "unknown_op"
23
+ CONCAT_MISMATCH = "concat_mismatch"
24
+ POST_OP_REQUIRES_CONTEXT = "post_op_requires_context"
25
+ CONTEXT_SOURCE_MISSING = "context_source_missing"
26
+ TRANSITION_TOO_LONG = "transition_too_long"
27
+ MUSIC_BED_DUCK_MULTISEGMENT = "music_bed_duck_multisegment"
28
+ STREAMING_UNSUPPORTED = "streaming_unsupported"
29
+
30
+
31
+ @dataclass
32
+ class PlanError:
33
+ """A structured validation failure within an edit plan.
34
+
35
+ Consumers branch on ``code``; ``detail`` is human-readable feedback.
36
+ """
37
+
38
+ code: PlanErrorCode
39
+ location: str | None = None
40
+ op: str | None = None
41
+ field: str | None = None
42
+ value: float | None = None
43
+ limit: float | None = None
44
+ detail: str | None = None
45
+
46
+ def to_prompt_line(self) -> str:
47
+ """Render this error as one deterministic feedback line."""
48
+ line = self.code.name
49
+ if self.location is not None:
50
+ line += f" at {self.location}"
51
+ if self.op is not None:
52
+ line += f" (op '{self.op}')"
53
+
54
+ clauses: list[str] = []
55
+ if self.field is not None:
56
+ if self.value is not None:
57
+ clauses.append(f"{self.field}={_fmt_num(self.value)}")
58
+ else:
59
+ clauses.append(self.field)
60
+ elif self.value is not None:
61
+ clauses.append(f"value={_fmt_num(self.value)}")
62
+ if self.limit is not None:
63
+ clauses.append(f"limit {_fmt_num(self.limit)}")
64
+
65
+ if clauses:
66
+ line += ": " + ", ".join(clauses)
67
+ if self.detail is not None:
68
+ line += f" -- {self.detail}"
69
+ return line
70
+
71
+
72
+ def _fmt_num(value: float) -> str:
73
+ if isinstance(value, float) and value.is_integer():
74
+ return str(int(value))
75
+ return str(value)
76
+
77
+
78
+ @dataclass
79
+ class PlanRepair:
80
+ """A field change made while repairing or normalizing an edit plan."""
81
+
82
+ location: str
83
+ field: str
84
+ old: float | str | None
85
+ new: float | str | None
86
+ code: PlanErrorCode
87
+
88
+
89
+ class PlanValidationError(ValueError):
90
+ """A ``ValueError`` whose ``errors`` attribute contains structured failures."""
91
+
92
+ def __init__(self, message: str, errors: list[PlanError]):
93
+ super().__init__(message)
94
+ self.errors = errors
95
+
96
+ def prompt_feedback(self) -> str:
97
+ """Return every carried error as newline-separated feedback."""
98
+ return "\n".join(error.to_prompt_line() for error in self.errors)
@@ -69,9 +69,8 @@ class TimeRange(BaseModel):
69
69
  *shape*; the numeric bounds (``>= 0``, ``stop >= start``, in-duration) are
70
70
  owned by :meth:`VideoEdit.validate` / :meth:`VideoEdit.check`, which report
71
71
  them as structured, collectable, repairable :class:`PlanError`s instead of
72
- aborting at ``from_dict``. The window is still clamped to
73
- ``min(stop, total_seconds)`` at run time, so a plan run without validation
74
- degrades rather than crashes.
72
+ aborting at ``from_dict``. The runner validates these bounds before decode
73
+ and clamps endpoints past the running duration.
75
74
  """
76
75
 
77
76
  model_config = ConfigDict(extra="forbid", frozen=True)
@@ -21,11 +21,11 @@ from typing import Any, get_args
21
21
  import numpy as np
22
22
  from tqdm import tqdm
23
23
 
24
- from videopython.base import _ffmpeg
24
+ from videopython import _ffmpeg
25
25
  from videopython.base._dimensions import require_even
26
- from videopython.base.exceptions import PlanError, PlanErrorCode
27
26
  from videopython.base.video import ALLOWED_VIDEO_FORMATS, ALLOWED_VIDEO_PRESETS, FrameIterator
28
27
  from videopython.editing.effects import Effect
28
+ from videopython.editing.errors import PlanError, PlanErrorCode
29
29
  from videopython.editing.operation import Operation
30
30
 
31
31
  logger = logging.getLogger(__name__)
@@ -24,7 +24,7 @@ from typing import ClassVar, Literal
24
24
  from PIL import ImageFont
25
25
  from pydantic import Field
26
26
 
27
- from videopython.base._ffmpeg import escape_filter_value
27
+ from videopython._ffmpeg import escape_filter_value
28
28
  from videopython.base.fonts import BUNDLED_FONT_FAMILIES, bundled_fonts_dir, load_font
29
29
  from videopython.base.transcription import Transcription
30
30
  from videopython.editing._ass import AnchorPoint, AssLook, build_ass
@@ -15,7 +15,7 @@ from pydantic import Field, model_validator
15
15
 
16
16
  from videopython.audio.audio import atempo_chain
17
17
  from videopython.base._dimensions import floor_to_even, round_to_even
18
- from videopython.base.exceptions import PlanError, PlanErrorCode, PlanValidationError
18
+ from videopython.editing.errors import PlanError, PlanErrorCode, PlanValidationError
19
19
  from videopython.editing.operation import BoundedTimeField, FilterCtx, OpCategory, Operation
20
20
 
21
21
  if TYPE_CHECKING: