2012-07-24 130 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