Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch #576

Merged
merged 2 commits into from
Oct 24, 2024
Merged

Patch #576

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions auto_editor/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
from fractions import Fraction
from os.path import splitext
from subprocess import run
from typing import Any

Expand All @@ -11,7 +12,7 @@

from auto_editor.ffwrapper import FFmpeg, FileInfo, initFileInfo
from auto_editor.lib.contracts import is_int, is_str
from auto_editor.make_layers import make_timeline
from auto_editor.make_layers import clipify, make_av, make_timeline
from auto_editor.output import Ensure, parse_bitrate
from auto_editor.render.audio import make_new_audio
from auto_editor.render.subtitle import make_new_subtitles
Expand All @@ -31,7 +32,7 @@ def set_output(
if src is None:
root, ext = "out", ".mp4"
else:
root, ext = os.path.splitext(str(src.path) if out is None else out)
root, ext = splitext(src.path if out is None else out)
if ext == "":
ext = src.path.suffix

Expand Down Expand Up @@ -164,7 +165,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None:
tl = None

if paths:
path_ext = os.path.splitext(paths[0])[1].lower()
path_ext = splitext(paths[0])[1].lower()
if path_ext == ".xml":
from auto_editor.formats.fcp7 import fcp7_read_xml

Expand Down Expand Up @@ -243,7 +244,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None:
from auto_editor.formats.fcp7 import fcp7_write_xml

is_resolve = export.startswith("resolve")
fcp7_write_xml(export_ops["name"], output, is_resolve, tl, log)
fcp7_write_xml(export_ops["name"], output, is_resolve, tl)
return

if export == "final-cut-pro":
Expand All @@ -267,7 +268,7 @@ def edit_media(paths: list[str], ffmpeg: FFmpeg, args: Args, log: Log) -> None:
shotcut_write_mlt(output, tl)
return

out_ext = os.path.splitext(output)[1].replace(".", "")
out_ext = splitext(output)[1].replace(".", "")

# Check if export options make sense.
ctr = container_constructor(out_ext.lower())
Expand Down Expand Up @@ -430,14 +431,15 @@ def make_media(tl: v3, output_path: str) -> None:
if tl.v1 is None:
log.error("Timeline too complex to use clip-sequence export")

from auto_editor.make_layers import clipify, make_av
from auto_editor.utils.func import append_filename

def pad_chunk(chunk: Chunk, total: int) -> Chunks:
start = [] if chunk[0] == 0 else [(0, chunk[0], 99999.0)]
end = [] if chunk[1] == total else [(chunk[1], total, 99999.0)]
return start + [chunk] + end

def append_filename(path: str, val: str) -> str:
root, ext = splitext(path)
return root + val + ext

total_frames = tl.v1.chunks[-1][1] - 1
clip_num = 0
for chunk in tl.v1.chunks:
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/formats/fcp7.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def premiere_write_audio(audio: Element, make_filedef, src: FileInfo, tl: v3) ->
audio.append(track)


def fcp7_write_xml(name: str, output: str, resolve: bool, tl: v3, log: Log) -> None:
def fcp7_write_xml(name: str, output: str, resolve: bool, tl: v3) -> None:
width, height = tl.res
timebase, ntsc = set_tb_ntsc(tl.tb)

Expand Down
4 changes: 1 addition & 3 deletions auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ def handle_strings() -> bool:
if is_method:
from auto_editor.utils.cmdkw import parse_method

return Token(
M, parse_method(name, result, env), self.lineno, self.column
)
return Token(M, parse_method(name, result), self.lineno, self.column)

if self.char == ".": # handle `object.method` syntax
self.advance()
Expand Down
7 changes: 0 additions & 7 deletions auto_editor/lang/stdenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from numpy.typing import NDArray

Number = int | float | complex | Fraction
Real = int | float | Fraction
BoolList = NDArray[np.bool_]
Node = tuple

Expand Down Expand Up @@ -831,12 +830,6 @@ def _xor(*vals: Any) -> bool | BoolList:
check_args("xor", vals, (2, None), (is_bool,))
return reduce(lambda a, b: a ^ b, vals)

def string_ref(s: str, ref: int) -> Char:
try:
return Char(s[ref])
except IndexError:
raise MyError(f"string index {ref} is out of range")

def number_to_string(val: Number) -> str:
if isinstance(val, complex):
join = "" if val.imag < 0 else "+"
Expand Down
4 changes: 2 additions & 2 deletions auto_editor/render/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def make_srt(input_: Input, stream: int) -> str:
return output_bytes.getvalue()


def _ensure(input_: Input, format: str, stream: int, log: Log) -> str:
def _ensure(input_: Input, format: str, stream: int) -> str:
output_bytes = io.BytesIO()
output = av.open(output_bytes, "w", format=format)

Expand Down Expand Up @@ -195,7 +195,7 @@ def make_new_subtitles(tl: v3, log: Log) -> list[str]:
if sub.codec == "mov_text":
ret = make_srt(input_, s)
else:
ret = _ensure(input_, format, s, log)
ret = _ensure(input_, format, s)
parser.parse(ret, sub.codec)
parser.edit(tl.v1.chunks)

Expand Down
13 changes: 5 additions & 8 deletions auto_editor/utils/cmdkw.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def __init__(self, name: str, *attrs: pAttr):
self.attrs = attrs


def _norm_name(s: str) -> str:
# Python does not allow - in variable names
return s.replace("-", "_")


class PLexer:
__slots__ = ("text", "pos", "char")

Expand Down Expand Up @@ -101,6 +96,10 @@ def parse_with_palet(
KEYWORD_SEP = "="
kwargs: dict[str, Any] = {}

def _norm_name(s: str) -> str:
# Python does not allow - in variable names
return s.replace("-", "_")

def go(text: str, c: Any) -> Any:
try:
env = _env if isinstance(_env, Env) else Env(_env)
Expand Down Expand Up @@ -174,9 +173,7 @@ def go(text: str, c: Any) -> Any:
return kwargs


def parse_method(
name: str, text: str, env: Env
) -> tuple[str, list[Any], dict[str, Any]]:
def parse_method(name: str, text: str) -> tuple[str, list[Any], dict[str, Any]]:
from auto_editor.lang.palet import Lexer, Parser

# Positional Arguments
Expand Down
33 changes: 0 additions & 33 deletions auto_editor/utils/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ def mut_margin(arr: BoolList, start_m: int, end_m: int) -> None:
arr[max(i + end_m, 0) : i] = False


def merge(start_list: np.ndarray, end_list: np.ndarray) -> BoolList:
result = np.zeros((len(start_list)), dtype=np.bool_)

for i, item in enumerate(start_list):
if item == True:
where = np.where(end_list[i:])[0]
if len(where) > 0:
result[i : where[0]] = True
return result


def get_stdout(cmd: list[str]) -> str:
from subprocess import DEVNULL, PIPE, Popen

Expand All @@ -116,25 +105,3 @@ def gcd(a: int, b: int) -> int:

c = gcd(width, height)
return width // c, height // c


def human_readable_time(time_in_secs: float) -> str:
units = "seconds"
if time_in_secs >= 3600:
time_in_secs = round(time_in_secs / 3600, 1)
if time_in_secs % 1 == 0:
time_in_secs = round(time_in_secs)
units = "hours"
if time_in_secs >= 60:
time_in_secs = round(time_in_secs / 60, 1)
if time_in_secs >= 10 or time_in_secs % 1 == 0:
time_in_secs = round(time_in_secs)
units = "minutes"
return f"{time_in_secs} {units}"


def append_filename(path: str, val: str) -> str:
from os.path import splitext

root, ext = splitext(path)
return root + val + ext