Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg: Support FFmpeg 5.0 #2434

Merged
merged 1 commit into from Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/feature/ffmpeg/ffmpeg-decoder.c
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ffmpeg-decoder.h"

#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>

void FFmpegDecoderInit(struct FFmpegDecoder* decoder) {
Expand Down Expand Up @@ -38,7 +39,7 @@ bool FFmpegDecoderOpen(struct FFmpegDecoder* decoder, const char* infile) {
#else
enum AVMediaType type = decoder->context->streams[i]->codec->codec_type;
#endif
struct AVCodec* codec;
const struct AVCodec* codec;
struct AVCodecContext* context = NULL;
if (type == AVMEDIA_TYPE_VIDEO && decoder->videoStream < 0) {
decoder->video = avcodec_alloc_context3(NULL);
Expand Down
25 changes: 14 additions & 11 deletions src/feature/ffmpeg/ffmpeg-encoder.c
Expand Up @@ -12,6 +12,9 @@

#include <libavcodec/version.h>
#include <libavcodec/avcodec.h>
#if LIBAVCODEC_VERSION_MAJOR >= 58
#include <libavcodec/bsf.h>
endrift marked this conversation as resolved.
Show resolved Hide resolved
#endif

#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
Expand Down Expand Up @@ -121,7 +124,7 @@ bool FFmpegEncoderSetAudio(struct FFmpegEncoder* encoder, const char* acodec, un
return true;
}

AVCodec* codec = avcodec_find_encoder_by_name(acodec);
const AVCodec* codec = avcodec_find_encoder_by_name(acodec);
if (!codec) {
return false;
}
Expand Down Expand Up @@ -193,7 +196,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
return true;
}

AVCodec* codec = avcodec_find_encoder_by_name(vcodec);
const AVCodec* codec = avcodec_find_encoder_by_name(vcodec);
if (!codec) {
return false;
}
Expand All @@ -213,7 +216,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
if (encoder->pixFormat == AV_PIX_FMT_NONE) {
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;
}
encoder->videoCodec = vcodec;
Expand All @@ -223,7 +226,7 @@ bool FFmpegEncoderSetVideo(struct FFmpegEncoder* encoder, const char* vcodec, in
}

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) {
return false;
}
Expand All @@ -241,9 +244,9 @@ void FFmpegEncoderSetLooping(struct FFmpegEncoder* encoder, bool loop) {
}

bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) {
AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
const AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0);
const AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
const AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !oformat || (!acodec && !vcodec)) {
return false;
}
Expand All @@ -257,8 +260,8 @@ bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) {
}

bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
const AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec);
const AVCodec* vcodec = avcodec_find_encoder_by_name(encoder->videoCodec);
if ((encoder->audioCodec && !acodec) || (encoder->videoCodec && !vcodec) || !FFmpegEncoderVerifyContainer(encoder)) {
return false;
}
Expand All @@ -272,9 +275,9 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
encoder->currentVideoFrame = 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
avformat_alloc_output_context2(&encoder->context, oformat, 0, outfile);
avformat_alloc_output_context2(&encoder->context, (AVOutputFormat*) oformat, 0, outfile);
#else
encoder->context = avformat_alloc_context();
strncpy(encoder->context->filename, outfile, sizeof(encoder->context->filename) - 1);
Expand Down