Начал менять логику pipeline
This commit is contained in:
@@ -2,9 +2,10 @@ import os
|
||||
import logging
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Generator
|
||||
|
||||
import cv2
|
||||
from typing import Generator
|
||||
import numpy as np
|
||||
|
||||
|
||||
class VideoMaker:
|
||||
@@ -35,7 +36,7 @@ class VideoMaker:
|
||||
with open(file, "w") as f:
|
||||
for video in videos:
|
||||
f.write(f"file '{video}'\n")
|
||||
cmd = f"ffmpeg -f concat -safe 0 -i {file} -c copy {output_path}"
|
||||
cmd = f"ffmpeg -y -f concat -safe 0 -i {file} -c copy {output_path}"
|
||||
logging.info(f"Running command: {cmd}")
|
||||
result = self.run_command(cmd)
|
||||
if result != 0:
|
||||
@@ -74,7 +75,7 @@ class VideoMaker:
|
||||
|
||||
def video_to_frames_generator(
|
||||
self, video_path: Path, output_dir: Path, chunk_seconds: int = 10
|
||||
) -> Generator[tuple[Path, ...], None, None]:
|
||||
) -> Generator[tuple[np.ndarray, ...], None, None]:
|
||||
"""Extracts frames from a video and saves them to disk, yielding paths to the saved frames."""
|
||||
|
||||
cap = cv2.VideoCapture(str(video_path))
|
||||
@@ -85,21 +86,12 @@ class VideoMaker:
|
||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
frames_per_chunk = int(fps * chunk_seconds)
|
||||
|
||||
frame_index = 0
|
||||
|
||||
while True:
|
||||
paths = []
|
||||
|
||||
for _ in range(frames_per_chunk):
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
cap.release()
|
||||
return
|
||||
|
||||
frame_path = output_dir / f"img_{frame_index:08d}.png"
|
||||
cv2.imwrite(str(frame_path), frame)
|
||||
|
||||
paths.append(frame_path)
|
||||
frame_index += 1
|
||||
|
||||
paths.append(frame)
|
||||
yield tuple(paths)
|
||||
|
||||
Reference in New Issue
Block a user