From 34276346ac379fecbd615322f18de837bd2c9ea2 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Fri, 28 Jan 2022 10:44:28 -0500
Subject: [PATCH] IO/FFMPEG: support FFmpeg 5.0 API changes

Fixes: #18445
---
 IO/FFMPEG/CMakeLists.txt                | 18 +++++++++++++++--
 IO/FFMPEG/vtkFFMPEGVideoSource.cxx      |  4 ++--
 IO/FFMPEG/vtkFFMPEGWriter.cxx           | 27 +++++++++++++------------
 4 files changed, 35 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/release/dev/ffmpeg-5.0.md

Index: paraview/VTK/IO/FFMPEG/CMakeLists.txt
===================================================================
--- paraview.orig/VTK/IO/FFMPEG/CMakeLists.txt	2024-05-21 23:57:26.275099695 +0200
+++ paraview/VTK/IO/FFMPEG/CMakeLists.txt	2024-05-21 23:57:26.267099616 +0200
@@ -34,6 +34,17 @@
     FFMPEG::swresample)
 endif ()
 
+set(ffmpeg_libraries)
+if (NOT FFMPEG_VERSION VERSION_LESS "5.0")
+  if (NOT FFMPEG_swresample_FOUND)
+    message(FATAL_ERROR
+      "FFMPEG 5.0 requires the `swresample` library.")
+  endif ()
+
+  list(APPEND ffmpeg_libraries
+    FFMPEG::swresample)
+endif ()
+
 vtk_module_add_module(VTK::IOFFMPEG
   CLASSES ${classes})
 vtk_module_link(VTK::IOFFMPEG
Index: paraview/VTK/IO/FFMPEG/vtkFFMPEGWriter.cxx
===================================================================
--- paraview.orig/VTK/IO/FFMPEG/vtkFFMPEGWriter.cxx	2024-05-21 23:57:26.275099695 +0200
+++ paraview/VTK/IO/FFMPEG/vtkFFMPEGWriter.cxx	2024-05-21 23:57:26.267099616 +0200
@@ -399,15 +399,9 @@
     return 0;
   }
 
-  if (this->Writer->GetCompression())
-  {
-    // choose a codec that is easily playable on windows
-    this->avOutputFormat->video_codec = AV_CODEC_ID_MJPEG;
-  }
-  else
-  {
-    this->avOutputFormat->video_codec = AV_CODEC_ID_RAWVIDEO;
-  }
+  enum AVCodecID video_codec = this->Writer->GetCompression()
+    ? AV_CODEC_ID_MJPEG // choose a codec that is easily playable on windows
+    : AV_CODEC_ID_RAWVIDEO;
 
   // assign the format to the context
   this->avFormatContext->oformat = this->avOutputFormat;
