I've been referencing
this article about how to create a custom IO-Context with FFmpeg, but he invoked the use of an IStream interface. I am simply just trying to use an std::ifstream object in order to create the Context and proceed with opening it in the
avformat_open_input()
function.
What I have tried:
Essentially what I have tried so far is close to what the user has done but I still find myself struggling with a lot of issues. I created the following typedef struct and functions below in order to run it but I have experienced a lot of errors and issues that I'm just unsure how to resolve. If anyone could take a look at this and show me what I need to correct or if there's an easier way to do this I'd truly appreciate it. Thanks.
typedef struct struct_stream
{
std::ifstream audio_stream;
}Stream;
Stream * audio_file = NULL;
(audio_file)->audio_stream(filename, std::ifstream::in);
unsigned char *buffer = (unsigned char *)av_malloc(3000);
AVIOContext *avio_ctx = NULL;
avio_ctx = avio_alloc_context(buffer, 3000, 0, audio_file, ReadFunc, NULL, SeekFunc);
AVFormatContext* pCtx = avformat_alloc_context();
pCtx->pb = pIOCtx;
int ret = avformat_open_input(&pCtx, "", NULL, NULL);
int ReadFunc(void* ptr, uint8_t* buf, int buf_size)
{
Stream* pStream = reinterpret_cast<Stream*>(ptr);
(pStream->audio_stream).read(buf, sizeof buf);
std::streamsize bytes = (pStream->audio_stream).gcount();
return (int) bytes;
}
int64_t SeekFunc(void* ptr, int64_t pos, int whence)
{
<a href="https://www.cplusplus.com/reference/istream/istream/seekg">resource</a>
}
If anyone happens to know how to perform this with an std::ifstream object or know what I can do to fix my program I'd really appreciate it. Thank you!