Skip to content

Commit b2c268b

Browse files
authored
add configurable loop count option (#4)
1 parent e6ee172 commit b2c268b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ blink_cursor = true
101101
user_name = "x0rzavi" # for prompt
102102
fps = 15
103103
color_scheme = "yoru"
104+
loop_count = 0 # infinite loop
104105

105106
[files]
106107
frame_base_name = "frame_"

gifos/config/gifos_settings.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ blink_cursor = true
66
user_name = "x0rzavi" # for prompt
77
fps = 15
88
color_scheme = "yoru"
9+
loop_count = 0 # infinite loop
910

1011
[files]
1112
frame_base_name = "frame_"

gifos/gifos.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(
127127
self.__show_cursor = gifos_settings.get("general", {}).get("show_cursor", True)
128128
self.__blink_cursor = gifos_settings.get("general", {}).get("blink_cursor", True)
129129
self.__fps = gifos_settings.get("general", {}).get("fps") or 20
130+
self.__loop_count = gifos_settings.get("general", {}).get("loop_count") or 0
130131
self.__user_name = gifos_settings.get("general", {}).get("user_name") or "x0rzavi"
131132
self.__prompt = (
132133
f"\x1b[0;91m{self.__user_name}\x1b[0m@\x1b[0;93mgifos ~> \x1b[0m"
@@ -810,13 +811,30 @@ def set_fps(self, fps: float) -> None:
810811
"""
811812
self.__fps = fps
812813

814+
def set_loop_count(self, loop_count: int) -> None:
815+
"""Set the loop count for GIF to be generated.
816+
817+
This method sets the loop count for the GIF to be generated. Specifications for the loop number
818+
are given by ffmpeg as follows:
819+
-1: No-loop (stop after first playback)
820+
0: Infinite loop
821+
1..65535: Loop n times up to a maximum of 65535
822+
823+
:param loop_count: The number of loops in the GIF to be generated.
824+
:type loop_count: int
825+
"""
826+
def limit(n: int, lower: int, upper: int):
827+
return min(max(n, lower), upper)
828+
829+
self.__loop_count = limit(loop_count, -1, 65535)
830+
813831
def gen_gif(self) -> None:
814832
"""Generate a GIF from the frames.
815833
816834
This method generates a GIF from the frames. The method uses the `ffmpeg` command to generate the GIF, with the frames per second (fps) set to the fps specified in the Terminal object. The generated GIF is saved with the name specified by `output_gif_name`.
817835
"""
818836
os.system(
819-
f"ffmpeg -hide_banner -loglevel error -r {self.__fps} -i '{frame_folder_name}/{frame_base_name}%d.png' -filter_complex '[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse' {output_gif_name}.gif"
837+
f"ffmpeg -hide_banner -loglevel error -r {self.__fps} -i '{frame_folder_name}/{frame_base_name}%d.png' -loop {self.__loop_count} -filter_complex '[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse' {output_gif_name}.gif"
820838
)
821839
print(
822840
f"INFO: Generated {output_gif_name}.gif approximately {round(self.__frame_count / self.__fps, 2)}s long"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy