Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented building single XCFramework #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

666tos
Copy link

@666tos 666tos commented Oct 8, 2019

Supported platforms

  • iOS: arm64 for device and X86_64 for simulator
  • tvOS: arm64 for device and X86_64 for simulator
  • macOS: X86_64
  • macOS-catalyst: X86_64

Issues

  • x86_64 binaries are built without ASM support, since ASM for x86_64 is actually x86 and that confuses xcodebuild -create-xcframework

Copy link
Owner

@kewlbear kewlbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

But before I merge, you should fix some issues I found while testing.

  1. uncomment BuildAll
  2. try to download FFmpeg source if missing
  3. macCatalyst fails to build
    src/libavcodec/videotoolbox.c:699:45: error: 'kCVPixelBufferOpenGLESCompatibilityKey' is
    unavailable: not available on macCatalyst
    CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFB...
  4. framework name should be FFmpeg (notice lower case m)

@666tos
Copy link
Author

666tos commented Oct 10, 2019

Now fixing issues and submitting PR with fix to FFmpeg

@kewlbear
Copy link
Owner

Don't you get an error like above while building for macCatalyst?

@simayang01
Copy link

simayang01 commented Oct 11, 2019

Don't you get an error like above while building for macCatalyst?

I got the same error such as 「'kCVPixelBufferOpenGLESCompatibilityKey' is
unavailable: not available on macCatalyst」

I got the source from Url:
https://ffmpeg.org/releases/ffmpeg-4.2.tar.bz2

hopes solve the problem and good luck !

@666tos
Copy link
Author

666tos commented Oct 11, 2019

I also had same error while building.
That's why I mentioned submitting PR with fix to FFmpeg
You can resolve the issue yourself by changing following lines in libavcodec/videotoolbox.c

#if TARGET_OS_IPHONE
     CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFBooleanTrue);
#else
     CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey, kCFBooleanTrue);
 #endif

to following code:

#if TARGET_ABI_USES_IOS_VALUES
    CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFBooleanTrue);
#elif TARGET_OS_OSX
    CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey, kCFBooleanTrue);
#endif

@666tos 666tos requested a review from kewlbear October 11, 2019 07:45
@simayang01
Copy link

I also had same error while building.
That's why I mentioned submitting PR with fix to FFmpeg
You can resolve the issue yourself by changing following lines in libavcodec/videotoolbox.c

#if TARGET_OS_IPHONE
     CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFBooleanTrue);
#else
     CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey, kCFBooleanTrue);
 #endif

to following code:

#if TARGET_ABI_USES_IOS_VALUES
    CFDictionarySetValue(buffer_attributes, kCVPixelBufferOpenGLESCompatibilityKey, kCFBooleanTrue);
#elif TARGET_OS_OSX
    CFDictionarySetValue(buffer_attributes, kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey, kCFBooleanTrue);
#endif

Everything worked well when I modify the libavcodec/videotoolbox.c, Thank you very much @666tos Your magic script really helped me .

@666tos
Copy link
Author

666tos commented Oct 11, 2019

👍

@roshnadsouza
Copy link

Hi,

I am trying to get the frames of the video, but then i get the below error.

[h264 @ 0x7f8c21030200] No start code is found.
[h264 @ 0x7f8c21030200] Error splitting the input into NAL units.

Can anyone please help me.

@tmm1
Copy link

tmm1 commented Dec 20, 2019

Isn't -miphoneos-version-min=13.0.0 also required for catalyst build?


libtool $LIBTOOL_FLAGS \
-static -D -arch_only $arch \
$object_files -o "$thin_dir/$LIBRARY_FILE"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to call libtool instead of using the .a generated by ffmpeg?

@tmm1
Copy link

tmm1 commented Dec 20, 2019

  • x86_64 binaries are built without ASM support, since ASM for x86_64 is actually x86 and that confuses xcodebuild -create-xcframework

This is due to yasm not injecting platform identifiers (via LC_BUILD_VERSION load command) into the generated mach-o objects. See https://stackoverflow.com/a/59103419/332798

@amayers
Copy link

amayers commented Mar 17, 2020

I've gotten the XCFramework to build using this and modifying the libavcodec/videotoolbox.c file as mentioned above. However I can't figure out how to import the FFmpeg headers using this method. I have the FFmpeg.xcframework linked & embedded. I've tried @import FFmpeg; #import <FFmpeg/<any header I can see in the headers folder>.h>, #import <FFmpeg/<nested folder>/<file>.h> and nothing seems to find them. This is all from Objective-C.

@Raees678
Copy link

Raees678 commented Jul 5, 2020

@amayers I'm having a similar issue with importing the framework using Swift in an iOS project. Did you manage to figure this out? All I get is No such module 'FFmpeg'. I have my framework embedded and signed in the Frameworks Libraries and Embedded content section of the General tab and have the framework added in the Link Binary with Libraries section in the Build Phases tab. I also have the Framework Search Paths set to the correct directory of the framework in the Build Settings tab. Is there something I am missing as to how to properly import FFmpeg.xcframework?

@amayers
Copy link

amayers commented Jul 10, 2020

@amayers I'm having a similar issue with importing the framework using Swift in an iOS project. Did you manage to figure this out? All I get is No such module 'FFmpeg'. I have my framework embedded and signed in the Frameworks Libraries and Embedded content section of the General tab and have the framework added in the Link Binary with Libraries section in the Build Phases tab. I also have the Framework Search Paths set to the correct directory of the framework in the Build Settings tab. Is there something I am missing as to how to properly import FFmpeg.xcframework?

@Raees678 Not with this repo. But I did get xcframeworks from https://github.com/tanersener/mobile-ffmpeg and with those I just dropped them in and it just worked. I didn’t try from Swift as I have an older Objective-C wrapper around the parts I needed. The strange thing is that project gives you a handful of xcframeworks instead of the one that this PR gives you.

That repo has a nice script to build it with just the things you want, or they have up to date prebuilt releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants