音视频开发_AVIO 自定 IO 内存输入模式
最近更新:2024-09-23
|
字数总计:127
|
阅读估时:1分钟
|
阅读量:次
- AVIO自定IO内存输入模式
- 自定义IO模式
- 与AVFormatContext进行关联
AVIO自定IO内存输入模式
自定义IO模式
1 2 3 4 5 6 7 8 9 10 11
| static int my_read_packet(void *opaque, uint8_t* buf, int buf_size) { FILE *in_file = (FILE*)opaque; int read_size = fread(buf, 1, buf_size, in_file); printf("my_read_packet read_size:%d, buf_size:%d\n", read_size, buf_size); if(read_size <=0) { return AVERROR_EOF; } return read_size; }
|
与AVFormatContext进行关联
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| FILE *in_file = NULL; in_file = fopen(in_file_name, "rb"); if(!in_file){return;}
uint8_t *io_buffer = av_malloc(BUF_SIZE); AVIOContext *avio_ctx = avio_alloc_context(io_buffer, BUF_SIZE, 0, (void*)in_file, my_read_packet, NULL, NULL); AVFormatContext *format_ctx = avformat_alloc_context(); format_ctx->pb = avio_ctx; int ret = avformat_open_input(&format_ctx, NULL, NULL, NULL); if(ret<0){return;}
fclose(in_file); av_free(io_buffer); avformat_close_input(&format_ctx);
|
2023-08-09
该篇文章被 Cleofwine
归为分类:
音视频