From a55f598aaf9679b6fce27132221b29d67d4efeaf Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Mon, 4 Apr 2022 03:21:33 +0300
Subject: [PATCH 67/71] Nearly all versioning in ffmpeg.C

---
 cinelerra-5.1/cinelerra/ffmpeg.C | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 4ed25453..5fd9cbe1 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -2105,7 +2105,11 @@ void FFMPEG::scan_audio_options(Asset *asset, EDL *edl)
 		cin_fmt = (int)av_get_sample_fmt(cin_sample_fmt);
 	if( cin_fmt < 0 ) {
 		char audio_codec[BCSTRLEN]; audio_codec[0] = 0;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,18,100)
 		const AVCodec *av_codec = !FFMPEG::get_codec(audio_codec, "audio", asset->acodec) ?
+#else
+		AVCodec *av_codec = !FFMPEG::get_codec(audio_codec, "audio", asset->acodec) ?
+#endif
 			avcodec_find_encoder_by_name(audio_codec) : 0;
 		if( av_codec && av_codec->sample_fmts )
 			cin_fmt = find_best_sample_fmt_of_list(av_codec->sample_fmts, AV_SAMPLE_FMT_FLT);
@@ -2141,7 +2145,11 @@ void FFMPEG::scan_video_options(Asset *asset, EDL *edl)
 			cin_fmt = (int)av_get_pix_fmt(cin_pix_fmt);
 	if( cin_fmt < 0 ) {
 		char video_codec[BCSTRLEN];  video_codec[0] = 0;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,18,100)
 		const AVCodec *av_codec = !get_codec(video_codec, "video", asset->vcodec) ?
+#else
+		AVCodec *av_codec = !get_codec(video_codec, "video", asset->vcodec) ?
+#endif
 			avcodec_find_encoder_by_name(video_codec) : 0;
 		if( av_codec && av_codec->pix_fmts ) {
 			if( 0 && edl ) { // frequently picks a bad answer
@@ -2335,10 +2343,15 @@ int FFCodecRemaps::add(const char *val)
 	return 0;
 }
 
-
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 int FFCodecRemaps::update(AVCodecID &codec_id, const AVCodec *&decoder)
 {
 	const AVCodec *codec = avcodec_find_decoder(codec_id);
+#else
+int FFCodecRemaps::update(AVCodecID &codec_id, AVCodec *&decoder)
+{
+	AVCodec *codec = avcodec_find_decoder(codec_id);
+#endif
 	if( !codec ) return -1;
 	const char *name = codec->name;
 	FFCodecRemaps &map = *this;
@@ -2558,7 +2571,11 @@ int FFMPEG::init_decoder(const char *filename)
 	char *sp = strrchr(bp, '.');
 	if( !sp ) sp = bp + strlen(bp);
 	FILE *fp = 0;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,18,100)
 	const AVInputFormat *ifmt = 0;
+#else
+	AVInputFormat *ifmt = 0;
+#endif
 	if( sp ) {
 		strcpy(sp, ".opts");
 		fp = fopen(file_opts, "r");
@@ -2779,7 +2796,11 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 	AVCodecContext *ctx = 0;
 
 	const AVCodecDescriptor *codec_desc = 0;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	const AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
+#else
+	AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
+#endif
 	if( !codec ) {
 		eprintf(_("cant find codec %s:%s\n"), codec_name, filename);
 		ret = 1;
-- 
2.35.1

