FFMpeg on iOS Swift

I am trying to learn FFMpeg in this tutorial: http://dranger.com/ffmpeg/tutorial01.html

I was hoping that just translating the C code to swift, I should run me, but I think I was wrong.

I tried to convert the following code:

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

in

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

This code breaks into: if avformat_open_input (pFormatCtx, path, nil, opaque)! = 0 {} On error EXC_BAD_ACCESS

Can anyone guess what is wrong here?

By the way, my FFMpeg library compiles without problems, so I donโ€™t think there might be a problem with the way I compiled or imported it. Iโ€™m probably mistaken, I think: / Any guesses

+4
source share
2

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

, .

+3

: http://en.swifter.tips/pointer-memory/.

, UnsafeMutablePointer allocated .

, :

let path = ...

let formatContext = UnsafeMutablePointer<UnsafeMutablePointer<AVFormatContext>>.alloc(1)

if (avformat_open_input(formatContext, path, nil, nil) != 0) {
    // TODO: Error handling
}

, formatContext.destroy().

0

Source: https://habr.com/ru/post/1627012/


All Articles