Skip to content

Commit ac98002

Browse files
Let OBS do the image reduction
1 parent 2eff1f7 commit ac98002

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
[![Latest-Release](https://img.shields.io/github/v/release/hyperion-project/hyperion-obs-plugin)](https://github.com/hyperion-project/hyperion-obs-plugin/releases)
44
[![GitHub Actions](https://github.com/hyperion-project/hyperion-obs-plugin/workflows/hyperion-obs/badge.svg?branch=main)](https://github.com/hyperion-project/hyperion-obs-plugin/actions)
55

6-
An [OBS Studio][obs] plugin that provides output capabilities to a
7-
[Hyperion.ng][hyperion] Server.
8-
6+
An [OBS Studio][obs] plugin that provides output capabilities to a [Hyperion.ng][hyperion] Server. \
97
The idea for this plugin originated from a [Hyperion.ng][hyperion] fork of [Murat Seker][m-seker].
108

119
## Usage with hyperion-obs
1210

1311
- Open OBS and select the menu entry `Tools > Hyperion Streaming`.
1412
- Enter the flatbuffer destination IP and select the appropriate port.
13+
- Optionally you can change the `Priority` or the image `Output Decimation` factor.
1514
- Click the `Start` button.
1615

1716
![hyperion-obs](screenshot/hyperion-obs.png)
@@ -67,4 +66,4 @@ sudo make install
6766
[obs]: https://obsproject.com/
6867
[obs_build]: https://github.com/obsproject/obs-studio/wiki/install-instructions#windows-build-directions
6968
[hyperion]: https://github.com/hyperion-project/hyperion.ng
70-
[m-seker]: https://github.com/m-seker/hyperion.ng/tree/feature/obs
69+
[m-seker]: https://github.com/m-seker

src/hyperion-obs.cpp

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <QMainWindow>
66
#include <QAction>
7-
#include <QImage>
87

98
#include "hyperion-obs.h"
109
#include "HyperionProperties.h"
@@ -26,7 +25,6 @@ struct hyperion_output
2625
FlatBufferConnection* client = nullptr;
2726
uint32_t width = 0;
2827
uint32_t height = 0;
29-
int sizeDecimation = DEFAULT_SIZEDECIMATION;
3028
bool active = false;
3129
pthread_mutex_t mutex;
3230
};
@@ -117,30 +115,25 @@ static void hyperion_output_destroy(void *data)
117115
static bool hyperion_output_start(void *data)
118116
{
119117
hyperion_output *out_data = static_cast<hyperion_output*>(data);
120-
out_data->width = obs_output_get_width(out_data->output);
121-
out_data->height = obs_output_get_height(out_data->output);
122-
123118
obs_data_t *settings = obs_output_get_settings(out_data->output);
124-
out_data->sizeDecimation = obs_data_get_int(settings, OBS_SETTINGS_SIZEDECIMATION);
119+
int sizeDecimation = obs_data_get_int(settings, OBS_SETTINGS_SIZEDECIMATION);
120+
121+
if ( sizeDecimation == 0)
122+
{
123+
sizeDecimation = DEFAULT_SIZEDECIMATION;
124+
}
125+
126+
out_data->width = obs_output_get_width(out_data->output) / sizeDecimation;
127+
out_data->height = obs_output_get_height(out_data->output) / sizeDecimation;
125128
obs_data_release(settings);
126129

127130
Connect(data);
128131

129-
video_t *video = obs_output_video(out_data->output);
130-
131-
if (video_output_get_format(video) != VIDEO_FORMAT_RGBA)
132-
{
133-
struct video_scale_info conv;
134-
conv.format = VIDEO_FORMAT_RGBA;
135-
conv.width = obs_output_get_width(out_data->output);
136-
conv.height = obs_output_get_height(out_data->output);
137-
138-
obs_output_set_video_conversion(out_data->output, &conv);
139-
}
140-
else
141-
{
142-
obs_output_set_video_conversion(out_data->output, nullptr);
143-
}
132+
struct video_scale_info conv;
133+
conv.format = VIDEO_FORMAT_RGBA;
134+
conv.width = out_data->width;
135+
conv.height = out_data->height;
136+
obs_output_set_video_conversion(out_data->output, &conv);
144137

145138
// double video_frame_rate = video_output_get_frame_rate(video);
146139

@@ -173,22 +166,21 @@ static void hyperion_output_raw_video(void *param, struct video_data *frame)
173166
{
174167
pthread_mutex_lock(&out_data->mutex);
175168

176-
if ( out_data->sizeDecimation == 0)
177-
{
178-
out_data->sizeDecimation = DEFAULT_SIZEDECIMATION;
179-
}
180-
int outputWidth = out_data->width / out_data->sizeDecimation;
181-
182-
QImage RGBAImage(static_cast<const uchar*>(frame->data[0]), static_cast<int>(out_data->width), static_cast<int>(out_data->height), 4 * out_data->width, QImage::Format_RGBA8888);
183-
QImage RGBImage = RGBAImage.scaledToWidth(outputWidth).convertToFormat(QImage::Format_RGB888);
169+
Image<ColorRgb> outputImage(out_data->width, out_data->height);
170+
uint8_t* rgba = frame->data[0];
171+
uint8_t* rgb = (uint8_t*)outputImage.memptr();
184172

185-
Image<ColorRgb> outputImage(RGBImage.width(), RGBImage.height());
186-
for (int y = 0; y < RGBImage.height(); y++)
173+
int ptr_src = 0, ptr_dst = 0;
174+
for (uint32_t i = 0; i < out_data->width * out_data->height; ++i)
187175
{
188-
memcpy((unsigned char*)outputImage.memptr() + y * outputImage.width() * 3, static_cast<unsigned char*>(RGBImage.scanLine(y)), RGBImage.width() * 3);
176+
rgb[ptr_dst++] = rgba[ptr_src++];
177+
rgb[ptr_dst++] = rgba[ptr_src++];
178+
rgb[ptr_dst++] = rgba[ptr_src++];
179+
ptr_src++;
189180
}
190181

191182
QMetaObject::invokeMethod(out_data->client, "setImage", Qt::QueuedConnection, Q_ARG(Image<ColorRgb>, outputImage));
183+
192184
pthread_mutex_unlock(&out_data->mutex);
193185
}
194186
}

0 commit comments

Comments
 (0)