Browse Source

Merge pull request #5501 from RytoEX/fix-ffmpeg-deprecations

Fix FFmpeg deprecations up to FFmpeg 4.4 and current FFmpeg git
Jim 3 years ago
parent
commit
91a9688d9f

+ 4 - 0
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);

+ 13 - 2
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"
@@ -451,10 +452,10 @@ static void create_audio_stream(struct ffmpeg_mux *ffm, int idx)
 	context->extradata_size = ffm->audio_header[idx].size;
 	context->channel_layout =
 		av_get_default_channel_layout(context->channels);
-	//AVlib default channel layout for 4 channels is 4.0 ; fix for quad
+	//avutil default channel layout for 4 channels is 4.0 ; fix for quad
 	if (context->channels == 4)
 		context->channel_layout = av_get_channel_layout("quad");
-	//AVlib default channel layout for 5 channels is 5.0 ; fix for 4.1
+	//avutil default channel layout for 5 channels is 5.0 ; fix for 4.1
 	if (context->channels == 5)
 		context->channel_layout = av_get_channel_layout("4.1");
 	if (ffm->output->oformat->flags & AVFMT_GLOBALHEADER)
@@ -564,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) {
@@ -630,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,
@@ -664,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);

+ 1 - 0
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>
 

+ 2 - 0
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)
 {

+ 1 - 0
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"

+ 19 - 2
plugins/obs-ffmpeg/obs-ffmpeg-output.c

@@ -345,7 +345,7 @@ static bool create_audio_stream(struct ffmpeg_data *data, int idx)
 	context->channel_layout =
 		av_get_default_channel_layout(context->channels);
 
-	//AVlib default channel layout for 5 channels is 5.0 ; fix for 4.1
+	//avutil default channel layout for 5 channels is 5.0 ; fix for 4.1
 	if (aoi.speakers == SPEAKERS_4POINT1)
 		context->channel_layout = av_get_channel_layout("4.1");
 
@@ -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;

+ 1 - 0
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>
 

+ 3 - 1
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)

+ 1 - 1
plugins/win-dshow/ffmpeg-decode.c

@@ -377,7 +377,7 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
 
 	frame->range = range;
 
-	*ts = decode->frame->pkt_pts;
+	*ts = decode->frame->pts;
 
 	frame->width = decode->frame->width;
 	frame->height = decode->frame->height;