iOS Swift上的FFMpeg

Ume*_*sam 5 ffmpeg ios swift xcode7

我正在尝试通过本教程学习FFMpeg:http://dranger.com/ffmpeg/tutorial01.html

我希望只是将C代码翻译成swift应该能让我开始运行,但我想我错了

我尝试转换以下代码:

AVFormatContext *pFormatCtx = NULL;
// Open video file
if(avformat_open_input(&pFormatCtx, argv[1], NULL, 0, NULL)!=0) {}
Run Code Online (Sandbox Code Playgroud)

至:

let pFormatCtx : UnsafeMutablePointer<UnsafeMutablePointer<AVFormatContext>> = nil
// Open video file
if avformat_open_input(pFormatCtx, path, nil, opaque) != 0 {}
Run Code Online (Sandbox Code Playgroud)

此代码中断:if avformat_open_input(pFormatCtx,path,nil,opaque)!= 0 {}出现EXC_BAD_ACCESS错误

任何人都可以猜到这里有什么不对吗?

顺便说一句,我有FFMpeg库编译没有问题所以我不认为我编译或导入它的方式可能有问题.我认为我可能传递错误的论点:/任何猜测?

Ume*_*sam 3

首先,我使用 Swift 2 和 xCode 7.2 ...

解决方案是将格式上下文创建为“UnsafeMutablePointer< AVFormatContext >”,然后通过avformat_open_input方法传递其地址。这是对我有用的代码:

var formatContext = UnsafeMutablePointer<AVFormatContext>()

if avformat_open_input(&formatContext, path, nil, nil) != 0 {
    print("Couldn't open file")
    return
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。