File size: 1,337 Bytes
67ce4ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Map LLM clip timing (segment + trim + hook) to one ffmpeg source window.



``humeo_core.primitives.compile`` already cuts with ``-ss`` / ``-t`` from ``Clip``;

this module is the single place that turns trim/hook fields into concrete bounds.

"""

from __future__ import annotations

from humeo_core.schemas import Clip


def effective_export_bounds(clip: Clip) -> tuple[float, float]:
    """Return ``(start_sec, end_sec)`` on the source timeline for the exported short.



    1. **Trim** narrows ``[start_time_sec, end_time_sec]``.

    2. Hook fields remain metadata and do not change the export window.

    """
    s0 = clip.start_time_sec
    s1 = clip.end_time_sec

    t_lo = s0 + clip.trim_start_sec
    t_hi = s1 - clip.trim_end_sec
    if t_hi <= t_lo:
        t_lo, t_hi = s0, s1

    if t_hi <= t_lo:
        t_lo, t_hi = s0, s1

    return t_lo, t_hi


def clip_for_render(clip: Clip) -> Clip:
    """Copy with ``start``/``end`` set to the actual cut; trim/hook cleared."""
    t0, t1 = effective_export_bounds(clip)
    return clip.model_copy(
        update={
            "start_time_sec": t0,
            "end_time_sec": t1,
            "trim_start_sec": 0.0,
            "trim_end_sec": 0.0,
            "hook_start_sec": None,
            "hook_end_sec": None,
        }
    )