6

I am planning to create a new app for personal use on my Mac that uses FFMPEG library, to store a feed from a RTSP IP camera.

Following this official installation procedure from FFMPEG I have manage to successfully achieve the following 2 steps:

To get ffmpeg for OS X, you first have to install ​Homebrew. If you don't want to use Homebrew, see the section below.

Then:
- brew install automake fdk-aac git lame libass libtool libvorbis libvpx \ opus sdl shtool texi2html theora wget x264 xvid yasm

Question: My question here because I am confused, is how to import a library into Xcode so I can use it in the application I am about to build for my Mac. I can see plenty of GitHub projects related to FFMPEG with IOS/Android, but none for OSX.

All the FFMPEG commands under terminal are working fine, such as converting a video etc.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
cmario
  • 605
  • 1
  • 7
  • 22

3 Answers3

4

If you look in /usr/local/Cellar/ffmpeg you will find the actual ffmpeg package and everything in homebrew is just symbolic links to that. For example:

/usr/local/bin/ffmpeg -> ../Cellar/ffmpeg/3.0.2/bin/ffmpeg

Now, if you stay in that directory and do this, you will find all the pkgconfig configuration settings for the constituent parts of ffmpeg:

find . -name \*.pc

./lib/pkgconfig/libavcodec.pc
./lib/pkgconfig/libavdevice.pc
./lib/pkgconfig/libavfilter.pc
./lib/pkgconfig/libavformat.pc
./lib/pkgconfig/libavresample.pc
./lib/pkgconfig/libavutil.pc
./lib/pkgconfig/libpostproc.pc
./lib/pkgconfig/libswresample.pc
./lib/pkgconfig/libswscale.pc

That means you can now find the include path and library paths that you need to put in the Xcode settings. So, for example, if you want the includes for libavutil, you can do:

pkg-config --cflags libavutil

and it will tell you:

-I/usr/local/Cellar/ffmpeg/3.0.2/include

If you want the library settings for libavfilter, you can do:

pkg-config --libs libavfilter

and it will tell you

-L/usr/local/Cellar/ffmpeg/3.0.2/lib -lavfilter

So that is how you get the settings for the compiler/linker. Then you need to put them into Xcode, and I have described that here - look at the bit with the yellow, red and blue boxes.

Hope that helps. Oh, you need to do:

brew install pkg-config

first to get the pkgconfig binary.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • You are not supposed to run anything under `/usr/local/Cellar` **directly** - that is why everything is symbolically linked from `/usr/local/bin` to the Cellar. The general idea is that you should use the binaries in `/usr/local/bin` by setting your PATH to include that directory. – Mark Setchell May 25 '16 at 13:32
  • hello there, managed to resolve that. I am at the point where I need to compile my ffmpeg library using the XCode command line tool. This is the command used for opencv - g++ $(pkg-config --cflags --libs opencv) process.cpp -o process. Can you give me the example I need to add to the terminal for the FFMPEG Library? – cmario May 25 '16 at 13:36
  • Now I am confused - I understood from your question that you wanted to use Xcode. Xcode is a graphical tool, not command line - which is why I linked to my other post about the settings in the Xcode GUI. And `clang/clang++` is the Apple Xcode compiler, not `gcc/g++` which is GNU. – Mark Setchell May 25 '16 at 13:45
  • This is in the answer you gave me: Then you need to put them into Xcode, and I have described that here - look at the bit with the yellow, red and blue boxes. Did everything successfully so far, the only thing left is what to put under - Header Search Paths - Other Linker Flags. I am using Swift – cmario May 25 '16 at 13:46
  • I have no idea - that's the first mention of `swift`! I have added the `swift` tag to your post in the hope that someone else can help you. Sorry. – Mark Setchell May 25 '16 at 13:53
  • Can I just use a bridge and enable my swift project to use objective-c files? – cmario May 25 '16 at 13:54
2

In general, you need to configure the Xcode target build settings to add /usr/local/include to the Header Search Path.

Then your #include <ffmpeg.h> (or whatever it's called) will start to work.

Then for linking to libffmpeg.a (or whatever it's called), you can do one of two things:

  1. Add the file to the Additional Libraries and Frameworks of the build settings (selecting it via a file open dialog).
  2. Add /usr/local/lib to the Library Search Paths and -lffmpeg to the Other Linker Flags.

(1. is better if you ask me).

I use Macports, so for me the paths are /opt/local/{include,lib} however with Homebrew there might be an additional level of directory (like /usr/local/ffmpeg/{include,lib}, but you should be able to work that out yourself.

I won't go into details of how to actually use FFMPEG as that is way too involved (and I know nothing about it).

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • Hi Sir, Need you serious Help in this Question. Thanks https://stackoverflow.com/questions/57952043/how-to-use-ffmpeg-library-in-ios-swift – Ahtazaz Sep 16 '19 at 11:36
1

Although this does not answer the specific question here ("how to import such and such libraries"),

for anyone googling here, these days to use FFmpeg in OSX you just

Use the famous import script of Kewlbear

which you can easily find here

https://github.com/kewlbear/FFmpeg-iOS-build-script

and which does everything.

It is a huge amount of non-trivial work maintaining such a build script, and fortunately there's someone who does that work on an ongoing basis.

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719