mirror of https://github.com/mgba-emu/mgba.git
FFmpeg: Support FFmpeg 5.0
This commit is contained in:
parent
667dffe515
commit
cdc7535167
|
@ -5,6 +5,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "ffmpeg-decoder.h"
|
#include "ffmpeg-decoder.h"
|
||||||
|
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
#include <libswscale/swscale.h>
|
#include <libswscale/swscale.h>
|
||||||
|
|
||||||
void FFmpegDecoderInit(struct FFmpegDecoder* decoder) {
|
void FFmpegDecoderInit(struct FFmpegDecoder* decoder) {
|
||||||
|
@ -38,7 +39,7 @@ bool FFmpegDecoderOpen(struct FFmpegDecoder* decoder, const char* infile) {
|
||||||
#else
|
#else
|
||||||
enum AVMediaType type = decoder->context->streams[i]->codec->codec_type;
|
enum AVMediaType type = decoder->context->streams[i]->codec->codec_type;
|
||||||
#endif
|
#endif
|
||||||
struct AVCodec* codec;
|
const struct AVCodec* codec;
|
||||||
struct AVCodecContext* context = NULL;
|
struct AVCodecContext* context = NULL;
|
||||||
if (type == AVMEDIA_TYPE_VIDEO && decoder->videoStream < 0) {
|
if (type == AVMEDIA_TYPE_VIDEO && decoder->videoStream < 0) {
|
||||||
decoder->video = avcodec_alloc_context3(NULL);
|
decoder->video = avcodec_alloc_context3(NULL);
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
#include <libavcodec/version.h>
|
#include <libavcodec/version.h>
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
|
#if LIBAVCODEC_VERSION_MAJOR >= 58
|
||||||
|
#include <libavcodec/bsf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <libavfilter/buffersink.h>
|
#include <libavfilter/buffersink.h>
|
||||||
#include <libavfilter/buffersrc.h>
|
#include <libavfilter/buffersrc.h>
|
||||||
|
@ -121,7 +124,7 @@ bool FFmpegEncoderSetAudio(struct FFmpegEncoder* encoder, const char* acodec, un
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodec* codec = avcodec_find_encoder_by_name(acodec);
|
const AVCodec* codec = avcodec_find_encoder_by_name(acodec);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +196,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodec* codec = avcodec_find_encoder_by_name(vcodec);
|
const AVCodec* codec = avcodec_find_encoder_by_name(vcodec);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +216,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
|
||||||
if (encoder->pixFormat == AV_PIX_FMT_NONE) {
|
if (encoder->pixFormat == AV_PIX_FMT_NONE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (vbr < 0 && !av_opt_find(&codec->priv_class, "crf", NULL, 0, 0)) {
|
if (vbr < 0 && !av_opt_find((void*) &codec->priv_class, "crf", NULL, 0, 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
encoder->videoCodec = vcodec;
|
encoder->videoCodec = vcodec;
|
||||||
|
@ -223,7 +226,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFmpegEncoderSetContainer(struct FFmpegEncoder* encoder, const char* container) {
|
bool FFmpegEncoderSetContainer(struct FFmpegEncoder* encoder, const char* container) {
|
||||||
AVOutputFormat* oformat = av_guess_format(container, 0, 0);
|
const AVOutputFormat* oformat = av_guess_format(container, 0, 0);
|
||||||
if (!oformat) {
|
if (!oformat) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -241,9 +244,9 @@ void FFmpegEncoderSetLooping(struct FFmpegEncoder* encoder, bool loop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) {
|
bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) {
|
||||||
AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
|
const AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
|
||||||
AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
|
const AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
|
||||||
AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
|
const AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
|
||||||
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !oformat || (!acodec && !vcodec)) {
|
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !oformat || (!acodec && !vcodec)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -257,8 +260,8 @@ bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
|
bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
|
||||||
AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
|
const AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
|
||||||
AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
|
const AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
|
||||||
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !FFmpegEncoderVerifyContainer(encoder)) {
|
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !FFmpegEncoderVerifyContainer(encoder)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -272,9 +275,9 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
|
||||||
encoder->currentVideoFrame = 0;
|
encoder->currentVideoFrame = 0;
|
||||||
encoder->skipResidue = 0;
|
encoder->skipResidue = 0;
|
||||||
|
|
||||||
AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
|
const AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
|
||||||
#ifndef USE_LIBAV
|
#ifndef USE_LIBAV
|
||||||
avformat_alloc_output_context2(&encoder->context, oformat, 0, outfile);
|
avformat_alloc_output_context2(&encoder->context, (AVOutputFormat*) oformat, 0, outfile);
|
||||||
#else
|
#else
|
||||||
encoder->context = avformat_alloc_context();
|
encoder->context = avformat_alloc_context();
|
||||||
strncpy(encoder->context->filename, outfile, sizeof(encoder->context->filename) - 1);
|
strncpy(encoder->context->filename, outfile, sizeof(encoder->context->filename) - 1);
|
||||||
|
|
Loading…
Reference in New Issue