Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] DNxHD support #1857

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/codec/exportformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ QList<ExportCodec::Codec> ExportFormat::GetVideoCodecs(ExportFormat::Format f)
case kFormatTIFF:
return {ExportCodec::kCodecTIFF};
case kFormatQuickTime:
return {ExportCodec::kCodecH264, ExportCodec::kCodecH264rgb, ExportCodec::kCodecH265, ExportCodec::kCodecProRes, ExportCodec::kCodecCineform};
return {ExportCodec::kCodecH264, ExportCodec::kCodecH264rgb, ExportCodec::kCodecH265, ExportCodec::kCodecProRes, ExportCodec::kCodecCineform, ExportCodec::kCodecDNxHD};
case kFormatWebM:
return {ExportCodec::kCodecVP9};
case kFormatOgg:
Expand Down
1 change: 1 addition & 0 deletions app/codec/ffmpeg/ffmpegencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ bool FFmpegEncoder::SetupCodecContext(AVStream* stream, AVCodecContext* codec_ct

if (codec->type == AVMEDIA_TYPE_VIDEO) {
stream->avg_frame_rate = codec_ctx->framerate;
stream->time_base = av_add_q(codec_ctx->time_base, {0, 1});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Is this to ensure a non-zero denominator?

Copy link
Contributor Author

@Quackdoc Quackdoc Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no. That wasn't supposed to make it in, Ill change this back to draft.

but explaining what it is, and what we need it for, we tell the encoder what framerate to use but when writing to an mxf, it also needs to be explicitly told what time_base it's being told to use. this is so that it can ensure interoperability between applications. (one of the reasons people love mxf so much)

just setting stream->time_base = codec_ctx->time_base will make any non-supported framerates error out. which isn't a massive issue since nearly all the video framerates that are exposed by default work fine. with the exception of 10fps and 15fps. so this was never supposed to make it in.

what WAS supposed to make it in, was a better error message explaining why the encode failed immediately instead of error that pops up now "failed to open file: failed to write format header: Invalid argument -22"

the {0, 1} was debugging crap that was supposed to be removed. but I pushed and old commit by accident. but I suppose this is a good time to ask, would it be better to just report why it failed, or find a way to just show the supported framerates?

I had done a fresh install since the time I worked on this so I lost the code either way. and while I don't think anybody who will export DNxHD will try to export 15 or 10 fps I'm not sure if the error message it currently serves is good enough or not.

EDIT: to be clear, the error gets reported to the terminal perfectly fine as Unsupported frame rate 15/1. Set -strict option to 'unofficial' or lower in order to allow it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an error message should be sufficient, you can see a similar use case here to inform users that H.264 and H.265 require dimensions to be a multiple of 2: https://github.com/olive-editor/olive/blob/master/app/dialog/export/export.cpp#L357

I think using a similar approach for this limitation would be perfectly fine

}

return true;
Expand Down
2 changes: 2 additions & 0 deletions app/dialog/export/codec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(OLIVE_SOURCES
dialog/export/codec/codecsection.h
dialog/export/codec/codecstack.cpp
dialog/export/codec/codecstack.h
dialog/export/codec/dnxhdsection.cpp
dialog/export/codec/dnxhdsection.h
dialog/export/codec/h264section.cpp
dialog/export/codec/h264section.h
dialog/export/codec/imagesection.cpp
Expand Down
70 changes: 70 additions & 0 deletions app/dialog/export/codec/dnxhdsection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/

#include "dnxhdsection.h"

#include <QGridLayout>
#include <QLabel>

namespace olive {

DNxHDSection::DNxHDSection(QWidget *parent) :
CodecSection(parent)
{
QGridLayout *layout = new QGridLayout(this);

layout->setMargin(0);

int row = 0;

layout->addWidget(new QLabel(tr("Profile:")), row, 0);

preset_combobox_ = new QComboBox();

preset_combobox_->setToolTip(tr("While using DNxHD you may need to manually change pixel format. \n\n"
"dnxhr_hqx profile will need you to manually specify pixel format `422p10le` in the advanced menu. \n\n"
"dnxhr_444 profile will need you to manually specify pixel format `444p10le` or `gbrp10le` in the advanced menu."));

/* Correspond to the following indexes for FFmpeg
*
*-profile <int> E..V....... (from 0 to 5) (default dnxhd)
* dnxhd 0 E..V.......
* dnxhr_444 5 E..V.......
* dnxhr_hqx 4 E..V.......
* dnxhr_hq 3 E..V.......
* dnxhr_sq 2 E..V.......
* dnxhr_lb 1 E..V.......
*
*/

//preset_combobox_->addItem(tr("dnxhd"));
preset_combobox_->addItem(tr("dnxhr_lb"));
preset_combobox_->addItem(tr("dnxhr_sq"));
preset_combobox_->addItem(tr("dnxhr_hq"));
preset_combobox_->addItem(tr("dnxhr_hqx"));
preset_combobox_->addItem(tr("dnxhr_444"));


preset_combobox_->setCurrentIndex(1);

layout->addWidget(preset_combobox_, row, 1);
}

void DNxHDSection::AddOpts(EncodingParams *params)
{
params->set_video_option(QStringLiteral("profile"), QString::number(preset_combobox_->currentIndex() + 1));
}

}
40 changes: 40 additions & 0 deletions app/dialog/export/codec/dnxhdsection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/

#ifndef DNXHDSECTION_H
#define DNXHDSECTION_H

#include <QComboBox>

#include "codecsection.h"

namespace olive {

class DNxHDSection : public CodecSection
{
Q_OBJECT
public:
DNxHDSection(QWidget *parent = nullptr);

virtual void AddOpts(EncodingParams* params) override;

private:
QComboBox *preset_combobox_;

};

}

#endif // DNXHDSECTION_H
6 changes: 6 additions & 0 deletions app/dialog/export/exportvideotab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ QWidget *ExportVideoTab::SetupCodecSection()
cineform_section_ = new CineformSection();
codec_stack_->addWidget(cineform_section_);

dnxhd_section_ = new DNxHDSection();
codec_stack_->addWidget(dnxhd_section_);

row++;

QPushButton* advanced_btn = new QPushButton(tr("Advanced"));
Expand Down Expand Up @@ -246,6 +249,9 @@ void ExportVideoTab::VideoCodecChanged()
case ExportCodec::kCodecCineform:
SetCodecSection(cineform_section_);
break;
case ExportCodec::kCodecDNxHD:
SetCodecSection(dnxhd_section_);
break;
default:
SetCodecSection(ExportCodec::IsCodecAStillImage(codec) ? image_section_ : nullptr);
}
Expand Down
2 changes: 2 additions & 0 deletions app/dialog/export/exportvideotab.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "dialog/export/codec/cineformsection.h"
#include "dialog/export/codec/codecstack.h"
#include "dialog/export/codec/h264section.h"
#include "dialog/export/codec/dnxhdsection.h"
#include "dialog/export/codec/imagesection.h"
#include "node/color/colormanager/colormanager.h"
#include "widget/colorwheel/colorspacechooser.h"
Expand Down Expand Up @@ -162,6 +163,7 @@ public slots:
H264Section* h264_section_;
H264Section* h265_section_;
CineformSection *cineform_section_;
DNxHDSection *dnxhd_section_;

ColorSpaceChooser* color_space_chooser_;

Expand Down