Skip to content

Display and control your Android device

Drop support for FFmpeg < 6.0

Romain Vimont10d093ac5247
diff --git a/app/meson.build b/app/meson.build
index 8816426f..41d541ad 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -123,9 +123,9 @@ cc = meson.get_compiler('c')
static = get_option('static')
dependencies = [
- dependency('libavformat', version: '>= 57.33', static: static),
- dependency('libavcodec', version: '>= 57.37', static: static),
- dependency('libavutil', static: static),
+ dependency('libavformat', version: '>= 60.3', static: static),
+ dependency('libavcodec', version: '>= 60.3', static: static),
+ dependency('libavutil', version: '>= 58.2', static: static),
dependency('libswresample', static: static),
dependency('sdl3', version: '>= 3.2.0', static: static),
]
diff --git a/app/src/audio_player.c b/app/src/audio_player.c
index f17c6d71..75d49ec5 100644
--- a/app/src/audio_player.c
+++ b/app/src/audio_player.c
@@ -54,14 +54,8 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink,
struct sc_audio_player *ap = DOWNCAST(sink);
-#ifdef SCRCPY_LAVU_HAS_CHLAYOUT
assert(ctx->ch_layout.nb_channels > 0 && ctx->ch_layout.nb_channels < 256);
uint8_t nb_channels = ctx->ch_layout.nb_channels;
-#else
- int tmp = av_get_channel_layout_nb_channels(ctx->channel_layout);
- assert(tmp > 0 && tmp < 256);
- uint8_t nb_channels = tmp;
-#endif
assert(ctx->sample_rate > 0);
assert(!av_sample_fmt_is_planar(SC_AV_SAMPLE_FMT));
diff --git a/app/src/audio_regulator.c b/app/src/audio_regulator.c
index 556553c7..f2b1966c 100644
--- a/app/src/audio_regulator.c
+++ b/app/src/audio_regulator.c
@@ -373,15 +373,8 @@ sc_audio_regulator_init(struct sc_audio_regulator *ar, size_t sample_size,
}
ar->swr_ctx = swr_ctx;
-#ifdef SCRCPY_LAVU_HAS_CHLAYOUT
av_opt_set_chlayout(swr_ctx, "in_chlayout", &ctx->ch_layout, 0);
av_opt_set_chlayout(swr_ctx, "out_chlayout", &ctx->ch_layout, 0);
-#else
- av_opt_set_channel_layout(swr_ctx, "in_channel_layout",
- ctx->channel_layout, 0);
- av_opt_set_channel_layout(swr_ctx, "out_channel_layout",
- ctx->channel_layout, 0);
-#endif
av_opt_set_int(swr_ctx, "in_sample_rate", ctx->sample_rate, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", ctx->sample_rate, 0);
diff --git a/app/src/compat.h b/app/src/compat.h
index a7ba289b..59db6087 100644
--- a/app/src/compat.h
+++ b/app/src/compat.h
@@ -16,42 +16,6 @@
# define SC_PRIsizet "Iu"
#endif
-// In ffmpeg/doc/APIchanges:
-// 2018-02-06 - 0694d87024 - lavf 58.9.100 - avformat.h
-// Deprecate use of av_register_input_format(), av_register_output_format(),
-// av_register_all(), av_iformat_next(), av_oformat_next().
-// Add av_demuxer_iterate(), and av_muxer_iterate().
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
-# define SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
-#else
-# define SCRCPY_LAVF_REQUIRES_REGISTER_ALL
-#endif
-
-// Not documented in ffmpeg/doc/APIchanges, but AV_CODEC_ID_AV1 has been added
-// by FFmpeg commit d42809f9835a4e9e5c7c63210abb09ad0ef19cfb (included in tag
-// n3.3).
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 89, 100)
-# define SCRCPY_LAVC_HAS_AV1
-#endif
-
-// In ffmpeg/doc/APIchanges:
-// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h
-// Deprecate AVFormatContext filename field which had limited length, use the
-// new dynamically allocated url field instead.
-//
-// 2018-01-28 - ea3672b7d6 - lavf 58.7.100 - avformat.h
-// Add url field to AVFormatContext and add ff_format_set_url helper function.
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 7, 100)
-# define SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
-#endif
-
-// Not documented in ffmpeg/doc/APIchanges, but the channel_layout API
-// has been replaced by chlayout in FFmpeg commit
-// f423497b455da06c1337846902c770028760e094.
-#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 23, 100)
-# define SCRCPY_LAVU_HAS_CHLAYOUT
-#endif
-
// In ffmpeg/doc/APIchanges:
// 2023-10-06 - 5432d2aacad - lavc 60.15.100 - avformat.h
// Deprecate AVFormatContext.{nb_,}side_data, av_stream_add_side_data(),
diff --git a/app/src/demuxer.c b/app/src/demuxer.c
index c0d27146..7e946de7 100644
--- a/app/src/demuxer.c
+++ b/app/src/demuxer.c
@@ -33,12 +33,7 @@ sc_demuxer_to_avcodec_id(uint32_t codec_id) {
case SC_CODEC_ID_H265:
return AV_CODEC_ID_HEVC;
case SC_CODEC_ID_AV1:
-#ifdef SCRCPY_LAVC_HAS_AV1
return AV_CODEC_ID_AV1;
-#else
- LOGE("AV1 not supported by this FFmpeg version");
- return AV_CODEC_ID_NONE;
-#endif
case SC_CODEC_ID_VP8:
return AV_CODEC_ID_VP8;
case SC_CODEC_ID_VP9:
@@ -257,12 +252,7 @@ run_demuxer(void *data) {
} else {
// Hardcoded audio properties
-#ifdef SCRCPY_LAVU_HAS_CHLAYOUT
params->ch_layout = (AVChannelLayout) AV_CHANNEL_LAYOUT_STEREO;
-#else
- params->channel_layout = AV_CH_LAYOUT_STEREO;
- params->channels = 2;
-#endif
params->sample_rate = 48000;
if (raw_codec_id == SC_CODEC_ID_FLAC) {
diff --git a/app/src/icon.c b/app/src/icon.c
index 880ea596..aef23e15 100644
--- a/app/src/icon.c
+++ b/app/src/icon.c
@@ -76,17 +76,7 @@ decode_image(const char *path) {
goto close_input;
}
-
-// In ffmpeg/doc/APIchanges:
-// 2021-04-27 - 46dac8cf3d - lavf 59.0.100 - avformat.h
-// av_find_best_stream now uses a const AVCodec ** parameter
-// for the returned decoder.
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 0, 100)
const AVCodec *codec;
-#else
- AVCodec *codec;
-#endif
-
int stream =
av_find_best_stream(ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &codec, 0);
if (stream < 0 ) {
diff --git a/app/src/main.c b/app/src/main.c
index 47117423..89d78299 100644
--- a/app/src/main.c
+++ b/app/src/main.c
@@ -76,10 +76,6 @@ main_scrcpy(int argc, char *argv[]) {
goto end;
}
-#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
- av_register_all();
-#endif
-
#ifdef HAVE_V4L2
if (args.opts.v4l2_device) {
avdevice_register_all();
diff --git a/app/src/recorder.c b/app/src/recorder.c
index 3d7925de..d1a34b89 100644
--- a/app/src/recorder.c
+++ b/app/src/recorder.c
@@ -22,16 +22,10 @@ static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
static const AVOutputFormat *
find_muxer(const char *name) {
-#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
void *opaque = NULL;
-#endif
const AVOutputFormat *oformat = NULL;
do {
-#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
oformat = av_muxer_iterate(&opaque);
-#else
- oformat = av_oformat_next(oformat);
-#endif
// until null or containing the requested name
} while (oformat && !sc_str_list_contains(oformat->name, ',', name));
return oformat;
@@ -160,11 +154,7 @@ sc_recorder_open_output_file(struct sc_recorder *recorder) {
return false;
}
- // contrary to the deprecated API (av_oformat_next()), av_muxer_iterate()
- // returns (on purpose) a pointer-to-const, but AVFormatContext.oformat
- // still expects a pointer-to-non-const (it has not be updated accordingly)
- // <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
- recorder->ctx->oformat = (AVOutputFormat *) format;
+ recorder->ctx->oformat = format;
av_dict_set(&recorder->ctx->metadata, "comment",
"Recorded by scrcpy " SCRCPY_VERSION, 0);
diff --git a/app/src/v4l2_sink.c b/app/src/v4l2_sink.c
index 3dfd4dd6..d4a0e510 100644
--- a/app/src/v4l2_sink.c
+++ b/app/src/v4l2_sink.c
@@ -17,16 +17,10 @@ static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
static const AVOutputFormat *
find_muxer(const char *name) {
-#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
void *opaque = NULL;
-#endif
const AVOutputFormat *oformat = NULL;
do {
-#ifdef SCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
oformat = av_muxer_iterate(&opaque);
-#else
- oformat = av_oformat_next(oformat);
-#endif
// until null or containing the requested name
} while (oformat && !sc_str_list_contains(oformat->name, ',', name));
return oformat;
@@ -189,25 +183,12 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs, const AVCodecContext *ctx,
return false;
}
- // contrary to the deprecated API (av_oformat_next()), av_muxer_iterate()
- // returns (on purpose) a pointer-to-const, but AVFormatContext.oformat
- // still expects a pointer-to-non-const (it has not be updated accordingly)
- // <https://github.com/FFmpeg/FFmpeg/commit/0694d8702421e7aff1340038559c438b61bb30dd>
- vs->format_ctx->oformat = (AVOutputFormat *) format;
-#ifdef SCRCPY_LAVF_HAS_AVFORMATCONTEXT_URL
+ vs->format_ctx->oformat = format;
vs->format_ctx->url = strdup(vs->device_name);
if (!vs->format_ctx->url) {
LOG_OOM();
goto error_avformat_free_context;
}
-#else
- size_t n = sc_strncpy(vs->format_ctx->filename, vs->device_name,
- sizeof(vs->format_ctx->filename));
- if (n == sizeof(vs->format_ctx->filename)) {
- LOGE("Device name too long: %s", vs->device_name);
- goto error_avformat_free_context;
- }
-#endif
AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder);
if (!ostream) {