Skip to content

Commit

Permalink
Implement QP 0 lossless x264 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Quackdoc committed Oct 6, 2022
1 parent 5420cea commit ea8b38e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/dialog/export/codec/h264section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ H264Section::H264Section(int default_crf, QWidget *parent) :

// These items must correspond to the CompressionMethod enum
compression_box->addItem(tr("Constant Rate Factor"));
compression_box->addItem(tr("Lossless"));
compression_box->addItem(tr("Target Bit Rate"));
compression_box->addItem(tr("Target File Size"));

Expand All @@ -87,6 +88,9 @@ H264Section::H264Section(int default_crf, QWidget *parent) :
crf_section_ = new H264CRFSection(default_crf);
compression_method_stack_->addWidget(crf_section_);

lossless_section_ = new H264LosslessSection();
compression_method_stack_->addWidget(lossless_section_);

bitrate_section_ = new H264BitRateSection();
compression_method_stack_->addWidget(bitrate_section_);

Expand Down Expand Up @@ -114,6 +118,10 @@ void H264Section::AddOpts(EncodingParams *params)
// Simply set CRF value
params->set_video_option(QStringLiteral("crf"), QString::number(crf_section_->GetValue()));

} else if (method == kLossless) {

params->set_video_option(QStringLiteral("qp"), QString::number(0));

} else {

int64_t target_rate, max_rate, min_rate;
Expand Down Expand Up @@ -237,6 +245,17 @@ H264BitRateSection::H264BitRateSection(QWidget *parent) :
max_rate_->SetValue(32.0);
}

H264LosslessSection::H264LosslessSection(QWidget *parent) :
QWidget(parent)
{
QGridLayout* layout = new QGridLayout(this);
layout->setMargin(0);

int row = 0;

layout->addWidget(new QLabel(tr("For true lossless, verify the pixel format before exporting")), row, 0);
}

int64_t H264BitRateSection::GetTargetBitRate() const
{
return qRound64(target_rate_->GetValue() * 1000000.0);
Expand Down
10 changes: 10 additions & 0 deletions app/dialog/export/codec/h264section.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class H264CRFSection : public QWidget

};

class H264LosslessSection : public QWidget
{
Q_OBJECT
public:
H264LosslessSection(QWidget* parent = nullptr);
};

class H264BitRateSection : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -98,6 +105,7 @@ class H264Section : public CodecSection
public:
enum CompressionMethod {
kConstantRateFactor,
kLossless,
kTargetBitRate,
kTargetFileSize
};
Expand All @@ -114,6 +122,8 @@ class H264Section : public CodecSection

H264CRFSection* crf_section_;

H264LosslessSection* lossless_section_;

H264BitRateSection* bitrate_section_;

H264FileSizeSection* filesize_section_;
Expand Down

0 comments on commit ea8b38e

Please sign in to comment.