2012-07-24 133 views
0

调用C方法对于以下代码返回(不建立ARC)应的属性归因作为保留,如果是从由参考

中.H

@interface VideoFrameExtractor : NSObject { 
AVFormatContext *pFormatCtx; 
AVCodecContext *pCodecCtx; 
} 

在.M

int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 
         AVInputFormat *fmt, 
         int buf_size, 
         AVFormatParameters *ap); 

    // Open video file 
    if(av_open_input_file(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, 0, NULL)!=0) 
     goto initError; // Couldn't open file 

    // Retrieve stream information 
    if(av_find_stream_info(pFormatCtx)<0) 
     goto initError; // Couldn't find stream information 

我们应该将pFormatCtx属性的属性设置为保留还是其他?问这个问题的原因是我们在引用av_find_stream_info调用中的属性时遇到了EXC_BAD_ACCESS错误。

+0

是来自ffmpeg的av_open_input_file和av_find_stream_info? – sergio 2012-07-24 07:55:48

+0

是的,只需使用llvm-gcc构建ffmpeg,然后尝试在iPhone模拟器上运行iFrameExtractor应用程序(使用ffmpeg)。立即出现问题 – tom 2012-07-24 08:02:05

回答

0

我们应该将pFormatCtx属性的属性设置为强还是其他?

av_open_input_file不是Objective C方法,它直接在ARC之外分配内存,没有任何引用计数。所以你绝对不需要通过强大的属性来处理这些引用。

你一定要在av_find_stream_info的方式寻找它可能会失败。

其实,我看到的是,你应该遵循一些步骤正确设置你的图书馆工作:

AVFormatContext* pFormatCtx = avformat_alloc_context(); 
avformat_open_input(&pFormatCtx, filename, NULL, NULL); 
int64_t duration = pFormatCtx->duration; 
// etc 
avformat_free_context(pFormatCtx); 

在任何情况下,检查文档,也看看this tutorial

+0

这很好。 S.O的帖子使用了示例代码片段中的std库。我该怎么做那个没有标准的图书馆? – tom 2012-07-24 08:10:59

+0

实际上,这篇文章提到了一个不同的场景(从内存中读取数据而不是磁盘),所以我删除了它的参考。这也解释了流和std的使用,但这绝对不是必需的。我现在给我的答案添加一些更多的提示... – sergio 2012-07-24 08:15:25

+0

我添加了行来执行avformat_alloc_context,但它仍然遇到了EXC_BAD_ACCESS错误。它可能是内存对齐问题? EXC_BAD_ACCESS的意思是说,当由av_find_stream_info调用时,pFormatCtx已被垃圾/释放。想知道为什么? – tom 2012-07-24 16:22:13