summaryrefslogtreecommitdiff
path: root/media-video/obs-studio/files/obs-studio-27.1.3-ffmpeg-5.0.patch
blob: a529dca715a90a644402c60b870923c080d46b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# https://git.exherbo.org/media.git/commit/?id=10c891cb37f4f7e42e95a00b27a5d4636266353e
# https://git.exherbo.org/media.git/commit/?id=e888c31724357431dbd0e73014ca87a552850d45

From 08547a1696fa381d0bda18aed57b9f87a6b1b334 Mon Sep 17 00:00:00 2001
From: Ryan Foster <RytoEX@gmail.com>
Date: Sat, 6 Nov 2021 18:57:35 -0400
Subject: [PATCH] obs-ffmpeg: Include avcodec header for AVCodecContext

FFmpeg commit e67e02d15672 [1] drops avcodec.h from avformat.h includes.
Therefore we need to include it explicitly.

[1]: https://github.com/FFmpeg/FFmpeg/commit/e67e02d15672a87da1b0566e197a1e19dc7e1e33
     lavf/avformat.h: drop the avcodec.h include
---
 plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 1 +
 plugins/obs-ffmpeg/obs-ffmpeg-formats.h    | 2 ++
 plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c      | 1 +
 plugins/obs-ffmpeg/obs-ffmpeg-output.h     | 1 +
 4 files changed, 5 insertions(+)

diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
index 1c160ced4b1f..e4c6cdb9fa2f 100644
--- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
+++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
@@ -27,6 +27,7 @@
 #include "ffmpeg-mux.h"
 
 #include <util/dstr.h>
+#include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 
 #define ANSI_COLOR_RED "\x1b[0;91m"
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-formats.h b/plugins/obs-ffmpeg/obs-ffmpeg-formats.h
index 62e3866d037a..b40ef37293b4 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-formats.h
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-formats.h
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <libavcodec/avcodec.h>
+
 static inline int64_t rescale_ts(int64_t val, AVCodecContext *context,
 				 AVRational new_base)
 {
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
index f2d93d2def89..e66010ce5f9c 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c
@@ -24,6 +24,7 @@
 
 #include <libavutil/opt.h>
 #include <libavutil/pixdesc.h>
+#include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 
 #include "obs-ffmpeg-formats.h"
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-output.h b/plugins/obs-ffmpeg/obs-ffmpeg-output.h
index 99f4dcd13b44..72d89dfacc4c 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-output.h
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-output.h
@@ -2,6 +2,7 @@
 
 #include <libavutil/opt.h>
 #include <libavutil/pixdesc.h>
+#include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 #include <libswscale/swscale.h>
 
From abf1d609d29196921df8f09ab6e07340b7cf9660 Mon Sep 17 00:00:00 2001
From: Ryan Foster <RytoEX@gmail.com>
Date: Sat, 6 Nov 2021 18:58:05 -0400
Subject: [PATCH] obs-ffmpeg: Include channel_layout.h

avcodec.h stopped including channel_layout.h per FFmpeg commit
1be3d8a0cb77 [1]. avformat.h stopped including avcodec.h per FFmpeg
commit e67e02d15672 [2]. As a result, we need to explicitly include
avutil/channel_layout.h when needed. Fixes compilation error against
FFmpeg later than the two mentioned commits.

[1]: https://github.com/FFmpeg/FFmpeg/commit/1be3d8a0cb77f8d34c1f39b47bf5328fe10c82d7
[2]: https://github.com/FFmpeg/FFmpeg/commit/e67e02d15672a87da1b0566e197a1e19dc7e1e33
---
 plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c b/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c
index 2e3899464362..cbcb9ac31bcb 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-audio-encoders.c
@@ -21,6 +21,7 @@
 #include <util/dstr.h>
 #include <obs-module.h>
 
+#include <libavutil/channel_layout.h>
 #include <libavutil/opt.h>
 #include <libavformat/avformat.h>

From ce734366bc0b95ff91930f463e7ebe528cf8eabf Mon Sep 17 00:00:00 2001
From: Ryan Foster <RytoEX@gmail.com>
Date: Sat, 6 Nov 2021 18:58:36 -0400
Subject: [PATCH] obs-ffmpeg: Respect AVFormatContext and AVOutputFormat
 constness

AVFormatContext::oformat was made const on April 27, 2021 [1]. If we
respect the constness of AVOutputFormat and do not cast results from
FFmpeg functions to non-const, we cannot modify the results after the
fact. Our choices are either to cast them to non-const (and presumably
have them implicitly casted back to const on later function calls), or
only try to modify the results in versions of FFmpeg where these are not
expected to be const.

Instead of relying on casts, we can set the encoder values in the
ffmpeg_cfg struct, which are later passed to new_stream.

Also modifies deps/media-playback. Removes compiler warnings.
Some avformat functions return const AV(In/Out)putFormat per [1], so
ifdef as needed.

[1]: https://github.com/FFmpeg/FFmpeg/commit/56450a0ee4fdda160f4039fc2ae33edfd27765c9
     lavf 59.0.100 avformat.h
     avformat: Constify the API wrt AV(In|Out)putFormat

     Also constify AVProbeData.
---
 deps/media-playback/media-playback/media.c |  4 ++++
 plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 10 ++++++++++
 plugins/obs-ffmpeg/obs-ffmpeg-output.c     | 19 ++++++++++++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/deps/media-playback/media-playback/media.c b/deps/media-playback/media-playback/media.c
index 9041b62e9cdd..a09b58ed5d10 100644
--- a/deps/media-playback/media-playback/media.c
+++ b/deps/media-playback/media-playback/media.c
@@ -608,7 +608,11 @@ static int interrupt_callback(void *data)
 
 static bool init_avformat(mp_media_t *m)
 {
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 	AVInputFormat *format = NULL;
+#else
+	const AVInputFormat *format = NULL;
+#endif
 
 	if (m->format_name && *m->format_name) {
 		format = av_find_input_format(m->format_name);
diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
index e4c6cdb9fa2f..ffce3ee33eec 100644
--- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
+++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
@@ -565,7 +565,11 @@ static inline bool ffmpeg_mux_get_extra_data(struct ffmpeg_mux *ffm)
 
 static inline int open_output_file(struct ffmpeg_mux *ffm)
 {
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 	AVOutputFormat *format = ffm->output->oformat;
+#else
+	const AVOutputFormat *format = ffm->output->oformat;
+#endif
 	int ret;
 
 	if ((format->flags & AVFMT_NOFILE) == 0) {
@@ -631,7 +635,11 @@ static bool ffmpeg_mux_is_network(struct ffmpeg_mux *ffm)
 
 static int ffmpeg_mux_init_context(struct ffmpeg_mux *ffm)
 {
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 	AVOutputFormat *output_format;
+#else
+	const AVOutputFormat *output_format;
+#endif
 	int ret;
 	bool is_http = false;
 	is_http = (strncmp(ffm->params.file, HTTP_PROTO,
@@ -665,8 +673,10 @@ static int ffmpeg_mux_init_context(struct ffmpeg_mux *ffm)
 		return FFM_ERROR;
 	}
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 	ffm->output->oformat->video_codec = AV_CODEC_ID_NONE;
 	ffm->output->oformat->audio_codec = AV_CODEC_ID_NONE;
+#endif
 
 	if (!init_streams(ffm)) {
 		free_avformat(ffm);
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-output.c b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
index 6bc1637b1796..7447e952b9c2 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-output.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
@@ -543,6 +543,7 @@ static enum AVCodecID get_codec_id(const char *name, int id)
 	return codec->id;
 }
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 static void set_encoder_ids(struct ffmpeg_data *data)
 {
 	data->output->oformat->video_codec = get_codec_id(
@@ -551,6 +552,7 @@ static void set_encoder_ids(struct ffmpeg_data *data)
 	data->output->oformat->audio_codec = get_codec_id(
 		data->config.audio_encoder, data->config.audio_encoder_id);
 }
+#endif
 
 bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
 {
@@ -570,7 +572,13 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
 
 	is_rtmp = (astrcmpi_n(config->url, "rtmp://", 7) == 0);
 
-	AVOutputFormat *output_format = av_guess_format(
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
+	AVOutputFormat *output_format;
+#else
+	const AVOutputFormat *output_format;
+#endif
+
+	output_format = av_guess_format(
 		is_rtmp ? "flv" : data->config.format_name, data->config.url,
 		is_rtmp ? NULL : data->config.format_mime_type);
 
@@ -596,6 +604,7 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
 		goto fail;
 	}
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
 	if (is_rtmp) {
 		data->output->oformat->video_codec = AV_CODEC_ID_H264;
 		data->output->oformat->audio_codec = AV_CODEC_ID_AAC;
@@ -603,6 +612,14 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
 		if (data->config.format_name)
 			set_encoder_ids(data);
 	}
+#else
+	if (is_rtmp) {
+		data->config.audio_encoder = "aac";
+		data->config.audio_encoder_id = AV_CODEC_ID_AAC;
+		data->config.video_encoder = "libx264";
+		data->config.video_encoder_id = AV_CODEC_ID_H264;
+	}
+#endif
 
 	if (!init_streams(data))
 		goto fail;

From d78971b4db34d5fffbd11d2acabf37a65e11cd58 Mon Sep 17 00:00:00 2001
From: pkv <pkv@obsproject.com>
Date: Fri, 17 Dec 2021 20:52:11 +0100
Subject: [PATCH] obs-ffmpeg: Further FFmpeg deprecations fixes for FFmpeg 4.4+

avcodec.h stopped including channel_layout.h per FFmpeg commit
1be3d8a0cb77 [1]. Fixes compilation error on macOS against
FFmpeg later than the mentioned commit.
[1] https://github.com/FFmpeg/FFmpeg/commit/1be3d8a0cb77f8d34c1f39b47bf5328fe10c82d7
---
 plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 1 +
 plugins/obs-ffmpeg/obs-ffmpeg-output.c     | 1 +
 2 files changed, 2 insertions(+)

diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
index c07e22abe266..db26cb425ce5 100644
--- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
+++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
@@ -29,6 +29,7 @@
 #include <util/dstr.h>
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
+#include <libavutil/channel_layout.h>
 
 #define ANSI_COLOR_RED "\x1b[0;91m"
 #define ANSI_COLOR_MAGENTA "\x1b[0;95m"
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-output.c b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
index d3637ebbb59b..7d1f12a60393 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-output.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-output.c
@@ -25,6 +25,7 @@
 #include "obs-ffmpeg-output.h"
 #include "obs-ffmpeg-formats.h"
 #include "obs-ffmpeg-compat.h"
+#include <libavutil/channel_layout.h>
 
 struct ffmpeg_output {
 	obs_output_t *output;
	
From c398ac9739a82bc95632eef9544dd0fb5bc5f0cf Mon Sep 17 00:00:00 2001
From: pkv <pkv@obsproject.com>
Date: Sat, 6 Nov 2021 18:59:37 -0400
Subject: [PATCH] obs-ffmpeg: Fix NVENC old codec naming removed in FFmpeg

Per FFmpeg commit 337f777f378c [1], FFmpeg removed nvenc_h264_encoder
and nvenc_hevc_encoder after deprecation in FFmpeg commit 888a5c794778
[2]. The names to be used are ff_h264_nvenc_encoder and
ff_hevc_nvenc_encoder. So we must allow alternative search of codec as
h264_nvenc or nvenc_h264 in obs-ffmpeg.c.

[1]: https://github.com/FFmpeg/FFmpeg/commit/337f777f378cfcc0d6f0d01fb7125905e8b0da55
[2]: https://github.com/FFmpeg/FFmpeg/commit/888a5c794778a2f2aad22e9b4a3952dff92b11fa
---
 plugins/obs-ffmpeg/obs-ffmpeg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
index 7330b2273544..399c5bfa64b6 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
@@ -180,7 +180,9 @@ static bool nvenc_supported(void)
 	bool success = false;
 
 	if (!nvenc) {
-		goto cleanup;
+		nvenc = avcodec_find_encoder_by_name("h264_nvenc");
+		if (!nvenc)
+			goto cleanup;
 	}
 
 #if defined(_WIN32)