SwiftFFmpeg icon indicating copy to clipboard operation
SwiftFFmpeg copied to clipboard

Provide example for packaging FFmpeg binaries

Open gregcotten opened this issue 5 years ago • 14 comments

I'd be happy to lend my advice as I am currently doing this in a shipping macOS app, but I'm wondering what the best way to do this would be. I currently use a build script to build the FFmpeg libraries from source + an xcodeproject to help generate .frameworks for CFFmpeg and SwiftFFmpeg. Not so sure if this is the best way but it gets the job done.

gregcotten avatar Jan 07 '20 21:01 gregcotten

Currently, due to the lack of support for binary dependencies in SPM, I have adopted a similar approach to you. Recently, SPM team put forward a proposal for binary dependencies (SE-0272) and it was approved. Once the proposal is implemented, we can integrate FFmpeg library internally.

sunlubo avatar Jan 08 '20 03:01 sunlubo

I'll keep an eye out for it!

gregcotten avatar Jan 14 '20 21:01 gregcotten

WWDC20 talk tomorrow regarding this very topic!

gregcotten avatar Jun 22 '20 22:06 gregcotten

I have added support for SE-0272 in https://github.com/sunlubo/SwiftFFmpeg/pull/41#issue-463928497. Can you try and verify it?

sunlubo avatar Aug 06 '20 10:08 sunlubo

Will test soon! Are the binaries dylib or static?

gregcotten avatar Aug 07 '20 04:08 gregcotten

static

sunlubo avatar Aug 07 '20 05:08 sunlubo

Great Work! Thank you.

What I'm seeing building a tiny project that uses this branch via SPM in Xcode12b4 on 10.15.6 is

Ld /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Products/Debug/binaryffmpeg.app/Contents/MacOS/binaryffmpeg normal (in target 'binaryffmpeg' from project 'binaryffmpeg')
    cd /Users/thies/Temp/binaryffmpeg
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -L/Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Products/Debug -F/Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Products/Debug -filelist /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Intermediates.noindex/binaryffmpeg.build/Debug/binaryffmpeg.build/Objects-normal/x86_64/binaryffmpeg.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../Frameworks -Xlinker -object_path_lto -Xlinker /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Intermediates.noindex/binaryffmpeg.build/Debug/binaryffmpeg.build/Objects-normal/x86_64/binaryffmpeg_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-link-runtime -L/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Intermediates.noindex/binaryffmpeg.build/Debug/binaryffmpeg.build/Objects-normal/x86_64/binaryffmpeg.swiftmodule -framework Security -framework CoreMedia -framework CoreVideo -framework AudioToolbox -framework VideoToolbox -framework OpenGL -framework CoreImage -framework AppKit -lz -lbz2 -liconv -llzma -framework libavcodec -framework libavdevice -framework libavfilter -framework libavformat -framework libavutil -framework libpostproc -framework libswresample -framework libswscale -Xlinker -dependency_info -Xlinker /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Intermediates.noindex/binaryffmpeg.build/Debug/binaryffmpeg.build/Objects-normal/x86_64/binaryffmpeg_dependency_info.dat -o /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Products/Debug/binaryffmpeg.app/Contents/MacOS/binaryffmpeg -Xlinker -add_ast_path -Xlinker /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Intermediates.noindex/SwiftFFmpeg.build/Debug/SwiftFFmpeg.build/Objects-normal/x86_64/SwiftFFmpeg.swiftmodule

ld: in /Users/thies/Library/Developer/Xcode/DerivedData/binaryffmpeg-cpzbcxscrwnfiyghxwaadmoptrun/Build/Products/Debug/libswscale.framework/libswscale(input.o), building for macOS, but linking in object file built for free standing, for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I saw this message before, but it did not cause the linker to fail. There is some write up about this problem here https://github.com/yasm/yasm/issues/141

thieso2 avatar Aug 07 '20 07:08 thieso2

It works fine on Xcode11E708 with 5.3-DEVELOPMENT-SNAPSHOT-2020-08-05-a toolchain. I will try Xcode12b4 in next few days.

sunlubo avatar Aug 08 '20 03:08 sunlubo

I think we need to have a LGPL-compliant version for the build script, and to do that I believe we'll need to use dynamic libraries.

gregcotten avatar Aug 23 '20 23:08 gregcotten

I think we need to have a LGPL-compliant version for the build script, and to do that I believe we'll need to use dynamic libraries.

which build script?

sunlubo avatar Aug 25 '20 00:08 sunlubo

This build script enables GPL parts of FFmpeg, which make it impossible to use in a closed-source commercial project.

gregcotten avatar Aug 25 '20 00:08 gregcotten

You mean this part?

--enable-gpl

sunlubo avatar Aug 25 '20 00:08 sunlubo

Yep

gregcotten avatar Aug 25 '20 00:08 gregcotten

The --enable-gpl option has been removed.

sunlubo avatar Aug 28 '20 04:08 sunlubo