ffmpeg 0.6.1 crashes closing file (sometimes)
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
Unfortunately, this bug cannot be replicated by everyone. Also, unfortunately, I can. An e-mail to Dave describing the reason for the crash and a possible solution is as follows:
In file VTK/IO/vtkFFMPEGWriter.cxx, in function vtkFFMPEGWriterInternal::End(), you really do two things. First, you are trying to clean up memory. Second, you are telling the ffmpeg libraries to finish the file (av_write_trailer). However, you are deleting memory that the ffmpeg library then tries to delete. Thus, my seg fault. So, the following lines delete the avStream (which is held as priv_data in avFormatContext):
if (this->avStream) { av_free(this->avStream); this->avStream = 0; }
Then, you tell ffmpeg to finish the file off and delete the avStream (which it holds as avFormatContext->channel[0].priv_data) here(I think I got that variable name correct): av_write_trailer(this->avFormatContext);
I have inverted these two sets of code as follows, and it gets rid of my crash. (I wonder why yours even worked…) if (this->avFormatContext) { if (this->openedFile) { av_write_trailer(this->avFormatContext); #ifdef VTK_FFMPEG_OLD_URL_FCLOSE url_fclose(&this->avFormatContext->pb); #else url_fclose(this->avFormatContext->pb); #endif this->openedFile = 0; }
av_free(this->avFormatContext);
this->avFormatContext = 0;
}
if (this->avStream) { av_free(this->avStream); this->avStream = 0; }
Please let me know if you agree and will fix the code as outlined, or if I need to look further.
Thanks,
Alan