Skip to content

Commit b8a91a0

Browse files
GH-59: Fix the last frame generation issue (GH-60)
2 parents f3fd16c + b90ca08 commit b8a91a0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/thumbnails/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .thumbnail import ThumbnailVTT
2323
from .thumbnail import register_thumbnail
2424

25-
__version__ = "0.1.6"
25+
__version__ = "0.1.7"
2626
__all__ = (
2727
"Generator",
2828
"Thumbnail",

src/thumbnails/video.py

+7-4
Original file line numberDiff line numberDiff 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."""

0 commit comments

Comments
 (0)