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??
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With