Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions streamer/pipeline_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class StreamingMode(enum.Enum):
VOD = 'vod'
"""Indicates a video-on-demand (VOD) stream, which is finite."""

class LimitResolutionMode(enum.Enum):
WIDTH = 'width'
"""Limit resolution by width, not height."""

HEIGHT = 'height'
"""Limit resolution by height, not width. (This is the default.)"""

class ManifestFormat(enum.Enum):
DASH = 'dash'
HLS = 'hls'
Expand Down Expand Up @@ -224,6 +231,12 @@ class PipelineConfig(configuration.Base):
streaming_mode = configuration.Field(StreamingMode, required=True).cast()
"""The streaming mode, which can be either 'vod' or 'live'."""

limit_resolution_by = configuration.Field(LimitResolutionMode, default=LimitResolutionMode.HEIGHT).cast()
"""Should the resolution be limited by height or width?

(Default is height.)
"""

quiet = configuration.Field(bool, default=False).cast()
"""If true, reduce the level of output.

Expand Down
12 changes: 9 additions & 3 deletions streamer/transcoder_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from streamer.input_configuration import Input, InputType, MediaType
from streamer.node_base import PolitelyWaitOnFinish
from streamer.output_stream import AudioOutputStream, OutputStream, TextOutputStream, VideoOutputStream
from streamer.pipeline_configuration import PipelineConfig, StreamingMode
from streamer.pipeline_configuration import LimitResolutionMode, PipelineConfig, StreamingMode
from typing import List, Union, Optional

class TranscoderNode(PolitelyWaitOnFinish):
Expand Down Expand Up @@ -220,9 +220,15 @@ def _encode_video(self, stream: VideoOutputStream, input: Input) -> List[str]:
# These filters are specific to Linux's vaapi.
filters.append('format=nv12')
filters.append('hwupload')
filters.append('scale_vaapi=-2:{0}'.format(stream.resolution.max_height))
if self._pipeline_config.limit_resolution_by == LimitResolutionMode.WIDTH:
filters.append('scale_vaapi={0}:-2'.format(stream.resolution.max_width))
else:
filters.append('scale_vaapi=-2:{0}'.format(stream.resolution.max_height))
else:
filters.append('scale=-2:{0}'.format(stream.resolution.max_height))
if self._pipeline_config.limit_resolution_by == LimitResolutionMode.WIDTH:
filters.append('scale={0}:-2'.format(stream.resolution.max_width))
else:
filters.append('scale=-2:{0}'.format(stream.resolution.max_height))

# To avoid weird rounding errors in Sample Aspect Ratio, set it explicitly
# to 1:1. Without this, you wind up with SAR set to weird values in DASH
Expand Down
Loading