[mod_av] Add support for FFmpeg 8 (#3250)

This commit is contained in:
Andrey Volk authored and GitHub committed 2026-10-28 18:27:37 +03:00
1 parent ad4b9dcb9b
commit 9fdd2cdfaf
3 files changed
+36 -14

No files matched your search

+12 -5
View File
@@ -42,6 +42,13 @@
#include <libavutil/opt.h> #include <libavutil/opt.h>
#include <libavutil/imgutils.h> #include <libavutil/imgutils.h>
/* AV_PROFILE_* replaced FF_PROFILE_* in FFmpeg 6.1, FFmpeg 8 removed the latter */
#ifndef AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE FF_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_MAIN FF_PROFILE_H264_MAIN
#define AV_PROFILE_H264_HIGH FF_PROFILE_H264_HIGH
#endif
int SLICE_SIZE = (SWITCH_DEFAULT_VIDEO_SIZE + 100); int SLICE_SIZE = (SWITCH_DEFAULT_VIDEO_SIZE + 100);
#define H264_NALU_BUFFER_SIZE 65536 #define H264_NALU_BUFFER_SIZE 65536
@@ -530,7 +537,7 @@ static void init_profile(avcodec_profile_t *aprofile, const char *name)
aprofile->decoder_thread_count = avcodec_globals.dec_threads; aprofile->decoder_thread_count = avcodec_globals.dec_threads;
if (!strcasecmp(name, "H264")) { if (!strcasecmp(name, "H264")) {
aprofile->ctx.profile = FF_PROFILE_H264_BASELINE; aprofile->ctx.profile = AV_PROFILE_H264_BASELINE;
aprofile->ctx.level = 31; aprofile->ctx.level = 31;
#ifdef AV_CODEC_FLAG_PSNR #ifdef AV_CODEC_FLAG_PSNR
aprofile->ctx.flags |= AV_CODEC_FLAG_PSNR; aprofile->ctx.flags |= AV_CODEC_FLAG_PSNR;
@@ -2071,7 +2078,7 @@ static void parse_profile(avcodec_profile_t *aprofile, switch_xml_t profile)
ctx = &aprofile->ctx; ctx = &aprofile->ctx;
ctx->profile = FF_PROFILE_H264_BASELINE; ctx->profile = AV_PROFILE_H264_BASELINE;
ctx->level = 31; ctx->level = 31;
for (param = switch_xml_child(profile, "param"); param; param = param->next) { for (param = switch_xml_child(profile, "param"); param; param = param->next) {
@@ -2094,11 +2101,11 @@ static void parse_profile(avcodec_profile_t *aprofile, switch_xml_t profile)
if (ctx->profile == 0 && !strcasecmp(aprofile->name, "H264")) { if (ctx->profile == 0 && !strcasecmp(aprofile->name, "H264")) {
if (!strcasecmp(value, "baseline")) { if (!strcasecmp(value, "baseline")) {
ctx->profile = FF_PROFILE_H264_BASELINE; ctx->profile = AV_PROFILE_H264_BASELINE;
} else if (!strcasecmp(value, "main")) { } else if (!strcasecmp(value, "main")) {
ctx->profile = FF_PROFILE_H264_MAIN; ctx->profile = AV_PROFILE_H264_MAIN;
} else if (!strcasecmp(value, "high")) { } else if (!strcasecmp(value, "high")) {
ctx->profile = FF_PROFILE_H264_HIGH; ctx->profile = AV_PROFILE_H264_HIGH;
} }
} }
} else if (!strcmp(name, "level")) { } else if (!strcmp(name, "level")) {
+23 -9
View File
@@ -281,6 +281,24 @@ GCC_DIAG_ON(deprecated-declarations)
#endif #endif
} }
static inline int av_get_ticks_per_frame(AVCodecContext *c)
{
#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_8_V)
int ticks;
GCC_DIAG_OFF(deprecated-declarations)
ticks = c->ticks_per_frame;
GCC_DIAG_ON(deprecated-declarations)
return ticks;
#else
/* FFmpeg 8 removed ticks_per_frame, which decoders of field based codecs set to 2 */
const AVCodecDescriptor *desc = avcodec_descriptor_get(c->codec_id);
return (desc && (desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1;
#endif
}
static char *const get_error_text(const int error, char *error_buffer, switch_size_t error_buflen) static char *const get_error_text(const int error, char *error_buffer, switch_size_t error_buflen)
{ {
av_strerror(error, error_buffer, error_buflen); av_strerror(error, error_buffer, error_buflen);
@@ -637,12 +655,14 @@ static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst,
c->rc_initial_buffer_occupancy = buffer_bytes * 8; c->rc_initial_buffer_occupancy = buffer_bytes * 8;
if (codec_id == AV_CODEC_ID_H264) { if (codec_id == AV_CODEC_ID_H264) {
#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_8_V) /* FFmpeg 8 removed ticks_per_frame */
#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) #if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
GCC_DIAG_OFF(deprecated-declarations) GCC_DIAG_OFF(deprecated-declarations)
#endif #endif
c->ticks_per_frame = 2; c->ticks_per_frame = 2;
#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) #if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
GCC_DIAG_ON(deprecated-declarations) GCC_DIAG_ON(deprecated-declarations)
#endif
#endif #endif
c->flags|=AV_CODEC_FLAG_LOOP_FILTER; // flags=+loop c->flags|=AV_CODEC_FLAG_LOOP_FILTER; // flags=+loop
@@ -1431,7 +1451,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
switch_goto_status(SWITCH_STATUS_FALSE, err); switch_goto_status(SWITCH_STATUS_FALSE, err);
} }
#if (LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) #if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_7_V)
handle->seekable = !(context->fc->iformat->flags & AVFMT_NOTIMESTAMPS); handle->seekable = !(context->fc->iformat->flags & AVFMT_NOTIMESTAMPS);
#else #else
handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0); handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0);
@@ -3240,21 +3260,15 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
if ((c = av_get_codec_context(mst)) && c->time_base.num) { if ((c = av_get_codec_context(mst)) && c->time_base.num) {
cp = av_stream_get_parser(st); cp = av_stream_get_parser(st);
#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) ticks = cp ? cp->repeat_pict + 1 : av_get_ticks_per_frame(c);
GCC_DIAG_OFF(deprecated-declarations)
#endif
ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame;
// mst->next_pts += ((int64_t)AV_TIME_BASE * st->codec->time_base.num * ticks) / st->codec->time_base.den; // mst->next_pts += ((int64_t)AV_TIME_BASE * st->codec->time_base.num * ticks) / st->codec->time_base.den;
} }
if (!context->video_start_time) { if (!context->video_start_time) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "start: %" SWITCH_INT64_T_FMT " ticks: %d ticks_per_frame: %d st num:%d st den:%d codec num:%d codec den:%d start: %" SWITCH_TIME_T_FMT ", duration:%" SWITCH_INT64_T_FMT " nb_frames:%" SWITCH_INT64_T_FMT " q2d:%f\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "start: %" SWITCH_INT64_T_FMT " ticks: %d ticks_per_frame: %d st num:%d st den:%d codec num:%d codec den:%d start: %" SWITCH_TIME_T_FMT ", duration:%" SWITCH_INT64_T_FMT " nb_frames:%" SWITCH_INT64_T_FMT " q2d:%f\n",
context->video_start_time, ticks, c ? c->ticks_per_frame : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1, context->video_start_time, ticks, c ? av_get_ticks_per_frame(c) : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1,
st->start_time, st->duration == AV_NOPTS_VALUE ? context->fc->duration / AV_TIME_BASE * 1000 : st->duration, st->nb_frames, av_q2d(st->time_base)); st->start_time, st->duration == AV_NOPTS_VALUE ? context->fc->duration / AV_TIME_BASE * 1000 : st->duration, st->nb_frames, av_q2d(st->time_base));
} }
#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V)
GCC_DIAG_ON(deprecated-declarations)
#endif
again: again:
+1
View File
@@ -43,6 +43,7 @@
#define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */ #define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */
#define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */ #define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */
#define LIBAVCODEC_7_V 61 /* FFmpeg version >= 7.0 */ #define LIBAVCODEC_7_V 61 /* FFmpeg version >= 7.0 */
#define LIBAVCODEC_8_V 62 /* FFmpeg version >= 8.0 */
#define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */ #define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */
#define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */ #define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */
#define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */ #define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */