Commit bdb28c53 by xiongziliang

重命名前确保关闭mp4文件:#416

parent c507e8a7
......@@ -93,6 +93,7 @@ void MP4File::openFile(const char *file,const char *mode) {
//创建智能指针
_file.reset(fp,[file_buf](FILE *fp) {
fflush(fp);
fclose(fp);
});
}
......
......@@ -25,6 +25,8 @@ namespace mediakit{
class MP4Muxer : public MediaSinkInterface, public MP4File{
public:
typedef std::shared_ptr<MP4Muxer> Ptr;
MP4Muxer(const char *file);
~MP4Muxer() override;
......@@ -42,9 +44,13 @@ public:
*/
void resetTracks() override ;
/**
* 手动关闭文件(对象析构时会自动关闭)
*/
void closeMP4();
private:
void openMP4();
void closeMP4();
void stampSync();
private:
......
......@@ -75,7 +75,7 @@ void MP4Recorder::asyncClose() {
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
const_cast<MP4Info&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
//关闭mp4非常耗时,所以要放在后台线程执行
const_cast<MP4Muxer::Ptr &>(muxer).reset();
muxer->closeMP4();
//临时文件名改成正式文件名,防止mp4未完成时被访问
rename(strFileTmp.data(),strFile.data());
//获取文件大小
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论