Skip to content
Snippets Groups Projects

Support for Python

Merged João Magalhães requested to merge joamag/python into master
Compare and Show latest version
1 file
+ 10
6
Compare changes
  • Side-by-side
  • Inline
+ 10
6
@@ -4,7 +4,7 @@ from math import ceil
from shutil import rmtree
from tempfile import mkdtemp
from contextlib import contextmanager
from typing import Any, Union
from typing import Any, Iterable, Union
from PIL.Image import Image, frombytes
@@ -103,12 +103,12 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
image = self.image()
image.save(filename, format=format)
def video(self, encoder="avc1", display=True) -> Any:
def video(self, encoder="avc1", display=True, file_name="output.mp4") -> Any:
from cv2 import VideoWriter, VideoWriter_fourcc, imread
from IPython.display import Video, display as _display
image_paths = glob(f"{self._capture_temp_dir}/*.png")
video_path = f"{self._capture_temp_dir}/video.mp4"
image_paths = glob(f"{self._capture_temp_dir}/frame_*.png")
video_path = f"{self._capture_temp_dir}/{file_name}"
encoder = VideoWriter(
video_path,
@@ -119,8 +119,8 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
try:
for image_file in sorted(image_paths):
img = imread(image_file)
encoder.write(img)
image = imread(image_file)
encoder.write(image)
finally:
encoder.release()
@@ -175,6 +175,10 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
def set_serial_enabled(self, value: bool):
self._system.set_serial_enabled(value)
@property
def palettes(self) -> Iterable[str]:
return PALETTES.keys()
@property
def version(self) -> str:
return self._system.version()
Loading