[Libav-user] custom write_packet callback not being invoked

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Libav-user] custom write_packet callback not being invoked

manoj s k
i have been trying to have a custom avio for write operations using ffmpeg/libav to write remuxed packets to a cache instead of a file or socket. read callbacks are working fine but write callback is never invoked. I followed example of 
but to no avail. My code is as shown below for write callback function:

int write_packet(void *opaque, uint8_t *buf, int buf_size) {

    cout << "in write_packet";

    outfile.open("segmentfile.ts", std::ios_base::app);

        if( !outfile ){

        cout << "Opening file failed" ;

                return 0;


        outfile << (uint8_t *)bd->buf;

    return buf_size;


and registration is via :

    avio_ctx_buffer = (uint8_t *)av_malloc(avio_ctx_buffer_size);

    if (!avio_ctx_buffer) {

        ret = AVERROR(ENOMEM);



    avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 1, &gbd, NULL, write_packet,NULL);

    if (!avio_ctx) {

        ret = AVERROR(ENOMEM);



    m_ofmt_ctx = avformat_alloc_context();

     AVOutputFormat* ofmt = av_guess_format(output_format_name.c_str(), nullptr, nullptr);

    if(!ofmt) {

        cout << "Output format not found " << output_format_name;

        return false;


    cout << "Creating all output contexts successful";

    m_ofmt_ctx->pb = avio_ctx;

    //m_ofmt_ctx->flags |= AVFMT_FLAG_CUSTOM_IO;

    m_ofmt_ctx->oformat = ofmt;

I am thinking after this registration, any time there is a write function, like av_interleaved_write_frame() , the callback must be called.But the call invocation is not happening. Is there something i need to do other than above registration to make write callback work?

I tried both having and removing "m_ofmt_ctx->flags |= AVFMT_FLAG_CUSTOM_IO;"

but neither works.


Libav-user mailing list
[hidden email]

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".