hopefully this patch series should bring dynamic compilation with system's
ffmpeg/libav* back into working order, as well  fix compilation with
system's openEXR 3. --with-git-ffmpeg should also work as long as you
manually delete old thirdparty/src/ffmpeg.git* patches = no BluRay encoding
out of the box but I hopefully have patches for this too)

sorry for mixing in freebsd/termux changes, but whole need for this patch
series arise from my desire to compile for those platforms

I'll send whole pile of patches as separate email
On Thursday, April 7, 2022, Andrew Randrianasulu <[email protected]>
wrote:

>
>
> On Thursday, April 7, 2022, Andrea paz via Cin <[email protected]>
> wrote:
>
>> @Andrew
>> I used "git am --whitespace-ignore ..."
>> the patches 003, 007 and 0009 give error and I skipped them, the
>> compilation was successful and I found no error messages. I don't know
>> what to test though: am I using ffmpeg 4.4 or 5, with these patches?
>> How do I check it?
>
>
>
> I tried to make ./configure --without-thirdparty works, so in this case
> you will be using system-wide installation of libv* libs. I heard Arch keep
> both  ffmpeg4 and ffmpeg5 (wisely) for now, so you might look at that libs
> you have installed and use 'ldd' to see actual ones Cingg linked to.
>
> Default still internal ffmpeg 4.4/static linking with intent to NOT
> breaking  this case, so fact it woks as usual in itself quite good news.
> You probably will notice bunch of new errors from new  ffmpeg filters
> (added in 5.0) at first startup when you successfully compile against
> system's ffmpeg 5.0.
>
>
>
>> @Phyllis
>> I have added read support for DPX. I'm wondering, how do you make
>> render presets for the internal engine?
>>
>
From b9c66c16bce5d56e7077bf8f15a70f09787ee93b Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Thu, 7 Apr 2022 21:32:17 +0300
Subject: [PATCH 64/66] ffmpeg.git conditional fixes

---
 cinelerra-5.1/cinelerra/fileac3.h       | 4 ++++
 cinelerra-5.1/cinelerra/pluginfclient.C | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/fileac3.h b/cinelerra-5.1/cinelerra/fileac3.h
index 8ae62c76..9355f312 100644
--- a/cinelerra-5.1/cinelerra/fileac3.h
+++ b/cinelerra-5.1/cinelerra/fileac3.h
@@ -60,7 +60,11 @@ public:
 
 private:
 	AVPacket avpkt;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
+	const AVCodec *codec;
+#else
 	AVCodec *codec;
+#endif
 	AVCodecContext *codec_context;
 	SwrContext *resample_context;
 
diff --git a/cinelerra-5.1/cinelerra/pluginfclient.C b/cinelerra-5.1/cinelerra/pluginfclient.C
index f4d9ba3a..32c3f4aa 100644
--- a/cinelerra-5.1/cinelerra/pluginfclient.C
+++ b/cinelerra-5.1/cinelerra/pluginfclient.C
@@ -913,14 +913,22 @@ int PluginFAClient::get_inchannels()
 {
 	AVFilterContext *fctx = ffilt->fctx;
 	AVFilterLink **links = !fctx->nb_inputs ? 0 : fctx->inputs;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,24,100)
+	return !links ? 0 : links[0]->ch_layout.nb_channels;
+#else
 	return !links ? 0 : links[0]->channels;
+#endif
 }
 
 int PluginFAClient::get_outchannels()
 {
 	AVFilterContext *fctx = ffilt->fctx;
 	AVFilterLink **links = !fctx->nb_outputs ? 0 : fctx->outputs;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,24,100)
+	return !links ? 0 : links[0]->ch_layout.nb_channels;
+#else
 	return !links ? 0 : links[0]->channels;
+#endif
 }
 
 int PluginFAClient::process_buffer(int64_t size, Samples **buffer, int64_t start_position, int sample_rate)
-- 
2.35.1

From 3145fe90bbc6570176e026093d27769a63d4ff8b Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Thu, 7 Apr 2022 21:33:40 +0300
Subject: [PATCH 65/66] Limit git clone depth to 1 (faster download, less
 space)

---
 cinelerra-5.1/thirdparty/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cinelerra-5.1/thirdparty/Makefile b/cinelerra-5.1/thirdparty/Makefile
index 85310cc4..504acb4a 100644
--- a/cinelerra-5.1/thirdparty/Makefile
+++ b/cinelerra-5.1/thirdparty/Makefile
@@ -47,7 +47,7 @@ pkg-built=$(BLD)/$(1).built
 ext=$(lastword $(subst ., ,$(1)))
 tarball=$(if $($(1).git),$(1).git,$(lastword $(sort $(wildcard src/$(1)*.tar.*))))
 unpack=$(call unpack_$(call ext,$(1)),$(1))
-unpack_git=git clone $($(1)) $(1)
+unpack_git=git clone --depth 1 $($(1)) $(1)
 unpack_gz=tar -xzf $(1)
 unpack_bz2=tar -xjf $(1)
 unpack_xz=tar -xJf $(1)
-- 
2.35.1

From 2c2d5b30976501548f623433d206a9ab80bae735 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
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

From 893ab286ec5a71d13e46fe5cf9553e2195b22572 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 02:33:54 +0300
Subject: [PATCH 58/66] More libavcodec versionkng in ffmpeg

---
 cinelerra-5.1/cinelerra/ffmpeg.C |  4 ++++
 cinelerra-5.1/cinelerra/ffmpeg.h | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index ec776578..d4f63ebf 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -3907,7 +3907,11 @@ AVCodecContext *FFMPEG::activate_decoder(AVStream *st)
 	AVDictionary *copts = 0;
 	av_dict_copy(&copts, opts, 0);
 	AVCodecID codec_id = st->codecpar->codec_id;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	const AVCodec *decoder = 0;
+#else
+	AVCodec *decoder = 0;
+#endif
 	switch( st->codecpar->codec_type ) {
 	case AVMEDIA_TYPE_VIDEO:
 		if( opt_video_decoder )
diff --git a/cinelerra-5.1/cinelerra/ffmpeg.h b/cinelerra-5.1/cinelerra/ffmpeg.h
index d2b4ac7f..1b46160a 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.h
+++ b/cinelerra-5.1/cinelerra/ffmpeg.h
@@ -89,7 +89,11 @@ public:
 	virtual int encode_activate();
 	virtual int decode_activate();
 	virtual AVHWDeviceType decode_hw_activate();
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	virtual int decode_hw_format(const AVCodec *decoder, AVHWDeviceType type);
+#else
+	virtual int decode_hw_format(AVCodec *decoder, AVHWDeviceType type);
+#endif
 	virtual int write_packet(FFPacket &pkt);
 	int read_packet();
 	int seek(int64_t no, double rate);
@@ -293,7 +297,11 @@ class FFCodecRemaps : public ArrayList<FFCodecRemap>
 public:
 	FFCodecRemaps() {}
 	int add(const char *val);
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	int update(AVCodecID &codec_id, const AVCodec *&decoder);
+#else
+	int update(AVCodecID &codec_id, AVCodec *&decoder);
+#endif
 };
 
 // for get_initial_timecode auto deletes
@@ -334,7 +342,11 @@ public:
 	static void ff_lock(const char *cp=0) { fflock.lock(cp); }
 	static void ff_unlock() { fflock.unlock(); }
 
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	int check_sample_rate(const AVCodec *codec, int sample_rate);
+#else
+	int check_sample_rate(AVCodec *codec, int sample_rate);
+#endif
 	AVRational check_frame_rate(const AVRational *p, double frame_rate);
 	AVRational to_sample_aspect_ratio(Asset *asset);
 	AVRational to_time_base(int sample_rate);
-- 
2.35.1

From 4a75de07f5949042bc6e80645281d3053635ef29 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 02:17:41 +0300
Subject: [PATCH 57/66] Ffmpeg versioning in bdwrite.C

---
 cinelerra-5.1/cinelerra/bdwrite.C | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
index 57966ead..178b5dcf 100644
--- a/cinelerra-5.1/cinelerra/bdwrite.C
+++ b/cinelerra-5.1/cinelerra/bdwrite.C
@@ -2530,7 +2530,12 @@ static int field_probe(AVFormatContext *fmt_ctx, AVStream *st)
   AVDictionary *copts = 0;
   //av_dict_copy(&copts, opts, 0);
   AVCodecID codec_id = st->codecpar->codec_id;
+#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
+  AVCodec *decoder = avcodec_find_decoder(codec_id);
+#endif
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
   const AVCodec *decoder = avcodec_find_decoder(codec_id);
+#endif
   AVCodecContext *ctx = avcodec_alloc_context3(decoder);
   if( !ctx ) {
     fprintf(stderr,"codec alloc failed\n");
@@ -2604,7 +2609,13 @@ int media_info::scan()
     stream *s = new stream(type, i);
     s->pid = st->id;
     AVCodecID codec_id = st->codecpar->codec_id;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
     const AVCodec *decoder = avcodec_find_decoder(codec_id);
+#endif
+#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
+    AVCodec *decoder = avcodec_find_decoder(codec_id);
+#endif
+
     s->ctx = avcodec_alloc_context3(decoder);
     if( !s->ctx ) {
       fprintf(stderr, "avcodec_alloc_context failed\n");
-- 
2.35.1

From 112c605164979e5302836b2d920f0bfbe2159183 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 02:48:04 +0300
Subject: [PATCH 59/66] Even more ffmpeg versioning in ffmpeg.C

---
 cinelerra-5.1/cinelerra/ffmpeg.C | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index d4f63ebf..4ed25453 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -3032,12 +3032,11 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 		}
 		if( ret >= 0 ) {
 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
-			//ret = avcodec_copy_context(st->codec, ctx);
-			//AVCodecContext *codec_ctx = avcodec_alloc_context3(ctx);
+#if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(58,134,100)
+			ret = avcodec_copy_context(st->codec, ctx);
+#else
 			ret = avcodec_parameters_to_context(ctx, st->codecpar);
-			// if (ret < 0)
-			//	fprintf(stderr, "could not copy codecpar to tmp codec_ctx\n");
-			//ret = avcodec_parameters_from_context(codec_ctx, 
+#endif
 _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
 			if( ret < 0 )
 				fprintf(stderr, "Could not copy the stream context\n");
@@ -3682,7 +3681,11 @@ Preferences *FFMPEG::ff_prefs()
 
 double FFVideoStream::get_rotation_angle()
 {
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 	size_t size = 0;
+#else
+	int size = 0;
+#endif
 	int *matrix = (int*)av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, &size);
 	int len = size/sizeof(*matrix);
 	if( !matrix || len < 5 ) return 0;
-- 
2.35.1

From f6f87c2c26f8c8ef67d39d456cbadbb5f80f15ba Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 03:21:33 +0300
Subject: [PATCH 60/66] 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

From 01a5d96cce0c6e296da3e01c0ba4850afb00bc55 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 03:33:36 +0300
Subject: [PATCH 61/66] Finished versioning in ffmpeg.C

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

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 5fd9cbe1..ff03e85e 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -380,8 +380,11 @@ AVHWDeviceType FFStream::decode_hw_activate()
 {
 	return AV_HWDEVICE_TYPE_NONE;
 }
-
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 int FFStream::decode_hw_format(const AVCodec *decoder, AVHWDeviceType type)
+#else
+int FFStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type)
+#endif
 {
 	return 0;
 }
@@ -406,7 +409,11 @@ int FFStream::decode_activate()
 		}
 		while( ret >= 0 && st != 0 && !reading ) {
 			AVCodecID codec_id = st->codecpar->codec_id;
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 			const AVCodec *decoder = 0;
+#else
+			AVCodec *decoder = 0;
+#endif
 			if( is_video() ) {
 				if( ffmpeg->opt_video_decoder )
 					decoder = avcodec_find_decoder_by_name(ffmpeg->opt_video_decoder);
@@ -1855,7 +1862,11 @@ FFMPEG::~FFMPEG()
 	delete [] opt_hw_dev;
 }
 
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 int FFMPEG::check_sample_rate(const AVCodec *codec, int sample_rate)
+#else
+int FFMPEG::check_sample_rate(AVCodec *codec, int sample_rate)
+#endif
 {
 	const int *p = codec->supported_samplerates;
 	if( !p ) return sample_rate;
-- 
2.35.1

From 3b85bb94f00219550702ab50696b4b8a45e0b729 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 4 Apr 2022 04:36:39 +0300
Subject: [PATCH 62/66] Really fix ffmpeg.C for ffmpeg 4.4

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

diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index ff03e85e..14c1171c 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -733,7 +733,11 @@ int FFStream::seek(int64_t no, double rate)
 	int nb_index_entries = avformat_index_get_entries_count(st);
 #endif
 	if( !tstmp ) {
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,16,100)
 		if( nb_index_entries > 0 ) tstmp = (avformat_index_get_entry(st, 0))->timestamp;
+#else
+		if( st->nb_index_entries > 0 ) tstmp = st->index_entries[0].timestamp;
+#endif
 		else if( st->start_time != AV_NOPTS_VALUE ) tstmp = st->start_time;
 #if LIBAVCODEC_VERSION_INT  <= AV_VERSION_INT(58,134,100)
 		else if( st->first_dts != AV_NOPTS_VALUE ) tstmp = st->first_dts;
-- 
2.35.1

From 6f0e1e8ad6ce5aa04c4fde8714dd20345b40bc14 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 2 Apr 2022 23:52:45 +0300
Subject: [PATCH 48/66] Hopefully fixed dynamic liba52

---
 cinelerra-5.1/configure.ac       | 2 +-
 cinelerra-5.1/libzmpeg3/Makefile | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/cinelerra-5.1/configure.ac b/cinelerra-5.1/configure.ac
index 10ca2129..ccdae6bb 100644
--- a/cinelerra-5.1/configure.ac
+++ b/cinelerra-5.1/configure.ac
@@ -628,7 +628,7 @@ CHECK_HEADERS([dav1d], [libdav1d headers], [dav1d/dav1d.h])
 CHECK_LIB([libwebp], [webp], [WebPGetEncoderVersion])
 CHECK_HEADERS([libwebp], [libwebp headers], [webp/encode.h])
 CHECK_LIB([a52dec], [a52], [a52_init])
-CHECK_HEADERS([a52dec], [a52 headers], [stdint.h a52.h])
+CHECK_HEADERS([a52dec], [a52 headers], [stdint.h a52dec/a52.h])
 CHECK_LIB([encore], [encore], [encore])
 CHECK_HEADERS([encore], [encore headers], [encore.h])
 CHECK_LIB([giflib], [gif], [DGifOpen])
diff --git a/cinelerra-5.1/libzmpeg3/Makefile b/cinelerra-5.1/libzmpeg3/Makefile
index 47a0596f..1e59d36f 100644
--- a/cinelerra-5.1/libzmpeg3/Makefile
+++ b/cinelerra-5.1/libzmpeg3/Makefile
@@ -79,6 +79,9 @@ UTILS += $(OBJDIR)/zmpeg3ifochk
 UTILS += $(OBJDIR)/zmpeg3cc2txt
 
 LIBS = -lm -lpthread
+ifeq ($(WITH_THIRDPARTY),no)
+LIBS += -la52
+endif
 
 LIBS += $(lib_a52dec) $(lib_djbfft) $(lib_libbthread)
 
-- 
2.35.1

From 03cb3feaedc3bd23b786cf2dd99ae624e22dee8d Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 2 Apr 2022 16:29:57 +0300
Subject: [PATCH 46/66] Make cin compile with ffmpeg 5 (unconditionally)

---
 cinelerra-5.1/cinelerra/bdwrite.C |  4 ++--
 cinelerra-5.1/cinelerra/ffmpeg.C  | 39 ++++++++++++++++++-------------
 cinelerra-5.1/cinelerra/ffmpeg.h  |  7 +++---
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
index 4dd5cc37..57966ead 100644
--- a/cinelerra-5.1/cinelerra/bdwrite.C
+++ b/cinelerra-5.1/cinelerra/bdwrite.C
@@ -2530,7 +2530,7 @@ static int field_probe(AVFormatContext *fmt_ctx, AVStream *st)
   AVDictionary *copts = 0;
   //av_dict_copy(&copts, opts, 0);
   AVCodecID codec_id = st->codecpar->codec_id;
-  AVCodec *decoder = avcodec_find_decoder(codec_id);
+  const AVCodec *decoder = avcodec_find_decoder(codec_id);
   AVCodecContext *ctx = avcodec_alloc_context3(decoder);
   if( !ctx ) {
     fprintf(stderr,"codec alloc failed\n");
@@ -2604,7 +2604,7 @@ int media_info::scan()
     stream *s = new stream(type, i);
     s->pid = st->id;
     AVCodecID codec_id = st->codecpar->codec_id;
-    AVCodec *decoder = avcodec_find_decoder(codec_id);
+    const AVCodec *decoder = avcodec_find_decoder(codec_id);
     s->ctx = avcodec_alloc_context3(decoder);
     if( !s->ctx ) {
       fprintf(stderr, "avcodec_alloc_context failed\n");
diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 3655d643..294343fb 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -381,7 +381,7 @@ AVHWDeviceType FFStream::decode_hw_activate()
 	return AV_HWDEVICE_TYPE_NONE;
 }
 
-int FFStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type)
+int FFStream::decode_hw_format(const AVCodec *decoder, AVHWDeviceType type)
 {
 	return 0;
 }
@@ -406,7 +406,7 @@ int FFStream::decode_activate()
 		}
 		while( ret >= 0 && st != 0 && !reading ) {
 			AVCodecID codec_id = st->codecpar->codec_id;
-			AVCodec *decoder = 0;
+			const AVCodec *decoder = 0;
 			if( is_video() ) {
 				if( ffmpeg->opt_video_decoder )
 					decoder = avcodec_find_decoder_by_name(ffmpeg->opt_video_decoder);
@@ -722,10 +722,11 @@ 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;
+	int nb_index_entries = avformat_index_get_entries_count(st);
 	if( !tstmp ) {
-		if( st->nb_index_entries > 0 ) tstmp = st->index_entries[0].timestamp;
+		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;
+		/* else if( st->first_dts != AV_NOPTS_VALUE ) tstmp = st->first_dts; */
 		else tstmp = INT64_MIN+1;
 	}
 	else if( nudge != AV_NOPTS_VALUE ) tstmp += nudge;
@@ -1850,7 +1851,7 @@ FFMPEG::~FFMPEG()
 	delete [] opt_hw_dev;
 }
 
-int FFMPEG::check_sample_rate(AVCodec *codec, int sample_rate)
+int FFMPEG::check_sample_rate(const AVCodec *codec, int sample_rate)
 {
 	const int *p = codec->supported_samplerates;
 	if( !p ) return sample_rate;
@@ -2100,7 +2101,7 @@ 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;
-		AVCodec *av_codec = !FFMPEG::get_codec(audio_codec, "audio", asset->acodec) ?
+		const AVCodec *av_codec = !FFMPEG::get_codec(audio_codec, "audio", asset->acodec) ?
 			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);
@@ -2136,7 +2137,7 @@ 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;
-		AVCodec *av_codec = !get_codec(video_codec, "video", asset->vcodec) ?
+		const AVCodec *av_codec = !get_codec(video_codec, "video", asset->vcodec) ?
 			avcodec_find_encoder_by_name(video_codec) : 0;
 		if( av_codec && av_codec->pix_fmts ) {
 			if( 0 && edl ) { // frequently picks a bad answer
@@ -2331,9 +2332,9 @@ int FFCodecRemaps::add(const char *val)
 }
 
 
-int FFCodecRemaps::update(AVCodecID &codec_id, AVCodec *&decoder)
+int FFCodecRemaps::update(AVCodecID &codec_id, const AVCodec *&decoder)
 {
-	AVCodec *codec = avcodec_find_decoder(codec_id);
+	const AVCodec *codec = avcodec_find_decoder(codec_id);
 	if( !codec ) return -1;
 	const char *name = codec->name;
 	FFCodecRemaps &map = *this;
@@ -2553,7 +2554,7 @@ int FFMPEG::init_decoder(const char *filename)
 	char *sp = strrchr(bp, '.');
 	if( !sp ) sp = bp + strlen(bp);
 	FILE *fp = 0;
-	AVInputFormat *ifmt = 0;
+	const AVInputFormat *ifmt = 0;
 	if( sp ) {
 		strcpy(sp, ".opts");
 		fp = fopen(file_opts, "r");
@@ -2774,7 +2775,7 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 	AVCodecContext *ctx = 0;
 
 	const AVCodecDescriptor *codec_desc = 0;
-	AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
+	const AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
 	if( !codec ) {
 		eprintf(_("cant find codec %s:%s\n"), codec_name, filename);
 		ret = 1;
@@ -3027,7 +3028,12 @@ int FFMPEG::open_encoder(const char *type, const char *spec)
 		}
 		if( ret >= 0 ) {
 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
-			ret = avcodec_copy_context(st->codec, ctx);
+			//ret = avcodec_copy_context(st->codec, ctx);
+			//AVCodecContext *codec_ctx = avcodec_alloc_context3(ctx);
+			ret = avcodec_parameters_to_context(ctx, st->codecpar);
+			// if (ret < 0)
+			//	fprintf(stderr, "could not copy codecpar to tmp codec_ctx\n");
+			//ret = avcodec_parameters_from_context(codec_ctx, 
 _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
 			if( ret < 0 )
 				fprintf(stderr, "Could not copy the stream context\n");
@@ -3672,7 +3678,7 @@ Preferences *FFMPEG::ff_prefs()
 
 double FFVideoStream::get_rotation_angle()
 {
-	int size = 0;
+	size_t size = 0;
 	int *matrix = (int*)av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, &size);
 	int len = size/sizeof(*matrix);
 	if( !matrix || len < 5 ) return 0;
@@ -3897,7 +3903,7 @@ AVCodecContext *FFMPEG::activate_decoder(AVStream *st)
 	AVDictionary *copts = 0;
 	av_dict_copy(&copts, opts, 0);
 	AVCodecID codec_id = st->codecpar->codec_id;
-	AVCodec *decoder = 0;
+	const AVCodec *decoder = 0;
 	switch( st->codecpar->codec_type ) {
 	case AVMEDIA_TYPE_VIDEO:
 		if( opt_video_decoder )
@@ -4089,10 +4095,11 @@ 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;
-	int nb_ent = st->nb_index_entries;
+	int nb_ent = avformat_index_get_entries_count(st);
 // some formats already have an index
 	if( nb_ent > 0 ) {
-		AVIndexEntry *ep = &st->index_entries[nb_ent-1];
+		// AVIndexEntry *ep = &st->index_entries[nb_ent-1];
+		const AVIndexEntry *ep = avformat_index_get_entry(st, nb_ent-1);
 		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 4f1624ce..6c7d68e0 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.h
+++ b/cinelerra-5.1/cinelerra/ffmpeg.h
@@ -25,6 +25,7 @@
 #include "vframe.inc"
 
 extern "C" {
+#include "libavcodec/bsf.h"
 #include "libavformat/avformat.h"
 #include "libavformat/avio.h"
 #include "libavcodec/avcodec.h"
@@ -86,7 +87,7 @@ public:
 	virtual int encode_activate();
 	virtual int decode_activate();
 	virtual AVHWDeviceType decode_hw_activate();
-	virtual int decode_hw_format(AVCodec *decoder, AVHWDeviceType type);
+	virtual int decode_hw_format(const AVCodec *decoder, AVHWDeviceType type);
 	virtual int write_packet(FFPacket &pkt);
 	int read_packet();
 	int seek(int64_t no, double rate);
@@ -290,7 +291,7 @@ class FFCodecRemaps : public ArrayList<FFCodecRemap>
 public:
 	FFCodecRemaps() {}
 	int add(const char *val);
-	int update(AVCodecID &codec_id, AVCodec *&decoder);
+	int update(AVCodecID &codec_id, const AVCodec *&decoder);
 };
 
 // for get_initial_timecode auto deletes
@@ -331,7 +332,7 @@ public:
 	static void ff_lock(const char *cp=0) { fflock.lock(cp); }
 	static void ff_unlock() { fflock.unlock(); }
 
-	int check_sample_rate(AVCodec *codec, int sample_rate);
+	int check_sample_rate(const AVCodec *codec, int sample_rate);
 	AVRational check_frame_rate(const AVRational *p, double frame_rate);
 	AVRational to_sample_aspect_ratio(Asset *asset);
 	AVRational to_time_base(int sample_rate);
-- 
2.35.1

From e6416bd94ed9ea4b8e029c2b9e31da903349b2c9 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 28 Mar 2022 00:34:03 +0300
Subject: [PATCH 28/66] fileexr forward port (openexr 3)

---
 cinelerra-5.1/cinelerra/fileexr.C | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/fileexr.C b/cinelerra-5.1/cinelerra/fileexr.C
index 9c782a11..fbc39862 100644
--- a/cinelerra-5.1/cinelerra/fileexr.C
+++ b/cinelerra-5.1/cinelerra/fileexr.C
@@ -50,8 +50,8 @@ public:
 	~EXRIStream();
 
 	bool read (char c[], int n);
-	Imf::Int64 tellg ();
-	void seekg (Imf::Int64 pos);
+	uint64_t tellg ();
+	void seekg (uint64_t pos);
 	void clear ();
 
 private:
@@ -67,8 +67,8 @@ public:
 	~EXROStream();
 
     virtual void write(const char c[], int n);
-    virtual Imf::Int64 tellp();
-    virtual void seekp(Imf::Int64 pos);
+    virtual uint64_t tellp();
+    virtual void seekp(uint64_t pos);
 
 private:
 	VFrame *data;
@@ -106,12 +106,12 @@ bool EXRIStream::read(char c[], int n)
 	return position >= size;
 }
 
-Imf::Int64 EXRIStream::tellg ()
+uint64_t EXRIStream::tellg ()
 {
 	return position;
 }
 
-void EXRIStream::seekg(Imf::Int64 pos)
+void EXRIStream::seekg(uint64_t pos)
 {
 	position = pos;
 }
@@ -141,12 +141,12 @@ void EXROStream::write(const char c[], int n)
 	data->set_compressed_size(MAX(position, data->get_compressed_size()));
 }
 
-Imf::Int64 EXROStream::tellp()
+uint64_t EXROStream::tellp()
 {
 	return position;
 }
 
-void EXROStream::seekp(Imf::Int64 pos)
+void EXROStream::seekp(uint64_t pos)
 {
 	position = pos;
 }
-- 
2.35.1

From e22f1a28267dec65e6b3a9dbeac4492f31b97e27 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 2 Apr 2022 23:55:20 +0300
Subject: [PATCH 49/66] Cinelerra/Makefile dynamic section fix for non-android,
 i hope

---
 cinelerra-5.1/cinelerra/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile
index 59643439..a06d88fd 100644
--- a/cinelerra-5.1/cinelerra/Makefile
+++ b/cinelerra-5.1/cinelerra/Makefile
@@ -447,10 +447,11 @@ LIBS += `pkg-config --libs libjpeg`
 LIBS += `pkg-config --libs uuid`
 LIBS += `pkg-config --libs theora`
 LIBS += `pkg-config --libs vorbis`
-LIBS += `pkg-config --libs tiff`
 LIBS += `pkg-config --libs sndfile`
 LIBS += -lgif -l:libtheora.a -l:libvorbis.a -ltiff 
+ifeq ($(shell uname -o), Android)
 LIBS += -landroid-shmem -liconv jpt.a
+endif
 LIBS += $(shared_libs)
 LIBS += $(system_libs)
 else
-- 
2.35.1

From b3feffe1923570c7c7218c633d92be2acc05f16f Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Mon, 28 Mar 2022 22:19:13 +0300
Subject: [PATCH 39/66] pkg-config based dynamic openexr link fix for
 freebsdv13

---
 cinelerra-5.1/cinelerra/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile
index 30f5e2c6..a0e08d5d 100644
--- a/cinelerra-5.1/cinelerra/Makefile
+++ b/cinelerra-5.1/cinelerra/Makefile
@@ -438,7 +438,7 @@ LIBS += -lavcodec -lavdevice -lavfilter -lavformat -lavutil
 LIBS += -lswresample -lswscale
 LIBS += -lintl -liconv
 LIBS += -lexecinfo
-
+LIBS += `pkg-config --libs OpenEXR`
 LIBS += $(shared_libs)
 LIBS += $(system_libs)
 else
-- 
2.35.1

From 8b33dec1edcded9db0773f6c491b50fd5cc38c34 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Sat, 2 Apr 2022 16:28:57 +0300
Subject: [PATCH 45/66] Add android-only hacked Dynamic makefile libs

---
 cinelerra-5.1/cinelerra/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile
index 7458d1a2..59643439 100644
--- a/cinelerra-5.1/cinelerra/Makefile
+++ b/cinelerra-5.1/cinelerra/Makefile
@@ -442,6 +442,15 @@ LIBS += -lintl -liconv
 LIBS += -lexecinfo
 endif
 LIBS += `pkg-config --libs OpenEXR`
+LIBS += `pkg-config --libs flac`
+LIBS += `pkg-config --libs libjpeg`
+LIBS += `pkg-config --libs uuid`
+LIBS += `pkg-config --libs theora`
+LIBS += `pkg-config --libs vorbis`
+LIBS += `pkg-config --libs tiff`
+LIBS += `pkg-config --libs sndfile`
+LIBS += -lgif -l:libtheora.a -l:libvorbis.a -ltiff 
+LIBS += -landroid-shmem -liconv jpt.a
 LIBS += $(shared_libs)
 LIBS += $(system_libs)
 else
-- 
2.35.1

From f006e5080e6a5f2da18784b096bf3da4c1846734 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <[email protected]>
Date: Fri, 1 Apr 2022 09:23:16 +0300
Subject: [PATCH 43/66] Attempt at freebsd/netbsd detection in
 cinelerra/Makefile

---
 cinelerra-5.1/cinelerra/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile
index a0e08d5d..7458d1a2 100644
--- a/cinelerra-5.1/cinelerra/Makefile
+++ b/cinelerra-5.1/cinelerra/Makefile
@@ -436,8 +436,11 @@ LIBS := $(LIBRARIES)
 ifeq ($(WANT_CIN_3RDPARTY),no)
 LIBS += -lavcodec -lavdevice -lavfilter -lavformat -lavutil
 LIBS += -lswresample -lswscale
+PLATFORM = $(shell uname -s)
+ifeq ($(PLATFORM), FreeBSD) || ($(PLATFORM), NetBSD)
 LIBS += -lintl -liconv
 LIBS += -lexecinfo
+endif
 LIBS += `pkg-config --libs OpenEXR`
 LIBS += $(shared_libs)
 LIBS += $(system_libs)
-- 
2.35.1

-- 
Cin mailing list
[email protected]
https://lists.cinelerra-gg.org/mailman/listinfo/cin

Reply via email to