mirror of
https://github.com/3b1b/manim.git
synced 2026-04-26 03:00:23 -04:00
Fix streaming issues by migrating from mplayer to ffplay and add Twitch support
This commit is contained in:
@@ -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"
|
||||
|
||||
1
manim.py
1
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
8
test1.py
8
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
|
||||
|
||||
Reference in New Issue
Block a user