49 printf(
"ptr:%p size:%zu\n", bd->
ptr, bd->
size);
52 memcpy(buf, bd->
ptr, buf_size);
59 int main(
int argc,
char *argv[])
64 size_t buffer_size, avio_ctx_buffer_size = 4096;
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];
84 bd.
size = buffer_size;
91 avio_ctx_buffer =
av_malloc(avio_ctx_buffer_size);
92 if (!avio_ctx_buffer) {
102 fmt_ctx->
pb = avio_ctx;
106 fprintf(stderr,
"Could not open input\n");
112 fprintf(stderr,
"Could not find stream information\n");
128 fprintf(stderr,
"Error occurred: %s\n",
av_err2str(ret));
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.
#define AVERROR_EOF
End of file.
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...
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)
Libavcodec external API header.
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.
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.