pixop / video-compare

Split screen video comparison tool using FFmpeg and SDL2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix for compiling on recent macOS / Apple Silicon (M1) with Homebrew

thomasbachem opened this issue · comments

For users having issues compiling video-compare on macOS Big Sur / Monterey having ffmpeg installed via Homebrew that run into this error when running make:

In file included from demuxer.cpp:1:
./demuxer.h:4:11: fatal error: 'libavformat/avformat.h' file not found
        #include "libavformat/avformat.h"
                 ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [demuxer.o] Error 1

This is because the compiler can't find the required libav dependencies from your ffmpeg install.

To make compilation work, you'll need to replace the paths referring to /opt/local/ with /opt/homebrew/ in the makefile.

I just stumbled over this when setting up my new M1 Max MacBook Pro and hope this helps others running into this issue :).

@jonfryd a solution could be to simply give both paths to the compiler, but that would display a warning when any of the paths wasn't found. Maybe you can include a switch checking for the existence of /opt/homebrew/ or something? I'd say that Homebrew is the de-facto standard package manager for macOS these days.

Because other than that, video-compare works seamlessly on Macs!

Thanks for sharing your experiences, @thomasbachem. It's cool to hear the tool works on one of those shiny new M1 Macs (I'm still on an 2017 Intel iMac and would love to try out an M1 one day).

Anyway, I think a simple solution like you are proposing makes sense for now. I'm using MacPorts myself (/opt/local), but perhaps the following will work for you, as well?

CXX = g++
CXXFLAGS = -g3 -Ofast -mavx2 -std=c++14 -D__STDC_CONSTANT_MACROS \
                   -Wall -Wextra -Wextra -pedantic \
                   -Wdisabled-optimization -Wctor-dtor-privacy -Wmissing-declarations \
                   -Woverloaded-virtual -Wshadow -Wno-unused -Winline
LDLIBS = -lavformat -lavcodec -lavutil -lswscale -lSDL2 -lSDL2_ttf -pthread

ifneq "$(wildcard /opt/homebrew)" ""
  CXXFLAGS += -I/opt/homebrew/include/
  LDLIBS += -L/opt/homebrew/lib/
else ifneq "$(wildcard /opt/local)" ""
  CXXFLAGS += -I/opt/local/include/
  LDLIBS += -L/opt/local/lib/
else
  CXXFLAGS += -I/usr/local/include/
  LDLIBS += -L/usr/local/lib/
endif

This would cover the case I need on another machine where the dependencies have been compiled manually and are all stored under /usr/local.

Awesome, thanks for looking into it so quickly – it works :)!