8

I have compiled the ffmpeg library and it was successfully created many files inside my folder.

Now I need to implement the same in my Xcode project. What is the best way for adding to my project.

I wish to create one framework but what files I need to add?

I have many .c files and .a files available after compilation.

1

1 Answer 1

18
+500

In the past I've successfully used this build script to integrate ffmpeg.

The pictorial instructions that follow work for both Objective-C and Swift projects, unless otherwise noted.

As a side note, you should make sure ffmpeg is the correct tool for the job. AVFoundation and VideoToolBox are both very powerful tools that Apple provides for doing many video operations.

For late 2018, get the folder from the kewlbear repo which will appear as in the below image, however, there is an additional file build-ffmpeg-iOS-framework.sh. In terminal, cd to that folder. With the current version, you must run build-ffmpeg-iOS-framework.sh , not build-ffmpeg.sh to follow the following tutorial:

Once you've executed the script, you'll have the following files:

enter image description here

Copy the FFmpeg-iOS folder to your project:

enter image description here

Add the files to your project:

(by dragging and dropping from finder) enter image description here

With these settings:

enter image description here

Add the include directory to your headers:

enter image description here

Link the required libraries:

enter image description here

Add the headers to the bridging header (Swift-only):

#import "libavcodec/avcodec.h"
#import "libavdevice/avdevice.h"
#import "libavfilter/avfilter.h"
#import "libavformat/avformat.h"
#import "libavutil/avutil.h"
#import "libswresample/swresample.h"
#import "libswscale/swscale.h"

Objective-C simple example:

#import "AppDelegate.h"
#import "libavformat/avformat.h"

@interface AppDelegate ()
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    AVFormatContext *context = avformat_alloc_context();

    return YES;
}

@end

And in Swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        let context = avformat_alloc_context()

        return true
    }
}
9
  • @AllenHumphreys libz.dylib , libbz2.dylib, libiconv.dylib changed . Please update the answer . Commented Mar 22, 2018 at 11:46
  • libz.dylib changed to libz.tbd and libiconv.dylib changed to libiconv.tbd . that's it i think. Let me know if i am wrong. Commented Mar 23, 2018 at 7:36
  • @AllenHumphreys thanks for your response. I know about ffmpeg usage. i have integrated and used in android. but i am stuck in how to take a reference of integrated libraries as i did from this answer. how can i get its reference in my code so that i can run the ffmpeg commands i know. Thank you for your generosity
    – Mili Shah
    Commented Jun 25, 2018 at 17:39
  • Would I need to do anything different to use this script to integrate ffmpeg for a MacOS (not iOS) project? I assume I would use the "x86_64" architecture.
    – robamaton
    Commented Jun 27, 2018 at 14:00
  • @robamaton I don't think you should need this script at all as ffmpeg (and all the component libraries) can be compiled for macOS using all the standard settings.
    – allenh
    Commented Jun 27, 2018 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.