diff --git a/libmpdemux/muxer.c b/libmpdemux/muxer.c index cb3995af31..aa23cde24b 100644 --- a/libmpdemux/muxer.c +++ b/libmpdemux/muxer.c @@ -69,6 +69,34 @@ muxer_t *muxer_new_muxer(int type,stream_t *stream){ return NULL; } +off_t muxer_close(muxer_t *muxer) +{ + off_t size; + /* flush muxer just in case, this is a no-op unless + * we created a stream but never wrote frames to it... */ + muxer_flush(muxer); + if (muxer->cont_write_index) muxer_write_index(muxer); + size=stream_tell(muxer->stream); + stream_seek(muxer->stream,0); + if (muxer->cont_write_header) muxer_write_header(muxer); // update header + return size; +} + +void muxer_free(muxer_t *muxer) +{ + int num; + for (num = 0; muxer->streams[num]; ++num) { + free(muxer->streams[num]->priv); + muxer->streams[num]->priv = NULL; + free(muxer->streams[num]); + muxer->streams[num] = NULL; + } + free(muxer->idx); + muxer->idx = NULL; + muxer->idx_size = 0; + free(muxer); +} + /* Flush the internal muxer buffer. * This is normally called from muxer_write_chunk() once all streams * have seen frames. */ diff --git a/libmpdemux/muxer.h b/libmpdemux/muxer.h index b6eeffe3b0..a53b951db9 100644 --- a/libmpdemux/muxer.h +++ b/libmpdemux/muxer.h @@ -133,6 +133,8 @@ extern const m_option_t mpegopts_conf[]; extern const m_option_t nuvopts_conf[]; muxer_t *muxer_new_muxer(int type,stream_t *stream); +off_t muxer_close(muxer_t *muxer); +void muxer_free(muxer_t *muxer); void muxer_flush(muxer_t *m); #define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a) #define muxer_stream_fix_parameters(muxer, a) muxer->fix_stream_parameters(a) diff --git a/mencoder.c b/mencoder.c index 9664846c3d..e522d45c14 100644 --- a/mencoder.c +++ b/mencoder.c @@ -1699,13 +1699,7 @@ if(aencoder) if(aencoder->fixup) aencoder->fixup(aencoder); -/* flush muxer just in case, this is a no-op unless - * we created a stream but never wrote frames to it... */ -muxer_flush(muxer); -if (muxer->cont_write_index) muxer_write_index(muxer); -muxer_f_size=stream_tell(muxer->stream); -stream_seek(muxer->stream,0); -if (muxer->cont_write_header) muxer_write_header(muxer); // update header +muxer_f_size=muxer_close(muxer); #if 0 if(ferror(muxer_f) || fclose(muxer_f) != 0) { mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile, out_filename); @@ -1730,6 +1724,9 @@ if(sh_audio) mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_AudioStreamResult, (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), (uint64_t)mux_a->size, (float)mux_a->timer); +muxer_free(muxer); +muxer=NULL; +mux_v=mux_a=NULL; m_config_free(mconfig); m_entry_list_free(filelist); if(sh_audio){ uninit_audio(sh_audio);sh_audio=NULL; }