[Libav-user] develop a stream in and stream out application using custom IO context

nitin mittal nitinmittal84 at gmail.com
Wed Apr 17 09:25:31 CEST 2013

Hi ,
       I am trying to develop a application which reads from a buffer,
transforms into different format and writes into a different buffer. I am
trying to use the custom IO context. my code for writing into stream is as

    filename = "output_file.flv";
    fmt = av_guess_format("flv", filename, NULL);

    // allocate the output media context
    oc = avformat_alloc_context();
    unsigned char *buffer = (unsigned char *)av_malloc(bsize);
    FILE *fr = fopen(filename,"w");
    pb2 = avio_alloc_context(buffer, bsize, 1, fr, NULL, write_packet2,

    oc->pb = pb2;
    pb2->write_flag =1;
    oc->flags = AVFMT_FLAG_CUSTOM_IO;

    oc->oformat = fmt;
    if((avformat_open_input(&oc,0, 0, 0)) != 0)
        printf("format could not open input");

my write packet function:
int write_packet2(void *opaque, uint8_t *buf, int buf_size)
  FILE* f= (FILE *)opaque;
  return fwrite(buf,1, buf_size,f);

This gets stuck in avformat_open_input function and never comes out of it.
So please tell what is the problem. Or if there is some sample code for
similar work.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130417/36655a10/attachment.html>

More information about the Libav-user mailing list