From f0db8fcc58dd66a7dfd019f99add721d8161b75a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 6 Feb 2022 15:41:27 +0100 Subject: [PATCH] Fix compilation with FFmpeg _before_ version 5.0. --- nageru/kaeru.cpp | 2 +- nageru/video_encoder.cpp | 2 +- shared/ffmpeg_raii.cpp | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nageru/kaeru.cpp b/nageru/kaeru.cpp index ce58aef..9ff672d 100644 --- a/nageru/kaeru.cpp +++ b/nageru/kaeru.cpp @@ -66,7 +66,7 @@ int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType ty unique_ptr create_mux(HTTPD *httpd, const AVOutputFormat *oformat, X264Encoder *x264_encoder, AudioEncoder *audio_encoder) { AVFormatContext *avctx = avformat_alloc_context(); - avctx->oformat = oformat; + avctx->oformat = const_castoformat)>(oformat); // const_cast is a hack to work in FFmpeg both before and after 5.0. uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE); avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, httpd, nullptr, nullptr, nullptr); diff --git a/nageru/video_encoder.cpp b/nageru/video_encoder.cpp index 8138e76..c75c4e3 100644 --- a/nageru/video_encoder.cpp +++ b/nageru/video_encoder.cpp @@ -191,7 +191,7 @@ RefCountedGLsync VideoEncoder::end_frame() void VideoEncoder::open_output_stream() { AVFormatContext *avctx = avformat_alloc_context(); - avctx->oformat = oformat; + avctx->oformat = const_castoformat)>(oformat); // const_cast is a hack to work in FFmpeg both before and after 5.0. uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE); avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, this, nullptr, nullptr, nullptr); diff --git a/shared/ffmpeg_raii.cpp b/shared/ffmpeg_raii.cpp index f2948e9..0e087c2 100644 --- a/shared/ffmpeg_raii.cpp +++ b/shared/ffmpeg_raii.cpp @@ -31,7 +31,11 @@ AVFormatContextWithCloser avformat_open_input_unique( { AVFormatContext *format_ctx = avformat_alloc_context(); format_ctx->interrupt_callback = interrupt_cb; +#ifdef ff_const59 + if (avformat_open_input(&format_ctx, pathname, const_cast(fmt), options) != 0) { +#else if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) { +#endif format_ctx = nullptr; } return AVFormatContextWithCloser(format_ctx); @@ -48,7 +52,11 @@ AVFormatContextWithCloser avformat_open_input_unique( unsigned char *buf = (unsigned char *)av_malloc(buf_size); format_ctx->pb = avio_alloc_context(buf, buf_size, /*write_flag=*/false, opaque, read_packet, /*write_packet=*/nullptr, /*seek=*/nullptr); +#ifdef ff_const59 + if (avformat_open_input(&format_ctx, "", const_cast(fmt), options) != 0) { +#else if (avformat_open_input(&format_ctx, "", fmt, options) != 0) { +#endif format_ctx = nullptr; } return AVFormatContextWithCloser(format_ctx); -- 2.39.2