Update AV1 patches
This commit is contained in:
parent
7e49dba2aa
commit
b4a7036386
2
main.sh
2
main.sh
@ -18,7 +18,7 @@ sed -i 's|-Werror-implicit-function-declaration||g' CMakeLists.txt
|
|||||||
sed -i 's| -Werror||g' cmake/Modules/CompilerConfig.cmake
|
sed -i 's| -Werror||g' cmake/Modules/CompilerConfig.cmake
|
||||||
sed -i 's| -Wswitch||g' cmake/Modules/CompilerConfig.cmake
|
sed -i 's| -Wswitch||g' cmake/Modules/CompilerConfig.cmake
|
||||||
|
|
||||||
for i in ../patches/* ; do echo "Applying Patch: $i" && patch -Np1 -i $i || echo "Applying Patch $i Failed!"; done
|
for i in ../patches/* ; do echo "Applying Patch: $i" && patch -Np1 -i $i || bash -c "echo "Applying Patch $i Failed!" && exit 2"; done
|
||||||
|
|
||||||
# Get build deps brute force
|
# Get build deps brute force
|
||||||
apt-get build-dep -y ./
|
apt-get build-dep -y ./
|
||||||
|
213
patches/0004-9475.patch
Normal file
213
patches/0004-9475.patch
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
From 9880ec62822d86d97491bac181329907f625b52f Mon Sep 17 00:00:00 2001
|
||||||
|
From: David Rosca <nowrep@gmail.com>
|
||||||
|
Date: Tue, 2 May 2023 13:14:18 +0200
|
||||||
|
Subject: [PATCH] libobs: Add AV1 parsing functions
|
||||||
|
|
||||||
|
One notable difference from the AVC/HEVC code is that it also inserts
|
||||||
|
the METADATA and SEQUENCE_HEADER OBUs into new_packet, otherwise the
|
||||||
|
resulting video file wouldn't play.
|
||||||
|
---
|
||||||
|
libobs/CMakeLists.txt | 2 +
|
||||||
|
libobs/cmake/legacy.cmake | 2 +
|
||||||
|
libobs/obs-av1.c | 123 ++++++++++++++++++++++++++++++++++++++
|
||||||
|
libobs/obs-av1.h | 35 +++++++++++
|
||||||
|
4 files changed, 162 insertions(+)
|
||||||
|
create mode 100644 libobs/obs-av1.c
|
||||||
|
create mode 100644 libobs/obs-av1.h
|
||||||
|
|
||||||
|
diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt
|
||||||
|
index 46112abe71f9d..36a75713c001f 100644
|
||||||
|
--- a/libobs/CMakeLists.txt
|
||||||
|
+++ b/libobs/CMakeLists.txt
|
||||||
|
@@ -33,6 +33,8 @@ target_sources(
|
||||||
|
obs-audio-controls.c
|
||||||
|
obs-audio-controls.h
|
||||||
|
obs-audio.c
|
||||||
|
+ obs-av1.c
|
||||||
|
+ obs-av1.h
|
||||||
|
obs-avc.c
|
||||||
|
obs-avc.h
|
||||||
|
obs-data.c
|
||||||
|
diff --git a/libobs/cmake/legacy.cmake b/libobs/cmake/legacy.cmake
|
||||||
|
index 5f13c4c0f04ab..dd77cdfb94229 100644
|
||||||
|
--- a/libobs/cmake/legacy.cmake
|
||||||
|
+++ b/libobs/cmake/legacy.cmake
|
||||||
|
@@ -32,6 +32,8 @@ target_sources(
|
||||||
|
obs-audio.c
|
||||||
|
obs-audio-controls.c
|
||||||
|
obs-audio-controls.h
|
||||||
|
+ obs-av1.c
|
||||||
|
+ obs-av1.h
|
||||||
|
obs-avc.c
|
||||||
|
obs-avc.h
|
||||||
|
obs-data.c
|
||||||
|
diff --git a/libobs/obs-av1.c b/libobs/obs-av1.c
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000..a015130537cf2
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/libobs/obs-av1.c
|
||||||
|
@@ -0,0 +1,123 @@
|
||||||
|
+// SPDX-FileCopyrightText: 2023 David Rosca <nowrep@gmail.com>
|
||||||
|
+//
|
||||||
|
+// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
+
|
||||||
|
+#include "obs-av1.h"
|
||||||
|
+
|
||||||
|
+#include "obs.h"
|
||||||
|
+
|
||||||
|
+static inline uint64_t leb128(const uint8_t *buf, size_t size, size_t *len)
|
||||||
|
+{
|
||||||
|
+ uint64_t value = 0;
|
||||||
|
+ uint8_t leb128_byte;
|
||||||
|
+
|
||||||
|
+ *len = 0;
|
||||||
|
+
|
||||||
|
+ for (int i = 0; i < 8; i++) {
|
||||||
|
+ if (size-- < 1)
|
||||||
|
+ break;
|
||||||
|
+ (*len)++;
|
||||||
|
+ leb128_byte = buf[i];
|
||||||
|
+ value |= (leb128_byte & 0x7f) << (i * 7);
|
||||||
|
+ if (!(leb128_byte & 0x80))
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return value;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static inline unsigned int get_bits(uint8_t val, unsigned int n,
|
||||||
|
+ unsigned int count)
|
||||||
|
+{
|
||||||
|
+ return (val >> (8 - n - count)) & ((1 << (count - 1)) * 2 - 1);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void parse_obu_header(const uint8_t *buf, size_t size, size_t *obu_start,
|
||||||
|
+ size_t *obu_size, int *obu_type)
|
||||||
|
+{
|
||||||
|
+ int extension_flag, has_size_field;
|
||||||
|
+ size_t size_len = 0;
|
||||||
|
+
|
||||||
|
+ *obu_start = 0;
|
||||||
|
+ *obu_size = 0;
|
||||||
|
+ *obu_type = 0;
|
||||||
|
+
|
||||||
|
+ if (size < 1)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ *obu_type = get_bits(*buf, 1, 4);
|
||||||
|
+ extension_flag = get_bits(*buf, 5, 1);
|
||||||
|
+ has_size_field = get_bits(*buf, 6, 1);
|
||||||
|
+
|
||||||
|
+ if (extension_flag)
|
||||||
|
+ (*obu_start)++;
|
||||||
|
+
|
||||||
|
+ (*obu_start)++;
|
||||||
|
+
|
||||||
|
+ if (has_size_field)
|
||||||
|
+ *obu_size = (size_t)leb128(buf + *obu_start, size - *obu_start,
|
||||||
|
+ &size_len);
|
||||||
|
+ else
|
||||||
|
+ *obu_size = size - 1;
|
||||||
|
+
|
||||||
|
+ *obu_start += size_len;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+bool obs_av1_keyframe(const uint8_t *data, size_t size)
|
||||||
|
+{
|
||||||
|
+ const uint8_t *start = data, *end = data + size;
|
||||||
|
+
|
||||||
|
+ while (start < end) {
|
||||||
|
+ size_t obu_start, obu_size;
|
||||||
|
+ int obu_type;
|
||||||
|
+ parse_obu_header(start, end - start, &obu_start, &obu_size,
|
||||||
|
+ &obu_type);
|
||||||
|
+
|
||||||
|
+ if (obu_size) {
|
||||||
|
+ if (obu_type == OBS_OBU_FRAME ||
|
||||||
|
+ obu_type == OBS_OBU_FRAME_HEADER) {
|
||||||
|
+ uint8_t val = *(start + obu_start);
|
||||||
|
+ if (!get_bits(val, 0, 1)) // show_existing_frame
|
||||||
|
+ return get_bits(val, 1, 2) ==
|
||||||
|
+ 0; // frame_type
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ start += obu_start + obu_size;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return false;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void obs_extract_av1_headers(const uint8_t *packet, size_t size,
|
||||||
|
+ uint8_t **new_packet_data, size_t *new_packet_size,
|
||||||
|
+ uint8_t **header_data, size_t *header_size)
|
||||||
|
+{
|
||||||
|
+ DARRAY(uint8_t) new_packet;
|
||||||
|
+ DARRAY(uint8_t) header;
|
||||||
|
+ const uint8_t *start = packet, *end = packet + size;
|
||||||
|
+
|
||||||
|
+ da_init(new_packet);
|
||||||
|
+ da_init(header);
|
||||||
|
+
|
||||||
|
+ while (start < end) {
|
||||||
|
+ size_t obu_start, obu_size;
|
||||||
|
+ int obu_type;
|
||||||
|
+ parse_obu_header(start, end - start, &obu_start, &obu_size,
|
||||||
|
+ &obu_type);
|
||||||
|
+
|
||||||
|
+ if (obu_type == OBS_OBU_METADATA ||
|
||||||
|
+ obu_type == OBS_OBU_SEQUENCE_HEADER) {
|
||||||
|
+ da_push_back_array(header, start, obu_start + obu_size);
|
||||||
|
+ }
|
||||||
|
+ da_push_back_array(new_packet, start, obu_start + obu_size);
|
||||||
|
+
|
||||||
|
+ start += obu_start + obu_size;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ *new_packet_data = new_packet.array;
|
||||||
|
+ *new_packet_size = new_packet.num;
|
||||||
|
+ *header_data = header.array;
|
||||||
|
+ *header_size = header.num;
|
||||||
|
+}
|
||||||
|
diff --git a/libobs/obs-av1.h b/libobs/obs-av1.h
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000..031299da0a415
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/libobs/obs-av1.h
|
||||||
|
@@ -0,0 +1,35 @@
|
||||||
|
+// SPDX-FileCopyrightText: 2023 David Rosca <nowrep@gmail.com>
|
||||||
|
+//
|
||||||
|
+// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
+
|
||||||
|
+#pragma once
|
||||||
|
+
|
||||||
|
+#include "util/c99defs.h"
|
||||||
|
+
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+extern "C" {
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
+enum {
|
||||||
|
+ OBS_OBU_SEQUENCE_HEADER = 1,
|
||||||
|
+ OBS_OBU_TEMPORAL_DELIMITER = 2,
|
||||||
|
+ OBS_OBU_FRAME_HEADER = 3,
|
||||||
|
+ OBS_OBU_TILE_GROUP = 4,
|
||||||
|
+ OBS_OBU_METADATA = 5,
|
||||||
|
+ OBS_OBU_FRAME = 6,
|
||||||
|
+ OBS_OBU_REDUNDANT_FRAME_HEADER = 7,
|
||||||
|
+ OBS_OBU_TILE_LIST = 8,
|
||||||
|
+ OBS_OBU_PADDING = 15,
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+/* Helpers for parsing AV1 OB units. */
|
||||||
|
+
|
||||||
|
+EXPORT bool obs_av1_keyframe(const uint8_t *data, size_t size);
|
||||||
|
+EXPORT void obs_extract_av1_headers(const uint8_t *packet, size_t size,
|
||||||
|
+ uint8_t **new_packet_data,
|
||||||
|
+ size_t *new_packet_size,
|
||||||
|
+ uint8_t **header_data, size_t *header_size);
|
||||||
|
+
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+}
|
||||||
|
+#endif
|
@ -1,15 +1,15 @@
|
|||||||
From 50270b270250a2a95a3d5e2799e40331fb4f83e9 Mon Sep 17 00:00:00 2001
|
From 38031cd5d1e9486f06c782fbc0162e9f95e3d116 Mon Sep 17 00:00:00 2001
|
||||||
From: Bleuzen <12885163+Bleuzen@users.noreply.github.com>
|
From: Bleuzen <12885163+Bleuzen@users.noreply.github.com>
|
||||||
Date: Thu, 27 Apr 2023 22:42:49 +0200
|
Date: Sat, 19 Aug 2023 02:50:09 +0200
|
||||||
Subject: [PATCH] obs-ffmpeg: Add NVENC AV1 FFmpeg encoder, part 1
|
Subject: [PATCH] obs-ffmpeg: Add NVENC AV1 FFmpeg encoder, part 1
|
||||||
|
|
||||||
---
|
---
|
||||||
plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c | 100 ++++++++++++++++++++++++--
|
plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c | 109 ++++++++++++++++++++++++--
|
||||||
plugins/obs-ffmpeg/obs-ffmpeg.c | 8 ++-
|
plugins/obs-ffmpeg/obs-ffmpeg.c | 9 ++-
|
||||||
2 files changed, 100 insertions(+), 8 deletions(-)
|
2 files changed, 109 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
||||||
index 8cd813837c1e8..35c3822453741 100644
|
index cfd4ea91916a2..80db3ba85ef39 100644
|
||||||
--- a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
--- a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
||||||
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
|
||||||
@@ -35,6 +35,7 @@ struct nvenc_encoder {
|
@@ -35,6 +35,7 @@ struct nvenc_encoder {
|
||||||
@ -34,7 +34,7 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
static inline bool valid_format(enum video_format format)
|
static inline bool valid_format(enum video_format format)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@@ -286,7 +294,9 @@ static void on_first_packet(void *data, AVPacket *pkt, struct darray *da)
|
@@ -281,7 +289,9 @@ static void on_first_packet(void *data, AVPacket *pkt, struct darray *da)
|
||||||
&enc->sei.array, &enc->sei.num);
|
&enc->sei.array, &enc->sei.num);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@ -45,7 +45,7 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
obs_extract_avc_headers(pkt->data, pkt->size,
|
obs_extract_avc_headers(pkt->data, pkt->size,
|
||||||
(uint8_t **)&da->array, &da->num,
|
(uint8_t **)&da->array, &da->num,
|
||||||
&enc->header.array, &enc->header.num,
|
&enc->header.array, &enc->header.num,
|
||||||
@@ -305,10 +315,11 @@ static void on_first_packet(void *data, AVPacket *pkt, struct darray *da)
|
@@ -300,10 +310,11 @@ static void on_first_packet(void *data, AVPacket *pkt, struct darray *da)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *nvenc_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
static void *nvenc_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
||||||
@ -58,21 +58,21 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
enc->hevc = hevc;
|
enc->hevc = hevc;
|
||||||
if (hevc) {
|
if (hevc) {
|
||||||
@@ -321,7 +332,12 @@ static void *nvenc_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
@@ -316,7 +327,12 @@ static void *nvenc_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
||||||
#else
|
#else
|
||||||
UNUSED_PARAMETER(hevc);
|
UNUSED_PARAMETER(hevc);
|
||||||
#endif
|
#endif
|
||||||
- {
|
- {
|
||||||
+ if (av1) {
|
+ if (av1) {
|
||||||
+ if (!ffmpeg_video_encoder_init(
|
+ if (!ffmpeg_video_encoder_init(
|
||||||
+ &enc->ffve, enc, encoder, "av1_nvenc", "nvenc_av1",
|
+ &enc->ffve, enc, encoder, "av1_nvenc", NULL,
|
||||||
+ ENCODER_NAME_AV1, on_init_error, on_first_packet))
|
+ ENCODER_NAME_AV1, on_init_error, on_first_packet))
|
||||||
+ goto fail;
|
+ goto fail;
|
||||||
+ } else {
|
+ } else {
|
||||||
if (!ffmpeg_video_encoder_init(&enc->ffve, enc, encoder,
|
if (!ffmpeg_video_encoder_init(&enc->ffve, enc, encoder,
|
||||||
"h264_nvenc", "nvenc_h264",
|
"h264_nvenc", "nvenc_h264",
|
||||||
ENCODER_NAME_H264, on_init_error,
|
ENCODER_NAME_H264, on_init_error,
|
||||||
@@ -365,12 +381,14 @@ static void *h264_nvenc_create(obs_data_t *settings, obs_encoder_t *encoder)
|
@@ -368,12 +384,14 @@ static void *h264_nvenc_create(obs_data_t *settings, obs_encoder_t *encoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psycho_aq = obs_data_get_bool(settings, "psycho_aq");
|
bool psycho_aq = obs_data_get_bool(settings, "psycho_aq");
|
||||||
@ -89,7 +89,7 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
return enc;
|
return enc;
|
||||||
@@ -404,18 +422,59 @@ static void *hevc_nvenc_create(obs_data_t *settings, obs_encoder_t *encoder)
|
@@ -415,18 +433,68 @@ static void *hevc_nvenc_create(obs_data_t *settings, obs_encoder_t *encoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool psycho_aq = obs_data_get_bool(settings, "psycho_aq");
|
bool psycho_aq = obs_data_get_bool(settings, "psycho_aq");
|
||||||
@ -114,10 +114,19 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
+ video_t *video = obs_encoder_video(encoder);
|
+ video_t *video = obs_encoder_video(encoder);
|
||||||
+ const struct video_output_info *voi = video_output_get_info(video);
|
+ const struct video_output_info *voi = video_output_get_info(video);
|
||||||
+ switch (voi->format) {
|
+ switch (voi->format) {
|
||||||
+ case VIDEO_FORMAT_I010:
|
+ case VIDEO_FORMAT_I010: {
|
||||||
+ case VIDEO_FORMAT_P010: {
|
|
||||||
+ const char *const text =
|
+ const char *const text =
|
||||||
+ obs_module_text("NVENC.10bitUnsupported");
|
+ obs_module_text("NVENC.I010Unsupported");
|
||||||
|
+ obs_encoder_set_last_error(encoder, text);
|
||||||
|
+ blog(LOG_ERROR, "[NVENC encoder] %s", text);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+ case VIDEO_FORMAT_P010:
|
||||||
|
+ break;
|
||||||
|
+ case VIDEO_FORMAT_P216:
|
||||||
|
+ case VIDEO_FORMAT_P416: {
|
||||||
|
+ const char *const text =
|
||||||
|
+ obs_module_text("NVENC.16bitUnsupported");
|
||||||
+ obs_encoder_set_last_error(encoder, text);
|
+ obs_encoder_set_last_error(encoder, text);
|
||||||
+ blog(LOG_ERROR, "[NVENC encoder] %s", text);
|
+ blog(LOG_ERROR, "[NVENC encoder] %s", text);
|
||||||
+ return NULL;
|
+ return NULL;
|
||||||
@ -151,7 +160,7 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
static bool nvenc_encode(void *data, struct encoder_frame *frame,
|
static bool nvenc_encode(void *data, struct encoder_frame *frame,
|
||||||
struct encoder_packet *packet, bool *received_packet)
|
struct encoder_packet *packet, bool *received_packet)
|
||||||
{
|
{
|
||||||
@@ -658,6 +717,12 @@ obs_properties_t *hevc_nvenc_properties_ffmpeg(void *unused)
|
@@ -669,6 +737,12 @@ obs_properties_t *hevc_nvenc_properties_ffmpeg(void *unused)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -164,7 +173,7 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
static bool nvenc_extra_data(void *data, uint8_t **extra_data, size_t *size)
|
static bool nvenc_extra_data(void *data, uint8_t **extra_data, size_t *size)
|
||||||
{
|
{
|
||||||
struct nvenc_encoder *enc = data;
|
struct nvenc_encoder *enc = data;
|
||||||
@@ -719,3 +784,24 @@ struct obs_encoder_info hevc_nvenc_encoder_info = {
|
@@ -730,3 +804,24 @@ struct obs_encoder_info hevc_nvenc_encoder_info = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@ -190,10 +199,10 @@ index 8cd813837c1e8..35c3822453741 100644
|
|||||||
+#endif
|
+#endif
|
||||||
+};
|
+};
|
||||||
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
index da0b2c2b46f7a..e06f8ac7a9192 100644
|
index 7eb9a876d82ff..07973ffc73b40 100644
|
||||||
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
|
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
@@ -43,6 +43,7 @@ extern struct obs_encoder_info h264_nvenc_encoder_info;
|
@@ -42,6 +42,7 @@ extern struct obs_encoder_info h264_nvenc_encoder_info;
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
extern struct obs_encoder_info hevc_nvenc_encoder_info;
|
extern struct obs_encoder_info hevc_nvenc_encoder_info;
|
||||||
#endif
|
#endif
|
||||||
@ -201,20 +210,28 @@ index da0b2c2b46f7a..e06f8ac7a9192 100644
|
|||||||
extern struct obs_encoder_info svt_av1_encoder_info;
|
extern struct obs_encoder_info svt_av1_encoder_info;
|
||||||
extern struct obs_encoder_info aom_av1_encoder_info;
|
extern struct obs_encoder_info aom_av1_encoder_info;
|
||||||
|
|
||||||
@@ -307,8 +308,11 @@ static bool nvenc_supported(bool *out_h264, bool *out_hevc, bool *out_av1)
|
@@ -272,7 +273,7 @@ static void do_nvenc_check_for_ubuntu_20_04(void)
|
||||||
|
static bool nvenc_codec_exists(const char *name, const char *fallback)
|
||||||
|
{
|
||||||
|
const AVCodec *nvenc = avcodec_find_encoder_by_name(name);
|
||||||
|
- if (!nvenc)
|
||||||
|
+ if (!nvenc && fallback)
|
||||||
|
nvenc = avcodec_find_encoder_by_name(fallback);
|
||||||
|
|
||||||
|
return nvenc != NULL;
|
||||||
|
@@ -302,8 +303,10 @@ static bool nvenc_supported(bool *out_h264, bool *out_hevc, bool *out_av1)
|
||||||
if (success) {
|
if (success) {
|
||||||
void *const lib = os_dlopen("libnvidia-encode.so.1");
|
void *const lib = os_dlopen("libnvidia-encode.so.1");
|
||||||
success = lib != NULL;
|
success = lib != NULL;
|
||||||
- if (success)
|
- if (success)
|
||||||
+ if (success) {
|
+ if (success) {
|
||||||
os_dlclose(lib);
|
os_dlclose(lib);
|
||||||
+ av1 = nvenc_codec_exists("av1_nvenc",
|
+ av1 = nvenc_codec_exists("av1_nvenc", NULL);
|
||||||
+ "nvenc_av1");
|
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void *const lib = os_dlopen("libnvidia-encode.so.1");
|
void *const lib = os_dlopen("libnvidia-encode.so.1");
|
||||||
@@ -432,6 +436,8 @@ bool obs_module_load(void)
|
@@ -427,6 +430,8 @@ bool obs_module_load(void)
|
||||||
if (hevc)
|
if (hevc)
|
||||||
obs_register_encoder(&hevc_nvenc_encoder_info);
|
obs_register_encoder(&hevc_nvenc_encoder_info);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
From 7f0532049b2fe1f3c1f37f45d540e0a7a18663df Mon Sep 17 00:00:00 2001
|
From a8d13ad4d98e70da648819afc219c65d256cf95d Mon Sep 17 00:00:00 2001
|
||||||
From: David Rosca <nowrep@gmail.com>
|
From: David Rosca <nowrep@gmail.com>
|
||||||
Date: Tue, 2 May 2023 13:14:18 +0200
|
Date: Tue, 2 May 2023 13:14:18 +0200
|
||||||
Subject: [PATCH 1/2] libobs: Add AV1 parsing functions
|
Subject: [PATCH 1/3] libobs: Add AV1 parsing functions
|
||||||
|
|
||||||
---
|
---
|
||||||
libobs/CMakeLists.txt | 2 +
|
libobs/CMakeLists.txt | 2 +
|
||||||
@ -13,7 +13,7 @@ Subject: [PATCH 1/2] libobs: Add AV1 parsing functions
|
|||||||
create mode 100644 libobs/obs-av1.h
|
create mode 100644 libobs/obs-av1.h
|
||||||
|
|
||||||
diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt
|
diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt
|
||||||
index d7bb1839c579e..0783feb07ccbb 100644
|
index 46112abe71f9d..36a75713c001f 100644
|
||||||
--- a/libobs/CMakeLists.txt
|
--- a/libobs/CMakeLists.txt
|
||||||
+++ b/libobs/CMakeLists.txt
|
+++ b/libobs/CMakeLists.txt
|
||||||
@@ -33,6 +33,8 @@ target_sources(
|
@@ -33,6 +33,8 @@ target_sources(
|
||||||
@ -26,10 +26,10 @@ index d7bb1839c579e..0783feb07ccbb 100644
|
|||||||
obs-avc.h
|
obs-avc.h
|
||||||
obs-data.c
|
obs-data.c
|
||||||
diff --git a/libobs/cmake/legacy.cmake b/libobs/cmake/legacy.cmake
|
diff --git a/libobs/cmake/legacy.cmake b/libobs/cmake/legacy.cmake
|
||||||
index e8458591c4f2f..a80c5b7c1df24 100644
|
index 5f13c4c0f04ab..dd77cdfb94229 100644
|
||||||
--- a/libobs/cmake/legacy.cmake
|
--- a/libobs/cmake/legacy.cmake
|
||||||
+++ b/libobs/cmake/legacy.cmake
|
+++ b/libobs/cmake/legacy.cmake
|
||||||
@@ -37,6 +37,8 @@ target_sources(
|
@@ -32,6 +32,8 @@ target_sources(
|
||||||
obs-audio.c
|
obs-audio.c
|
||||||
obs-audio-controls.c
|
obs-audio-controls.c
|
||||||
obs-audio-controls.h
|
obs-audio-controls.h
|
||||||
@ -209,23 +209,23 @@ index 0000000000000..031299da0a415
|
|||||||
+}
|
+}
|
||||||
+#endif
|
+#endif
|
||||||
|
|
||||||
From 479e25f59234622e2f868b5f3f295f8c4f702db0 Mon Sep 17 00:00:00 2001
|
From 5d0940dd512515d7885aafdd01cff6a875431418 Mon Sep 17 00:00:00 2001
|
||||||
From: David Rosca <nowrep@gmail.com>
|
From: David Rosca <nowrep@gmail.com>
|
||||||
Date: Tue, 2 May 2023 13:39:13 +0200
|
Date: Tue, 2 May 2023 13:39:13 +0200
|
||||||
Subject: [PATCH 2/2] obs-ffmpeg: Add AV1 support for VA-API
|
Subject: [PATCH 2/3] obs-ffmpeg: Add AV1 support for VA-API
|
||||||
|
|
||||||
---
|
---
|
||||||
plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c | 295 +++++++++++++++++---------
|
plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c | 284 ++++++++++++++++----------
|
||||||
plugins/obs-ffmpeg/obs-ffmpeg.c | 19 ++
|
plugins/obs-ffmpeg/obs-ffmpeg.c | 19 ++
|
||||||
plugins/obs-ffmpeg/vaapi-utils.c | 60 ++++++
|
plugins/obs-ffmpeg/vaapi-utils.c | 55 +++++
|
||||||
plugins/obs-ffmpeg/vaapi-utils.h | 4 +
|
plugins/obs-ffmpeg/vaapi-utils.h | 4 +
|
||||||
4 files changed, 274 insertions(+), 104 deletions(-)
|
4 files changed, 254 insertions(+), 108 deletions(-)
|
||||||
|
|
||||||
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
index c5aa0128a54b9..d6e61f8cb41b9 100644
|
index 25c5f79007a31..7543d68b6f750 100644
|
||||||
--- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
--- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
@@ -26,6 +26,7 @@
|
@@ -24,6 +24,7 @@
|
||||||
#include <media-io/video-io.h>
|
#include <media-io/video-io.h>
|
||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
#include <obs-avc.h>
|
#include <obs-avc.h>
|
||||||
@ -233,7 +233,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
#include <obs-hevc.h>
|
#include <obs-hevc.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -53,8 +54,15 @@
|
@@ -51,8 +52,15 @@
|
||||||
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
||||||
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
|
|
||||||
AVBufferRef *vadevice_ref;
|
AVBufferRef *vadevice_ref;
|
||||||
AVBufferRef *vaframes_ref;
|
AVBufferRef *vaframes_ref;
|
||||||
@@ -85,59 +93,48 @@ static const char *h264_vaapi_getname(void *unused)
|
@@ -83,59 +91,48 @@ static const char *h264_vaapi_getname(void *unused)
|
||||||
return "FFmpeg VAAPI H.264";
|
return "FFmpeg VAAPI H.264";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +326,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
|
|
||||||
static bool vaapi_init_codec(struct vaapi_encoder *enc, const char *path)
|
static bool vaapi_init_codec(struct vaapi_encoder *enc, const char *path)
|
||||||
{
|
{
|
||||||
@@ -234,7 +231,7 @@ static const rc_mode_t *get_rc_mode(const char *name)
|
@@ -232,7 +229,7 @@ static const rc_mode_t *get_rc_mode(const char *name)
|
||||||
return rc_mode ? rc_mode : RC_MODES;
|
return rc_mode ? rc_mode : RC_MODES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,16 +335,16 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
{
|
{
|
||||||
struct vaapi_encoder *enc = data;
|
struct vaapi_encoder *enc = data;
|
||||||
|
|
||||||
@@ -249,7 +246,7 @@ static bool vaapi_update(void *data, obs_data_t *settings, bool hevc)
|
@@ -247,7 +244,7 @@ static bool vaapi_update(void *data, obs_data_t *settings, bool hevc)
|
||||||
int bf = (int)obs_data_get_int(settings, "bf");
|
int bf = (int)obs_data_get_int(settings, "bf");
|
||||||
int qp = rc_mode->qp ? (int)obs_data_get_int(settings, "qp") : 0;
|
int qp = rc_mode->qp ? (int)obs_data_get_int(settings, "qp") : 0;
|
||||||
|
|
||||||
- av_opt_set_int(enc->context->priv_data, "qp", qp, 0);
|
- av_opt_set_int(enc->context->priv_data, "qp", qp, 0);
|
||||||
+ enc->context->global_quality = enc->codec == CODEC_AV1 ? qp * 4 : qp;
|
+ enc->context->global_quality = enc->codec == CODEC_AV1 ? qp * 5 : qp;
|
||||||
|
|
||||||
int level = (int)obs_data_get_int(settings, "level");
|
int level = (int)obs_data_get_int(settings, "level");
|
||||||
int bitrate = rc_mode->bitrate
|
int bitrate = rc_mode->bitrate
|
||||||
@@ -279,21 +276,15 @@ static bool vaapi_update(void *data, obs_data_t *settings, bool hevc)
|
@@ -277,21 +274,15 @@ static bool vaapi_update(void *data, obs_data_t *settings, bool hevc)
|
||||||
info.range = voi->range;
|
info.range = voi->range;
|
||||||
|
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
@ -369,25 +369,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
|
|
||||||
enc->context->profile = profile;
|
enc->context->profile = profile;
|
||||||
enc->context->max_b_frames = bf;
|
enc->context->max_b_frames = bf;
|
||||||
@@ -355,6 +346,17 @@ static bool vaapi_update(void *data, obs_data_t *settings, bool hevc)
|
@@ -418,16 +409,28 @@ static void vaapi_destroy(void *data)
|
||||||
enc->context->gop_size = 120;
|
|
||||||
}
|
|
||||||
|
|
||||||
+#define FOUR_K_CX 3840
|
|
||||||
+#define FOUR_K_CY 2160
|
|
||||||
+#define PIXELCOUNT_4K (FOUR_K_CX * FOUR_K_CY)
|
|
||||||
+
|
|
||||||
+ /* If 4K+, set tiles to 2x2 uniform tiles. */
|
|
||||||
+ if (enc->codec == CODEC_AV1 &&
|
|
||||||
+ (enc->context->width * enc->context->height) >= PIXELCOUNT_4K) {
|
|
||||||
+ av_opt_set_int(enc->context->priv_data, "tile_cols", 2, 0);
|
|
||||||
+ av_opt_set_int(enc->context->priv_data, "tile_rows", 2, 0);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
enc->height = enc->context->height;
|
|
||||||
|
|
||||||
const char *ffmpeg_opts = obs_data_get_string(settings, "ffmpeg_opts");
|
|
||||||
@@ -424,8 +426,20 @@ static void vaapi_destroy(void *data)
|
|
||||||
bfree(enc);
|
bfree(enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,8 +390,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
+ enum codec_type codec)
|
+ enum codec_type codec)
|
||||||
{
|
{
|
||||||
struct vaapi_encoder *enc;
|
struct vaapi_encoder *enc;
|
||||||
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
|
|
||||||
@@ -435,8 +449,8 @@ static void *vaapi_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
|
||||||
enc = bzalloc(sizeof(*enc));
|
enc = bzalloc(sizeof(*enc));
|
||||||
enc->encoder = encoder;
|
enc->encoder = encoder;
|
||||||
|
|
||||||
@ -420,7 +401,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
|
|
||||||
enc->first_packet = true;
|
enc->first_packet = true;
|
||||||
|
|
||||||
@@ -453,7 +467,7 @@ static void *vaapi_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
@@ -444,7 +447,7 @@ static void *vaapi_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +410,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
return enc;
|
return enc;
|
||||||
@@ -465,13 +479,18 @@ static void *vaapi_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
@@ -456,13 +459,18 @@ static void *vaapi_create_internal(obs_data_t *settings, obs_encoder_t *encoder,
|
||||||
|
|
||||||
static void *h264_vaapi_create(obs_data_t *settings, obs_encoder_t *encoder)
|
static void *h264_vaapi_create(obs_data_t *settings, obs_encoder_t *encoder)
|
||||||
{
|
{
|
||||||
@ -450,7 +431,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -501,9 +520,8 @@ static inline void copy_data(AVFrame *pic, const struct encoder_frame *frame,
|
@@ -492,9 +500,8 @@ static inline void copy_data(AVFrame *pic, const struct encoder_frame *frame,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +443,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
{
|
{
|
||||||
struct vaapi_encoder *enc = data;
|
struct vaapi_encoder *enc = data;
|
||||||
AVFrame *hwframe = NULL;
|
AVFrame *hwframe = NULL;
|
||||||
@@ -569,7 +587,7 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
@@ -556,22 +563,26 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
||||||
|
|
||||||
enc->first_packet = false;
|
enc->first_packet = false;
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
@ -471,9 +452,11 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
obs_extract_hevc_headers(
|
obs_extract_hevc_headers(
|
||||||
enc->packet->data, enc->packet->size,
|
enc->packet->data, enc->packet->size,
|
||||||
&new_packet, &size, &enc->header,
|
&new_packet, &size, &enc->header,
|
||||||
@@ -579,12 +597,18 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
&enc->header_size, &enc->sei,
|
||||||
#else
|
&enc->sei_size);
|
||||||
UNUSED_PARAMETER(hevc);
|
} else
|
||||||
|
-#else
|
||||||
|
- UNUSED_PARAMETER(hevc);
|
||||||
#endif
|
#endif
|
||||||
- {
|
- {
|
||||||
+ if (enc->codec == CODEC_H264) {
|
+ if (enc->codec == CODEC_H264) {
|
||||||
@ -491,7 +474,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
da_copy_array(enc->buffer, new_packet, size);
|
da_copy_array(enc->buffer, new_packet, size);
|
||||||
@@ -600,14 +624,17 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
@@ -587,14 +598,17 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
||||||
packet->size = enc->buffer.num;
|
packet->size = enc->buffer.num;
|
||||||
packet->type = OBS_ENCODER_VIDEO;
|
packet->type = OBS_ENCODER_VIDEO;
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
@ -511,7 +494,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
*received_packet = true;
|
*received_packet = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -623,54 +650,65 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
@@ -610,54 +624,61 @@ static bool vaapi_encode_internal(void *data, struct encoder_frame *frame,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,19 +520,17 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
-}
|
-}
|
||||||
+ if (codec == CODEC_H264) {
|
+ if (codec == CODEC_H264) {
|
||||||
+ return VAProfileH264ConstrainedBaseline;
|
+ return VAProfileH264ConstrainedBaseline;
|
||||||
+#if VA_CHECK_VERSION(1, 14, 0)
|
|
||||||
+ } else if (codec == CODEC_AV1) {
|
+ } else if (codec == CODEC_AV1) {
|
||||||
+ return VAProfileAV1Profile0;
|
+ return VAProfileAV1Profile0;
|
||||||
|
+#if ENABLE_HEVC
|
||||||
|
+ } else if (codec == CODEC_HEVC) {
|
||||||
|
+ return VAProfileHEVCMain;
|
||||||
#endif
|
#endif
|
||||||
-
|
-
|
||||||
-static void set_visible(obs_properties_t *ppts, const char *name, bool visible)
|
-static void set_visible(obs_properties_t *ppts, const char *name, bool visible)
|
||||||
-{
|
-{
|
||||||
- obs_property_t *p = obs_properties_get(ppts, name);
|
- obs_property_t *p = obs_properties_get(ppts, name);
|
||||||
- obs_property_set_visible(p, visible);
|
- obs_property_set_visible(p, visible);
|
||||||
+#if ENABLE_HEVC
|
|
||||||
+ } else if (codec == CODEC_HEVC) {
|
|
||||||
+ return VAProfileHEVCMain;
|
|
||||||
+#endif
|
|
||||||
+ }
|
+ }
|
||||||
+ return VAProfileNone;
|
+ return VAProfileNone;
|
||||||
}
|
}
|
||||||
@ -586,8 +567,8 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
+ obs_data_set_default_int(settings, "level", 120);
|
+ obs_data_set_default_int(settings, "level", 120);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
#else
|
-#else
|
||||||
UNUSED_PARAMETER(hevc);
|
- UNUSED_PARAMETER(hevc);
|
||||||
#endif
|
#endif
|
||||||
- {
|
- {
|
||||||
+ if (codec == CODEC_H264) {
|
+ if (codec == CODEC_H264) {
|
||||||
@ -603,7 +584,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
obs_data_set_default_int(settings, "bitrate", 2500);
|
obs_data_set_default_int(settings, "bitrate", 2500);
|
||||||
obs_data_set_default_int(settings, "keyint_sec", 0);
|
obs_data_set_default_int(settings, "keyint_sec", 0);
|
||||||
obs_data_set_default_int(settings, "bf", 0);
|
obs_data_set_default_int(settings, "bf", 0);
|
||||||
@@ -683,12 +721,7 @@ static void vaapi_defaults_internal(obs_data_t *settings, bool hevc)
|
@@ -670,12 +691,7 @@ static void vaapi_defaults_internal(obs_data_t *settings, bool hevc)
|
||||||
if (!va_dpy)
|
if (!va_dpy)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -617,7 +598,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_CBR, device))
|
if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_CBR, device))
|
||||||
obs_data_set_default_string(settings, "rate_control", "CBR");
|
obs_data_set_default_string(settings, "rate_control", "CBR");
|
||||||
else if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_VBR, device))
|
else if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_VBR, device))
|
||||||
@@ -701,12 +734,17 @@ static void vaapi_defaults_internal(obs_data_t *settings, bool hevc)
|
@@ -688,12 +704,17 @@ static void vaapi_defaults_internal(obs_data_t *settings, bool hevc)
|
||||||
|
|
||||||
static void h264_vaapi_defaults(obs_data_t *settings)
|
static void h264_vaapi_defaults(obs_data_t *settings)
|
||||||
{
|
{
|
||||||
@ -637,21 +618,19 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
|
static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
|
||||||
@@ -742,6 +780,13 @@ static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
|
@@ -729,6 +750,11 @@ static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
|
||||||
goto fail;
|
goto fail;
|
||||||
profile = VAProfileH264High;
|
profile = VAProfileH264High;
|
||||||
break;
|
break;
|
||||||
+#if VA_CHECK_VERSION(1, 14, 0)
|
|
||||||
+ case FF_PROFILE_AV1_MAIN:
|
+ case FF_PROFILE_AV1_MAIN:
|
||||||
+ if (!vaapi_display_av1_supported(va_dpy, device))
|
+ if (!vaapi_display_av1_supported(va_dpy, device))
|
||||||
+ goto fail;
|
+ goto fail;
|
||||||
+ profile = VAProfileAV1Profile0;
|
+ profile = VAProfileAV1Profile0;
|
||||||
+ break;
|
+ break;
|
||||||
+#endif
|
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
case FF_PROFILE_HEVC_MAIN:
|
case FF_PROFILE_HEVC_MAIN:
|
||||||
if (!vaapi_display_hevc_supported(va_dpy, device))
|
if (!vaapi_display_hevc_supported(va_dpy, device))
|
||||||
@@ -813,7 +858,7 @@ static bool get_device_name_from_pci(struct pci_access *pacc, char *pci_slot,
|
@@ -800,7 +826,7 @@ static bool get_device_name_from_pci(struct pci_access *pacc, char *pci_slot,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -660,7 +639,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
{
|
{
|
||||||
obs_properties_t *props = obs_properties_create();
|
obs_properties_t *props = obs_properties_create();
|
||||||
obs_property_t *list;
|
obs_property_t *list;
|
||||||
@@ -904,16 +949,18 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
@@ -891,16 +917,18 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
||||||
obs_module_text("Profile"),
|
obs_module_text("Profile"),
|
||||||
OBS_COMBO_TYPE_LIST,
|
OBS_COMBO_TYPE_LIST,
|
||||||
OBS_COMBO_FORMAT_INT);
|
OBS_COMBO_FORMAT_INT);
|
||||||
@ -681,7 +660,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
obs_property_set_modified_callback(list, vaapi_device_modified);
|
obs_property_set_modified_callback(list, vaapi_device_modified);
|
||||||
@@ -922,15 +969,34 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
@@ -909,15 +937,34 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
||||||
OBS_COMBO_TYPE_LIST,
|
OBS_COMBO_TYPE_LIST,
|
||||||
OBS_COMBO_FORMAT_INT);
|
OBS_COMBO_FORMAT_INT);
|
||||||
obs_property_list_add_int(list, "Auto", FF_LEVEL_UNKNOWN);
|
obs_property_list_add_int(list, "Auto", FF_LEVEL_UNKNOWN);
|
||||||
@ -725,7 +704,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
|
|
||||||
list = obs_properties_add_list(props, "rate_control",
|
list = obs_properties_add_list(props, "rate_control",
|
||||||
obs_module_text("RateControl"),
|
obs_module_text("RateControl"),
|
||||||
@@ -965,14 +1031,20 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
@@ -952,14 +999,20 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
|
||||||
static obs_properties_t *h264_vaapi_properties(void *unused)
|
static obs_properties_t *h264_vaapi_properties(void *unused)
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER(unused);
|
UNUSED_PARAMETER(unused);
|
||||||
@ -748,7 +727,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1001,12 +1073,27 @@ struct obs_encoder_info h264_vaapi_encoder_info = {
|
@@ -988,12 +1041,27 @@ struct obs_encoder_info h264_vaapi_encoder_info = {
|
||||||
.get_name = h264_vaapi_getname,
|
.get_name = h264_vaapi_getname,
|
||||||
.create = h264_vaapi_create,
|
.create = h264_vaapi_create,
|
||||||
.destroy = vaapi_destroy,
|
.destroy = vaapi_destroy,
|
||||||
@ -778,7 +757,7 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
@@ -1017,12 +1104,12 @@ struct obs_encoder_info hevc_vaapi_encoder_info = {
|
@@ -1004,11 +1072,11 @@ struct obs_encoder_info hevc_vaapi_encoder_info = {
|
||||||
.get_name = hevc_vaapi_getname,
|
.get_name = hevc_vaapi_getname,
|
||||||
.create = hevc_vaapi_create,
|
.create = hevc_vaapi_create,
|
||||||
.destroy = vaapi_destroy,
|
.destroy = vaapi_destroy,
|
||||||
@ -792,12 +771,11 @@ index c5aa0128a54b9..d6e61f8cb41b9 100644
|
|||||||
+ .get_video_info = vaapi_video_info,
|
+ .get_video_info = vaapi_video_info,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
index c62d0d65fff7b..bd7e1cafea3d1 100644
|
index 7eb9a876d82ff..981bb9c6550ff 100644
|
||||||
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
|
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
|
||||||
@@ -48,6 +48,7 @@ extern struct obs_encoder_info aom_av1_encoder_info;
|
@@ -47,6 +47,7 @@ extern struct obs_encoder_info aom_av1_encoder_info;
|
||||||
|
|
||||||
#ifdef LIBAVUTIL_VAAPI_AVAILABLE
|
#ifdef LIBAVUTIL_VAAPI_AVAILABLE
|
||||||
extern struct obs_encoder_info h264_vaapi_encoder_info;
|
extern struct obs_encoder_info h264_vaapi_encoder_info;
|
||||||
@ -805,7 +783,7 @@ index c62d0d65fff7b..bd7e1cafea3d1 100644
|
|||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
extern struct obs_encoder_info hevc_vaapi_encoder_info;
|
extern struct obs_encoder_info hevc_vaapi_encoder_info;
|
||||||
#endif
|
#endif
|
||||||
@@ -342,6 +343,17 @@ static bool h264_vaapi_supported(void)
|
@@ -337,6 +338,17 @@ static bool h264_vaapi_supported(void)
|
||||||
* that support H264. */
|
* that support H264. */
|
||||||
return vaapi_get_h264_default_device() != NULL;
|
return vaapi_get_h264_default_device() != NULL;
|
||||||
}
|
}
|
||||||
@ -823,7 +801,7 @@ index c62d0d65fff7b..bd7e1cafea3d1 100644
|
|||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
static bool hevc_vaapi_supported(void)
|
static bool hevc_vaapi_supported(void)
|
||||||
{
|
{
|
||||||
@@ -452,6 +464,13 @@ bool obs_module_load(void)
|
@@ -447,6 +459,13 @@ bool obs_module_load(void)
|
||||||
blog(LOG_INFO, "FFmpeg VAAPI H264 encoding not supported");
|
blog(LOG_INFO, "FFmpeg VAAPI H264 encoding not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,10 +816,10 @@ index c62d0d65fff7b..bd7e1cafea3d1 100644
|
|||||||
if (hevc_vaapi_supported()) {
|
if (hevc_vaapi_supported()) {
|
||||||
blog(LOG_INFO, "FFmpeg VAAPI HEVC encoding supported");
|
blog(LOG_INFO, "FFmpeg VAAPI HEVC encoding supported");
|
||||||
diff --git a/plugins/obs-ffmpeg/vaapi-utils.c b/plugins/obs-ffmpeg/vaapi-utils.c
|
diff --git a/plugins/obs-ffmpeg/vaapi-utils.c b/plugins/obs-ffmpeg/vaapi-utils.c
|
||||||
index 4198ee59c6ab4..ad527ec525e0e 100644
|
index 4198ee59c6ab4..2c8eddd3676fa 100644
|
||||||
--- a/plugins/obs-ffmpeg/vaapi-utils.c
|
--- a/plugins/obs-ffmpeg/vaapi-utils.c
|
||||||
+++ b/plugins/obs-ffmpeg/vaapi-utils.c
|
+++ b/plugins/obs-ffmpeg/vaapi-utils.c
|
||||||
@@ -261,6 +261,66 @@ const char *vaapi_get_h264_default_device()
|
@@ -261,6 +261,61 @@ const char *vaapi_get_h264_default_device()
|
||||||
return default_h264_device;
|
return default_h264_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,16 +827,11 @@ index 4198ee59c6ab4..ad527ec525e0e 100644
|
|||||||
+{
|
+{
|
||||||
+ bool ret = false;
|
+ bool ret = false;
|
||||||
+
|
+
|
||||||
+#if VA_CHECK_VERSION(1, 14, 0)
|
|
||||||
+ CHECK_PROFILE(ret, VAProfileAV1Profile0, dpy, device_path);
|
+ CHECK_PROFILE(ret, VAProfileAV1Profile0, dpy, device_path);
|
||||||
+
|
+
|
||||||
+ if (!ret) {
|
+ if (!ret) {
|
||||||
+ CHECK_PROFILE_LP(ret, VAProfileAV1Profile0, dpy, device_path);
|
+ CHECK_PROFILE_LP(ret, VAProfileAV1Profile0, dpy, device_path);
|
||||||
+ }
|
+ }
|
||||||
+#else
|
|
||||||
+ UNUSED_PARAMETER(dpy);
|
|
||||||
+ UNUSED_PARAMETER(device_path);
|
|
||||||
+#endif
|
|
||||||
+
|
+
|
||||||
+ return ret;
|
+ return ret;
|
||||||
+}
|
+}
|
||||||
@ -923,3 +896,99 @@ index b90b2394710b3..2d7ee29dc9ab9 100644
|
|||||||
#ifdef ENABLE_HEVC
|
#ifdef ENABLE_HEVC
|
||||||
bool vaapi_display_hevc_supported(VADisplay dpy, const char *device_path);
|
bool vaapi_display_hevc_supported(VADisplay dpy, const char *device_path);
|
||||||
bool vaapi_device_hevc_supported(const char *device_path);
|
bool vaapi_device_hevc_supported(const char *device_path);
|
||||||
|
|
||||||
|
From 1b2b4da94760c829366e129cddda7cfe886f7b48 Mon Sep 17 00:00:00 2001
|
||||||
|
From: David Rosca <nowrep@gmail.com>
|
||||||
|
Date: Fri, 22 Sep 2023 08:11:46 +0200
|
||||||
|
Subject: [PATCH 3/3] obs-ffmpeg: Set better VA-API defaults
|
||||||
|
|
||||||
|
Use High profile for H264 and auto level with all codecs.
|
||||||
|
Remove setting default value for unused "rendermode" option.
|
||||||
|
---
|
||||||
|
plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c | 29 ++++++++++-----------------
|
||||||
|
1 file changed, 11 insertions(+), 18 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
|
index 7543d68b6f750..0ec7fa2ec43d0 100644
|
||||||
|
--- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
|
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
|
||||||
|
@@ -663,26 +663,21 @@ static void vaapi_defaults_internal(obs_data_t *settings, enum codec_type codec)
|
||||||
|
const char *const device = vaapi_default_device(codec);
|
||||||
|
obs_data_set_default_string(settings, "vaapi_device", device);
|
||||||
|
#ifdef ENABLE_HEVC
|
||||||
|
- if (codec == CODEC_HEVC) {
|
||||||
|
+ if (codec == CODEC_HEVC)
|
||||||
|
obs_data_set_default_int(settings, "profile",
|
||||||
|
FF_PROFILE_HEVC_MAIN);
|
||||||
|
- obs_data_set_default_int(settings, "level", 120);
|
||||||
|
-
|
||||||
|
- } else
|
||||||
|
+ else
|
||||||
|
#endif
|
||||||
|
- if (codec == CODEC_H264) {
|
||||||
|
+ if (codec == CODEC_H264)
|
||||||
|
obs_data_set_default_int(settings, "profile",
|
||||||
|
- FF_PROFILE_H264_CONSTRAINED_BASELINE);
|
||||||
|
- obs_data_set_default_int(settings, "level", 40);
|
||||||
|
- } else if (codec == CODEC_AV1) {
|
||||||
|
+ FF_PROFILE_H264_HIGH);
|
||||||
|
+ else if (codec == CODEC_AV1)
|
||||||
|
obs_data_set_default_int(settings, "profile",
|
||||||
|
FF_PROFILE_AV1_MAIN);
|
||||||
|
- obs_data_set_default_int(settings, "level", 8);
|
||||||
|
- }
|
||||||
|
+ obs_data_set_default_int(settings, "level", FF_LEVEL_UNKNOWN);
|
||||||
|
obs_data_set_default_int(settings, "bitrate", 2500);
|
||||||
|
obs_data_set_default_int(settings, "keyint_sec", 0);
|
||||||
|
obs_data_set_default_int(settings, "bf", 0);
|
||||||
|
- obs_data_set_default_int(settings, "rendermode", 0);
|
||||||
|
obs_data_set_default_int(settings, "qp", 20);
|
||||||
|
obs_data_set_default_int(settings, "maxrate", 0);
|
||||||
|
|
||||||
|
@@ -770,7 +765,7 @@ static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_CBR, device))
|
||||||
|
- obs_property_list_add_string(rc_p, "CBR (default)", "CBR");
|
||||||
|
+ obs_property_list_add_string(rc_p, "CBR", "CBR");
|
||||||
|
|
||||||
|
if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_VBR, device))
|
||||||
|
obs_property_list_add_string(rc_p, "VBR", "VBR");
|
||||||
|
@@ -922,8 +917,7 @@ static obs_properties_t *vaapi_properties_internal(enum codec_type codec)
|
||||||
|
obs_property_list_add_int(list, "Main10",
|
||||||
|
FF_PROFILE_HEVC_MAIN_10);
|
||||||
|
} else if (codec == CODEC_H264) {
|
||||||
|
- obs_property_list_add_int(list,
|
||||||
|
- "Constrained Baseline (default)",
|
||||||
|
+ obs_property_list_add_int(list, "Constrained Baseline",
|
||||||
|
FF_PROFILE_H264_CONSTRAINED_BASELINE);
|
||||||
|
obs_property_list_add_int(list, "Main", FF_PROFILE_H264_MAIN);
|
||||||
|
obs_property_list_add_int(list, "High", FF_PROFILE_H264_HIGH);
|
||||||
|
@@ -940,8 +934,7 @@ static obs_properties_t *vaapi_properties_internal(enum codec_type codec)
|
||||||
|
if (codec == CODEC_H264) {
|
||||||
|
obs_property_list_add_int(list, "3.0", 30);
|
||||||
|
obs_property_list_add_int(list, "3.1", 31);
|
||||||
|
- obs_property_list_add_int(
|
||||||
|
- list, "4.0 (default) (Compatibility mode)", 40);
|
||||||
|
+ obs_property_list_add_int(list, "4.0", 40);
|
||||||
|
obs_property_list_add_int(list, "4.1", 41);
|
||||||
|
obs_property_list_add_int(list, "4.2", 42);
|
||||||
|
obs_property_list_add_int(list, "5.0", 50);
|
||||||
|
@@ -950,7 +943,7 @@ static obs_properties_t *vaapi_properties_internal(enum codec_type codec)
|
||||||
|
} else if (codec == CODEC_HEVC) {
|
||||||
|
obs_property_list_add_int(list, "3.0", 90);
|
||||||
|
obs_property_list_add_int(list, "3.1", 93);
|
||||||
|
- obs_property_list_add_int(list, "4.0 (default)", 120);
|
||||||
|
+ obs_property_list_add_int(list, "4.0", 120);
|
||||||
|
obs_property_list_add_int(list, "4.1", 123);
|
||||||
|
obs_property_list_add_int(list, "5.0", 150);
|
||||||
|
obs_property_list_add_int(list, "5.1", 153);
|
||||||
|
@@ -958,7 +951,7 @@ static obs_properties_t *vaapi_properties_internal(enum codec_type codec)
|
||||||
|
} else if (codec == CODEC_AV1) {
|
||||||
|
obs_property_list_add_int(list, "3.0", 4);
|
||||||
|
obs_property_list_add_int(list, "3.1", 5);
|
||||||
|
- obs_property_list_add_int(list, "4.0 (default)", 8);
|
||||||
|
+ obs_property_list_add_int(list, "4.0", 8);
|
||||||
|
obs_property_list_add_int(list, "4.1", 9);
|
||||||
|
obs_property_list_add_int(list, "5.0", 12);
|
||||||
|
obs_property_list_add_int(list, "5.1", 13);
|
||||||
|
Loading…
Reference in New Issue
Block a user