只贴出部分代码,重在说明过程。
与解码文件的大致过程类似,只不过自定义了AVFormatContext
struct IOData
{
char* data;
size_t len;
};
int FrVideoAcqHT::io_get_data(void *opaque, uint8_t *buf, int buf_size)
{
FrVideoAcqHT* acq = (FrVideoAcqHT*)opaque;
//以下为通过缓冲区读文件解码方式
/*if (!feof(acq->f))
{
int true_size = fread(buf, 1, 1024, acq->f);
printf("read:%d\n", true_size);
return true_size;
}
else
{
printf("read failed\n");
return -1;
}*/
//不断读取数据
while (true)
{
IOData data;
if (acq->data_queue.Pop(data))
{
memcpy(buf, data.data, data.len);
return data.len;
}
else
{
Sleep(1000);
}
}
}
av_register_all();
AVFormatContext* fctx = avformat_alloc_context();
av_buf = av_malloc(AV_IO_BUF_LEN);
avio =