| 75 | } |
| 76 | |
| 77 | bool OfflineVideoEncoder::open(int width, int height, double frameRate, bool hasAlpha, |
| 78 | int maxKeyFrameInterval, int quality) { |
| 79 | this->width = width; |
| 80 | this->height = height; |
| 81 | this->frameRate = frameRate; |
| 82 | |
| 83 | param.width = width; |
| 84 | param.height = height; |
| 85 | param.frameRate = frameRate; |
| 86 | param.hasAlpha = hasAlpha; |
| 87 | param.quality = quality; |
| 88 | param.maxKeyFrameInterval = maxKeyFrameInterval; |
| 89 | |
| 90 | stride[0] = SIZE_ALIGN(width); |
| 91 | stride[1] = SIZE_ALIGN(stride[0] / 2); |
| 92 | stride[2] = stride[1]; |
| 93 | h264Buf.resize(width * height + 1024); |
| 94 | data[0].resize(stride[0] * (SIZE_ALIGN(height) / 1), 128); |
| 95 | data[1].resize(stride[1] * (SIZE_ALIGN(height) / 2), 128); |
| 96 | data[2].resize(stride[2] * (SIZE_ALIGN(height) / 2), 128); |
| 97 | |
| 98 | rootPath = GetOfflineFolder(); |
| 99 | DeleteFile(rootPath); |
| 100 | CreateDir(rootPath); |
| 101 | std::string encodeParamFilePath = JoinPaths(rootPath, "EncoderParam.txt"); |
| 102 | std::string paramStr = |
| 103 | QString( |
| 104 | R"({ "Width": %1, "Height": %2, "FrameRate": %3, "HasAlpha": %4, "MaxKeyFrameInterval": %5, "Quality": %6 })") |
| 105 | .arg(width) |
| 106 | .arg(height) |
| 107 | .arg(frameRate, 0, 'f', 2) |
| 108 | .arg(hasAlpha) |
| 109 | .arg(maxKeyFrameInterval) |
| 110 | .arg(quality) |
| 111 | .toStdString(); |
| 112 | WriteTextFile(encodeParamFilePath, paramStr); |
| 113 | |
| 114 | QString workingDirectory = QString::fromStdString(GetH264EncoderToolsFolder()); |
| 115 | QString toolExecutable = |
| 116 | QString::fromStdString(JoinPaths(workingDirectory.toStdString(), "H264EncoderTools")); |
| 117 | #ifdef _WIN32 |
| 118 | if (!toolExecutable.endsWith(".exe")) { |
| 119 | toolExecutable.append(".exe"); |
| 120 | } |
| 121 | #endif |
| 122 | toolExecutable = QDir::toNativeSeparators(toolExecutable); |
| 123 | QString offlineFolderPath = QString::fromStdString(GetOfflineFolder()); |
| 124 | offlineFolderPath = QDir::toNativeSeparators(offlineFolderPath); |
| 125 | if (!offlineFolderPath.endsWith(QDir::separator())) { |
| 126 | offlineFolderPath.append(QDir::separator()); |
| 127 | } |
| 128 | QStringList arguments; |
| 129 | arguments << offlineFolderPath; |
| 130 | process = std::make_unique<QProcess>(); |
| 131 | process->setWorkingDirectory(workingDirectory); |
| 132 | process->start(toolExecutable, arguments); |
| 133 | |
| 134 | return process->waitForStarted(); |
no test coverage detected