Skip to content

Commit

Permalink
mp4boxでのmux時、in-place editingを行わないようにしてmuxを高速化。
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed May 4, 2023
1 parent 9b07066 commit 053f660
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Amatsukaze/Muxer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class AMTMuxder : public AMTObject {
}
}

tstring tmpOutPath = setting_.getVfrTmpFilePath(key, muxFormat);
const tstring tmpOut1Path = setting_.getVfrTmpFile1Path(key, muxFormat);
const tstring tmpOut2Path = setting_.getVfrTmpFile2Path(key, muxFormat);

tstring metaFile;
if (muxFormat == FORMAT_M2TS || muxFormat == FORMAT_TS) {
Expand Down Expand Up @@ -240,7 +241,7 @@ class AMTMuxder : public AMTObject {
setting_.getTimelineEditorPath(), setting_.getMp4BoxPath(),
encVideoFile, encoderOutputInContainer(setting_.getEncoder(), muxFormat),
vfmt, audioFiles,
outPath, tmpOutPath, chapterFile,
outPath, tmpOut1Path, tmpOut2Path, chapterFile,
fileOut.timecode, timebase, subsFiles, subsTitles, metaFile);

for (int i = 0; i < (int)args.size(); ++i) {
Expand Down Expand Up @@ -301,7 +302,7 @@ class AMTSimpleMuxder : public AMTObject {
setting_.getMuxerPath(), setting_.getTimelineEditorPath(), setting_.getMp4BoxPath(),
encVideoFile, encoderOutputInContainer(setting_.getEncoder(), setting_.getFormat()),
videoFormat, audioFiles, outFilePath,
tstring(), tstring(), tstring(), std::pair<int, int>(),
tstring(), tstring(), tstring(), tstring(), std::pair<int, int>(),
std::vector<tstring>(), std::vector<tstring>(), tstring());
ctx.info("[Mux開始]");
ctx.infoF("%s", args[0].first);
Expand Down
21 changes: 15 additions & 6 deletions Amatsukaze/TranscodeSetting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ static std::vector<std::pair<tstring, bool>> makeMuxerArgs(
const VideoFormat& videoFormat,
const std::vector<tstring>& inAudios,
const tstring& outpath,
const tstring& tmpoutpath,
const tstring& tmpout1path,
const tstring& tmpout2path,
const tstring& chapterpath,
const tstring& timecodepath,
std::pair<int, int> timebase,
Expand All @@ -330,7 +331,7 @@ static std::vector<std::pair<tstring, bool>> makeMuxerArgs(
bool needTimecode = (timecodepath.size() > 0);
bool needSubs = (inSubs.size() > 0);

tstring dst = needTimecode ? tmpoutpath : outpath;
tstring dst = (needTimecode || needChapter || needSubs) ? tmpout1path : outpath;
#if 0
// まずはmuxerで映像、音声、チャプターをmux
if (videoFormat.fixedFrameRate) {
Expand Down Expand Up @@ -384,22 +385,25 @@ static std::vector<std::pair<tstring, bool>> makeMuxerArgs(
sb.clear();

if (needTimecode) {
tstring timelineeditorout = (needChapter || needSubs) ? tmpout2path : outpath;
// 必要ならtimelineeditorでtimecodeを埋め込む
sb.append(_T("\"%s\""), timelineeditorpath)
.append(_T(" --track 1"))
.append(_T(" --timecode \"%s\""), timecodepath)
.append(_T(" --media-timescale %d"), timebase.first)
.append(_T(" --media-timebase %d"), timebase.second)
.append(_T(" \"%s\""), dst)
.append(_T(" \"%s\""), outpath);
.append(_T(" \"%s\""), timelineeditorout);
ret.push_back(std::make_pair(sb.str(), false));
sb.clear();
needTimecode = false;
dst = timelineeditorout;
}

if (needChapter || needSubs) {
// 字幕とチャプターを埋め込む
sb.append(_T("\"%s\" -brand mp42 -ab mp41 -ab iso2"), mp4boxpath);
sb.append(_T(" -add \"%s\""), dst);
for (int i = 0; i < (int)inSubs.size(); ++i) {
if (subsTitles[i] == _T("SRT")) { // mp4はSRTのみ
sb.append(_T(" -add \"%s#:name=%s\""), inSubs[i], subsTitles[i]);
Expand All @@ -411,7 +415,7 @@ static std::vector<std::pair<tstring, bool>> makeMuxerArgs(
sb.append(_T(" -chap \"%s\""), chapterpath);
needChapter = false;
}
sb.append(_T(" \"%s\""), outpath);
sb.append(_T(" -new \"%s\""), outpath);
ret.push_back(std::make_pair(sb.str(), true));
sb.clear();
}
Expand Down Expand Up @@ -1079,8 +1083,13 @@ class ConfigWrapper : public AMTObject
tmpDir.path(), key.video, key.format, key.div, GetCMSuffix(key.cm), GetNicoJKSuffix(type)));
}

tstring getVfrTmpFilePath(EncodeFileKey key, ENUM_FORMAT format) const {
return regtmp(StringFormat(_T("%s/t%d-%d-%d%s.%s"),
tstring getVfrTmpFile1Path(EncodeFileKey key, ENUM_FORMAT format) const {
return regtmp(StringFormat(_T("%s/t1%d-%d-%d%s.%s"),
tmpDir.path(), key.video, key.format, key.div, GetCMSuffix(key.cm), getOutputExtention(format)));
}

tstring getVfrTmpFile2Path(EncodeFileKey key, ENUM_FORMAT format) const {
return regtmp(StringFormat(_T("%s/t2%d-%d-%d%s.%s"),
tmpDir.path(), key.video, key.format, key.div, GetCMSuffix(key.cm), getOutputExtention(format)));
}

Expand Down

0 comments on commit 053f660

Please sign in to comment.