NCrusher
NCrusher

Reputation: 93

Building FFmpeg for use in Swift

With the new XCode/Swift release comes the ability to use binary dependencies. This seems to me to be an ideal time to create an SPM package for FFMpeg.

However, while I've spent the last year learning to code i Swift, I'm actually not all that familiar with how to build libraries, especially those as complex as FFmpeg with all the configurable libraries and third-party dependencies.

There's kewlbear's iOS build scripts, but these are for iOS/tvOS and ideally an FFMpeg SPM package would be usable for MacOS also. It's also not updated for the newest Xcode and Swift versions.

My personal interest is simply in audio and I don't need a lot of bells and whistles, but I figure the ideal situation would be a full package with the entire source and whatever dependencies it needs, and then when it's used as a package dependency, the compiler will just use the parts it needs.

I guess my question is...how would I ideally compile the ffmpeg code for this purpose. I'm trying to follow the directions for compiling yourself, but I'm stuck at the point of compiling gettext because I'm not sure if I should follow the directions (in the gettext source code) for compiling a fat binary for multiple architectures, and when I try to run:

      ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
                  CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
                  CPP="gcc -E" CXXCPP="g++ -E"

I get the following error:

 checking whether the C compiler works... no configure: error: in
 `/Users/nolainecrusher/Downloads/FFMpeg-source/gettext-0.21/gettext-runtime':
 configure: error: C compiler cannot create executables See
 `config.log' for more details configure: error: ./configure failed for
 gettext-runtime

and config.log doesn't really tell me anything useful:

This is what I see at the end of the log:

 mkdir_p='$(MKDIR_P)' oldincludedir='/usr/include' pdfdir='${docdir}'
 prefix='/usr/local' program_transform_name='s,x,x,' psdir='${docdir}'
 sbindir='${exec_prefix}/sbin' sharedstatedir='${prefix}/com' subdirs='
 gettext-runtime libtextstyle gettext-tools' sysconfdir='${prefix}/etc'
 target_alias=''

I feel like maybe I'm going about this the wrong way, but I'm not sure what the right way is.

Upvotes: 3

Views: 2130

Answers (1)

user15478717
user15478717

Reputation:

See the following:

A Swift wrapper package for FFmpeg and A C wrapper package for FFmpeg

SwiftFFmpeg assumes ffmpeg is installed locally and will link with those libraries. Also, SwiftFFmpeg uses CFFmpeg as a package dependency, and your app can use SwiftFFmpeg as a dependency.

If you want to see a build script for compiling ffmpeg (x86_64 and arm64), check out my own audio player project.

Upvotes: 3

Related Questions