From f0deafd72226984b3490d75616d7514b3f65c2f8 Mon Sep 17 00:00:00 2001 From: "Weiwei.Zhou" Date: Thu, 10 Oct 2019 13:37:56 +0800 Subject: [PATCH] =?UTF-8?q?mp4=E5=BD=95=E5=88=B6=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E6=98=AF=E5=90=A6=E8=BF=9B=E8=A1=8C=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=B8=A7=E7=B4=A2=E5=BC=95=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=A4=B4=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 2 ++ src/Common/config.cpp | 4 ++++ src/Common/config.h | 2 ++ src/Http/HttpSession.cpp | 4 +--- src/MediaFile/MP4Muxer.cpp | 21 +++++++-------------- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 2b2081e8..3507a45d 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -117,6 +117,8 @@ fileSecond=3600 #mp4点播每次流化数据量,单位毫秒, #减少该值可以让点播数据发送量更平滑,增大该值则更节省cpu资源 sampleMS=100 +#mp4录制完成后是否进行二次关键帧索引写入头部 +fastStart=0 #MP4点播(rtsp/rtmp/http-flv/ws-flv)是否循环播放文件 fileRepeat=0 diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 49f43e7b..5f15e24d 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -271,6 +271,9 @@ const string kFilePath = RECORD_FIELD"filePath"; //mp4文件写缓存大小 const string kFileBufSize = RECORD_FIELD"fileBufSize"; +//mp4录制完成后是否进行二次关键帧索引写入头部 +const string kFastStart = RECORD_FIELD"fastStart"; + //mp4文件是否重头循环读取 const string kFileRepeat = RECORD_FIELD"fileRepeat"; @@ -280,6 +283,7 @@ onceToken token([](){ mINI::Instance()[kFileSecond] = RECORD_FILE_SECOND; mINI::Instance()[kFilePath] = RECORD_FILE_PATH; mINI::Instance()[kFileBufSize] = 64 * 1024; + mINI::Instance()[kFastStart] = false; mINI::Instance()[kFileRepeat] = false; },nullptr); diff --git a/src/Common/config.h b/src/Common/config.h index 31a27d2d..0cf7e34b 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -270,6 +270,8 @@ extern const string kFileSecond; extern const string kFilePath; //mp4文件写缓存大小 extern const string kFileBufSize; +//mp4录制完成后是否进行二次关键帧索引写入头部 +extern const string kFastStart; //mp4文件是否重头循环读取 extern const string kFileRepeat; } //namespace Record diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index b1c124d9..02283d04 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -584,6 +584,7 @@ void HttpSession::Handle_Req_GET(int64_t &content_len) { if (iRangeEnd == 0) { iRangeEnd = tFileStat.st_size - 1; } + auto httpHeader = makeHttpHeader(bClose, iRangeEnd - iRangeStart + 1, get_mime_type(strFile.data())); const char *pcHttpResult = NULL; if (strRange.size() == 0) { //全部下载 @@ -592,9 +593,6 @@ void HttpSession::Handle_Req_GET(int64_t &content_len) { //分节下载 pcHttpResult = "206 Partial Content"; fseek(pFilePtr.get(), iRangeStart, SEEK_SET); - } - auto httpHeader = makeHttpHeader(bClose, iRangeEnd - iRangeStart + 1, get_mime_type(strFile.data())); - if (strRange.size() != 0) { //分节下载返回Content-Range头 httpHeader.emplace("Content-Range",StrPrinter<<"bytes " << iRangeStart << "-" << iRangeEnd << "/" << tFileStat.st_size<< endl); } diff --git a/src/MediaFile/MP4Muxer.cpp b/src/MediaFile/MP4Muxer.cpp index a8a38ab4..c1b5bad3 100644 --- a/src/MediaFile/MP4Muxer.cpp +++ b/src/MediaFile/MP4Muxer.cpp @@ -33,11 +33,11 @@ namespace mediakit{ #if defined(_WIN32) || defined(_WIN64) -#define fseek64 _fseeki64 -#define ftell64 _ftelli64 + #define fseek64 _fseeki64 + #define ftell64 _ftelli64 #else -#define fseek64 fseek -#define ftell64 ftell + #define fseek64 fseek + #define ftell64 ftell #endif void MP4MuxerBase::init(int flags) { @@ -236,7 +236,9 @@ MP4MuxerFile::MP4MuxerFile(const char *file) { fclose(fp); }); - init(MOV_FLAG_FASTSTART); + GET_CONFIG(bool, mp4FastStart, Record::kFastStart); + + init(mp4FastStart ? MOV_FLAG_FASTSTART : 0); } MP4MuxerFile::~MP4MuxerFile() { @@ -254,15 +256,6 @@ int MP4MuxerFile::onWrite(const void *data, uint64_t bytes) { return bytes == fwrite(data, 1, bytes, _file.get()) ? 0 : ferror(_file.get()); } - -#if defined(_WIN32) || defined(_WIN64) - #define fseek64 _fseeki64 - #define ftell64 _ftelli64 -#else - #define fseek64 fseek - #define ftell64 ftell -#endif - int MP4MuxerFile::onSeek(uint64_t offset) { return fseek64(_file.get(), offset, SEEK_SET); }