File tree 1 file changed +7
-4
lines changed
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):
88
88
output = os .path .join (self .tempdir .name , filename )
89
89
os .close (os .open (output , os .O_CREAT , mode = 0o664 ))
90
90
91
- cmd = (
92
- ffmpeg_bin ,
93
- "-ss" , offset ,
91
+ ffmpeg_options = (
94
92
"-i" , self .filepath ,
95
93
"-loglevel" , "error" ,
96
94
"-vframes" , "1" ,
97
95
output ,
98
96
"-y" ,
99
97
)
100
98
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 ()
102
105
103
106
def extract_frames (self ):
104
107
"""Extracts the frames from the video by given intervals."""
You can’t perform that action at this time.
0 commit comments