Adding ffmpeg to our Xcode project

前端 未结 1 1114
迷失自我
迷失自我 2021-02-01 11:01

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 wa

相关标签:
1条回答
  • 2021-02-01 11:26

    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:

    Copy the FFmpeg-iOS folder to your project:

    Add the files to your project:

    (by dragging and dropping from finder)

    With these settings:

    Add the include directory to your headers:

    Link the required libraries:

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题