iOS Swift上的FFMpeg(FFMpeg on iOS Swift)

编程入门 行业动态 更新时间:2024-10-26 22:29:11
iOS Swift上的FFMpeg(FFMpeg on iOS Swift)

我正在尝试通过本教程学习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.

更多推荐

本文发布于:2023-08-07 12:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   Swift   FFMpeg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!