Skip to content

Commit

Permalink
Merge pull request #36 from pozitronik/issue_34
Browse files Browse the repository at this point in the history
Issue 34
  • Loading branch information
pozitronik authored Jul 26, 2023
2 parents 8595261 + 75dbc65 commit e545373
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 5 additions & 2 deletions sinner/handlers/frame/CV2VideoHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def detect_fc(self) -> int: # this value can be inaccurate
capture.set(cv2.CAP_PROP_POS_FRAMES, search_position - 1)
ret, _ = capture.read()
if (step == 1 or step == initial_step) and ret is True and last_ret is False:
break
capture.set(cv2.CAP_PROP_POS_FRAMES, search_position)
check_ret, _ = capture.read()
if check_ret is False:
break
if last_ret != ret:
step = int(step / 2)
if step == 0:
Expand All @@ -70,7 +73,7 @@ def detect_fc(self) -> int: # this value can be inaccurate
return search_position

def get_frames_paths(self, path: str) -> List[NumeratedFramePath]:
fc = self.detect_fc()
fc = self.fc
i = self.current_frame_index
# fixme: do not ignore, if frames already ignored over the frame index
with tqdm(
Expand Down
4 changes: 2 additions & 2 deletions sinner/handlers/frame/FFmpegVideoHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def detect_fc(self) -> int:
return 0

def get_frames_paths(self, path: str) -> List[NumeratedFramePath]:
filename_length = len(str(self.detect_fc())) # a way to determine frame names length
filename_length = len(str(self.fc)) # a way to determine frame names length
Path(path).mkdir(parents=True, exist_ok=True)
self.run(['-i', self._target_path, '-pix_fmt', 'rgb24', os.path.join(path, f'%{filename_length}d.png')])
return super().get_frames_paths(path)
Expand All @@ -83,7 +83,7 @@ def extract_frame(self, frame_number: int) -> NumeratedFrame:

def result(self, from_dir: str, filename: str, audio_target: str | None = None) -> bool:
self.update_status(f"Resulting frames from {from_dir} to {filename} with {self.output_fps} FPS")
filename_length = len(str(self.detect_fc())) # a way to determine frame names length
filename_length = len(str(self.fc)) # a way to determine frame names length
Path(os.path.dirname(filename)).mkdir(parents=True, exist_ok=True)
command = ['-r', str(self.output_fps), '-i', os.path.join(from_dir, f'%0{filename_length}d.png'), '-c:v', 'h264_nvenc', '-preset', 'medium', '-qp', '18', '-pix_fmt', 'yuv420p', '-vf',
'colorspace=bt709:iall=bt601-6-625:fast=1', filename]
Expand Down
8 changes: 3 additions & 5 deletions sinner/handlers/frame/VideoHandler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from argparse import Namespace

from sinner.handlers.frame.CV2VideoHandler import CV2VideoHandler
from sinner.handlers.frame.FFmpegVideoHandler import FFmpegVideoHandler
from sinner.validators.AttributeLoader import Rules


class VideoHandler(CV2VideoHandler):
class VideoHandler(CV2VideoHandler, FFmpegVideoHandler):
keep_audio: bool

fps: float
Expand All @@ -23,6 +21,6 @@ def rules(self) -> Rules:
]

def result(self, from_dir: str, filename: str, audio_target: str | None = None) -> bool:
if audio_target is not None and self.keep_audio:
return FFmpegVideoHandler(self._target_path, Namespace()).result(from_dir, filename, audio_target)
if FFmpegVideoHandler.available():
return FFmpegVideoHandler.result(self, from_dir, filename, audio_target)
return super().result(from_dir, filename, audio_target)

0 comments on commit e545373

Please sign in to comment.