Stop video processing and signal completion.
(self)
| 316 | |
| 317 | # @misc_helpers.benchmark |
| 318 | def stop_processing(self): |
| 319 | """Stop video processing and signal completion.""" |
| 320 | if not self.processing: |
| 321 | # print("Processing not active. No action to perform.") |
| 322 | video_control_actions.reset_media_buttons(self.main_window) |
| 323 | |
| 324 | return False |
| 325 | |
| 326 | print("Stopping video processing.") |
| 327 | self.processing = False |
| 328 | |
| 329 | if self.file_type=='video' or self.file_type=='webcam': |
| 330 | |
| 331 | # print("Stopping Timers") |
| 332 | self.frame_read_timer.stop() |
| 333 | self.frame_display_timer.stop() |
| 334 | self.gpu_memory_update_timer.stop() |
| 335 | self.join_and_clear_threads() |
| 336 | |
| 337 | |
| 338 | # print("Clearing Threads and Queues") |
| 339 | self.threads.clear() |
| 340 | self.frames_to_display.clear() |
| 341 | self.webcam_frames_to_display.queue.clear() |
| 342 | |
| 343 | with self.frame_queue.mutex: |
| 344 | self.frame_queue.queue.clear() |
| 345 | |
| 346 | self.current_frame_number = self.main_window.videoSeekSlider.value() |
| 347 | self.media_capture.set(cv2.CAP_PROP_POS_FRAMES, self.current_frame_number) |
| 348 | |
| 349 | if self.recording and self.file_type=='video': |
| 350 | self.recording_sp.stdin.close() |
| 351 | self.recording_sp.wait() |
| 352 | |
| 353 | self.play_end_time = float(self.media_capture.get(cv2.CAP_PROP_POS_FRAMES) / float(self.fps)) |
| 354 | |
| 355 | if self.file_type=='video': |
| 356 | if self.recording: |
| 357 | final_file_path = misc_helpers.get_output_file_path(self.media_path, self.main_window.control['OutputMediaFolder']) |
| 358 | if Path(final_file_path).is_file(): |
| 359 | os.remove(final_file_path) |
| 360 | print("Adding audio...") |
| 361 | args = ["ffmpeg", |
| 362 | '-hide_banner', |
| 363 | '-loglevel', 'error', |
| 364 | "-i", self.temp_file, |
| 365 | "-ss", str(self.play_start_time), "-to", str(self.play_end_time), "-i", self.media_path, |
| 366 | "-c", "copy", # may be c:v |
| 367 | "-map", "0:v:0", "-map", "1:a:0?", |
| 368 | "-shortest", |
| 369 | final_file_path] |
| 370 | subprocess.run(args, check=False) #Add Audio |
| 371 | os.remove(self.temp_file) |
| 372 | |
| 373 | self.end_time = time.perf_counter() |
| 374 | processing_time = self.end_time - self.start_time |
| 375 | print(f"\nProcessing completed in {processing_time} seconds") |
no test coverage detected