From 2c2d5b30976501548f623433d206a9ab80bae735 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Mon, 4 Apr 2022 02:07:50 +0300
Subject: [PATCH 56/66] Beginning of ffmpeg versioned compilation

---
 cinelerra-5.1/cinelerra/ffmpeg.C | 17 +++++++++++++++--
 cinelerra-5.1/cinelerra/ffmpeg.h |  4 +++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 294343fb..ec776578 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -722,11 +722,15 @@ int FFStream::seek(int64_t no, double rate)
 	double secs = pos < 0 ? 0. : pos / rate;
 	AVRational time_base = st->time_base;
 	int64_t tstmp = time_base.num > 0 ? secs * time_base.den/time_base.num : 0;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	int nb_index_entries = avformat_index_get_entries_count(st);
+#endif
 	if( !tstmp ) {
 		if( nb_index_entries > 0 ) tstmp = (avformat_index_get_entry(st, 0))->timestamp;
 		else if( st->start_time != AV_NOPTS_VALUE ) tstmp = st->start_time;
-		/* else if( st->first_dts != AV_NOPTS_VALUE ) tstmp = st->first_dts; */
+#if LIBAVCODEC_VERSION_INT  <= AV_VERSION_INT(58,134,100)
+		else if( st->first_dts != AV_NOPTS_VALUE ) tstmp = st->first_dts;
+#endif
 		else tstmp = INT64_MIN+1;
 	}
 	else if( nudge != AV_NOPTS_VALUE ) tstmp += nudge;
@@ -4095,11 +4099,20 @@ void FFStream::load_markers(IndexMarks &marks, double rate)
 	int in = 0;
 	int64_t sz = marks.size();
 	int max_entries = fmt_ctx->max_index_size / sizeof(AVIndexEntry) - 1;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	int nb_ent = avformat_index_get_entries_count(st);
+#endif
+#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
+	int nb_ent = st->nb_index_entries;
+#endif
 // some formats already have an index
 	if( nb_ent > 0 ) {
-		// AVIndexEntry *ep = &st->index_entries[nb_ent-1];
+#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
+		AVIndexEntry *ep = &st->index_entries[nb_ent-1];
+#endif
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 		const AVIndexEntry *ep = avformat_index_get_entry(st, nb_ent-1);
+#endif
 		int64_t tstmp = ep->timestamp;
 		if( nudge != AV_NOPTS_VALUE ) tstmp -= nudge;
 		double secs = ffmpeg->to_secs(tstmp, st->time_base);
diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h
index 6c7d68e0..d2b4ac7f 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.h
+++ b/cinelerra-5.1/cinelerra/ffmpeg.h
@@ -25,10 +25,12 @@
 #include "vframe.inc"
 
 extern "C" {
-#include "libavcodec/bsf.h"
 #include "libavformat/avformat.h"
 #include "libavformat/avio.h"
 #include "libavcodec/avcodec.h"
+#if LIBAVCODEC_VERSION_INT  >= AV_VERSION_INT(59,18,100)
+#include "libavcodec/bsf.h"
+#endif
 #include "libavfilter/avfilter.h"
 #include "libavutil/avutil.h"
 #include "libavfilter/buffersrc.h"
-- 
2.35.1

