将 ffmpeg 添加到我们的 Xcode 项目中 [英] Adding ffmpeg to our Xcode project

查看:23
本文介绍了将 ffmpeg 添加到我们的 Xcode 项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编译了 ffmpeg 库,它在我的文件夹中成功创建了许多文件.

现在我需要在我的 Xcode 项目中实现相同的功能.添加到我的项目的最佳方式是什么.

我想创建一个框架,但我需要添加哪些文件?

编译后我有很多 .c 文件和 .a 文件可用.

解决方案

过去我已经成功使用了

将 FFmpeg-iOS 文件夹复制到您的项目中:

将文件添加到您的项目中:

(通过从 finder 拖放)

使用这些设置:

将包含目录添加到您的标题中:

链接所需的库:

将标头添加到桥接头(仅限 Swift):

#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 简单示例:

#import "AppDelegate.h";#import "libavformat/avformat.h";@interface AppDelegate()@结尾@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {AVFormatContext *context = avformat_alloc_context();返回是;}@结尾

在 Swift 中:

导入 UIKit@UIApplicationMain类 AppDelegate: UIResponder, UIApplicationDelegate {变量窗口:UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) ->布尔{让上下文 = avformat_alloc_context()返回真}}

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.

解决方案

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
    }
}

这篇关于将 ffmpeg 添加到我们的 Xcode 项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆