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

Add an option to export H.264 with VAAPI GPU acceleration #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ osx_installer/create-dmg-master/builder/create-dmg.builder
platform/build-MLVApp-Desktop_Qt_5_15_3_clangOMP_64bit-Release/*
platform/build-MLVApp-Desktop_Qt_5_15_3_llvm16OMP_64bit-Release/*
platform/build-MLVApp-Desktop_Qt_5_15_10_llvm16OMP_64bit-Release/*
platform/qt/.moc/
platform/qt/.obj/
platform/qt/.qmake.stash
platform/qt/.rcc/
platform/qt/.ui/
platform/qt/*.fpm
platform/qt/Makefile
platform/qt/ffmpeg
platform/qt/pixel_maps
platform/qt/releases
1 change: 1 addition & 0 deletions platform/qt/ExportSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void ExportSettingsDialog::on_comboBoxCodec_currentIndexChanged(int index)
enableResize = false;
}
else if( index == CODEC_H264
|| index == CODEC_H264_VAAPI
|| index == CODEC_H265_8
|| index == CODEC_H265_10
|| index == CODEC_H265_12 )
Expand Down
38 changes: 23 additions & 15 deletions platform/qt/ExportSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
#define CODEC_CDNG_LOSSLESS 7
#define CODEC_CDNG_FAST 8
#define CODEC_H264 9
#define CODEC_H265_8 10
#define CODEC_H265_10 11
#define CODEC_H265_12 12
#define CODEC_TIFF 13
#define CODEC_PNG 14
#define CODEC_JPG2K 15
#define CODEC_MJPEG 16
#define CODEC_FFVHUFF 17
#define CODEC_MLV 18
#define CODEC_DNXHD 19
#define CODEC_DNXHR 20
#define CODEC_CINEFORM_10 21
#define CODEC_CINEFORM_12 22
#define CODEC_VP9 23
#define CODEC_AUDIO_ONLY 24
#define CODEC_H264_VAAPI 10
#define CODEC_H265_8 11
#define CODEC_H265_10 12
#define CODEC_H265_12 13
#define CODEC_TIFF 14
#define CODEC_PNG 15
#define CODEC_JPG2K 16
#define CODEC_MJPEG 17
#define CODEC_FFVHUFF 18
#define CODEC_MLV 19
#define CODEC_DNXHD 20
#define CODEC_DNXHR 21
#define CODEC_CINEFORM_10 22
#define CODEC_CINEFORM_12 23
#define CODEC_VP9 24
#define CODEC_AUDIO_ONLY 25

#define CODEC_AVI_OPTION_YUV420 0
#define CODEC_AVI_OPTION_V210 1
Expand All @@ -57,6 +58,13 @@
#define CODEC_H264_M_MKV 5
#define CODEC_H264_AVFOUNDATION 6

#define CODEC_H264_VAAPI_H_MOV 0
#define CODEC_H264_VAAPI_H_MP4 1
#define CODEC_H264_VAAPI_H_MKV 2
#define CODEC_H264_VAAPI_M_MOV 3
#define CODEC_H264_VAAPI_M_MP4 4
#define CODEC_H264_VAAPI_M_MKV 5

#define CODEC_H265_H_MOV 0
#define CODEC_H265_H_MP4 1
#define CODEC_H265_H_MKV 2
Expand Down
5 changes: 5 additions & 0 deletions platform/qt/ExportSettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
<string>H.264</string>
</property>
</item>
<item>
<property name="text">
<string>H.264 VAAPI (Intel/AMD GPU)</string>
</property>
</item>
<item>
<property name="text">
<string>H.265 8bit 4:2:0</string>
Expand Down
40 changes: 34 additions & 6 deletions platform/qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ void MainWindow::startExportPipe(QString fileName)
#else
writeMlvAudioToWaveCut( m_pMlvObject, wavFileName.toLatin1().data(), m_exportQueue.first()->cutIn(), m_exportQueue.first()->cutOut() );
#endif
if( m_codecProfile == CODEC_H264 || m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
if( m_codecProfile == CODEC_H264 || m_codecProfile == CODEC_H264_VAAPI || m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
ffmpegAudioCommand = QString( "-i \"%1\" -c:a aac " ).arg( wavFileName );
else if( m_codecProfile == CODEC_VP9 ) ffmpegAudioCommand = QString( "-i \"%1\" -c:a libopus " ).arg( wavFileName );
else ffmpegAudioCommand = QString( "-i \"%1\" -c:a copy " ).arg( wavFileName );
Expand Down Expand Up @@ -1910,13 +1910,19 @@ void MainWindow::startExportPipe(QString fileName)
}
}

QString hwuploadString = QString( "" );
if (m_codecProfile == CODEC_H264_VAAPI) {
hwuploadString = QString( ",format=nv12,hwupload," );
}

//Colorspace conversion (for getting right colors)
QString resizeFilter = QString( "" );
//a colorspace conversion is always needed to get right colors
resizeFilter = QString( "-vf %1scale=in_color_matrix=bt601:out_color_matrix=bt709%2%3 " )
resizeFilter = QString( "-vf %1scale=in_color_matrix=bt601:out_color_matrix=bt709%2%3%4 " )
.arg( moireeFilter )
.arg( hdrString )
.arg( vidstabString );
.arg( vidstabString )
.arg( hwuploadString );
//qDebug() << resizeFilter;

//Color tag
Expand Down Expand Up @@ -2349,6 +2355,26 @@ void MainWindow::startExportPipe(QString fileName)
.arg( resizeFilter )
.arg( output ) );
}
else if( m_codecProfile == CODEC_H264_VAAPI )
{
if( m_codecOption == CODEC_H264_VAAPI_H_MOV || m_codecOption == CODEC_H264_VAAPI_M_MOV ) output.append( QString( ".mov" ) );
else if( m_codecOption == CODEC_H264_VAAPI_H_MP4 || m_codecOption == CODEC_H264_VAAPI_M_MP4 ) output.append( QString( ".mp4" ) );
else output.append( QString( ".mkv" ) );

int quality;
if( m_codecOption == CODEC_H264_VAAPI_H_MOV || m_codecOption == CODEC_H264_VAAPI_H_MP4 || m_codecOption == CODEC_H264_VAAPI_H_MKV )
quality = 17;
else
quality = 22;

program.append( QString( " -init_hw_device vaapi=vaapi0: -filter_hw_device vaapi0 -r %1 -y -f rawvideo -s %2 -pix_fmt rgb48 -i - -c:v h264_vaapi -global_quality %3 -color_primaries %5 -color_trc %5 -colorspace bt709 %6 \"%7\"" )
.arg( fps )
.arg( resolution )
.arg( quality )
.arg( colorTag )
.arg( resizeFilter )
.arg( output ) );
}
else if( m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
{
QString bitdepth;
Expand Down Expand Up @@ -6539,16 +6565,18 @@ void MainWindow::on_actionExport_triggered()
}
else
{
if( ( m_codecProfile == CODEC_H264 || m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
&& ( m_codecOption == CODEC_H264_H_MP4 || m_codecOption == CODEC_H265_H_MP4
if( ( m_codecProfile == CODEC_H264 || m_codecProfile == CODEC_H264_VAAPI || m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
&& ( m_codecOption == CODEC_H264_VAAPI_H_MP4 || m_codecOption == CODEC_H264_VAAPI_M_MP4
|| m_codecOption == CODEC_H264_H_MP4 || m_codecOption == CODEC_H265_H_MP4
|| m_codecOption == CODEC_H264_M_MP4 || m_codecOption == CODEC_H265_M_MP4 ) )
{
saveFileName.append( ".mp4" );
fileType = tr("MPEG-4 (*.mp4)");
fileEnding = ".mp4";
}
else if( ( m_codecProfile == CODEC_H264 || m_codecProfile == CODEC_H265_8 || m_codecProfile == CODEC_H265_10 || m_codecProfile == CODEC_H265_12 )
&& ( m_codecOption == CODEC_H264_H_MKV || m_codecOption == CODEC_H265_H_MKV
&& ( m_codecOption == CODEC_H264_VAAPI_H_MKV || m_codecOption == CODEC_H264_VAAPI_M_MP4
|| m_codecOption == CODEC_H264_H_MKV || m_codecOption == CODEC_H265_H_MKV
|| m_codecOption == CODEC_H264_M_MKV || m_codecOption == CODEC_H265_M_MKV) )
{
saveFileName.append( ".mkv" );
Expand Down