Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
FFmpeg: adapt to ffmpeg7 for dumping. (#248)
Browse files Browse the repository at this point in the history
* FFmpeg: update layout api for ffmpeg 6.x and ffmpeg 7.

After ffmpeg 5.1, it is deprecated, and has been completely removed in ffmpeg 7.

Our current project is using 6.0 headers, modifying it will not have any side effects.

Since lavu 57.24.100(ffmpeg 5.1)

* FFmpeg: dynamic_library and dumping adapt to ffmpeg7.1.

But keeping support for older versions.

* externals/library-headers: update ffmpeg to 7.1
  • Loading branch information
kongfl888 authored Oct 12, 2024
1 parent 7d00f47 commit cdce026
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion externals/library-headers
Submodule library-headers updated 83 files
+2 −2 README.md
+485 −549 ffmpeg/include/libavcodec/avcodec.h
+31 −0 ffmpeg/include/libavcodec/avfft.h
+16 −9 ffmpeg/include/libavcodec/codec.h
+7 −1 ffmpeg/include/libavcodec/codec_desc.h
+11 −3 ffmpeg/include/libavcodec/codec_id.h
+29 −28 ffmpeg/include/libavcodec/codec_par.h
+0 −3 ffmpeg/include/libavcodec/d3d11va.h
+145 −0 ffmpeg/include/libavcodec/defs.h
+5 −1 ffmpeg/include/libavcodec/dirac.h
+0 −3 ffmpeg/include/libavcodec/dxva2.h
+21 −0 ffmpeg/include/libavcodec/jni.h
+171 −15 ffmpeg/include/libavcodec/packet.h
+19 −5 ffmpeg/include/libavcodec/vdpau.h
+1 −1 ffmpeg/include/libavcodec/version.h
+11 −11 ffmpeg/include/libavcodec/version_major.h
+0 −65 ffmpeg/include/libavcodec/videotoolbox.h
+0 −171 ffmpeg/include/libavcodec/xvmc.h
+1 −1 ffmpeg/include/libavdevice/version.h
+8 −1 ffmpeg/include/libavdevice/version_major.h
+93 −205 ffmpeg/include/libavfilter/avfilter.h
+4 −4 ffmpeg/include/libavfilter/buffersink.h
+4 −7 ffmpeg/include/libavfilter/buffersrc.h
+1 −1 ffmpeg/include/libavfilter/version.h
+3 −1 ffmpeg/include/libavfilter/version_major.h
+526 −245 ffmpeg/include/libavformat/avformat.h
+4 −10 ffmpeg/include/libavformat/avio.h
+1 −1 ffmpeg/include/libavformat/version.h
+7 −5 ffmpeg/include/libavformat/version_major.h
+5 −4 ffmpeg/include/libavutil/audio_fifo.h
+3 −0 ffmpeg/include/libavutil/avassert.h
+1 −2 ffmpeg/include/libavutil/avstring.h
+5 −14 ffmpeg/include/libavutil/avutil.h
+9 −6 ffmpeg/include/libavutil/bprint.h
+1 −7 ffmpeg/include/libavutil/bswap.h
+126 −158 ffmpeg/include/libavutil/channel_layout.h
+34 −23 ffmpeg/include/libavutil/common.h
+11 −0 ffmpeg/include/libavutil/cpu.h
+160 −0 ffmpeg/include/libavutil/dovi_meta.h
+1 −0 ffmpeg/include/libavutil/error.h
+1 −1 ffmpeg/include/libavutil/eval.h
+67 −0 ffmpeg/include/libavutil/executor.h
+1 −1 ffmpeg/include/libavutil/ffversion.h
+2 −208 ffmpeg/include/libavutil/fifo.h
+0 −18 ffmpeg/include/libavutil/file.h
+65 −3 ffmpeg/include/libavutil/film_grain_params.h
+282 −71 ffmpeg/include/libavutil/frame.h
+33 −0 ffmpeg/include/libavutil/hdr_dynamic_metadata.h
+62 −1 ffmpeg/include/libavutil/hdr_dynamic_vivid_metadata.h
+7 −19 ffmpeg/include/libavutil/hwcontext.h
+5 −0 ffmpeg/include/libavutil/hwcontext_cuda.h
+142 −0 ffmpeg/include/libavutil/hwcontext_d3d12va.h
+25 −2 ffmpeg/include/libavutil/hwcontext_qsv.h
+14 −4 ffmpeg/include/libavutil/hwcontext_videotoolbox.h
+136 −35 ffmpeg/include/libavutil/hwcontext_vulkan.h
+690 −0 ffmpeg/include/libavutil/iamf.h
+51 −5 ffmpeg/include/libavutil/imgutils.h
+43 −10 ffmpeg/include/libavutil/intreadwrite.h
+9 −0 ffmpeg/include/libavutil/mastering_display_metadata.h
+55 −0 ffmpeg/include/libavutil/mathematics.h
+1 −3 ffmpeg/include/libavutil/mem.h
+568 −272 ffmpeg/include/libavutil/opt.h
+5 −0 ffmpeg/include/libavutil/pixdesc.h
+30 −5 ffmpeg/include/libavutil/pixfmt.h
+14 −0 ffmpeg/include/libavutil/random_seed.h
+4 −0 ffmpeg/include/libavutil/rational.h
+2 −2 ffmpeg/include/libavutil/samplefmt.h
+16 −0 ffmpeg/include/libavutil/spherical.h
+96 −0 ffmpeg/include/libavutil/stereo3d.h
+7 −7 ffmpeg/include/libavutil/timecode.h
+12 −5 ffmpeg/include/libavutil/timestamp.h
+34 −0 ffmpeg/include/libavutil/tx.h
+12 −10 ffmpeg/include/libavutil/version.h
+2 −2 ffmpeg/include/libavutil/video_enc_params.h
+107 −0 ffmpeg/include/libavutil/video_hint.h
+1 −1 ffmpeg/include/libpostproc/version.h
+1 −1 ffmpeg/include/libpostproc/version_major.h
+4 −67 ffmpeg/include/libswresample/swresample.h
+1 −1 ffmpeg/include/libswresample/version.h
+1 −1 ffmpeg/include/libswresample/version_major.h
+26 −2 ffmpeg/include/libswscale/swscale.h
+1 −1 ffmpeg/include/libswscale/version.h
+1 −1 ffmpeg/include/libswscale/version_major.h
4 changes: 2 additions & 2 deletions src/citra_qt/dumping/option_set_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static const std::unordered_map<AVOptionType, const char*> TypeNameMap{{
{AV_OPT_TYPE_STRING, QT_TR_NOOP("string")},
{AV_OPT_TYPE_DICT, QT_TR_NOOP("dictionary")},
{AV_OPT_TYPE_VIDEO_RATE, QT_TR_NOOP("video rate")},
{AV_OPT_TYPE_CHANNEL_LAYOUT, QT_TR_NOOP("channel layout")},
{AV_OPT_TYPE_CHLAYOUT, QT_TR_NOOP("channel layout")},
}};

static const std::unordered_map<AVOptionType, const char*> TypeDescriptionMap{{
Expand All @@ -39,7 +39,7 @@ static const std::unordered_map<AVOptionType, const char*> TypeDescriptionMap{{
{AV_OPT_TYPE_DICT,
QT_TR_NOOP("Comma-splitted list of &lt;key>=&lt;value>. Do not put spaces.")},
{AV_OPT_TYPE_VIDEO_RATE, QT_TR_NOOP("&lt;num>/&lt;den>, or preset values like 'pal'.")},
{AV_OPT_TYPE_CHANNEL_LAYOUT, QT_TR_NOOP("Hexadecimal channel layout mask starting with '0x'.")},
{AV_OPT_TYPE_CHLAYOUT, QT_TR_NOOP("Hexadecimal channel layout mask starting with '0x'.")},
}};

/// Get the preset values of an option. returns {display value, real value}
Expand Down
6 changes: 6 additions & 0 deletions src/common/dynamic_library/ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ avcodec_find_encoder_by_name_func avcodec_find_encoder_by_name;
avcodec_free_context_func avcodec_free_context;
avcodec_get_class_func avcodec_get_class;
avcodec_get_hw_config_func avcodec_get_hw_config;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
avcodec_get_supported_config_func avcodec_get_supported_config;
#endif
avcodec_open2_func avcodec_open2;
avcodec_parameters_from_context_func avcodec_parameters_from_context;
avcodec_receive_frame_func avcodec_receive_frame;
Expand Down Expand Up @@ -232,6 +235,9 @@ static bool LoadAVCodec() {
LOAD_SYMBOL(avcodec, avcodec_free_context);
LOAD_SYMBOL(avcodec, avcodec_get_class);
LOAD_SYMBOL(avcodec, avcodec_get_hw_config);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
LOAD_SYMBOL(avcodec, avcodec_get_supported_config);
#endif
LOAD_SYMBOL(avcodec, avcodec_open2);
LOAD_SYMBOL(avcodec, avcodec_parameters_from_context);
LOAD_SYMBOL(avcodec, avcodec_receive_frame);
Expand Down
7 changes: 7 additions & 0 deletions src/common/dynamic_library/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ typedef const AVCodec* (*avcodec_find_encoder_by_name_func)(const char*);
typedef void (*avcodec_free_context_func)(AVCodecContext**);
typedef const AVClass* (*avcodec_get_class_func)();
typedef const AVCodecHWConfig* (*avcodec_get_hw_config_func)(const AVCodec*, int);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
typedef int (*avcodec_get_supported_config_func)(const AVCodecContext*, const AVCodec*,
enum AVCodecConfig, unsigned, const void**, int*);
#endif
typedef int (*avcodec_open2_func)(AVCodecContext*, const AVCodec*, AVDictionary**);
typedef int (*avcodec_parameters_from_context_func)(AVCodecParameters* par, const AVCodecContext*);
typedef int (*avcodec_receive_frame_func)(AVCodecContext*, AVFrame*);
Expand All @@ -138,6 +142,9 @@ extern avcodec_find_encoder_by_name_func avcodec_find_encoder_by_name;
extern avcodec_free_context_func avcodec_free_context;
extern avcodec_get_class_func avcodec_get_class;
extern avcodec_get_hw_config_func avcodec_get_hw_config;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
extern avcodec_get_supported_config_func avcodec_get_supported_config;
#endif
extern avcodec_open2_func avcodec_open2;
extern avcodec_parameters_from_context_func avcodec_parameters_from_context;
extern avcodec_receive_frame_func avcodec_receive_frame;
Expand Down
60 changes: 48 additions & 12 deletions src/core/dumping/ffmpeg_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,21 @@ bool FFmpegVideoStream::Init(FFmpegMuxer& muxer, const Layout::FramebufferLayout
codec_context->gop_size = 12;

// Get pixel format for codec
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
const enum AVPixelFormat* pix_fmts = NULL;
int ret = FFmpeg::avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_PIX_FORMAT, 0,
(const void**)&pix_fmts, NULL);
#else
const enum AVPixelFormat* pix_fmts = codec->pix_fmts;
int ret = 0;
#endif

auto options = ToAVDictionary(Settings::values.video_encoder_options);
auto pixel_format_opt = FFmpeg::av_dict_get(options, "pixel_format", nullptr, 0);
if (pixel_format_opt) {
sw_pixel_format = FFmpeg::av_get_pix_fmt(pixel_format_opt->value);
} else if (codec->pix_fmts) {
sw_pixel_format = GetPixelFormat(codec_context.get(), codec->pix_fmts);
} else if (ret >= 0 && pix_fmts) {
sw_pixel_format = GetPixelFormat(codec_context.get(), pix_fmts);
} else {
sw_pixel_format = AV_PIX_FMT_YUV420P;
}
Expand Down Expand Up @@ -285,11 +294,20 @@ void FFmpegVideoStream::ProcessFrame(VideoFrame& frame) {
}

bool FFmpegVideoStream::InitHWContext(const AVCodec* codec) {
for (std::size_t i = 0; codec->pix_fmts[i] != AV_PIX_FMT_NONE; ++i) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
const enum AVPixelFormat* pix_fmts = NULL;
int ret = FFmpeg::avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_PIX_FORMAT, 0,
(const void**)&pix_fmts, NULL);
#else
const enum AVPixelFormat* pix_fmts = codec->pix_fmts;
int ret = 0;
#endif

for (std::size_t i = 0; (ret >= 0 && pix_fmts) && (pix_fmts[i] != AV_PIX_FMT_NONE); ++i) {
const AVCodecHWConfig* config;
for (int j = 0;; ++j) {
config = FFmpeg::avcodec_get_hw_config(codec, j);
if (!config || config->pix_fmt == codec->pix_fmts[i]) {
if (!config || config->pix_fmt == pix_fmts[i]) {
break;
}
}
Expand All @@ -303,7 +321,7 @@ bool FFmpegVideoStream::InitHWContext(const AVCodec* codec) {
continue;
}

codec_context->pix_fmt = codec->pix_fmts[i];
codec_context->pix_fmt = pix_fmts[i];

// Create HW device context
AVBufferRef* hw_device_context;
Expand Down Expand Up @@ -351,7 +369,7 @@ bool FFmpegVideoStream::InitHWContext(const AVCodec* codec) {

AVHWFramesContext* hw_frames_context =
reinterpret_cast<AVHWFramesContext*>(hw_frames_context_ref->data);
hw_frames_context->format = codec->pix_fmts[i];
hw_frames_context->format = pix_fmts[i];
hw_frames_context->sw_format = sw_pixel_format;
hw_frames_context->width = codec_context->width;
hw_frames_context->height = codec_context->height;
Expand Down Expand Up @@ -455,6 +473,7 @@ bool FFmpegAudioStream::Init(FFmpegMuxer& muxer) {
}

frame_count = 0;
int ret;

// Initialize audio codec
const AVCodec* codec =
Expand All @@ -468,16 +487,33 @@ bool FFmpegAudioStream::Init(FFmpegMuxer& muxer) {
// Configure audio codec context
codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
codec_context->bit_rate = Settings::values.audio_bitrate;
if (codec->sample_fmts) {
codec_context->sample_fmt = codec->sample_fmts[0];

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
const enum AVSampleFormat* sample_fmts = NULL;
ret = FFmpeg::avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
(const void**)&sample_fmts, NULL);
#else
const enum AVSampleFormat* sample_fmts = codec->sample_fmts;
ret = 0;
#endif
if (ret >= 0 && sample_fmts) {
codec_context->sample_fmt = sample_fmts[0];
} else {
codec_context->sample_fmt = AV_SAMPLE_FMT_S16P;
}

if (codec->supported_samplerates) {
codec_context->sample_rate = codec->supported_samplerates[0];
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // lavc 61.13.100
const int* supported_samplerates = NULL;
ret = FFmpeg::avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0,
(const void**)&supported_samplerates, NULL);
#else
const int* supported_samplerates = codec->supported_samplerates;
ret = 0;
#endif
if (ret >= 0 && supported_samplerates) {
codec_context->sample_rate = supported_samplerates[0];
// Prefer native sample rate if supported
const int* ptr = codec->supported_samplerates;
const int* ptr = supported_samplerates;
while ((*ptr)) {
if ((*ptr) == AudioCore::native_sample_rate) {
codec_context->sample_rate = AudioCore::native_sample_rate;
Expand Down Expand Up @@ -956,7 +992,7 @@ std::string FormatDefaultValue(const AVOption* option,
case AV_OPT_TYPE_VIDEO_RATE: {
return ToStdString(option->default_val.str);
}
case AV_OPT_TYPE_CHANNEL_LAYOUT: {
case AV_OPT_TYPE_CHLAYOUT: {
return fmt::format("{:#x}", option->default_val.i64);
}
default:
Expand Down

0 comments on commit cdce026

Please sign in to comment.