Original Post
Hello,
I try to read a mpeg2 video from a stream with ffmpeg library. In my first tests, I tried to read from a byte buffer, but now I read directly from a file (in my ReadPacket function) in order to be sure it's right data.
I tried many way to do that, but av_open_input_stream function return always -1.
I post my code here and hope someone could help me ! If someone have a full code to do that, i''ll be happy to see it. Thanks.
And my readPacket func :
I try to read a mpeg2 video from a stream with ffmpeg library. In my first tests, I tried to read from a byte buffer, but now I read directly from a file (in my ReadPacket function) in order to be sure it's right data.
I tried many way to do that, but av_open_input_stream function return always -1.
I post my code here and hope someone could help me ! If someone have a full code to do that, i''ll be happy to see it. Thanks.
av_log_set_level(AV_LOG_VERBOSE);
avcodec_init();
av_register_all();
avcodec_register_all();
pFormatCtx = avformat_alloc_context();
if (!pFormatCtx)
{
return -1;
}
FILE* f = fopen("D:\\projets\\test_data\\video\\video_ts.mpg", "rb");
int bioBufferSize = 8000;
unsigned char *bioBuffer = (unsigned char *)av_malloc(bioBufferSize + FF_INPUT_BUFFER_PADDING_SIZE);
ByteIOContext *bioContext = new ByteIOContext();
int ret = init_put_byte(bioContext, bioBuffer, bioBufferSize, 0, (void *)f, readPackets, NULL, seekPackets);
AVFormatParameters params, *ap = ¶ms
memset(ap, 0, sizeof(*ap));
ap->prealloced_context = 1
//pFormatCtx->video_codec_id = findCodecOrDie("mpeg2video", AVMEDIA_TYPE_VIDEO, 0, avcodecOpts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
//pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
AVInputFormat *inputFormat = av_find_input_format("mpegts");
//pFormatCtx->iformat = inputFormat;
ret = av_open_input_stream(&pFormatCtx, bioContext, "stream", inputFormat, ap);
av_close_input_stream(pFormatCtx);
av_free(bioBuffer);
delete bioContext;
fclose(f);
[...]
And my readPacket func :
static int readPackets(void *opaque, uint8_t *buf, int buf_size)
{
FILE* f = (FILE *)opaque;
int read = fread(buf, 1, buf_size, f);
return read;
}