Store video frames in {basename}/{mode}/{palette}/ directory to

disambiguate different values (for palettes in particular)
This commit is contained in:
kris 2019-06-20 21:15:52 +01:00
parent a732a0e034
commit 7d041a6a84
2 changed files with 26 additions and 14 deletions

View File

@ -44,9 +44,11 @@ class FileFrameGrabber(FrameGrabber):
yield Image.fromarray(frame_array) yield Image.fromarray(frame_array)
@staticmethod @staticmethod
def _output_dir(filename) -> str: def _output_dir(filename, video_mode, palette) -> str:
# TODO: should include palette return "%s/%s/%s" % (
return ".".join(filename.split(".")[:-1]) ".".join(filename.split(".")[:-1]),
video_mode.name,
palette.name)
def _palette_arg(self) -> str: def _palette_arg(self) -> str:
return "P%d" % self.palette.value return "P%d" % self.palette.value
@ -57,11 +59,9 @@ class FileFrameGrabber(FrameGrabber):
We do the encoding in a background thread to parallelize. We do the encoding in a background thread to parallelize.
""" """
frame_dir = self._output_dir(self.filename) frame_dir = self._output_dir(
try: self.filename, self.video_mode, self.palette)
os.mkdir(frame_dir) os.makedirs(frame_dir, exist_ok=True)
except FileExistsError:
pass
q = queue.Queue(maxsize=10) q = queue.Queue(maxsize=10)

View File

@ -1,23 +1,35 @@
import unittest import unittest
import frame_grabber import frame_grabber
import palette
import video_mode
class TestFileFrameGrabber(unittest.TestCase): class TestFileFrameGrabber(unittest.TestCase):
def test_output_dir(self): def test_output_dir(self):
self.assertEqual( self.assertEqual(
"/foo/bar", "/foo/bar/DHGR/NTSC",
frame_grabber.FileFrameGrabber._output_dir("/foo/bar.mp4") frame_grabber.FileFrameGrabber._output_dir(
"/foo/bar.mp4", video_mode.VideoMode.DHGR, palette.Palette.NTSC
)
) )
self.assertEqual( self.assertEqual(
"/foo/bar.blee", "/foo/bar.blee/HGR/IIGS",
frame_grabber.FileFrameGrabber._output_dir("/foo/bar.blee.mp4") frame_grabber.FileFrameGrabber._output_dir(
"/foo/bar.blee.mp4",
video_mode.VideoMode.HGR,
palette.Palette.IIGS
)
) )
self.assertEqual( self.assertEqual(
"/foo/bar blee", "/foo/bar blee/DHGR/IIGS",
frame_grabber.FileFrameGrabber._output_dir("/foo/bar blee.mp4") frame_grabber.FileFrameGrabber._output_dir(
"/foo/bar blee.mp4",
video_mode.VideoMode.DHGR,
palette.Palette.IIGS
)
) )