meganz / sdk

MEGA C++ SDK
BSD 2-Clause "Simplified" License
1.32k stars 504 forks source link

Can't build with FFMpeg 6.0 #2635

Open Vascom opened 1 year ago

Vascom commented 1 year ago

FFMpeg removed AV_CODEC_CAP_TRUNCATED and CODEC_CAP_TRUNCATED definitions and now I can't build MegaSync with this error:

mega/src/gfx/freeimage.cpp: In member function 'bool mega::GfxProviderFreeImage::readbitmapFfmpeg(mega::FileSystemAccess*, const mega::LocalPath&, int)':
mega/src/gfx/freeimage.cpp:215:23: error: 'CODEC_CAP_TRUNCATED' was not declared in this scope; did you mean 'CAP_TRUNCATED'?
  215 | #define CAP_TRUNCATED CODEC_CAP_TRUNCATED
      |                       ^~~~~~~~~~~~~~~~~~~
mega/src/gfx/freeimage.cpp:334:33: note: in expansion of macro 'CAP_TRUNCATED'
  334 |     if (decoder->capabilities & CAP_TRUNCATED)
      |                                 ^~~~~~~~~~~~~
mega/src/gfx/freeimage.cpp:406:19: warning: 'void av_init_packet(AVPacket*)' is deprecated [-Wdeprecated-declarations]
  406 |     av_init_packet(&packet);
      |     ~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/ffmpeg/libavformat/avformat.h:316:
/usr/include/ffmpeg/libavcodec/packet.h:512:6: note: declared here
  512 | void av_init_packet(AVPacket *pkt);
      |      ^~~~~~~~~~~~~~
make[1]: *** [Makefile:13285: freeimage.o] Error 1

Please help me fix it.

Commit at ffmpeg in that removed definitions: https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/3ceffe783965767e62d59e8e68ecd265c98460ec

Vascom commented 1 year ago

This patch solve the problem.

--- src/MEGASync/mega/src/gfx/freeimage.cpp.orig
+++ src/MEGASync/mega/src/gfx/freeimage.cpp
@@ -209,11 +209,13 @@ bool GfxProviderFreeImage::readbitmapFre

 #ifdef HAVE_FFMPEG

+#if LIBAVCODEC_VERSION_MAJOR < 60
 #ifdef AV_CODEC_CAP_TRUNCATED
 #define CAP_TRUNCATED AV_CODEC_CAP_TRUNCATED
 #else
 #define CAP_TRUNCATED CODEC_CAP_TRUNCATED
 #endif
+#endif

 const char *GfxProviderFreeImage::supportedformatsFfmpeg()
 {
@@ -331,10 +333,12 @@ bool GfxProviderFreeImage::readbitmapFfm
     // Force seeking to key frames
     formatContext->seek2any = false;
     videoStream->skip_to_keyframe = true;
+#if LIBAVCODEC_VERSION_MAJOR < 60
     if (decoder->capabilities & CAP_TRUNCATED)
     {
         codecContext->flags |= CAP_TRUNCATED;
     }
+#endif

     AVPixelFormat sourcePixelFormat = static_cast<AVPixelFormat>(codecParm->format);
     AVPixelFormat targetPixelFormat = AV_PIX_FMT_BGR24; //raw data expected by freeimage is in this format
sl1pkn07 commented 1 year ago

Hi

can you summit a PR for better track?

greetings

HeronErin commented 5 months ago

I am having this issue aswell, and the patch solves the compilation issues.

Volkanite commented 4 weeks ago

This patch solve the problem.

--- src/MEGASync/mega/src/gfx/freeimage.cpp.orig
+++ src/MEGASync/mega/src/gfx/freeimage.cpp
@@ -209,11 +209,13 @@ bool GfxProviderFreeImage::readbitmapFre

 #ifdef HAVE_FFMPEG

+#if LIBAVCODEC_VERSION_MAJOR < 60
 #ifdef AV_CODEC_CAP_TRUNCATED
 #define CAP_TRUNCATED AV_CODEC_CAP_TRUNCATED
 #else
 #define CAP_TRUNCATED CODEC_CAP_TRUNCATED
 #endif
+#endif

 const char *GfxProviderFreeImage::supportedformatsFfmpeg()
 {
@@ -331,10 +333,12 @@ bool GfxProviderFreeImage::readbitmapFfm
     // Force seeking to key frames
     formatContext->seek2any = false;
     videoStream->skip_to_keyframe = true;
+#if LIBAVCODEC_VERSION_MAJOR < 60
     if (decoder->capabilities & CAP_TRUNCATED)
     {
         codecContext->flags |= CAP_TRUNCATED;
     }
+#endif

     AVPixelFormat sourcePixelFormat = static_cast<AVPixelFormat>(codecParm->format);
     AVPixelFormat targetPixelFormat = AV_PIX_FMT_BGR24; //raw data expected by freeimage is in this format

This patch (with a little tweaking) also fixed compilation on Gentoo.