Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix streaming issues by migrating from mplayer to ffplay and add Twitch support

Mehmet Mert Yildirane071ac62a162
diff --git a/constants.py b/constants.py
index 14ef7de89..ca7835986 100644
--- a/constants.py
+++ b/constants.py
@@ -212,5 +212,12 @@ locals().update(COLOR_MAP)
for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]:
locals()[name.replace("_C", "")] = locals()[name]
+# Streaming related configurations
IS_LIVE_STREAMING = True
LIVE_STREAM_NAME = "LiveStream"
+IS_STREAMING_TO_TWITCH = False
+TWITCH_STREAM_KEY = "YOUR_STREAM_KEY"
+STREAMING_PROTOCOL = "tcp"
+STREAMING_IP = "127.0.0.1"
+STREAMING_PORT = "2000"
+STREAMING_CLIENT = "ffplay"
diff --git a/manim.py b/manim.py
index 0448d1e40..49eefad67 100644
--- a/manim.py
+++ b/manim.py
@@ -27,6 +27,5 @@ class Manim():
"skip_animations": False,
"camera_config": HIGH_QUALITY_CAMERA_CONFIG,
"frame_duration": PRODUCTION_QUALITY_FRAME_DURATION,
- "is_live_streaming": IS_LIVE_STREAMING
}
return Scene(**kwargs)
diff --git a/scene/scene.py b/scene/scene.py
index 5b65b9f08..95a863eaa 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -67,7 +67,7 @@ class Scene(Container):
self.setup()
if self.write_to_movie:
self.open_movie_pipe()
- if self.is_live_streaming:
+ if IS_LIVE_STREAMING:
return None
try:
self.construct(*self.construct_args)
@@ -624,9 +624,13 @@ class Scene(Container):
'-vcodec', 'libx264',
'-pix_fmt', 'yuv420p',
]
- if self.is_live_streaming:
- command += ['-f', 'mpegts']
- command += ['tcp://127.0.0.1:2000']
+ if IS_LIVE_STREAMING:
+ if IS_STREAMING_TO_TWITCH:
+ command += ['-f', 'flv']
+ command += ['rtmp://live.twitch.tv/app/' + TWITCH_STREAM_KEY]
+ else:
+ command += ['-f', 'mpegts']
+ command += [STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT]
else:
command += [temp_file_path]
print(' '.join(command))
@@ -636,7 +640,7 @@ class Scene(Container):
def close_movie_pipe(self):
self.writing_process.stdin.close()
self.writing_process.wait()
- if self.is_live_streaming:
+ if IS_LIVE_STREAMING:
return True
if os.name == 'nt':
shutil.move(*self.args_to_rename_file)
diff --git a/test1.py b/test1.py
index 169eb3414..70d65e882 100644
--- a/test1.py
+++ b/test1.py
@@ -9,14 +9,20 @@ 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()
-# mplayer -cache 8092 ffmpeg://tcp://127.0.0.1:2000?listen
+# ffplay tcp://127.0.0.1:2000?listen
# for listening the stream
# start mplayer before running this script