mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Add a stream lock and an idle state for stream to provide continuous frame flow
This commit is contained in:
parent
e071ac62a1
commit
a229bdc9c9
3 changed files with 34 additions and 28 deletions
|
@ -7,6 +7,11 @@ import random
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
import warnings
|
import warnings
|
||||||
|
from time import sleep
|
||||||
|
try:
|
||||||
|
import thread # Low-level threading API (Python 2.7)
|
||||||
|
except ImportError:
|
||||||
|
import _thread as thread # Low-level threading API (Python 3.x)
|
||||||
|
|
||||||
from tqdm import tqdm as ProgressDisplay
|
from tqdm import tqdm as ProgressDisplay
|
||||||
|
|
||||||
|
@ -58,6 +63,7 @@ class Scene(Container):
|
||||||
self.frame_num = 0
|
self.frame_num = 0
|
||||||
self.current_scene_time = 0
|
self.current_scene_time = 0
|
||||||
self.original_skipping_status = self.skip_animations
|
self.original_skipping_status = self.skip_animations
|
||||||
|
self.stream_lock = False
|
||||||
if self.name is None:
|
if self.name is None:
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
if self.random_seed is not None:
|
if self.random_seed is not None:
|
||||||
|
@ -455,6 +461,8 @@ class Scene(Container):
|
||||||
raise EndSceneEarlyException()
|
raise EndSceneEarlyException()
|
||||||
|
|
||||||
def play(self, *args, **kwargs):
|
def play(self, *args, **kwargs):
|
||||||
|
if IS_LIVE_STREAMING:
|
||||||
|
self.stream_lock = False
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
warnings.warn("Called Scene.play with no animations")
|
warnings.warn("Called Scene.play with no animations")
|
||||||
return
|
return
|
||||||
|
@ -491,8 +499,21 @@ class Scene(Container):
|
||||||
else:
|
else:
|
||||||
self.continual_update(0)
|
self.continual_update(0)
|
||||||
self.num_plays += 1
|
self.num_plays += 1
|
||||||
|
|
||||||
|
if IS_LIVE_STREAMING:
|
||||||
|
self.stream_lock = True
|
||||||
|
thread.start_new_thread(self.idle_stream, ())
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def idle_stream(self):
|
||||||
|
while(self.stream_lock):
|
||||||
|
self.update_frame()
|
||||||
|
n_frames = 1
|
||||||
|
frame = self.get_frame()
|
||||||
|
self.add_frames(*[frame] * n_frames)
|
||||||
|
sleep(self.frame_duration * 999/1000)
|
||||||
|
|
||||||
def clean_up_animations(self, *animations):
|
def clean_up_animations(self, *animations):
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
animation.clean_up(self)
|
animation.clean_up(self)
|
||||||
|
|
13
stream_starter.py
Normal file
13
stream_starter.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from big_ol_pile_of_manim_imports import *
|
||||||
|
import subprocess
|
||||||
|
from time import sleep
|
||||||
|
from manim import Manim
|
||||||
|
|
||||||
|
if not IS_STREAMING_TO_TWITCH:
|
||||||
|
FNULL = open(os.devnull, 'w')
|
||||||
|
subprocess.Popen([STREAMING_CLIENT, STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT + '?listen'], stdout=FNULL, stderr=FNULL)
|
||||||
|
sleep(3)
|
||||||
|
|
||||||
|
manim = Manim()
|
||||||
|
|
||||||
|
print("YOUR STREAM IS READY!")
|
28
test1.py
28
test1.py
|
@ -1,28 +0,0 @@
|
||||||
from big_ol_pile_of_manim_imports import *
|
|
||||||
from manim import Manim
|
|
||||||
|
|
||||||
|
|
||||||
manim = Manim()
|
|
||||||
|
|
||||||
circle = Circle()
|
|
||||||
square = Square()
|
|
||||||
line = Line(np.array([3,0,0]),np.array([5,0,0]))
|
|
||||||
triangle = Polygon(np.array([0,0,0]),np.array([1,1,0]),np.array([1,-1,0]))
|
|
||||||
|
|
||||||
manim.wait(3)
|
|
||||||
manim.add(line)
|
|
||||||
manim.wait(3)
|
|
||||||
manim.play(ShowCreation(circle))
|
|
||||||
manim.wait(3)
|
|
||||||
manim.play(FadeOut(circle))
|
|
||||||
manim.wait(3)
|
|
||||||
manim.play(GrowFromCenter(square))
|
|
||||||
manim.wait(3)
|
|
||||||
manim.play(Transform(square,triangle))
|
|
||||||
manim.wait(10)
|
|
||||||
|
|
||||||
manim.close_movie_pipe()
|
|
||||||
|
|
||||||
# ffplay tcp://127.0.0.1:2000?listen
|
|
||||||
# for listening the stream
|
|
||||||
# start mplayer before running this script
|
|
Loading…
Add table
Reference in a new issue