From e11e0f20770284cb9205903dffd3a58b3d75981e Mon Sep 17 00:00:00 2001 From: Rodney Date: Jul 27 2022 18:06:22 +0000 Subject: Merge pull request #4486 from justburner/FixMTStartFrameFFMPEG Fix Starting frame Multi-thread FFMPEG --- diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp index e70d0f3..9a58f3f 100644 --- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp +++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp @@ -18,22 +18,24 @@ Ffmpeg::Ffmpeg() { m_ffmpegTimeout = Preferences::instance()->getFfmpegTimeout() * 1000; std::string strPath = m_ffmpegPath.toStdString(); m_intermediateFormat = "png"; + m_startNumber = 2147483647; // Lowest frame determines starting frame } Ffmpeg::~Ffmpeg() {} bool Ffmpeg::checkFfmpeg() { - // check the user defined path in preferences first - QString path = Preferences::instance()->getFfmpegPath() + "/ffmpeg"; + // ffmpeg executable #if defined(_WIN32) - path = path + ".exe"; + QString exe = "/ffmpeg.exe"; +#else + QString exe = "/ffmpeg"; #endif + + // check the user defined path in preferences first + QString path = Preferences::instance()->getFfmpegPath() + exe; if (TSystem::doesExistFileOrLevel(TFilePath(path))) return true; // check the OpenToonz root directory next - path = QDir::currentPath() + "/ffmpeg"; -#if defined(_WIN32) - path = path + ".exe"; -#endif + path = QDir::currentPath() + exe; if (TSystem::doesExistFileOrLevel(TFilePath(path))) { Preferences::instance()->setValue(ffmpegPath, QDir::currentPath()); return true; @@ -103,10 +105,11 @@ void Ffmpeg::setPath(TFilePath path) { m_path = path; } void Ffmpeg::createIntermediateImage(const TImageP &img, int frameIndex) { m_frameCount++; - if (m_frameNumberOffset == -1) m_frameNumberOffset = frameIndex - 1; + frameIndex--; // ffmpeg start at 0 by default + if (frameIndex < m_startNumber) m_startNumber = frameIndex; QString tempPath = getFfmpegCache().getQString() + "//" + QString::fromStdString(m_path.getName()) + "tempOut" + - QString::number(frameIndex - m_frameNumberOffset) + "." + + QString::number(frameIndex) + "." + m_intermediateFormat; std::string saveStatus = ""; TRasterImageP tempImage(img); @@ -151,6 +154,10 @@ void Ffmpeg::runFfmpeg(QStringList preIArgs, QStringList postIArgs, args = args + preIArgs; if (!includesInPath) { // NOTE: if including the in path, it needs to be in // the preIArgs argument. + if (m_startNumber != 0) { + args << "-start_number"; + args << QString::number(m_startNumber); + } args << "-i"; args << tempName; } @@ -277,10 +284,13 @@ ffmpegFileInfo Ffmpeg::getInfo() { QByteArray ba = infoText.readAll(); infoText.close(); QString text = QString::fromStdString(ba.toStdString()); - m_lx = text.split(" ")[0].toInt(); - m_ly = text.split(" ")[1].toInt(); - m_frameRate = text.split(" ")[2].toDouble(); - m_frameCount = text.split(" ")[3].toInt(); + QStringList textlist = text.split(" "); + if (textlist.count() >= 4) { + m_lx = textlist[0].toInt(); + m_ly = textlist[1].toInt(); + m_frameRate = textlist[2].toDouble(); + m_frameCount = textlist[3].toInt(); + } } else { QFile infoText(tempPath); getSize(); @@ -463,6 +473,11 @@ void Ffmpeg::getFramesFromMovie(int frame) { // frameArgs << "-accurate_seek"; // frameArgs << "-ss"; // frameArgs << "0" + QString::number(frameIndex / m_info->m_frameRate); + if (m_path.getType() == "webm") { + // To load in webm transparency + preIFrameArgs << "-vcodec"; + preIFrameArgs << "libvpx"; + } preIFrameArgs << "-i"; preIFrameArgs << m_path.getQString(); postIFrameArgs << "-y"; diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h index 6ec415a..359b84b 100644 --- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h +++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h @@ -47,7 +47,7 @@ public: private: QString m_intermediateFormat, m_ffmpegPath, m_audioPath, m_audioFormat; int m_frameCount = 0, m_lx, m_ly, m_bpp, m_bitsPerSample, m_channelCount, - m_ffmpegTimeout = 30000, m_frameNumberOffset = -1; + m_ffmpegTimeout = 30000, m_startNumber = 2147483647; double m_frameRate = 24.0; bool m_ffmpegExists = false, m_ffprobeExists = false, m_hasSoundTrack = false; TFilePath m_path;