Add ability to lower cpu affinity (Linux only for the moment).

Start work on paths to save file and different args based on format.
This commit is contained in:
Adam Bissen 2024-01-13 16:36:56 +00:00
parent 28ab770b3e
commit eff090af47
4 changed files with 61 additions and 17 deletions

View File

@ -73,7 +73,7 @@ Window {
anchors.left: parent.left
text: "Start Encode"
font.pixelSize: 14
onClicked: handbrake.startEncode()
onClicked: handbrake.startEncode(txtVideoFile.text, searchResult.text)
flat: false
height: font.pixelSize + 10
width: 100
@ -93,6 +93,34 @@ Window {
width: 100
}
Button {
id: btnLowerAffinity
anchors.topMargin: 25
anchors.leftMargin: 25
anchors.top: btnStartEncode.bottom
anchors.left: parent.left
text: "Lower Affinity"
font.pixelSize: 14
onClicked: handbrake.setCoreUsage(18)
flat: false
height: font.pixelSize + 10
width: 100
}
Button {
id: btnRaiseAffinity
anchors.topMargin: 25
anchors.leftMargin: 25
anchors.top: btnStartEncode.bottom
anchors.left: btnLowerAffinity.right
text: "Raise Affinity"
font.pixelSize: 14
onClicked: handbrake.setCoreUsage(24)
flat: false
height: font.pixelSize + 10
width: 100
}
Text {
id: handbrakeStatus
anchors.left: btnVideoFile.left
@ -124,7 +152,6 @@ Window {
default:
hdrType.text = "Error"
}
movieDB.searchMovieTitleFile(fileName);
}
}

View File

@ -2,13 +2,14 @@
#include <QFile>
#include <QProcess>
#include <QDebug>
#include <QThread>
#include <QFileInfo>
QHandbrake::QHandbrake(QObject *parent)
: QObject{parent} {
}
uint8_t QHandbrake::setPath(QString pathIn)
{
uint8_t QHandbrake::setPath(QString pathIn) {
if (QFile::exists(pathIn)) {
exePath = pathIn;
return 1;
@ -16,9 +17,14 @@ uint8_t QHandbrake::setPath(QString pathIn)
return -1;
}
uint8_t QHandbrake::startEncode()
{
uint8_t QHandbrake::startEncode(const QString path,const QString title) {
QFileInfo inFile = QFileInfo(path);
qInfo() << inFile.absolutePath();
qInfo() << inFile.baseName();
//HandBrakeCLI -i "../%TITLE%/%TITLE% - 4k.mkv" -o "../%TITLE%/temp/handbrake.mkv" -f av_mkv -m -e x265_10bit --encoder-preset slower -q 20 --encoder-profile auto --all-audio -E copy --audio-copy-mask aac,eac3,dts,ac3,truehd,dtshd,mp3 --crop-mode auto --auto-anamorphic --all-subtitles > "../%TITLE%/temp/log.txt"
const QStringList args4kHD = {"-i", path, "-o", "test.mkv", "-f", "av_mkv", "-m", "-e", "x265_10bit", "--encoder-preset", "slower", "-q", "20", "--encoder-profile", "auto", "--all-audio", "-E", "copy", "--audio-copy-mask", "aac,eac3,dts,ac3,truehd,dtshd,mp3", "--crop-mode", "auto", "--auto-anamorphic", "--all-subtitles"} ;
QStringList arguments;
arguments << "-i" << "Cosmos.mkv" << "-o" << "test.mkv" << "-f" << "av_mkv" << "-m" << "-e" << "x265_10bit" << "--encoder-preset" << "slower" << "-q" << "20" << "--encoder-profile" << "auto" << "--all-audio" << "-E" << "copy" << "--audio-copy-mask" << "aac,eac3,dts,ac3,truehd,dtshd,mp3" << "--crop-mode" << "auto" << "--auto-anamorphic" << "--all-subtitles";
@ -28,6 +34,7 @@ uint8_t QHandbrake::startEncode()
emit statusChanged("Encode started.");
QObject::connect(HBProcess, &QProcess::readyReadStandardOutput, this, &QHandbrake::printStandardStatus);
QObject::connect(HBProcess, &QProcess::finished, HBProcess, &QHandbrake::deleteLater);
return true;
}
@ -39,7 +46,22 @@ uint8_t QHandbrake::stopEncode() {
return true;
}
uint8_t QHandbrake::setCoreUsage(uint8_t cores) {
tasksetProcess = new QProcess(parent());
QString argCores = QString::number(QThread::idealThreadCount() - cores) + "-" + QString::number(QThread::idealThreadCount() - 1); //Set affinity to lowest numbered cores.
QStringList arguments = {"-a", "-pc", argCores, QString::number(HBProcess->processId())};
qInfo() << arguments;
tasksetProcess->start("/usr/bin/taskset", arguments);
QObject::connect(tasksetProcess, &QProcess::finished, tasksetProcess, &QHandbrake::deleteLater);
QObject::connect(tasksetProcess, &QProcess::readyReadStandardOutput, this, &QHandbrake::printOutput);
return true;
}
void QHandbrake::printStandardStatus() {
emit statusChanged(HBProcess->readAllStandardOutput().trimmed());
//qInfo() << HBProcess->readAllStandardOutput().trimmed();
}
void QHandbrake::printOutput() {
qInfo() << tasksetProcess->readAllStandardOutput().trimmed();
}

View File

@ -11,13 +11,15 @@ class QHandbrake : public QObject
public:
explicit QHandbrake(QObject *parent = nullptr);
uint8_t setPath(QString pathIn);
Q_INVOKABLE uint8_t startEncode();
Q_INVOKABLE uint8_t startEncode(const QString path,const QString title);
Q_INVOKABLE uint8_t stopEncode();
Q_INVOKABLE uint8_t setCoreUsage(uint8_t cores);
private:
QString exePath = "";
QProcess *HBProcess;
QProcess *HBProcess, *tasksetProcess;
void printStandardStatus();
void printOutput();
signals:
void statusChanged(QString status);

View File

@ -25,17 +25,10 @@ int main(int argc, char *argv[])
}
QMovieDB movieDB(settings.value("MovieDB API Key").toString());
//movieDB.searchMovieTitle("TheWitcher"); //No Result Example
//movieDB.searchMovieTitle("10 cloverfield lane"); //Single Result Example
//movieDB.searchMovieTitle("The Shawshank Redemption"); //Multi-result
// //Check if HDR/DolbyVision
// enum QMediaInfo::HDR_Type hdrType = mInfo.getHDRType(__T("Cosmos.mkv"));
// if (hdrType >= 0) {
// qInfo() << hdrType;
// } else {
// qWarning() << "Could not open file.";
// }
QHandbrake handbrake;
#ifdef linux
if (handbrake.setPath("/usr/bin/HandBrakeCLI")) {