[FFmpeg-trac] #520(avformat:new): Issue with using multiple avio_open_dyn_buf() / avio_close_dyn_buf()

FFmpeg trac at avcodec.org
Thu Sep 29 23:00:23 CEST 2011


#520: Issue with using multiple avio_open_dyn_buf() / avio_close_dyn_buf()
----------------------------------+-------------------------------------
             Reporter:  env01     |                     Type:  defect
               Status:  new       |                 Priority:  important
            Component:  avformat  |                  Version:  0.8.4
             Keywords:            |               Blocked By:
             Blocking:            |  Reproduced by developer:  0
Analyzed by developer:  0         |
----------------------------------+-------------------------------------
 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.  Using avio_open_dyn_buf() and
 avio_close_dyn_buf() I am able get the buffer.

 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.


     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);

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/520>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list