Update README.md and streaming config

This commit is contained in:
Devin Neal 2018-12-22 18:25:35 -08:00
parent 27f677e45f
commit 2ebe54ec07
6 changed files with 59 additions and 23 deletions

View file

@ -15,7 +15,7 @@ Manim runs on python 3.7. You can install the python requirements with
git clone https://github.com/3b1b/manim.git git clone https://github.com/3b1b/manim.git
cd manim cd manim
pip install -r requirements.txt pip install -r requirements.txt
python3 extract_scene.py example_scenes.py SquareToCircle -pl python3 -m manim example_scenes.py SquareToCircle -pl
``` ```
### Using `virtualenv` and `virtualenvwrapper` ### Using `virtualenv` and `virtualenvwrapper`
@ -23,7 +23,7 @@ After installing `virtualenv` and `virtualenvwrapper`
```sh ```sh
git clone https://github.com/3b1b/manim.git git clone https://github.com/3b1b/manim.git
mkvirtualenv -a manim -r requirements.txt manim mkvirtualenv -a manim -r requirements.txt manim
python3 extract_scene.py example_scenes.py SquareToCircle -pl python3 -m manim example_scenes.py SquareToCircle -pl
``` ```
### Using Docker ### Using Docker
@ -41,14 +41,14 @@ The image does not contain a copy of the repo. This is intentional, as it allows
4. Render an animation 4. Render an animation
```sh ```sh
cd manim cd manim
python3 extract_scene.py example_scenes.py SquareToCircle -l python3 -m manim example_scenes.py SquareToCircle -l
``` ```
Note that the image doesn't have any development tools installed and can't preview animations. Its purpose is building and testing only. Note that the image doesn't have any development tools installed and can't preview animations. Its purpose is building and testing only.
## Using manim ## Using manim
Try running the following: Try running the following:
```sh ```sh
python3 extract_scene.py example_scenes.py SquareToCircle -pl python3 -m manim example_scenes.py SquareToCircle -pl
``` ```
The -p is for previewing, meaning the the video file will automatically open when it is done rendering. The -p is for previewing, meaning the the video file will automatically open when it is done rendering.
Use -l for a faster rendering at a lower quality. Use -l for a faster rendering at a lower quality.
@ -69,18 +69,24 @@ Documentation is in progress at [manim.readthedocs.io](https://manim.readthedocs
Todd Zimmerman put together a [tutorial](https://talkingphysics.wordpress.com/2018/06/11/learning-how-to-animate-videos-using-manim-series-a-journey/) on getting started with manim, but it uses an outdated version that runs on python 2.7. It may not be fully compatible with the current version of manim, but it does a good job laying out the basics. Todd Zimmerman put together a [tutorial](https://talkingphysics.wordpress.com/2018/06/11/learning-how-to-animate-videos-using-manim-series-a-journey/) on getting started with manim, but it uses an outdated version that runs on python 2.7. It may not be fully compatible with the current version of manim, but it does a good job laying out the basics.
### Live Streaming ### Live Streaming
To live stream your animations, simply assign `IS_LIVE_STREAMING = True` in `constants.py` file and from your Python Interactive Shell (`python3`) import the stream starter with `from stream_starter import *` while under the project directory. This will provide a clean interactive shell to enter your commands. `manim` object is a `Manim()` instance so as soon as you play an animation with `manim.play()` your stream will start. A video player will pop-up and you can broadcast that video using [OBS Studio](https://obsproject.com/) which is the most practical way of streaming with this math animation library. An example: To live stream your animations, simply run manim with the `--livestreaming` option.
``` ```sh
>>> from stream_starter import * > python -m manim --livestream
YOUR STREAM IS READY! Writing to media/videos/scene/scene/1080p30/LiveStreamTemp.mp4
>>> circle = Circle()
>>> manim.play(ShowCreation(circle)) Manim is now running in streaming mode. Stream animations by passing
Animation 0: ShowCreationCircle: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 60/60 [00:01<00:00, 37.30it/s] them to manim.play(), e.g.
<scene.scene.Scene object at 0x7f0756d5a8d0> >>> c = Circle()
>>> manim.play(ShowCreation(c))
>>>
``` ```
It is also possible to stream directly to Twitch. To do that simply assign `IS_STREAMING_TO_TWITCH = True` in `constants.py` file and put your Twitch Stream Key to `TWITCH_STREAM_KEY = "YOUR_STREAM_KEY"` and when you follow the above example the stream will directly start on your Twitch channel(with no audio support). It is also possible to stream directly to Twitch. To do that simply pass
--livestream and --to-twitch to manim and specify the stream key with
--with-key. Then when you follow the above example the stream will directly
start on your Twitch channel (with no audio support).
## Contributing ## Contributing

View file

@ -20,8 +20,6 @@ def parse_cli():
nargs="?", nargs="?",
help="Name of the Scene class you want to see", help="Name of the Scene class you want to see",
) )
module_location.add_argument("--livestream", action="store_true")
parser.add_argument("--to-twitch", action="store_true")
optional_args = [ optional_args = [
("-p", "--preview"), ("-p", "--preview"),
("-w", "--write_to_movie"), ("-w", "--write_to_movie"),
@ -40,12 +38,33 @@ def parse_cli():
parser.add_argument("-n", "--start_at_animation_number") parser.add_argument("-n", "--start_at_animation_number")
parser.add_argument("-r", "--resolution") parser.add_argument("-r", "--resolution")
parser.add_argument("-c", "--color") parser.add_argument("-c", "--color")
module_location.add_argument(
"--livestream",
action="store_true",
help="Run in streaming mode",
)
parser.add_argument(
"--to-twitch",
action="store_true",
help="Stream to twitch",
)
parser.add_argument(
"--with-key",
dest="twitch_key",
help="Stream key for twitch",
)
args = parser.parse_args() args = parser.parse_args()
if args.file is None and not args.livestream: if args.file is None and not args.livestream:
parser.print_help() parser.print_help()
sys.exit(2) sys.exit(2)
else: if args.to_twitch and not args.livestream:
return args print("You must run in streaming mode in order to stream to twitch")
sys.exit(2)
if args.to_twitch and args.twitch_key is None:
print("Specify the twitch stream key with --with-key")
sys.exit(2)
return args
except argparse.ArgumentError as err: except argparse.ArgumentError as err:
print(str(err)) print(str(err))
sys.exit(2) sys.exit(2)

View file

@ -237,3 +237,9 @@ STREAMING_IP = "127.0.0.1"
STREAMING_PORT = "2000" STREAMING_PORT = "2000"
STREAMING_CLIENT = "ffplay" STREAMING_CLIENT = "ffplay"
STREAMING_URL = f"{STREAMING_PROTOCOL}://{STREAMING_IP}:{STREAMING_PORT}?listen" STREAMING_URL = f"{STREAMING_PROTOCOL}://{STREAMING_IP}:{STREAMING_PORT}?listen"
STREAMING_CONSOLE_BANNER = """
Manim is now running in streaming mode. Stream animations by passing
them to manim.play(), e.g.
>>> c = Circle()
>>> manim.play(ShowCreation(c))
"""

View file

@ -8,4 +8,7 @@ if not args.livestream:
config = config.get_configuration(args) config = config.get_configuration(args)
extract_scene.main(config) extract_scene.main(config)
else: else:
stream_starter.start_livestream(args.to_twitch) stream_starter.start_livestream(
to_twitch=args.to_twitch,
twitch_key=args.twitch_key,
)

View file

@ -53,6 +53,7 @@ class Scene(Container):
"end_at_animation_number": None, "end_at_animation_number": None,
"livestreaming": False, "livestreaming": False,
"to_twitch": False, "to_twitch": False,
"twitch_key": None,
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -658,7 +659,7 @@ class Scene(Container):
if self.livestreaming: if self.livestreaming:
if self.to_twitch: if self.to_twitch:
command += ['-f', 'flv'] command += ['-f', 'flv']
command += ['rtmp://live.twitch.tv/app/' + TWITCH_STREAM_KEY] command += ['rtmp://live.twitch.tv/app/' + self.twitch_key]
else: else:
command += ['-f', 'mpegts'] command += ['-f', 'mpegts']
command += [STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT] command += [STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT]

View file

@ -3,10 +3,11 @@ from time import sleep
import code import code
import constants import constants
import os import os
import readline
import subprocess import subprocess
def start_livestream(to_twitch=False): def start_livestream(to_twitch=False, twitch_key=None):
class Manim(): class Manim():
def __new__(cls): def __new__(cls):
@ -32,6 +33,7 @@ def start_livestream(to_twitch=False):
"frame_duration": constants.MEDIUM_QUALITY_FRAME_DURATION, "frame_duration": constants.MEDIUM_QUALITY_FRAME_DURATION,
"livestreaming": True, "livestreaming": True,
"to_twitch": to_twitch, "to_twitch": to_twitch,
"twitch_key": twitch_key,
} }
return Scene(**kwargs) return Scene(**kwargs)
@ -43,10 +45,9 @@ def start_livestream(to_twitch=False):
stderr=FNULL) stderr=FNULL)
sleep(3) sleep(3)
manim = Manim()
print("YOUR STREAM IS READY!")
variables = globals().copy() variables = globals().copy()
variables.update(locals()) variables.update(locals())
shell = code.InteractiveConsole(variables) shell = code.InteractiveConsole(variables)
shell.push("manim = Manim()")
shell.push("from big_ol_pile_of_manim_imports import *") shell.push("from big_ol_pile_of_manim_imports import *")
shell.interact() shell.interact(banner=constants.STREAMING_CONSOLE_BANNER)