ffmpeg從內存讀取文件


正常情況,ffmpeg直接從文件讀取

AVFormatContext * _ctx = NULL;
avformat_open_input(&_ctx, _filePath, 0, 0);

 我們也可以自定義從內存讀取,這樣,可以用於讀取一些加密的視頻文件

    int fill_iobuffer(void * opaque,uint8_t *buf, int bufsize){  
        if(!feof(fp_open)){  
            int true_size=fread(buf,1,bufsize,fp_open);  
            return true_size;  
        }else{  
            return -1;  
        }  
    }



AVFormatContext * _ctx = NULL;
unsigned char* _iobuffer = (unsigned char*)av_malloc(32768);
AVIOContext* _avio = avio_alloc_context(_iobuffer , 32768 , 0 , NULL,fill_iobuffer,NULL,NULL);
_ctx->pb = _avio;

fp_open=fopen(_filename,"rb+");  

if ((ret = avformat_open_input(&_ctx, "nothing", 0, 0)) < 0) {
	printf( "Could not open input file.");
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM