mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Fix streaming issues by migrating from mplayer to ffplay and add Twitch support
This commit is contained in:
parent
f898644a3c
commit
e071ac62a1
4 changed files with 23 additions and 7 deletions
|
@ -212,5 +212,12 @@ locals().update(COLOR_MAP)
|
||||||
for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]:
|
for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]:
|
||||||
locals()[name.replace("_C", "")] = locals()[name]
|
locals()[name.replace("_C", "")] = locals()[name]
|
||||||
|
|
||||||
|
# Streaming related configurations
|
||||||
IS_LIVE_STREAMING = True
|
IS_LIVE_STREAMING = True
|
||||||
LIVE_STREAM_NAME = "LiveStream"
|
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,
|
"skip_animations": False,
|
||||||
"camera_config": HIGH_QUALITY_CAMERA_CONFIG,
|
"camera_config": HIGH_QUALITY_CAMERA_CONFIG,
|
||||||
"frame_duration": PRODUCTION_QUALITY_FRAME_DURATION,
|
"frame_duration": PRODUCTION_QUALITY_FRAME_DURATION,
|
||||||
"is_live_streaming": IS_LIVE_STREAMING
|
|
||||||
}
|
}
|
||||||
return Scene(**kwargs)
|
return Scene(**kwargs)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Scene(Container):
|
||||||
self.setup()
|
self.setup()
|
||||||
if self.write_to_movie:
|
if self.write_to_movie:
|
||||||
self.open_movie_pipe()
|
self.open_movie_pipe()
|
||||||
if self.is_live_streaming:
|
if IS_LIVE_STREAMING:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
self.construct(*self.construct_args)
|
self.construct(*self.construct_args)
|
||||||
|
@ -624,9 +624,13 @@ class Scene(Container):
|
||||||
'-vcodec', 'libx264',
|
'-vcodec', 'libx264',
|
||||||
'-pix_fmt', 'yuv420p',
|
'-pix_fmt', 'yuv420p',
|
||||||
]
|
]
|
||||||
if self.is_live_streaming:
|
if IS_LIVE_STREAMING:
|
||||||
command += ['-f', 'mpegts']
|
if IS_STREAMING_TO_TWITCH:
|
||||||
command += ['tcp://127.0.0.1:2000']
|
command += ['-f', 'flv']
|
||||||
|
command += ['rtmp://live.twitch.tv/app/' + TWITCH_STREAM_KEY]
|
||||||
|
else:
|
||||||
|
command += ['-f', 'mpegts']
|
||||||
|
command += [STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT]
|
||||||
else:
|
else:
|
||||||
command += [temp_file_path]
|
command += [temp_file_path]
|
||||||
print(' '.join(command))
|
print(' '.join(command))
|
||||||
|
@ -636,7 +640,7 @@ class Scene(Container):
|
||||||
def close_movie_pipe(self):
|
def close_movie_pipe(self):
|
||||||
self.writing_process.stdin.close()
|
self.writing_process.stdin.close()
|
||||||
self.writing_process.wait()
|
self.writing_process.wait()
|
||||||
if self.is_live_streaming:
|
if IS_LIVE_STREAMING:
|
||||||
return True
|
return True
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
shutil.move(*self.args_to_rename_file)
|
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]))
|
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]))
|
triangle = Polygon(np.array([0,0,0]),np.array([1,1,0]),np.array([1,-1,0]))
|
||||||
|
|
||||||
|
manim.wait(3)
|
||||||
manim.add(line)
|
manim.add(line)
|
||||||
|
manim.wait(3)
|
||||||
manim.play(ShowCreation(circle))
|
manim.play(ShowCreation(circle))
|
||||||
|
manim.wait(3)
|
||||||
manim.play(FadeOut(circle))
|
manim.play(FadeOut(circle))
|
||||||
|
manim.wait(3)
|
||||||
manim.play(GrowFromCenter(square))
|
manim.play(GrowFromCenter(square))
|
||||||
|
manim.wait(3)
|
||||||
manim.play(Transform(square,triangle))
|
manim.play(Transform(square,triangle))
|
||||||
|
manim.wait(10)
|
||||||
|
|
||||||
manim.close_movie_pipe()
|
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
|
# for listening the stream
|
||||||
# start mplayer before running this script
|
# start mplayer before running this script
|
||||||
|
|
Loading…
Add table
Reference in a new issue