@@ -74,6 +74,8 @@ def __init__(
7474 # key_hash supports resume from previous run
7575 self .temp_dir = Path (temp_dir ) / f"dlc_vid_{ key_hash } "
7676 self .temp_dir .mkdir (parents = True , exist_ok = True )
77+ if not self .temp_dir .exists (): # pragma: no cover
78+ raise FileNotFoundError (f"Could not create { self .temp_dir } " )
7779 logger .debug (f"Temporary directory: { self .temp_dir } " )
7880
7981 if not Path (video_filename ).exists ():
@@ -109,6 +111,7 @@ def __init__(
109111 self .timeout = 30 if test_mode else 300
110112
111113 self .ffmpeg_log_args = ["-hide_banner" , "-loglevel" , "error" ]
114+
112115 self .ffmpeg_fmt_args = ["-c:v" , "libx264" , "-pix_fmt" , "yuv420p" ]
113116
114117 prev_backend = matplotlib .get_backend ()
@@ -123,7 +126,12 @@ def __init__(
123126 )
124127 self .process_frames ()
125128 plt .close (self .fig )
126- logger .info (f"Finished video: { self .output_video_filename } " )
129+
130+ if Path (self .output_video_filename ).exists ():
131+ logger .info (f"Finished video: { self .output_video_filename } " )
132+ else :
133+ logger .error (f"Failed to create: { self .output_video_filename } " )
134+
127135 logger .debug (f"Dropped frames: { self .dropped_frames } " )
128136
129137 if not debug :
@@ -187,6 +195,9 @@ def _set_frame_info(self):
187195 if self .debug : # If debugging, limit frames to available data
188196 self .n_frames = min (len (self .position_mean ), self .n_frames )
189197
198+ if self .n_frames == 0 : # pragma: no cover
199+ raise ValueError ("No frames to process!" ) # pragma: no cover
200+
190201 self .pad_len = len (str (self .n_frames ))
191202
192203 def _set_plot_bases (self ):
@@ -490,11 +501,18 @@ def ffmpeg_extract(self, start_frame, end_frame):
490501 ]
491502 ret = subprocess .run (ffmpeg_cmd , stderr = subprocess .PIPE )
492503
504+ if ret .returncode != 0 : # pragma: no cover
505+ logger .error (f"Error extracting frames: { ret .stderr } " )
506+ if not self .temp_dir .glob ("orig_*.png" ): # pragma: no cover
507+ raise FileNotFoundError ("No frames were extracted!" )
508+
493509 extracted = len (list (self .temp_dir .glob ("orig_*.png" )))
494510 logger .debug (f"Extracted frames: { start_frame } , len: { extracted } " )
495- if extracted < self .batch_size - 1 :
511+
512+ frame_diff = end_frame - start_frame + 1 # may be less than batch size
513+ if extracted < frame_diff :
496514 logger .warning (
497- f"Could not extract frames: { extracted } / { self . batch_size - 1 } "
515+ f"Could not extract frames: { extracted } / { frame_diff } "
498516 )
499517 one_err = "\n " .join (str (ret .stderr ).split ("\\ " )[- 3 :- 1 ])
500518 logger .debug (f"\n Extract Error: { one_err } " )
@@ -536,9 +554,16 @@ def ffmpeg_stitch_partial(self, start_frame, output_partial_video):
536554 except subprocess .CalledProcessError as e : # pragma: no cover
537555 logger .error (f"Err stitching video: { e .stderr } " ) # pragma: no cover
538556
557+ if not Path (output_partial_video ).exists (): # pragma: no cover
558+ logger .error (f"Partial video not created: { output_partial_video } " )
559+
539560 def concat_partial_videos (self ):
540561 """Concatenate all the partial videos into one final video."""
541562 partial_vids = sorted (self .temp_dir .glob ("partial_*.mp4" ))
563+
564+ if not partial_vids : # pragma: no cover
565+ raise FileNotFoundError ("No partial videos to concatenate!" )
566+
542567 logger .debug (f"Concat part vids: { len (partial_vids )} " )
543568 concat_list_path = self .temp_dir / "concat_list.txt"
544569 with open (concat_list_path , "w" ) as f :
@@ -568,6 +593,7 @@ def concat_partial_videos(self):
568593 )
569594 except subprocess .CalledProcessError as e :
570595 logger .error (f"Error stitching partial video: { e .stderr } " )
596+ raise # pragma: no cover
571597
572598
573599def make_video (** kwargs ):
0 commit comments