我正在尝试通过本教程学习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) {}至:
let pFormatCtx : UnsafeMutablePointer<UnsafeMutablePointer<AVFormatContext>> = nil // Open video file if avformat_open_input(pFormatCtx, path, nil, opaque) != 0 {}此代码断开: if avformat_open_input(pFormatCtx,path,nil,opaque)!= 0 {}出现EXC_BAD_ACCESS错误
谁能猜到这里有什么不对?
顺便说一句,我有FFMpeg库编译没有问题所以我不认为我编译或导入它的方式可能存在问题。 我想可能会传递错误的参数:/任何猜测?
I'm trying to learn FFMpeg through this tutorial: http://dranger.com/ffmpeg/tutorial01.html
I was hoping that just translating the C code to swift should get me up and running but I guess I was mistaken
I tried converting the following code:
AVFormatContext *pFormatCtx = NULL; // Open video file if(avformat_open_input(&pFormatCtx, argv[1], NULL, 0, NULL)!=0) {}to:
let pFormatCtx : UnsafeMutablePointer<UnsafeMutablePointer<AVFormatContext>> = nil // Open video file if avformat_open_input(pFormatCtx, path, nil, opaque) != 0 {}This code breaks at: if avformat_open_input(pFormatCtx, path, nil, opaque) != 0 {} With an EXC_BAD_ACCESS error
can anyone guess whats wrong here??
By the way I have the FFMpeg library compiling without an issue so I don't think there might be an issue with the way I compiled or imported it. I'm probably passing wrong arguments I think :/ Any guesses??
最满意答案
首先,我使用Swift 2和xCode 7.2 ......
解决方案是将Context格式创建为“UnsafeMutablePointer <AVFormatContext>” ,然后通过avformat_open_input方法传递其地址。 这是适合我的代码:
var formatContext = UnsafeMutablePointer<AVFormatContext>() if avformat_open_input(&formatContext, path, nil, nil) != 0 { print("Couldn't open file") return }希望这可以帮助。
First off I'm using Swift 2 with xCode 7.2 ...
The solution was to create the format Context as an "UnsafeMutablePointer< AVFormatContext >" and then pass its address through the avformat_open_input method. Here's the code that worked for me:
var formatContext = UnsafeMutablePointer<AVFormatContext>() if avformat_open_input(&formatContext, path, nil, nil) != 0 { print("Couldn't open file") return }Hope this helps.
更多推荐
发布评论