From 975dbfe2388e2a6bcff59c9aaf81c1eea8beb422 Mon Sep 17 00:00:00 2001 From: manongjohn Date: Sun, 30 Jan 2022 09:29:27 -0500 Subject: [PATCH] Use libx264 or libopenh264 for mp4 renders if ffmpeg supported --- toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp | 22 ++++++++++++++++++++++ toonz/sources/image/ffmpeg/tiio_ffmpeg.h | 1 + toonz/sources/image/ffmpeg/tiio_mp4.cpp | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp index b148c789..828d1718 100644 --- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp +++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.cpp @@ -124,6 +124,28 @@ bool Ffmpeg::checkFormat(std::string format) { return false; } +bool Ffmpeg::checkCodecs(std::string codec) { + QString path = Preferences::instance()->getFfmpegPath() + "/ffmpeg"; +#if defined(_WIN32) + path = path + ".exe"; +#endif + QStringList args; + args << "-codecs"; + QProcess ffmpeg; + ffmpeg.start(path, args); + if (waitFfmpeg(ffmpeg, 60000)) { // 1 minute timeout + QString results = ffmpeg.readAllStandardError(); + results += ffmpeg.readAllStandardOutput(); + ffmpeg.close(); + std::string strResults = results.toStdString(); + std::string::size_type n; + n = strResults.find(codec); + if (n != std::string::npos) + return true; + } + return false; +} + TFilePath Ffmpeg::getFfmpegCache() { QString cacheRoot = ToonzFolder::getCacheRootFolder().getQString(); if (!TSystem::doesExistFileOrLevel(TFilePath(cacheRoot + "/ffmpeg"))) { diff --git a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h index 654e331e..d6bd9b39 100644 --- a/toonz/sources/image/ffmpeg/tiio_ffmpeg.h +++ b/toonz/sources/image/ffmpeg/tiio_ffmpeg.h @@ -34,6 +34,7 @@ public: static bool checkFfmpeg(); static bool checkFfprobe(); static bool checkFormat(std::string format); + static bool checkCodecs(std::string format); double getFrameRate(); TDimension getSize(); int getFrameCount(); diff --git a/toonz/sources/image/ffmpeg/tiio_mp4.cpp b/toonz/sources/image/ffmpeg/tiio_mp4.cpp index 55982247..d7b01916 100644 --- a/toonz/sources/image/ffmpeg/tiio_mp4.cpp +++ b/toonz/sources/image/ffmpeg/tiio_mp4.cpp @@ -90,6 +90,13 @@ TLevelWriterMp4::~TLevelWriterMp4() { postIArgs << QString::number(outLx) + "x" + QString::number(outLy); postIArgs << "-b"; postIArgs << QString::number(finalBitrate) + "k"; + if (Ffmpeg::checkCodecs("libopenh264")) { + postIArgs << "-c:v"; + postIArgs << "libopenh264"; + } else if (Ffmpeg::checkCodecs("libxh264")) { + postIArgs << "-c:v"; + postIArgs << "libxh264"; + } ffmpegWriter->runFfmpeg(preIArgs, postIArgs, false, false, true); ffmpegWriter->cleanUpFiles();