[Libav-user] Multiple avio_open_dyn_buf() / avio_close_dyn_buf() paired issue

env01 Hoang.Nguyen at envisioninc.com
Tue Sep 27 22:54:15 CEST 2011


I have a system requirement for building an ffmpeg wrapper library that takes
both audio and images as inputs and output an mp4 video buffer as output. 
The inputs are of unknown length since they are being captured in real time
and could be going for hours.  I have included below test code fragment that
is working since I am able to play the output as an mp4 file.

However, it is not a practical solution since it would require a huge amount
of memory especially when there are multiple users with hour’s long
recordings.  So I tried reducing the amount of dynamic memory being used by
doing multiple avio_open_dyn_buf() / avio_close_dyn_bufz() paired.  That
appears to corrupt my output as I am no longer able to play the output as an
mp4 file.  Any suggestions?


    ofstream ostream;
    uint8_t *tmp = NULL;

    ostream.open(filename, ios::out | ios::binary);

    if(avio_open_dyn_buf(&fmtCtx->pb) != 0) {
        cout << "ERROR: Unable to open dynamic buffer" << endl;
        exit(1);
    }

    avformat_write_header(fmtCtx, NULL);

    /*
     * multiple close/open of the dynamic buffer is causing            
     * an issue with the playback.   Why?
     *            
    int size2 = avio_close_dyn_buf(fmtCtx->pb, &tmp);            
    ostream.write((char*)tmp, size2);            
    av_free(tmp);            

    if(avio_open_dyn_buf(&fmtCtx->pb) != 0) {            
      cout << "ERROR: Unable to open dynamic buffer" << endl;            
      exit(1);            
    }
    */

    for(int i=0; i < numOfImages; ++i) {
        WriteVideoFrame(fmtCtx, vidStream, vid);
        WriteAudioFrame(fmtCtx, audStream, aud);
    }

    av_write_trailer(fmtCtx);

    CloseVideo(fmtCtx, vidStream);
    CloseAudio(fmtCtx, audStream);

    for(int i = 0; i < fmtCtx->nb_streams; i++) {
        av_freep(&fmtCtx->streams[i]->codec);
        av_freep(&fmtCtx->streams[i]);
    }

    int size1 = avio_close_dyn_buf(fmtCtx->pb, &tmp);
    ostream.write((char*)tmp, size1);
    av_free(tmp);

    av_free(fmtCtx);


--
View this message in context: http://libav-users.943685.n4.nabble.com/Multiple-avio-open-dyn-buf-avio-close-dyn-buf-paired-issue-tp3849089p3849089.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list