Skip to content

Commit

Permalink
Added option to rotate and flip the video
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasGBL committed Apr 29, 2024
1 parent 58c66d6 commit 6586b44
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/ffmpegwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct TrimSettings;
struct CodecConfig;
struct Resolution;
struct Video;
enum TRANSFORM_CONFIG;

class QTime;
class QString;
Expand All @@ -16,6 +17,7 @@ struct ExportSettings {
bool vertical;
bool audioOnly;
bool videoOnly;
TRANSFORM_CONFIG transformConfig ;
};

class FFMPEGWrapper
Expand All @@ -33,6 +35,7 @@ class FFMPEGWrapper
QString getMBitRateString(double MBitRate);
QString getFramerateFilter(double Framerate, double vidFramerate);
QString getScaleFilterString(Resolution const & res, Resolution const & vidRes, int HardwareAcceleration, bool vertical);
QString getTransformFilterString(TRANSFORM_CONFIG const& t_config, bool vertical);

QString getVideoCodecString(CodecConfig const & codec, bool trimOnly);
QString getAudioCodecString(const Video& video, const TrimSettings& settings, const CodecConfig& codec, const ExportSettings& exports);
Expand Down
10 changes: 10 additions & 0 deletions include/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ Resolution const RESOLUTIONS[] = {
}
};

enum TRANSFORM_CONFIG {
IDENTITY,
PLUS90,
PLUS180,
PLUS270,
HFLIP,
VFLIP,
SIZE //last element, denoted as size
};

float const FRAMERATES[] = {
0,
30,
Expand Down
16 changes: 16 additions & 0 deletions src/ffmpegwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bool FFMPEGWrapper::exportFile(const Video& video, const TrimSettings& settings,
std::vector<QString> filters;
QString framerateFilter = getFramerateFilter(exports.framerate, video.framerate);
QString scaleFilter = getScaleFilterString(res, video.resolution, codec.hw_acceleration, exports.vertical);
QString transformFilter = getTransformFilterString(exports.transformConfig, exports.vertical);

//options part2
QString audioCodec = getAudioCodecString(video, settings, codec, exports);
Expand Down Expand Up @@ -60,6 +61,8 @@ bool FFMPEGWrapper::exportFile(const Video& video, const TrimSettings& settings,
filters.push_back(framerateFilter);
if (scaleFilter.length() > 0)
filters.push_back(scaleFilter);
if (transformFilter.length() > 0)
filters.push_back(transformFilter);

//Add filters:
QString videoFilterString("-vf \"");
Expand Down Expand Up @@ -152,6 +155,19 @@ QString FFMPEGWrapper::getScaleFilterString(Resolution const& res, Resolution co
}
}

QString FFMPEGWrapper::getTransformFilterString(TRANSFORM_CONFIG const& t_config, bool vertical)
{
QString options[6] = {
"",
"transpose=1",
"transpose=1,transpose=1",
"transpose=2",
"hflip",
"vflip"
};
return options[t_config];
}

QString FFMPEGWrapper::getVideoCodecString(CodecConfig const& codec, bool trimOnly)
{
QString prefix = "-c:v ";
Expand Down
15 changes: 11 additions & 4 deletions src/videolowwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void VideoLowWindow::quickH264(double MBitRate)
false,
false,
false,
false
false,
TRANSFORM_CONFIG::IDENTITY
};
handleExportExitCode(
ffmpeg->exportFile(
Expand All @@ -128,7 +129,8 @@ void VideoLowWindow::quickHEVC(double MBitRate)
false,
false,
false,
false
false,
TRANSFORM_CONFIG::IDENTITY
};
handleExportExitCode(
ffmpeg->exportFile(
Expand Down Expand Up @@ -229,13 +231,17 @@ void VideoLowWindow::exportVideo()
std::cout << "export" << std::endl;
if (currentVideo) {
auto codec = getCodecConfig();
int transformIndex = ui->transformCombobox->currentIndex();
TRANSFORM_CONFIG transform = static_cast<TRANSFORM_CONFIG>((transformIndex < TRANSFORM_CONFIG::IDENTITY || transformIndex >= TRANSFORM_CONFIG::SIZE) ? 0 : transformIndex);

ExportSettings exp = {
ui->BitrateDoubleSpinBox->value(),
FRAMERATES[ui->FramerateComboBox->currentIndex()],
false,
ui->verticalVideoCheckbox->isChecked(),
ui->AudioOnlyCheckBox->isChecked(),
ui->RemoveAudioCheckBox->isChecked()
ui->RemoveAudioCheckBox->isChecked(),
transform
};

handleExportExitCode(
Expand Down Expand Up @@ -269,7 +275,8 @@ void VideoLowWindow::quickTrimOnly()
true,
false,
false,
false
false,
TRANSFORM_CONFIG::IDENTITY
};
handleExportExitCode(
ffmpeg->exportFile(
Expand Down
45 changes: 45 additions & 0 deletions src/videolowwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,51 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="rotationLabel">
<property name="text">
<string>Rotation (clockwise) / Mirror:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="transformCombobox">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>+90°</string>
</property>
</item>
<item>
<property name="text">
<string>+180°</string>
</property>
</item>
<item>
<property name="text">
<string>+270°</string>
</property>
</item>
<item>
<property name="text">
<string>Horizontal Flip</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical Flip</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 6586b44

Please sign in to comment.