47 printf(
"ptr:%p size:%zu\n", bd->
ptr, bd->
size);
50 memcpy(buf, bd->
ptr, buf_size);
57 int main(
int argc,
char *argv[])
62 size_t buffer_size, avio_ctx_buffer_size = 4096;
68 fprintf(stderr,
"usage: %s input_file\n"
69 "API example program to show how to read from a custom buffer "
70 "accessed through AVIOContext.\n", argv[0]);
73 input_filename = argv[1];
85 bd.
size = buffer_size;
92 avio_ctx_buffer =
av_malloc(avio_ctx_buffer_size);
93 if (!avio_ctx_buffer) {
103 fmt_ctx->
pb = avio_ctx;
107 fprintf(stderr,
"Could not open input\n");
113 fprintf(stderr,
"Could not find stream information\n");
129 fprintf(stderr,
"Error occurred: %s\n",
av_err2str(ret));
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static AVFormatContext * fmt_ctx
unsigned char * buffer
Start of the buffer.
static av_cold int end(AVCodecContext *avctx)
AVFormatContext * avformat_alloc_context(void)
Allocate an 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, streams, container, programs, metadata, side data, codec and time base.
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 av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
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...
Libavcodec external API header.
size_t size
size left in the buffer
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static const char * input_filename
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
AVIOContext * pb
I/O context.
int main(int argc, char *argv[])
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_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.