fstark / macflim

MacFlim flim player source code and utilities
MIT License
90 stars 4 forks source link

flimmaker doesn’t compile with FFmpeg 5 #35

Closed aaronk6 closed 3 weeks ago

aaronk6 commented 2 years ago

flimmaker doesn’t compile with FFmpeg 5. It fails with the following error below. It’s probably because of some deprecated APIs since it’s working fine with FFmpeg 4.

Certainly not an urgency for me, but still wanted to make sure it’s reported in case anybody else encounters this. Since FFmpeg 5 is the default version that gets installed when simply running brew install ffmpeg on a recent OS, I’m sure some people will run into this. Maybe worth mentioning in the README in case it’s hard to fix.

$ make
c++  -std=c++2a -c -O3 reader.cpp -o reader.o
reader.cpp:92:5: error: unknown type name 'AVCodecContext'
    AVCodecContext *video_codec_context_;
    ^
reader.cpp:93:5: error: unknown type name 'AVCodecContext'
    AVCodecContext *audio_codec_context_;
    ^
reader.cpp:304:15: error: no matching function for call to 'av_find_best_stream'
        ixv = av_find_best_stream( format_context_,
              ^~~~~~~~~~~~~~~~~~~
/opt/homebrew/include/libavformat/avformat.h:2171:5: note: candidate function not viable: no known conversion from 'AVCodec **' to 'const AVCodec **' for 5th argument
int av_find_best_stream(AVFormatContext *ic,
    ^
reader.cpp:310:15: error: no matching function for call to 'av_find_best_stream'
        ixa = av_find_best_stream( format_context_,
              ^~~~~~~~~~~~~~~~~~~
/opt/homebrew/include/libavformat/avformat.h:2171:5: note: candidate function not viable: no known conversion from 'AVCodec **' to 'const AVCodec **' for 5th argument
int av_find_best_stream(AVFormatContext *ic,
    ^
reader.cpp:372:32: error: use of undeclared identifier 'avcodec_alloc_context3'
        video_codec_context_ = avcodec_alloc_context3( video_decoder_ );
                               ^
reader.cpp:382:36: error: use of undeclared identifier 'avcodec_alloc_context3'
            audio_codec_context_ = avcodec_alloc_context3( audio_decoder_ );
                                   ^
reader.cpp:478:9: warning: 'av_init_packet' is deprecated [-Wdeprecated-declarations]
        av_init_packet(&pkt_);
        ^
/opt/homebrew/include/libavcodec/packet.h:511:1: note: 'av_init_packet' has been explicitly marked deprecated here
attribute_deprecated
^
/opt/homebrew/include/libavutil/attributes.h:100:49: note: expanded from macro 'attribute_deprecated'
#    define attribute_deprecated __attribute__((deprecated))
                                                ^
reader.cpp:567:16: error: no viable conversion from returned value of type 'unique_ptr<ffmpeg_reader>' to function return type 'unique_ptr<input_reader>'
        return std::make_unique<ffmpeg_reader>( movie_path, from, to );
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:121:59: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'typename __unique_if<ffmpeg_reader>::__unique_single' (aka 'unique_ptr<ffmpeg_reader>') to 'const std::unique_ptr<input_reader> &' for 1st argument
class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
                                                          ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:185:21: note: candidate constructor template not viable: no known conversion from 'typename __unique_if<ffmpeg_reader>::__unique_single' (aka 'unique_ptr<ffmpeg_reader>') to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:213:3: note: candidate constructor not viable: no known conversion from 'typename __unique_if<ffmpeg_reader>::__unique_single' (aka 'unique_ptr<ffmpeg_reader>') to 'std::unique_ptr<input_reader> &&' for 1st argument
  unique_ptr(unique_ptr&& __u) _NOEXCEPT
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:222:3: note: candidate template ignored: requirement 'is_convertible<ffmpeg_reader *, input_reader *>::value' was not satisfied [with _Up = ffmpeg_reader, _Ep = std::default_delete<ffmpeg_reader>]
  unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:190:12: note: explicit constructor is not a candidate
  explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {}
           ^
1 warning and 7 errors generated.
make: *** [reader.o] Error 1

A workaround is to downgrade FFmpeg to version 4.x. When using Homebrew:

brew install ffmpeg@4
brew unlink ffmpeg
brew link ffmpeg@4

This commit could be helpful for adding FFmpeg 5 support: https://github.com/opencv/opencv/commit/5440fd6cb43ea65a056c46b691fcdab1a425e92d

fstark commented 2 years ago

Thx for the report and workaround. ffmpeg integration was a huge pain de to lack of usable documentation. I always knew that this would have a large maintenance cost, but it is such an useful feature...

I can't just switch the code to ffmpeg5 because a) it will probably be painful, b) it will break for everyone that uses v4, so I need to see if there is a way to support both with the same binary (ideally), or with #defines in the source code and some Makefile option.

fstark commented 3 weeks ago

This have been fixed by @hunterirving (but I associated it with the wrong issue).