[FFmpeg-user] cannot get custom IO to work.
PeterTaps
ptrtap at yahoo.com
Wed Dec 7 11:33:43 CET 2011
Folks,
I am trying to create a custom input stream. However, avformat_open_input
fails will a random error value. I would appreciate it if someone can tell
me what is it that I am doing wrong. Here is the simplified code.
Thank you in advance for your help.
Regards,
Peter
#define BUFSIZE (4 * 1024)
static int ReadPacket(void* opaque, uint8_t* buf, int bufsize) {
FILE* file = (FILE*) opaque;
int len = ::fread(buf, 1, bufsize, file);
return len;
}
int main(int argc, char* argv[]) {
av_register_all();
// av_log_set_level(AV_LOG_DEBUG);
const char* fileName = "/home/peter/sample_mpeg4.mp4";
FILE* file = fopen(fileName, "rb");
unsigned char* buffer = (unsigned char*) av_malloc(BUFSIZE);
AVIOContext* avContext = avio_alloc_context(buffer, BUFSIZE, 1, file,
ReadPacket, NULL, NULL);
AVFormatContext* pFormatCtx = avformat_alloc_context();
pFormatCtx->pb = avContext;
int val = avformat_open_input(&pFormatCtx, fileName, NULL, NULL);
if (val != 0) {
printf("Open input failed. Err: %d\n", val);
pFormatCtx = 0; // it is already freed
av_free(avContext);
av_free(buffer);
fclose(file);
return -1;
}
--
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/cannot-get-custom-IO-to-work-tp4168480p4168480.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.
More information about the ffmpeg-user
mailing list