File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -88,17 +88,20 @@ def _extract_frame(self, start_time):
8888 output = os .path .join (self .tempdir .name , filename )
8989 os .close (os .open (output , os .O_CREAT , mode = 0o664 ))
9090
91- cmd = (
92- ffmpeg_bin ,
93- "-ss" , offset ,
91+ ffmpeg_options = (
9492 "-i" , self .filepath ,
9593 "-loglevel" , "error" ,
9694 "-vframes" , "1" ,
9795 output ,
9896 "-y" ,
9997 )
10098
101- subprocess .Popen (cmd ).wait ()
99+ subprocess .Popen ((ffmpeg_bin , "-ss" , offset , * ffmpeg_options )).wait ()
100+
101+ if os .stat (output ).st_size == 0 :
102+ # Check if the frame is empty. If so, try to extract it again with a smaller offset.
103+ # This handles the case when ffmpeg cannot extract the last frame of the video.
104+ subprocess .Popen ((ffmpeg_bin , "-sseof" , "-0.1" , * ffmpeg_options )).wait ()
102105
103106 def extract_frames (self ):
104107 """Extracts the frames from the video by given intervals."""
You can’t perform that action at this time.
0 commit comments