Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding ffmpeg to our Xcode project

Tags:

xcode

ios

ffmpeg

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.

like image 345
Saranjith Avatar asked Aug 10 '17 12:08

Saranjith


1 Answers

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
    }
}
like image 61
allenh Avatar answered Nov 08 '22 11:11

allenh