New config parameter --viewer.codec defaults to VP8, but allows H264 (#1343)

* New config parameter --viewer.codec defaults to H264 rather than VP8

* make quantize clearer

* change codec to Literal

default is VP8 due to libx264 log spam, see https://github.com/nerfstudio-project/nerfstudio/pull/1343#issuecomment-1416235500

* isort

* pylint, including python 3.7 compatibility
This commit is contained in:
machenmusik authored and GitHub committed 2023-02-03 13:38:40 -08:00
1 parent 59d7e99c80
commit 319a2b965c
3 files changed
+15 -4

No files matched your search

+4
View File
@@ -23,6 +23,8 @@ from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Any, List, Optional, Tuple, Type from typing import Any, List, Optional, Tuple, Type
from typing_extensions import Literal
# model instances # model instances
from nerfstudio.utils import writer from nerfstudio.utils import writer
@@ -149,3 +151,5 @@ class ViewerConfig(PrintableConfig):
skip_openrelay: bool = False skip_openrelay: bool = False
"""Avoid using openrelay to communicate with the viewer. Try disabling if you have trouble """Avoid using openrelay to communicate with the viewer. Try disabling if you have trouble
connecting to the viewer""" connecting to the viewer"""
codec: Literal["H264", "VP8"] = "VP8"
"""Video codec that viewer will use."""
+3 -2
View File
@@ -63,7 +63,7 @@ def three_js_perspective_camera_focal_length(fov: float, image_height: int):
def get_intrinsics_matrix_and_camera_to_world_h( def get_intrinsics_matrix_and_camera_to_world_h(
camera_object: Dict[str, Any], image_height: int camera_object: Dict[str, Any], image_height: int, image_width: Optional[int] = None
) -> Tuple[torch.Tensor, torch.Tensor]: ) -> Tuple[torch.Tensor, torch.Tensor]:
"""Returns the camera intrinsics matrix and the camera to world homogeneous matrix. """Returns the camera intrinsics matrix and the camera to world homogeneous matrix.
@@ -74,7 +74,8 @@ def get_intrinsics_matrix_and_camera_to_world_h(
# intrinsics # intrinsics
fov = camera_object["fov"] fov = camera_object["fov"]
aspect = camera_object["aspect"] aspect = camera_object["aspect"]
image_width = aspect * image_height if image_width is None:
image_width = aspect * image_height
pp_w = image_width / 2.0 pp_w = image_width / 2.0
pp_h = image_height / 2.0 pp_h = image_height / 2.0
if (camera_object["camera_type"] == "perspective") | (camera_object["camera_type"] == "fisheye"): if (camera_object["camera_type"] == "perspective") | (camera_object["camera_type"] == "fisheye"):
+8 -2
View File
@@ -689,7 +689,8 @@ class ViewerState:
video = SingleFrameStreamTrack() video = SingleFrameStreamTrack()
self.video_tracks.add(video) self.video_tracks.add(video)
video_sender = pc.addTrack(video) video_sender = pc.addTrack(video)
force_codec(pc, video_sender, "video/VP8") print(f"viewer using video/{self.config.codec}")
force_codec(pc, video_sender, f"video/{self.config.codec}")
await pc.setRemoteDescription(offer) await pc.setRemoteDescription(offer)
answer = await pc.createAnswer() answer = await pc.createAnswer()
@@ -831,6 +832,11 @@ class ViewerState:
if image_width > self.max_resolution: if image_width > self.max_resolution:
image_width = self.max_resolution image_width = self.max_resolution
image_height = int(image_width / aspect_ratio) image_height = int(image_width / aspect_ratio)
if self.config.codec != "VP8":
# force even values to allow hardware encoder usage
quantize = 2
image_width = int(image_width / quantize) * quantize
image_height = int(image_height / quantize) * quantize
return image_height, image_width return image_height, image_width
def _process_invalid_output(self, output_type: str) -> str: def _process_invalid_output(self, output_type: str) -> str:
@@ -904,7 +910,7 @@ class ViewerState:
return return
intrinsics_matrix, camera_to_world_h = get_intrinsics_matrix_and_camera_to_world_h( intrinsics_matrix, camera_to_world_h = get_intrinsics_matrix_and_camera_to_world_h(
camera_object, image_height=image_height camera_object, image_height=image_height, image_width=image_width
) )
camera_to_world = camera_to_world_h[:3, :] camera_to_world = camera_to_world_h[:3, :]