Skip to content

Commit f658c99

Browse files
committed
feat: support lossy compression for multiview video export
1 parent acbf471 commit f658c99

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

moai/conf/model/monitors/exporting/local/multiview_video2d.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ _target_: moai.export.local.video2d.MultiviewVideo2d
44
path: ???
55
extension: mp4
66
overwrite: False
7+
prefix: ''
8+
suffix: ''
9+
lossy: false

moai/export/local/video2d.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@
1818
_internal_video_id_ = 0
1919

2020

21-
def _create_video_writer(path: str, overwrite: bool, fps: float = 60.0):
21+
def _create_video_writer(
22+
path: str, overwrite: bool, prefix: str, suffix: str, lossy: bool, fps: float = 60.0
23+
):
2224
global _internal_video_id_
25+
sp_kwargs = (
26+
{"c:v": "libx264"}
27+
if lossy
28+
else {"c:v": "libx265", "qp": "0", "x265-params": "lossless=1"}
29+
)
2330
vid = ffmpegio.open(
24-
f"{path}/{_internal_video_id_}.mp4" if os.path.isdir(path) else path,
31+
(
32+
os.path.join(path, f"{prefix}{_internal_video_id_}{suffix}.mp4")
33+
if os.path.isdir(path)
34+
else path
35+
),
2536
"wv",
2637
fps,
2738
overwrite=overwrite,
@@ -36,7 +47,8 @@ def _create_video_writer(path: str, overwrite: bool, fps: float = 60.0):
3647
# # 'c:v': 'h264_cuvid',
3748
# },
3849
# NOTE: forced lossless coding params and x265
39-
sp_kwargs={"c:v": "libx265", "qp": "0", "x265-params": "lossless=1"},
50+
# sp_kwargs={"c:v": "libx265", "qp": "0", "x265-params": "lossless=1"},
51+
sp_kwargs=sp_kwargs,
4052
# TODO: make such profiles selectable, e.g. lossless gray8, lossy rgb8, etc.
4153
)
4254
_internal_video_id_ += 1
@@ -57,6 +69,9 @@ def __init__(
5769
path: str,
5870
extension: str = "mp4",
5971
overwrite: bool = False,
72+
prefix: str = "",
73+
suffix: str = "",
74+
lossy: bool = False,
6075
):
6176
self.path = (
6277
ensure_path(log, "output folder", path) if os.path.isdir(path) else path
@@ -65,6 +80,9 @@ def __init__(
6580
log, "output format", extension, MultiviewVideo2d.__FORMATS__
6681
)
6782
self.overwrite = overwrite
83+
self.prefix = prefix
84+
self.suffix = suffix
85+
self.lossy = lossy
6886

6987
def on_predict_epoch_end(self, *args):
7088
self.close()
@@ -93,6 +111,9 @@ def __call__(
93111
_create_video_writer,
94112
path=self.path,
95113
overwrite=self.overwrite,
114+
prefix=self.prefix,
115+
suffix=self.suffix,
116+
lossy=self.lossy,
96117
fps=float(np.ceil(fps.squeeze())),
97118
)
98119
self.video_writers = defaultdict(self.video_writer_lambda)

0 commit comments

Comments
 (0)