Merge pull request #319 from Rosuav/video-info

Create an endpoint to view basic video info eg canvas size
This commit is contained in:
Stéphane Lepin 2019-05-10 18:30:06 +02:00 committed by GitHub
commit f815228677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 204 additions and 0 deletions

View File

@ -2824,6 +2824,97 @@
"lead": "", "lead": "",
"type": "class", "type": "class",
"examples": [] "examples": []
},
{
"subheads": [],
"description": "Get basic OBS video information",
"return": [
"{int} `baseWidth` Base (canvas) width",
"{int} `baseHeight` Base (canvas) height",
"{int} `outputWidth` Output width",
"{int} `outputHeight` Output height",
"{String} `scaleType` Scaling method used if output size differs from base size",
"{double} `fps` Frames rendered per second",
"{String} `videoFormat` Video color format",
"{String} `colorSpace` Color space for YUV",
"{String} `colorRange` Color range (full or partial)"
],
"api": "requests",
"name": "GetVideoInfo",
"category": "general",
"since": "4.6.0",
"returns": [
{
"type": "int",
"name": "baseWidth",
"description": "Base (canvas) width"
},
{
"type": "int",
"name": "baseHeight",
"description": "Base (canvas) height"
},
{
"type": "int",
"name": "outputWidth",
"description": "Output width"
},
{
"type": "int",
"name": "outputHeight",
"description": "Output height"
},
{
"type": "String",
"name": "scaleType",
"description": "Scaling method used if output size differs from base size"
},
{
"type": "double",
"name": "fps",
"description": "Frames rendered per second"
},
{
"type": "String",
"name": "videoFormat",
"description": "Video color format"
},
{
"type": "String",
"name": "colorSpace",
"description": "Color space for YUV"
},
{
"type": "String",
"name": "colorRange",
"description": "Color range (full or partial)"
}
],
"names": [
{
"name": "",
"description": "GetVideoInfo"
}
],
"categories": [
{
"name": "",
"description": "general"
}
],
"sinces": [
{
"name": "",
"description": "4.6.0"
}
],
"heading": {
"level": 2,
"text": "GetVideoInfo"
},
"lead": "",
"type": "class",
"examples": []
} }
], ],
"profiles": [ "profiles": [

View File

@ -111,6 +111,7 @@ auth_response = base64_encode(auth_response_hash)
+ [SetFilenameFormatting](#setfilenameformatting) + [SetFilenameFormatting](#setfilenameformatting)
+ [GetFilenameFormatting](#getfilenameformatting) + [GetFilenameFormatting](#getfilenameformatting)
+ [GetStats](#getstats) + [GetStats](#getstats)
+ [GetVideoInfo](#getvideoinfo)
* [Profiles](#profiles-1) * [Profiles](#profiles-1)
+ [SetCurrentProfile](#setcurrentprofile) + [SetCurrentProfile](#setcurrentprofile)
+ [GetCurrentProfile](#getcurrentprofile) + [GetCurrentProfile](#getcurrentprofile)
@ -1181,6 +1182,34 @@ _No specified parameters._
| `stats` | _OBSStats_ | OBS stats | | `stats` | _OBSStats_ | OBS stats |
---
### GetVideoInfo
- Added in v4.6.0
Get basic OBS video information
**Request Fields:**
_No specified parameters._
**Response Items:**
| Name | Type | Description |
| ---- | :---: | ------------|
| `baseWidth` | _int_ | Base (canvas) width |
| `baseHeight` | _int_ | Base (canvas) height |
| `outputWidth` | _int_ | Output width |
| `outputHeight` | _int_ | Output height |
| `scaleType` | _String_ | Scaling method used if output size differs from base size |
| `fps` | _double_ | Frames rendered per second |
| `videoFormat` | _String_ | Video color format |
| `colorSpace` | _String_ | Color space for YUV |
| `colorRange` | _String_ | Color range (full or partial) |
--- ---
## Profiles ## Profiles

View File

@ -31,6 +31,7 @@ QHash<QString, HandlerResponse(*)(WSRequestHandler*)> WSRequestHandler::messageM
{ "GetStats", WSRequestHandler::HandleGetStats }, { "GetStats", WSRequestHandler::HandleGetStats },
{ "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat }, { "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat },
{ "GetVideoInfo", WSRequestHandler::HandleGetVideoInfo },
{ "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting }, { "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting },
{ "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting }, { "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting },

View File

@ -65,6 +65,7 @@ class WSRequestHandler : public QObject {
static HandlerResponse HandleGetStats(WSRequestHandler* req); static HandlerResponse HandleGetStats(WSRequestHandler* req);
static HandlerResponse HandleSetHeartbeat(WSRequestHandler* req); static HandlerResponse HandleSetHeartbeat(WSRequestHandler* req);
static HandlerResponse HandleGetVideoInfo(WSRequestHandler* req);
static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req); static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req);
static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req); static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req);

View File

@ -5,6 +5,54 @@
#include "WSRequestHandler.h" #include "WSRequestHandler.h"
#define CASE(x) case x: return #x;
const char *describe_output_format(int format) {
switch (format) {
default:
CASE(VIDEO_FORMAT_NONE)
CASE(VIDEO_FORMAT_I420)
CASE(VIDEO_FORMAT_NV12)
CASE(VIDEO_FORMAT_YVYU)
CASE(VIDEO_FORMAT_YUY2)
CASE(VIDEO_FORMAT_UYVY)
CASE(VIDEO_FORMAT_RGBA)
CASE(VIDEO_FORMAT_BGRA)
CASE(VIDEO_FORMAT_BGRX)
CASE(VIDEO_FORMAT_Y800)
CASE(VIDEO_FORMAT_I444)
}
}
const char *describe_color_space(int cs) {
switch (cs) {
default:
CASE(VIDEO_CS_DEFAULT)
CASE(VIDEO_CS_601)
CASE(VIDEO_CS_709)
}
}
const char *describe_color_range(int range) {
switch (range) {
default:
CASE(VIDEO_RANGE_DEFAULT)
CASE(VIDEO_RANGE_PARTIAL)
CASE(VIDEO_RANGE_FULL)
}
}
const char *describe_scale_type(int scale) {
switch (scale) {
default:
CASE(VIDEO_SCALE_DEFAULT)
CASE(VIDEO_SCALE_POINT)
CASE(VIDEO_SCALE_FAST_BILINEAR)
CASE(VIDEO_SCALE_BILINEAR)
CASE(VIDEO_SCALE_BICUBIC)
}
}
#undef CASE
/** /**
* Returns the latest version of the plugin and the API. * Returns the latest version of the plugin and the API.
* *
@ -181,3 +229,37 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) {
obs_data_set_obj(response, "stats", stats); obs_data_set_obj(response, "stats", stats);
return req->SendOKResponse(response); return req->SendOKResponse(response);
} }
/**
* Get basic OBS video information
*
* @return {int} `baseWidth` Base (canvas) width
* @return {int} `baseHeight` Base (canvas) height
* @return {int} `outputWidth` Output width
* @return {int} `outputHeight` Output height
* @return {String} `scaleType` Scaling method used if output size differs from base size
* @return {double} `fps` Frames rendered per second
* @return {String} `videoFormat` Video color format
* @return {String} `colorSpace` Color space for YUV
* @return {String} `colorRange` Color range (full or partial)
*
* @api requests
* @name GetVideoInfo
* @category general
* @since 4.6.0
*/
HandlerResponse WSRequestHandler::HandleGetVideoInfo(WSRequestHandler* req) {
obs_video_info ovi;
obs_get_video_info(&ovi);
OBSDataAutoRelease response = obs_data_create();
obs_data_set_int(response, "baseWidth", ovi.base_width);
obs_data_set_int(response, "baseHeight", ovi.base_height);
obs_data_set_int(response, "outputWidth", ovi.output_width);
obs_data_set_int(response, "outputHeight", ovi.output_height);
obs_data_set_double(response, "fps", (double)ovi.fps_num / ovi.fps_den);
obs_data_set_string(response, "videoFormat", describe_output_format(ovi.output_format));
obs_data_set_string(response, "colorSpace", describe_color_space(ovi.colorspace));
obs_data_set_string(response, "colorRange", describe_color_range(ovi.range));
obs_data_set_string(response, "scaleType", describe_scale_type(ovi.scale_type));
return req->SendOKResponse(response);
}