Skip to content

Commit

Permalink
Let OBS do the image reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulchen-Panther committed Dec 14, 2021
1 parent 2eff1f7 commit ac98002
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
[![Latest-Release](https://img.shields.io/github/v/release/hyperion-project/hyperion-obs-plugin)](https://github.com/hyperion-project/hyperion-obs-plugin/releases)
[![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)

An [OBS Studio][obs] plugin that provides output capabilities to a
[Hyperion.ng][hyperion] Server.

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

## Usage with hyperion-obs

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

![hyperion-obs](screenshot/hyperion-obs.png)
Expand Down Expand Up @@ -67,4 +66,4 @@ sudo make install
[obs]: https://obsproject.com/
[obs_build]: https://github.com/obsproject/obs-studio/wiki/install-instructions#windows-build-directions
[hyperion]: https://github.com/hyperion-project/hyperion.ng
[m-seker]: https://github.com/m-seker/hyperion.ng/tree/feature/obs
[m-seker]: https://github.com/m-seker
56 changes: 24 additions & 32 deletions src/hyperion-obs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <QMainWindow>
#include <QAction>
#include <QImage>

#include "hyperion-obs.h"
#include "HyperionProperties.h"
Expand All @@ -26,7 +25,6 @@ struct hyperion_output
FlatBufferConnection* client = nullptr;
uint32_t width = 0;
uint32_t height = 0;
int sizeDecimation = DEFAULT_SIZEDECIMATION;
bool active = false;
pthread_mutex_t mutex;
};
Expand Down Expand Up @@ -117,30 +115,25 @@ static void hyperion_output_destroy(void *data)
static bool hyperion_output_start(void *data)
{
hyperion_output *out_data = static_cast<hyperion_output*>(data);
out_data->width = obs_output_get_width(out_data->output);
out_data->height = obs_output_get_height(out_data->output);

obs_data_t *settings = obs_output_get_settings(out_data->output);
out_data->sizeDecimation = obs_data_get_int(settings, OBS_SETTINGS_SIZEDECIMATION);
int sizeDecimation = obs_data_get_int(settings, OBS_SETTINGS_SIZEDECIMATION);

if ( sizeDecimation == 0)
{
sizeDecimation = DEFAULT_SIZEDECIMATION;
}

out_data->width = obs_output_get_width(out_data->output) / sizeDecimation;
out_data->height = obs_output_get_height(out_data->output) / sizeDecimation;
obs_data_release(settings);

Connect(data);

video_t *video = obs_output_video(out_data->output);

if (video_output_get_format(video) != VIDEO_FORMAT_RGBA)
{
struct video_scale_info conv;
conv.format = VIDEO_FORMAT_RGBA;
conv.width = obs_output_get_width(out_data->output);
conv.height = obs_output_get_height(out_data->output);

obs_output_set_video_conversion(out_data->output, &conv);
}
else
{
obs_output_set_video_conversion(out_data->output, nullptr);
}
struct video_scale_info conv;
conv.format = VIDEO_FORMAT_RGBA;
conv.width = out_data->width;
conv.height = out_data->height;
obs_output_set_video_conversion(out_data->output, &conv);

// double video_frame_rate = video_output_get_frame_rate(video);

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

if ( out_data->sizeDecimation == 0)
{
out_data->sizeDecimation = DEFAULT_SIZEDECIMATION;
}
int outputWidth = out_data->width / out_data->sizeDecimation;

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);
QImage RGBImage = RGBAImage.scaledToWidth(outputWidth).convertToFormat(QImage::Format_RGB888);
Image<ColorRgb> outputImage(out_data->width, out_data->height);
uint8_t* rgba = frame->data[0];
uint8_t* rgb = (uint8_t*)outputImage.memptr();

Image<ColorRgb> outputImage(RGBImage.width(), RGBImage.height());
for (int y = 0; y < RGBImage.height(); y++)
int ptr_src = 0, ptr_dst = 0;
for (uint32_t i = 0; i < out_data->width * out_data->height; ++i)
{
memcpy((unsigned char*)outputImage.memptr() + y * outputImage.width() * 3, static_cast<unsigned char*>(RGBImage.scanLine(y)), RGBImage.width() * 3);
rgb[ptr_dst++] = rgba[ptr_src++];
rgb[ptr_dst++] = rgba[ptr_src++];
rgb[ptr_dst++] = rgba[ptr_src++];
ptr_src++;
}

QMetaObject::invokeMethod(out_data->client, "setImage", Qt::QueuedConnection, Q_ARG(Image<ColorRgb>, outputImage));

pthread_mutex_unlock(&out_data->mutex);
}
}
Expand Down

0 comments on commit ac98002

Please sign in to comment.