22
33import cv2
44import os
5- import funscript_editor .utils .logging as logging
65import time
76import platform
87
1312import subprocess as sp
1413import numpy as np
1514
16- from funscript_editor .utils .watchdog import Watchdog
17- from funscript_editor .utils .config import SETTINGS
15+ try :
16+ import funscript_editor .utils .logging as logging
17+ from funscript_editor .utils .watchdog import Watchdog
18+ from funscript_editor .utils .config import SETTINGS
19+ except :
20+ import logging as logging
21+ from utils .watchdog import Watchdog
22+ SETTINGS = {
23+ 'ffmpeg_timeout_in_seconds' : 16
24+ }
1825
1926@dataclass
2027class VideoInfo :
@@ -157,6 +164,9 @@ def get_projection(
157164 for k , v in config ['parameter' ].items ():
158165 video_filter = video_filter .replace ('${' + k + '}' , str (v ))
159166
167+ width_factor = 2 if "out_stereo=sbs" in video_filter else 1
168+ height_factor = 2 if "out_stereo=tb" in video_filter else 1
169+
160170 command = [
161171 FFmpegStream .get_ffmpeg_command (),
162172 '-hide_banner' ,
@@ -182,15 +192,15 @@ def get_projection(
182192 command ,
183193 stdin = sp .PIPE ,
184194 stdout = sp .PIPE ,
185- bufsize = 3 * config ['parameter' ]['width' ] * config ['parameter' ]['height' ]
195+ bufsize = 3 * config ['parameter' ]['width' ] * width_factor * config ['parameter' ]['height' ] * height_factor
186196 )
187197
188198 pipe .stdin .write (frame .tobytes ())
189199 projection = np .frombuffer (
190- pipe .stdout .read (config ['parameter' ]['width' ] * config ['parameter' ]['height' ] * 3 ),
200+ pipe .stdout .read (config ['parameter' ]['width' ] * width_factor * config ['parameter' ]['height' ] * height_factor * 3 ),
191201 dtype = 'uint8'
192202 ).reshape (
193- (config ['parameter' ]['height' ], config ['parameter' ]['width' ], 3 )
203+ (config ['parameter' ]['height' ] * height_factor , config ['parameter' ]['width' ] * width_factor , 3 )
194204 )
195205
196206 pipe .terminate ()
@@ -364,6 +374,9 @@ def run(self) -> None:
364374
365375 seek = FFmpegStream .frame_to_timestamp (self .start_frame , self .video_info .fps )
366376
377+ width_factor = 2 if "out_stereo=sbs" in video_filter else 1
378+ height_factor = 2 if "out_stereo=tb" in video_filter else 1
379+
367380 command = [
368381 FFmpegStream .get_ffmpeg_command (),
369382 '-hide_banner' ,
@@ -388,17 +401,17 @@ def run(self) -> None:
388401 command ,
389402 stdout = sp .PIPE ,
390403 stderr = sp .PIPE ,
391- bufsize = 3 * self .config ['parameter' ]['height' ] * self .config ['parameter' ]['width' ]
404+ bufsize = 3 * self .config ['parameter' ]['height' ] * height_factor * self .config ['parameter' ]['width' ] * width_factor
392405 )
393406
394407 while not self .stopped :
395408 self .watchdog .trigger ()
396- data = self .pipe .stdout .read (self .config ['parameter' ]['width' ] * self .config ['parameter' ]['height' ] * 3 )
409+ data = self .pipe .stdout .read (self .config ['parameter' ]['width' ] * width_factor * self .config ['parameter' ]['height' ] * height_factor * 3 )
397410 if not data :
398411 break
399412
400413 frame = np .frombuffer (data , dtype = 'uint8' ).reshape (
401- (self .config ['parameter' ]['height' ], self .config ['parameter' ]['width' ], 3 )
414+ (self .config ['parameter' ]['height' ] * height_factor , self .config ['parameter' ]['width' ] * width_factor , 3 )
402415 )
403416 if frame is None :
404417 break
0 commit comments