Use libx264 or libopenh264 for mp4 renders if ffmpeg supported

This commit is contained in:
manongjohn 2022-01-30 09:29:27 -05:00
parent 7d7ddd1311
commit 975dbfe238
3 changed files with 30 additions and 0 deletions

View file

@ -124,6 +124,28 @@ bool Ffmpeg::checkFormat(std::string format) {
return false; 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() { TFilePath Ffmpeg::getFfmpegCache() {
QString cacheRoot = ToonzFolder::getCacheRootFolder().getQString(); QString cacheRoot = ToonzFolder::getCacheRootFolder().getQString();
if (!TSystem::doesExistFileOrLevel(TFilePath(cacheRoot + "/ffmpeg"))) { if (!TSystem::doesExistFileOrLevel(TFilePath(cacheRoot + "/ffmpeg"))) {

View file

@ -34,6 +34,7 @@ public:
static bool checkFfmpeg(); static bool checkFfmpeg();
static bool checkFfprobe(); static bool checkFfprobe();
static bool checkFormat(std::string format); static bool checkFormat(std::string format);
static bool checkCodecs(std::string format);
double getFrameRate(); double getFrameRate();
TDimension getSize(); TDimension getSize();
int getFrameCount(); int getFrameCount();

View file

@ -90,6 +90,13 @@ TLevelWriterMp4::~TLevelWriterMp4() {
postIArgs << QString::number(outLx) + "x" + QString::number(outLy); postIArgs << QString::number(outLx) + "x" + QString::number(outLy);
postIArgs << "-b"; postIArgs << "-b";
postIArgs << QString::number(finalBitrate) + "k"; 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->runFfmpeg(preIArgs, postIArgs, false, false, true);
ffmpegWriter->cleanUpFiles(); ffmpegWriter->cleanUpFiles();