obs-studio: up to 30.0.2, use ffmpeg 6.1

This commit is contained in:
Mateusz Słodkowicz 2023-12-12 14:59:45 +01:00
parent 8ce2a96f81
commit d288af17ca
Signed by: materus
GPG Key ID: 28D140BCA60B4FD1
5 changed files with 4136 additions and 14 deletions

View File

@ -1,4 +1,4 @@
import ./generic.nix rec {
version = "6.0";
sha256 = "sha256-RVbgsafIbeUUNXmUbDQ03ZN42oaUo0njqROo7KOQgv0=";
version = "6.1";
sha256 = "sha256-NzhD2D16bCVCyCXo0TRwZYp3Ta5eFSfoQPa+iRkeNZg=";
}

View File

@ -94,7 +94,7 @@
, withVoAmrwbenc ? withFullDeps # AMR-WB encoder
, withVorbis ? withHeadlessDeps # Vorbis de/encoding, native encoder exists
, withVpx ? withHeadlessDeps && stdenv.buildPlatform == stdenv.hostPlatform # VP8 & VP9 de/encoding
, withVulkan ? withFullDeps && !stdenv.isDarwin
, withVulkan ? false
, withWebp ? withFullDeps # WebP encoder
, withX264 ? withHeadlessDeps # H.264/AVC encoder
, withX265 ? withHeadlessDeps # H.265/HEVC encoder
@ -130,7 +130,6 @@
, withMultithread ? true # Multithreading via pthreads/win32 threads
, withNetwork ? withHeadlessDeps # Network support
, withPixelutils ? withHeadlessDeps # Pixel utils in libavutil
, withLTO ? false # build with link-time optimization
/*
* Program options
*/
@ -235,8 +234,6 @@
, libXext
, libxml2
, xz
, nv-codec-headers
, nv-codec-headers-11
, openal
, ocl-icd # OpenCL ICD
, opencl-headers # OpenCL headers
@ -352,10 +349,6 @@ stdenv.mkDerivation (finalAttrs: {
--replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
substituteInPlace doc/filters.texi \
--replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
'' + lib.optionalString withVulkan ''
# FIXME: horrible hack, remove for next release
substituteInPlace libavutil/hwcontext_vulkan.c \
--replace VK_EXT_VIDEO_DECODE VK_KHR_VIDEO_DECODE
'';
patches = map (patch: fetchpatch patch) (extraPatches
@ -389,7 +382,6 @@ stdenv.mkDerivation (finalAttrs: {
(enableFeature withSmallBuild "small")
(enableFeature withRuntimeCPUDetection "runtime-cpudetect")
(enableFeature withLTO "lto")
(enableFeature withGrayscale "gray")
(enableFeature withSwscaleAlpha "swscale-alpha")
(enableFeature withHardcodedTables "hardcoded-tables")
@ -557,9 +549,25 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [ removeReferencesTo addOpenGLRunpath perl pkg-config texinfo yasm ];
# TODO This was always in buildInputs before, why?
buildInputs = optionals withFullDeps [ libdc1394 ]
buildInputs =
let
nv-codec-headers = stdenv.mkDerivation rec {
pname = "nv-codec-headers";
version = "12.1.14.0";
src = fetchgit {
url = "https://git.videolan.org/git/ffmpeg/nv-codec-headers.git";
rev = "n${version}";
sha256 = "sha256-WJYuFmMGSW+B32LwE7oXv/IeTln6TNEeXSkquHh85Go=";
};
makeFlags = [
"PREFIX=$(out)"
];
};
in
optionals withFullDeps [ libdc1394 ]
++ optionals (withFullDeps && !stdenv.isDarwin) [ libraw1394 ] # TODO where does this belong to
++ optionals (withNvdec || withNvenc) [ (if (lib.versionAtLeast version "6") then nv-codec-headers-11 else nv-codec-headers) ]
++ optionals (withNvdec || withNvenc || withCuda) [ nv-codec-headers ]
++ optionals withAmf [ amf-headers ]
++ optionals withAlsa [ alsa-lib ]
++ optionals withAom [ libaom ]

File diff suppressed because it is too large Load Diff

View File

@ -61,7 +61,7 @@ let
in
stdenv.mkDerivation rec {
pname = "obs-studio-amf";
version = "30.0.0";
version = "30.0.2";
src = fetchFromGitHub {
owner = "obsproject";
repo = "obs-studio";
@ -74,6 +74,8 @@ stdenv.mkDerivation rec {
./obs-amf-patch.patch # OBS AMF Patch
./Enable-file-access-and-universal-access-for-file-URL.patch
./fix-nix-plugin-path.patch
./av1-vaapi.patch
./ffmpeg61.patch
];
nativeBuildInputs = [

View File

@ -0,0 +1,286 @@
From 7ed9b1f3a6b5e73a39daf906c8e8c19e93fce4b4 Mon Sep 17 00:00:00 2001
From: Stephen Seo <seo.disparate@gmail.com>
Date: Wed, 29 Nov 2023 22:06:09 +0900
Subject: [PATCH 1/4] deps/media-playback: Use new (nb_)coded_side_data FFmpeg
6.1 API
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.
The change in deps/media-playback/media-playback/decode.c is due to
FFmpeg moving "side_data" into AVCodecParameters which is mentioned in
commit [1] in FFmpeg's repository.
In summary of the "side_data" change, AVStream.side_data is deprecated
and replaced with AVStream.codecpar->coded_side_data, and
AVStream.nb_side_data is replaced with
AVStream.codecpar->nb_coded_side_data.
[1]: avcodec/codec_par: add side data to AVCodecParameters
https://github.com/FFmpeg/FFmpeg/commit/21d7cc6fa9a26e94965fa71b25655d07568450fe
---
deps/media-playback/media-playback/decode.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/deps/media-playback/media-playback/decode.c b/deps/media-playback/media-playback/decode.c
index 55b91c140ace4..40853f171bde7 100644
--- a/deps/media-playback/media-playback/decode.c
+++ b/deps/media-playback/media-playback/decode.c
@@ -114,8 +114,14 @@ static uint16_t get_max_luminance(const AVStream *stream)
{
uint32_t max_luminance = 0;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
for (int i = 0; i < stream->nb_side_data; i++) {
const AVPacketSideData *const sd = &stream->side_data[i];
+#else
+ for (int i = 0; i < stream->codecpar->nb_coded_side_data; i++) {
+ const AVPacketSideData *const sd =
+ &stream->codecpar->coded_side_data[i];
+#endif
switch (sd->type) {
case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: {
const AVMasteringDisplayMetadata *mastering =
From 92fc9f69ccff2cb12bb8ef877e9238f5d46588a8 Mon Sep 17 00:00:00 2001
From: Stephen Seo <seo.disparate@gmail.com>
Date: Wed, 29 Nov 2023 22:08:42 +0900
Subject: [PATCH 2/4] deps/media-playback: In check for key-frame, use new
FFmpeg 6.1 API
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.
AVFrame.key_frame was replaced with a flag in AVFrame.flags. The commit
adding the flag is [1] in FFmpeg's repository, and the deprecation is in
commit [2].
In summary of the "key_frame" change, AVFrame.key_frame is deprecated,
and AVFrame.flags indicates with a bit flag if it is a key frame (with
the enum/defined AV_FRAME_FLAG_KEY).
[1]: avutil/frame: add a keyframe flag to AVFrame
https://github.com/FFmpeg/FFmpeg/commit/cc11191fda0471017b03c1434d6d8cb79f6914e5
[2]: avutil/frame: deprecate key_frame
https://github.com/FFmpeg/FFmpeg/commit/3e06f6f04020bef32fa42bc9d7f96e76a46453aa
---
deps/media-playback/media-playback/media.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/deps/media-playback/media-playback/media.c b/deps/media-playback/media-playback/media.c
index 566eb9e35c9ef..07b040dd8235c 100644
--- a/deps/media-playback/media-playback/media.c
+++ b/deps/media-playback/media-playback/media.c
@@ -504,7 +504,12 @@ void mp_media_next_video(mp_media_t *m, bool preload)
}
if (!m->is_local_file && !d->got_first_keyframe) {
+
+#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58, 29, 100)
if (!f->key_frame)
+#else
+ if (!(f->flags & AV_FRAME_FLAG_KEY))
+#endif
return;
d->got_first_keyframe = true;
From ed1e0795acde8349ab18b631c545f56e5a3acb9d Mon Sep 17 00:00:00 2001
From: Stephen Seo <seo.disparate@gmail.com>
Date: Wed, 29 Nov 2023 20:07:10 +0900
Subject: [PATCH 3/4] libobs: Fence off unnecessary code due to FFmpeg v6.1
changes
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.
This commit prevents obs from using the "fenced" code if using FFmpeg
6.1, since in FFmpeg commit [1] the "side_data" is added to
`AVCodecParameters`, and therefore the existing/following
`avcodec_parameters_copy(...)` will account for the metadata.
[1]: avcodec/codec_par: add side data to AVCodecParameters
https://github.com/FFmpeg/FFmpeg/commit/21d7cc6fa9a26e94965fa71b25655d07568450fe
---
libobs/media-io/media-remux.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libobs/media-io/media-remux.c b/libobs/media-io/media-remux.c
index 7d5eead200012..827d4e59b18ed 100644
--- a/libobs/media-io/media-remux.c
+++ b/libobs/media-io/media-remux.c
@@ -91,6 +91,7 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
return false;
}
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
#if FF_API_BUFFER_SIZE_T
int content_size;
#else
@@ -125,6 +126,7 @@ static inline bool init_output(media_remux_job_t job, const char *out_filename)
mastering_size);
}
}
+#endif
ret = avcodec_parameters_copy(out_stream->codecpar,
in_stream->codecpar);
From 6d0381f98ce0a5624901b0042d624ea972a10c2b Mon Sep 17 00:00:00 2001
From: Stephen Seo <seo.disparate@gmail.com>
Date: Wed, 29 Nov 2023 20:09:08 +0900
Subject: [PATCH 4/4] obs-ffmpeg: Use new side-data FFmpeg 6.1 API
Fixes for using FFmpeg 6.1 due to deprecations. Uses `#if` macros to
allow builds for using older versions of FFmpeg.
This commit replaces usage of `av_stream_add_side_data(...)` with
`av_packet_side_data_add(...)`, as the former was deprecated in favor of
the latter.
The FFmpeg commit that deprecated `av_stream_add_side_data(...)` is [1].
The FFmpeg commit that introduced `av_packet_side_data_add(...)` is [2].
Note that the deprecation commit is after the new API function. The
commit in between [3] appears to be changes that migrates to the usage
of the new API function.
[1]: avformat/avformat: use the side data from AVStream.codecpar
https://github.com/FFmpeg/FFmpeg/commit/5432d2aacad5fa7420fe2d9369ed061d521e92d6
[2]: avcodec/packet: add generic side data helpers
https://github.com/FFmpeg/FFmpeg/commit/74279227dd28d01b447edb8e617a545982171c2c
[3]: avcodec/codec_par: add side data to AVCodecParameters
https://github.com/FFmpeg/FFmpeg/commit/21d7cc6fa9a26e94965fa71b25655d07568450fe
---
plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 16 ++++++++++++++++
plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c | 16 ++++++++++++++++
plugins/obs-ffmpeg/obs-ffmpeg-output.c | 16 ++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
index 740b60e5bf46e..8fb84aa7c4e0b 100644
--- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
+++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
@@ -498,9 +498,17 @@ static void create_video_stream(struct ffmpeg_mux *ffm)
av_content_light_metadata_alloc(&content_size);
content->MaxCLL = max_luminance;
content->MaxFALL = max_luminance;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(ffm->video_stream,
AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
(uint8_t *)content, content_size);
+#else
+ av_packet_side_data_add(
+ &ffm->video_stream->codecpar->coded_side_data,
+ &ffm->video_stream->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_CONTENT_LIGHT_LEVEL, (uint8_t *)content,
+ content_size, 0);
+#endif
AVMasteringDisplayMetadata *const mastering =
av_mastering_display_metadata_alloc();
@@ -516,10 +524,18 @@ static void create_video_stream(struct ffmpeg_mux *ffm)
mastering->max_luminance = av_make_q(max_luminance, 1);
mastering->has_primaries = 1;
mastering->has_luminance = 1;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(ffm->video_stream,
AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
(uint8_t *)mastering,
sizeof(*mastering));
+#else
+ av_packet_side_data_add(
+ &ffm->video_stream->codecpar->coded_side_data,
+ &ffm->video_stream->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+ (uint8_t *)mastering, sizeof(*mastering), 0);
+#endif
}
if (ffm->output->oformat->flags & AVFMT_GLOBALHEADER)
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c b/plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c
index f33ee77365274..a56dd91bcc38e 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-mpegts.c
@@ -168,9 +168,17 @@ static bool create_video_stream(struct ffmpeg_output *stream,
av_content_light_metadata_alloc(&content_size);
content->MaxCLL = hdr_nominal_peak_level;
content->MaxFALL = hdr_nominal_peak_level;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(data->video,
AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
(uint8_t *)content, content_size);
+#else
+ av_packet_side_data_add(
+ &data->video->codecpar->coded_side_data,
+ &data->video->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_CONTENT_LIGHT_LEVEL, (uint8_t *)content,
+ content_size, 0);
+#endif
AVMasteringDisplayMetadata *const mastering =
av_mastering_display_metadata_alloc();
@@ -186,10 +194,18 @@ static bool create_video_stream(struct ffmpeg_output *stream,
mastering->max_luminance = av_make_q(hdr_nominal_peak_level, 1);
mastering->has_primaries = 1;
mastering->has_luminance = 1;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(data->video,
AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
(uint8_t *)mastering,
sizeof(*mastering));
+#else
+ av_packet_side_data_add(
+ &data->video->codecpar->coded_side_data,
+ &data->video->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+ (uint8_t *)mastering, sizeof(*mastering), 0);
+#endif
}
context = avcodec_alloc_context3(NULL);
context->codec_type = codec->type;
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-output.c b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
index ec02b59cda9d8..c7786153392e5 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-output.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
@@ -213,9 +213,17 @@ static bool create_video_stream(struct ffmpeg_data *data)
av_content_light_metadata_alloc(&content_size);
content->MaxCLL = hdr_nominal_peak_level;
content->MaxFALL = hdr_nominal_peak_level;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(data->video,
AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
(uint8_t *)content, content_size);
+#else
+ av_packet_side_data_add(
+ &data->video->codecpar->coded_side_data,
+ &data->video->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_CONTENT_LIGHT_LEVEL, (uint8_t *)content,
+ content_size, 0);
+#endif
AVMasteringDisplayMetadata *const mastering =
av_mastering_display_metadata_alloc();
@@ -231,10 +239,18 @@ static bool create_video_stream(struct ffmpeg_data *data)
mastering->max_luminance = av_make_q(hdr_nominal_peak_level, 1);
mastering->has_primaries = 1;
mastering->has_luminance = 1;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 31, 102)
av_stream_add_side_data(data->video,
AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
(uint8_t *)mastering,
sizeof(*mastering));
+#else
+ av_packet_side_data_add(
+ &data->video->codecpar->coded_side_data,
+ &data->video->codecpar->nb_coded_side_data,
+ AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+ (uint8_t *)mastering, sizeof(*mastering), 0);
+#endif
}
closest_format = data->config.format;