@@ -33,14 +33,16 @@ class FunscriptGeneratorWindow(QtWidgets.QMainWindow):
3333 end_time (float): end position in video (timestamp in milliseconds) use -1.0 for video end.
3434 output_file (str, Funscript): csv output file path (Optional you can pass a funscript object where to store the result)
3535 include_multiaxis (bool): include multiaxis output
36+ no_tracking (bool): Use previous tracking result
3637 """
3738
3839 def __init__ (self ,
3940 video_file : str ,
4041 start_time : float ,
4142 end_time : float ,
4243 output_file : str ,
43- include_multiaxis : bool = False ):
44+ include_multiaxis : bool = False ,
45+ no_tracking : bool = False ):
4446 super (FunscriptGeneratorWindow , self ).__init__ ()
4547 self .allow_close = False
4648 self .raw_output = False
@@ -72,29 +74,22 @@ def __init__(self,
7274 sys .exit ()
7375
7476 self .video_info = FFmpegStream .get_video_info (video_file )
75- cap = cv2 .VideoCapture (video_file )
76- self .fps = cap .get (cv2 .CAP_PROP_FPS )
77- height = cap .get (cv2 .CAP_PROP_FRAME_HEIGHT )
78- width = cap .get (cv2 .CAP_PROP_FRAME_WIDTH )
79- video_aspect_ratio = float (width ) / max ((1 , float (height )))
80- cap .release ()
81-
8277 self .video_file = video_file
83- self .is_sbs_vr_video = True if 1.9 < video_aspect_ratio < 2.1 else False
8478 self .output_file = output_file
85-
86- self .start_frame = int (round (float (start_time )/ (float (1000 )/ float (self .fps )))) if start_time > 0.0 else 0
87- self .end_frame = int (round (float (end_time )/ (float (1000 )/ float (self .fps )))) if end_time > 0.0 and start_time < end_time else - 1
79+ self .start_frame = FFmpegStream .millisec_to_frame (start_time , self .video_info .fps )
80+ self .end_frame = FFmpegStream .millisec_to_frame (end_time , self .video_info .fps ) if end_time > 0.0 and start_time < end_time else - 1
8881
8982 self .__logger .info ("Set End Time to Frame Number %d" , self .end_frame )
90-
9183 self .__logger .info ("Hyperparameter:" + str (HYPERPARAMETER ))
9284 self .__logger .info ("Config:" + str (SETTINGS ))
9385
94- self .settings = {}
95- self .settings_dialog = SettingsDialog (self .settings , include_vr = True , include_multiaxis = include_multiaxis )
96- self .settings_dialog .applySettings .connect (self .run )
97- self .settings_dialog .show ()
86+ if no_tracking :
87+ self .continue_with_tracking_result ()
88+ else :
89+ self .settings = {}
90+ self .settings_dialog = SettingsDialog (self .settings , include_vr = True , include_multiaxis = include_multiaxis )
91+ self .settings_dialog .applySettings .connect (self .run )
92+ self .settings_dialog .show ()
9893
9994
10095 __logger = logging .getLogger (__name__ )
@@ -103,6 +98,43 @@ def __init__(self,
10398 openCutWidget = QtCore .pyqtBoundSignal
10499
105100
101+ def continue_with_tracking_result (self ):
102+ self .__logger .info ("Use previous tracking result" )
103+ if not os .path .exists (definitions .RAW_TRACKING_DATA_CAHCE_FILE ):
104+ self .__show_message ("Tracking result not found" )
105+ sys .exit ()
106+
107+ with open (definitions .RAW_TRACKING_DATA_CAHCE_FILE , 'r' ) as fd :
108+ cache_content = json .load (fd )
109+
110+ if any (x not in cache_content for x in ["videoFile" , "fps" , "actions" ]):
111+ self .__show_message ("Invalid tracking result cache file" )
112+ sys .exit ()
113+
114+ current_video_filename = os .path .basename (self .video_file )
115+ if cache_content ["videoFile" ] != current_video_filename :
116+ self .__show_message (f"tracking result for { current_video_filename } not found" )
117+ sys .exit ()
118+
119+ if cache_content ["fps" ] != self .video_info .fps :
120+ self .__show_message (f"Video propberies has changed" )
121+ sys .exit ()
122+
123+ self .funscripts = {metric : Funscript (self .video_info .fps ) \
124+ for metric in cache_content ["actions" ]}
125+
126+ self .score = {metric : [ \
127+ item ["pos" ] \
128+ for item in cache_content ["actions" ][metric ] \
129+ ] \
130+ for metric in cache_content ["actions" ] }
131+
132+ start_time = min ([cache_content ["actions" ][metric ][0 ]["at" ] for metric in cache_content ["actions" ]])
133+ self .start_frame = FFmpegStream .millisec_to_frame (float (start_time ), self .video_info .fps )
134+ self .__logger .info ("Set start frame to %d" , self .start_frame )
135+ self .__next_postprocessing (None , [], [])
136+
137+
106138 def closeEvent (self , event ):
107139 if self .allow_close :
108140 event .accept ()
@@ -134,7 +166,7 @@ def __show_message(self, message :str, error: bool = False) -> None:
134166
135167 # Step 1
136168 def __tracking_completed (self , score , projection_config , tracking_points , msg , success ) -> None :
137- self .funscripts = {k .replace ('inverted' , '' ).strip (): Funscript (self .fps ) \
169+ self .funscripts = {k .replace ('inverted' , '' ).strip (): Funscript (self .video_info . fps ) \
138170 for k in self .settings ['trackingMetrics' ].split ('+' )}
139171
140172 if not success :
@@ -192,6 +224,8 @@ def __scaling_completed(self, score):
192224 raw_tracking_data_json_output = {
193225 'version' : 1 ,
194226 'comment' : "MTFG RAW DATA" ,
227+ 'fps' : self .video_info .fps ,
228+ 'videoFile' : os .path .basename (self .video_file ),
195229 'actions' : {}
196230 }
197231
@@ -208,7 +242,7 @@ def __scaling_completed(self, score):
208242
209243 if not self .raw_output :
210244 self .__logger .info ("Post Processing Data" )
211- #NOTE: delete the raw data from funscript
245+ #NOTE: delete the raw data from funscripts
212246 for key in self .funscripts :
213247 self .funscripts [key ].clear_actions ()
214248 self .__next_postprocessing (None , [], [])
0 commit comments