[Bf-blender-cvs] [af6a1b08e3f] blender-v3.1-release: VSE: Refactor our code to be compatible with ffmpeg 5.0

Sebastian Parborg noreply at git.blender.org
Fri Feb 18 18:24:45 CET 2022


Commit: af6a1b08e3f0d0070ac9423868d2d3f81057717a
Author: Sebastian Parborg
Date:   Fri Feb 18 18:20:06 2022 +0100
Branches: blender-v3.1-release
https://developer.blender.org/rBaf6a1b08e3f0d0070ac9423868d2d3f81057717a

VSE: Refactor our code to be compatible with ffmpeg 5.0

In ffmpeg 5.0, several variables were made const to try to prevent bad API usage.
Removed some dead code that wasn't used anymore as well.

Reviewed By: Richard Antalik

Differential Revision: http://developer.blender.org/D14063

===================================================================

M	extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
M	extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
M	source/blender/blenkernel/BKE_writeffmpeg.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/writeffmpeg.c
M	source/blender/imbuf/intern/IMB_anim.h
M	source/blender/imbuf/intern/anim_movie.c
M	source/blender/imbuf/intern/indexer.c
M	source/blender/imbuf/intern/util.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
index de3ca099696..69bb45119a6 100644
--- a/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
+++ b/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
@@ -177,7 +177,7 @@ void FFMPEGReader::init(int stream)
 
 	// get a decoder and open it
 #ifndef FFMPEG_OLD_CODE
-	AVCodec* aCodec = avcodec_find_decoder(m_formatCtx->streams[m_stream]->codecpar->codec_id);
+	const AVCodec* aCodec = avcodec_find_decoder(m_formatCtx->streams[m_stream]->codecpar->codec_id);
 
 	if(!aCodec)
 		AUD_THROW(FileException, "File couldn't be read, no decoder found with ffmpeg.");
diff --git a/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp b/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
index 10517d1d596..32eb2330594 100644
--- a/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
+++ b/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
@@ -23,6 +23,7 @@
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avio.h>
+#include <libavutil/channel_layout.h>
 }
 
 AUD_NAMESPACE_BEGIN
@@ -171,66 +172,66 @@ FFMPEGWriter::FFMPEGWriter(std::string filename, DeviceSpecs specs, Container fo
 	if(avformat_alloc_output_context2(&m_formatCtx, nullptr, formats[format], filename.c_str()) < 0)
 		AUD_THROW(FileException, "File couldn't be written, format couldn't be found with ffmpeg.");
 
-	AVOutputFormat* outputFmt = m_formatCtx->oformat;
+	const AVOutputFormat* outputFmt = m_formatCtx->oformat;
 
 	if(!outputFmt) {
 		avformat_free_context(m_formatCtx);
 		AUD_THROW(FileException, "File couldn't be written, output format couldn't be found with ffmpeg.");
 	}
 
-	outputFmt->audio_codec = AV_CODEC_ID_NONE;
+	AVCodecID audio_codec = AV_CODEC_ID_NONE;
 
 	switch(codec)
 	{
 	case CODEC_AAC:
-		outputFmt->audio_codec = AV_CODEC_ID_AAC;
+		audio_codec = AV_CODEC_ID_AAC;
 		break;
 	case CODEC_AC3:
-		outputFmt->audio_codec = AV_CODEC_ID_AC3;
+		audio_codec = AV_CODEC_ID_AC3;
 		break;
 	case CODEC_FLAC:
-		outputFmt->audio_codec = AV_CODEC_ID_FLAC;
+		audio_codec = AV_CODEC_ID_FLAC;
 		break;
 	case CODEC_MP2:
-		outputFmt->audio_codec = AV_CODEC_ID_MP2;
+		audio_codec = AV_CODEC_ID_MP2;
 		break;
 	case CODEC_MP3:
-		outputFmt->audio_codec = AV_CODEC_ID_MP3;
+		audio_codec = AV_CODEC_ID_MP3;
 		break;
 	case CODEC_OPUS:
-		outputFmt->audio_codec = AV_CODEC_ID_OPUS;
+		audio_codec = AV_CODEC_ID_OPUS;
 		break;
 	case CODEC_PCM:
 		switch(specs.format)
 		{
 		case FORMAT_U8:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_U8;
+			audio_codec = AV_CODEC_ID_PCM_U8;
 			break;
 		case FORMAT_S16:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_S16LE;
+			audio_codec = AV_CODEC_ID_PCM_S16LE;
 			break;
 		case FORMAT_S24:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_S24LE;
+			audio_codec = AV_CODEC_ID_PCM_S24LE;
 			break;
 		case FORMAT_S32:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_S32LE;
+			audio_codec = AV_CODEC_ID_PCM_S32LE;
 			break;
 		case FORMAT_FLOAT32:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_F32LE;
+			audio_codec = AV_CODEC_ID_PCM_F32LE;
 			break;
 		case FORMAT_FLOAT64:
-			outputFmt->audio_codec = AV_CODEC_ID_PCM_F64LE;
+			audio_codec = AV_CODEC_ID_PCM_F64LE;
 			break;
 		default:
-			outputFmt->audio_codec = AV_CODEC_ID_NONE;
+			audio_codec = AV_CODEC_ID_NONE;
 			break;
 		}
 		break;
 	case CODEC_VORBIS:
-		outputFmt->audio_codec = AV_CODEC_ID_VORBIS;
+		audio_codec = AV_CODEC_ID_VORBIS;
 		break;
 	default:
-		outputFmt->audio_codec = AV_CODEC_ID_NONE;
+		audio_codec = AV_CODEC_ID_NONE;
 		break;
 	}
 
@@ -268,10 +269,10 @@ FFMPEGWriter::FFMPEGWriter(std::string filename, DeviceSpecs specs, Container fo
 
 	try
 	{
-		if(outputFmt->audio_codec == AV_CODEC_ID_NONE)
+		if(audio_codec == AV_CODEC_ID_NONE)
 			AUD_THROW(FileException, "File couldn't be written, audio codec not found with ffmpeg.");
 
-		AVCodec* codec = avcodec_find_encoder(outputFmt->audio_codec);
+		const AVCodec* codec = avcodec_find_encoder(audio_codec);
 		if(!codec)
 			AUD_THROW(FileException, "File couldn't be written, audio encoder couldn't be found with ffmpeg.");
 
diff --git a/source/blender/blenkernel/BKE_writeffmpeg.h b/source/blender/blenkernel/BKE_writeffmpeg.h
index 4c966c55e41..d959bb85c81 100644
--- a/source/blender/blenkernel/BKE_writeffmpeg.h
+++ b/source/blender/blenkernel/BKE_writeffmpeg.h
@@ -85,12 +85,8 @@ void BKE_ffmpeg_filepath_get(char *string,
 
 void BKE_ffmpeg_preset_set(struct RenderData *rd, int preset);
 void BKE_ffmpeg_image_type_verify(struct RenderData *rd, struct ImageFormatData *imf);
-void BKE_ffmpeg_codec_settings_verify(struct RenderData *rd);
 bool BKE_ffmpeg_alpha_channel_is_supported(const struct RenderData *rd);
 
-int BKE_ffmpeg_property_add_string(struct RenderData *rd, const char *type, const char *str);
-void BKE_ffmpeg_property_del(struct RenderData *rd, void *type, void *prop_);
-
 void *BKE_ffmpeg_context_create(void);
 void BKE_ffmpeg_context_free(void *context_v);
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 203676d0dd8..6d5abbd90d3 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -333,12 +333,6 @@ static void scene_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
     scene_dst->r.avicodecdata->lpParms = MEM_dupallocN(scene_dst->r.avicodecdata->lpParms);
   }
 
-  if (scene_src->r.ffcodecdata.properties) {
-    /* intentionally check sce_dst not sce_src. */ /* XXX ??? comment outdated... */
-    scene_dst->r.ffcodecdata.properties = IDP_CopyProperty_ex(scene_src->r.ffcodecdata.properties,
-                                                              flag_subdata);
-  }
-
   if (scene_src->display.shading.prop) {
     scene_dst->display.shading.prop = IDP_CopyProperty(scene_src->display.shading.prop);
   }
@@ -409,10 +403,6 @@ static void scene_free_data(ID *id)
     MEM_freeN(scene->r.avicodecdata);
     scene->r.avicodecdata = NULL;
   }
-  if (scene->r.ffcodecdata.properties) {
-    IDP_FreeProperty(scene->r.ffcodecdata.properties);
-    scene->r.ffcodecdata.properties = NULL;
-  }
 
   scene_free_markers(scene, do_id_user);
   BLI_freelistN(&scene->transform_spaces);
@@ -1030,9 +1020,6 @@ static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_addres
       BLO_write_raw(writer, (size_t)sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
     }
   }
-  if (sce->r.ffcodecdata.properties) {
-    IDP_BlendWrite(writer, sce->r.ffcodecdata.properties);
-  }
 
   /* writing dynamic list of TimeMarkers to the blend file */
   LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) {
@@ -1272,11 +1259,6 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
     BLO_read_data_address(reader, &sce->r.avicodecdata->lpFormat);
     BLO_read_data_address(reader, &sce->r.avicodecdata->lpParms);
   }
-  if (sce->r.ffcodecdata.properties) {
-    BLO_read_data_address(reader, &sce->r.ffcodecdata.properties);
-    IDP_BlendDataRead(reader, &sce->r.ffcodecdata.properties);
-  }
-
   BLO_read_list(reader, &(sce->markers));
   LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) {
     BLO_read_data_address(reader, &marker->prop);
@@ -1889,10 +1871,6 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type)
       sce_copy->r.avicodecdata->lpParms = MEM_dupallocN(sce_copy->r.avicodecdata->lpParms);
     }
 
-    if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
-      sce_copy->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
-    }
-
     BKE_sound_reset_scene_runtime(sce_copy);
 
     /* grease pencil */
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index 9effeb831b6..45bd977c109 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -56,6 +56,7 @@
  * like M_SQRT1_2 leading to warnings with MSVC */
 #  include <libavcodec/avcodec.h>
 #  include <libavformat/avformat.h>
+#  include <libavutil/channel_layout.h>
 #  include <libavutil/imgutils.h>
 #  include <libavutil/opt.h>
 #  include <libavutil/rational.h>
@@ -115,8 +116,6 @@ typedef struct FFMpegContext {
     printf
 
 static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value);
-static void ffmpeg_dict_set_float(AVDictionary **dict, const char *key, float value);
-static void ffmpeg_set_expert_options(RenderData *rd);
 static void ffmpeg_filepath_get(FFMpegContext *context,
                                 char *string,
                                 const struct RenderData *rd,
@@ -428,99 +427,6 @@ static AVFrame *generate_video_frame(FFMpegContext *context, const uint8_t *pixe
   return context->current_frame;
 }
 
-static void set_ffmpeg_property_option(IDProperty *prop, AVDictionary **dictionary)
-{
-  char name[128];
-  char *param;
-
-  PRINT("FFMPEG expert option: %s: ", prop->name);
-
-  BLI_strncpy(name, prop->name, sizeof(name));
-
-  param = strchr(name, ':');
-
-  if (param) {
-    *param++ = '\0';
-  }
-
-  switch (prop->type) {
-    case IDP_STRING:
-      PRINT("%s.\n", IDP_String(prop));
-      av_dict_set(dictionary, name, IDP_String(prop), 0);
-      break;
-    case IDP_FLOAT:
-      PRINT("%g.\n", IDP_Float(prop));
-      ffmpeg_dict_set_float(dictionary, prop->name, IDP_Float(prop));
-      break;
-    case IDP_INT:
-      PRINT("%d.\n", IDP_Int(prop));
-
-      if (param) {
-        if (IDP_Int(prop)) {
-          av_dict_set(dictionary, name, param, 0);
-        }
-        else {
-          return;
-        }
-      }
-      else {
-        ffmpeg_dict_set_int(dictionary, prop->name, IDP_Int(prop));
-      }
-      break;
-  }
-}
-
-static int ffmpeg_proprty_valid(AVCodecContext *c, const char *prop_name, IDProperty *curr)
-{
-  int valid = 1;
-
-  if (STREQ(prop_name, "video")) {
-    if (STREQ(curr->name, "bf")) {
-      /* flash codec doesn't support b frames */
-      valid &= c->codec_id != AV_CODEC_ID_FLV1;
-    }
-  }
-
-  return valid;
-}
-
-static void set_ffmpeg_properties(RenderData *rd,
-                                  AVCodecContext *c,
-                         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list