42static int read_packet(
void *opaque, uint8_t *buf,
int buf_size)
49 printf(
"ptr:%p size:%zu\n", bd->
ptr, bd->
size);
52 memcpy(buf, bd->
ptr, buf_size);
59int main(
int argc,
char *argv[])
63 uint8_t *buffer = NULL, *avio_ctx_buffer = NULL;
64 size_t buffer_size, avio_ctx_buffer_size = 4096;
65 char *input_filename = NULL;
70 fprintf(stderr,
"usage: %s input_file\n"
71 "API example program to show how to read from a custom buffer "
72 "accessed through AVIOContext.\n", argv[0]);
75 input_filename = argv[1];
78 ret =
av_file_map(input_filename, &buffer, &buffer_size, 0, NULL);
84 bd.
size = buffer_size;
91 avio_ctx_buffer =
av_malloc(avio_ctx_buffer_size);
92 if (!avio_ctx_buffer) {
106 fprintf(stderr,
"Could not open input\n");
112 fprintf(stderr,
"Could not find stream information\n");
129 fprintf(stderr,
"Error occurred: %s\n",
av_err2str(ret));
Libavcodec external API header.
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
int main(int argc, char *argv[])
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static AVFormatContext * fmt_ctx
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
av_warn_unused_result int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_freep(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
void * av_malloc(size_t size) av_malloc_attrib
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVIOContext * pb
I/O context.
unsigned char * buffer
Start of the buffer.
size_t size
size left in the buffer