<div dir="ltr">Hi ,<div style> 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 follows:</div>
<div style><br></div><div style><div> filename = "output_file.flv";</div><div> fmt = av_guess_format("flv", filename, NULL);</div><div> </div><div> // allocate the output media context</div>
<div>
oc = avformat_alloc_context();</div><div> unsigned char *buffer = (unsigned char *)av_malloc(bsize);</div><div> FILE *fr = fopen(filename,"w");</div><div> pb2 = avio_alloc_context(buffer, bsize, 1, fr, NULL, write_packet2, NULL);</div>
<div> </div><div> oc->pb = pb2;</div><div> pb2->write_flag =1;</div><div> oc->flags = AVFMT_FLAG_CUSTOM_IO;</div><div><br></div><div> oc->oformat = fmt;</div><div> if((avformat_open_input(&oc,0, 0, 0)) != 0)</div>
<div> {</div><div> printf("format could not open input");</div><div> exit(0);</div><div> }</div><div>.</div><div>.</div><div>.</div><div><br></div><div style>my write packet function:</div>
<div style><div>int write_packet2(void *opaque, uint8_t *buf, int buf_size)</div><div>{</div><div> FILE* f= (FILE *)opaque;</div><div> return fwrite(buf,1, buf_size,f);</div><div>}</div><div><br></div><div style>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.</div>
<div style><br></div><div style>Regards,</div><div style>Nitin</div></div></div></div>