I have a valid mp4 file which I can open and work with using "av_open_input_file", I would like to be able to use the "av_open_input_stream" on the same file. I have the following code which produces an error code of -1 from the "av_open_input_stream(...) function.

I would really really like to get this working as it has been frustrating me for a long time! If someone could at least point me in the right direction that would be amazing. Sorry if code posts are not allowed but I could see no other way of describing the problem.

Thanks,
Mark.


int read_data(void *opaque, uint8_t *buf, int buf_size)
{
   // first read from file, until ffmpeg works
   // (later try to receive data from network)
   FILE * fp = (FILE *) opaque;
   if (!fp)
   {
       return -1;
   }

   int cnt = fread(buf, sizeof(uint8_t), buf_size, fp);
   return cnt;
}

int Reader()
{
   char* fileName = "mpeg4test.mp4";

   AVFormatContext *pFormatCtx;
   int i, videoStream;
   AVCodecContext *pCodecCtx;
   AVCodec *pCodec;
   AVFrame *pFrame;
   AVPacket packet;
   int frameFinished;
   int buffer_current_pos;

   FILE * fp = fopen(fileName, "r");

   // Register all formats and codecs
   av_register_all();

   uint8_t pDataBuffer[32768];
   long lSize = 32768;

   read_data(fp, pDataBuffer, lSize);

   AVProbeData pd;
   pd.buf = pDataBuffer;
   pd.buf_size = lSize;
   pd.filename = "";

   AVInputFormat* pAVInputFormat = av_probe_input_format(&pd, 1);
   if(!pAVInputFormat)
   {
       return false;
   }
   pAVInputFormat->flags |= AVFMT_NOFILE;

   ByteIOContext ByteIOCtx;
if(init_put_byte(&ByteIOCtx, pDataBuffer, lSize, 0, fp, read_data, NULL, NULL) < 0)
   {
       return false;
   }

int err = av_open_input_stream(&pFormatCtx, &ByteIOCtx, "", pAVInputFormat, NULL);
   if(err < 0)
   {

etc...etc...
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to