mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Removed live_streaming conditions, as those don't work anyway and will be replaced in functionality soon. Also have the ffmpeg pipe take in raw bytes directly, rather than going through the intermediary of a numpy array
This commit is contained in:
parent
ed376e475d
commit
8488b9053d
1 changed files with 5 additions and 32 deletions
|
@ -34,7 +34,7 @@ class SceneFileWriter(object):
|
||||||
# Previous output_file_name
|
# Previous output_file_name
|
||||||
# TODO, address this in extract_scene et. al.
|
# TODO, address this in extract_scene et. al.
|
||||||
"file_name": None,
|
"file_name": None,
|
||||||
"input_file_path": "", # ??
|
"input_file_path": "",
|
||||||
"output_directory": None,
|
"output_directory": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,38 +171,20 @@ class SceneFileWriter(object):
|
||||||
def begin_animation(self, allow_write=False):
|
def begin_animation(self, allow_write=False):
|
||||||
if self.write_to_movie and allow_write:
|
if self.write_to_movie and allow_write:
|
||||||
self.open_movie_pipe()
|
self.open_movie_pipe()
|
||||||
if self.livestreaming:
|
|
||||||
self.stream_lock = False
|
|
||||||
|
|
||||||
def end_animation(self, allow_write=False):
|
def end_animation(self, allow_write=False):
|
||||||
if self.write_to_movie and allow_write:
|
if self.write_to_movie and allow_write:
|
||||||
self.close_movie_pipe()
|
self.close_movie_pipe()
|
||||||
if self.livestreaming:
|
|
||||||
self.stream_lock = True
|
|
||||||
thread.start_new_thread(self.idle_stream, ())
|
|
||||||
|
|
||||||
def write_frame(self, frame):
|
def write_frame(self, raw_bytes):
|
||||||
if self.write_to_movie:
|
if self.write_to_movie:
|
||||||
self.writing_process.stdin.write(frame.tostring())
|
self.writing_process.stdin.write(raw_bytes)
|
||||||
|
|
||||||
def save_final_image(self, image):
|
def save_final_image(self, image):
|
||||||
file_path = self.get_image_file_path()
|
file_path = self.get_image_file_path()
|
||||||
image.save(file_path)
|
image.save(file_path)
|
||||||
self.print_file_ready_message(file_path)
|
self.print_file_ready_message(file_path)
|
||||||
|
|
||||||
def idle_stream(self):
|
|
||||||
while self.stream_lock:
|
|
||||||
a = datetime.datetime.now()
|
|
||||||
self.update_frame()
|
|
||||||
n_frames = 1
|
|
||||||
frame = self.get_frame()
|
|
||||||
self.add_frames(*[frame] * n_frames)
|
|
||||||
b = datetime.datetime.now()
|
|
||||||
time_diff = (b - a).total_seconds()
|
|
||||||
frame_duration = 1 / self.scene.camera.frame_rate
|
|
||||||
if time_diff < frame_duration:
|
|
||||||
sleep(frame_duration - time_diff)
|
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
if self.write_to_movie:
|
if self.write_to_movie:
|
||||||
if hasattr(self, "writing_process"):
|
if hasattr(self, "writing_process"):
|
||||||
|
@ -231,6 +213,7 @@ class SceneFileWriter(object):
|
||||||
'-pix_fmt', 'rgba',
|
'-pix_fmt', 'rgba',
|
||||||
'-r', str(fps), # frames per second
|
'-r', str(fps), # frames per second
|
||||||
'-i', '-', # The imput comes from a pipe
|
'-i', '-', # The imput comes from a pipe
|
||||||
|
'-vf', 'vflip',
|
||||||
'-an', # Tells FFMPEG not to expect any audio
|
'-an', # Tells FFMPEG not to expect any audio
|
||||||
'-loglevel', 'error',
|
'-loglevel', 'error',
|
||||||
]
|
]
|
||||||
|
@ -247,22 +230,12 @@ class SceneFileWriter(object):
|
||||||
'-vcodec', 'libx264',
|
'-vcodec', 'libx264',
|
||||||
'-pix_fmt', 'yuv420p',
|
'-pix_fmt', 'yuv420p',
|
||||||
]
|
]
|
||||||
if self.livestreaming:
|
|
||||||
if self.to_twitch:
|
|
||||||
command += ['-f', 'flv']
|
|
||||||
command += ['rtmp://live.twitch.tv/app/' + self.twitch_key]
|
|
||||||
else:
|
|
||||||
command += ['-f', 'mpegts']
|
|
||||||
command += [STREAMING_PROTOCOL + '://' + STREAMING_IP + ':' + STREAMING_PORT]
|
|
||||||
else:
|
|
||||||
command += [temp_file_path]
|
command += [temp_file_path]
|
||||||
self.writing_process = subprocess.Popen(command, stdin=subprocess.PIPE)
|
self.writing_process = subprocess.Popen(command, stdin=subprocess.PIPE)
|
||||||
|
|
||||||
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.livestreaming:
|
|
||||||
return True
|
|
||||||
shutil.move(
|
shutil.move(
|
||||||
self.temp_partial_movie_file_path,
|
self.temp_partial_movie_file_path,
|
||||||
self.partial_movie_file_path,
|
self.partial_movie_file_path,
|
||||||
|
|
Loading…
Add table
Reference in a new issue