Skip to content

Commit

Permalink
* Fix ffmpeg path escaping on windows
Browse files Browse the repository at this point in the history
* Fixes to hardware acceleration when processing subs is disabled
* Allow quality control when processing subs is disabled
  • Loading branch information
Mantas-2155X committed Mar 31, 2024
1 parent 8a98936 commit a3c5295
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions HardSubberGUI/HardSubberGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<PackageVersion>1.0.1</PackageVersion>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
<FileVersion>1.5.0.0</FileVersion>
<AssemblyVersion>1.5.1.0</AssemblyVersion>
<FileVersion>1.5.1.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
Expand Down
95 changes: 48 additions & 47 deletions HardSubberGUI/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,71 +365,72 @@ public static void ActFile(string file, string output, bool processVideo,
}

process.StartInfo.Arguments += $"-i '{info.FullName}' ";
if (processVideo)
{
var scaleString = resize ? $"scale={resw}:{resh}," : "";

var scaleString = resize ? $"scale={resw}:{resh}," : "";

var escaped = info.FullName;
escaped = !IsWindows ? Escape.Aggregate(info.FullName, (current, str) => current.Replace(str, "\\\\\\" + str)) : EscapeWindowsString(escaped);
var escaped = info.FullName;
escaped = !IsWindows ? Escape.Aggregate(info.FullName, (current, str) => current.Replace(str, "\\\\\\" + str)) : EscapeWindowsString(escaped);

if (hwaccel)
if (hwaccel)
{
switch (CurrentGPU)
{
switch (CurrentGPU)
case GPU.AMD:
{
case GPU.AMD:
if (IsWindows)
{
if (IsWindows)
{
if (processVideo)
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex},format=nv12 ";
process.StartInfo.Arguments += "-c:v h264_amf ";
}
else
{
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex},format=nv12,hwupload ";
process.StartInfo.Arguments += "-c:v h264_vaapi ";
}
break;
}
case GPU.NVIDIA:
{
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex},format=nv12,hwupload_cuda ";
process.StartInfo.Arguments += "-c:v h264_nvenc ";
break;
process.StartInfo.Arguments += $"-filter_complex {scaleString}format=nv12 ";

process.StartInfo.Arguments += "-c:v h264_amf ";
}
case GPU.None:
else
{
throw new Exception("ERR_HWACCEL_NOTSUPPORTED");
if (processVideo)
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex},format=nv12,hwupload ";
else
process.StartInfo.Arguments += $"-filter_complex {scaleString}format=nv12,hwupload ";

process.StartInfo.Arguments += "-c:v h264_vaapi ";
}
break;
}
case GPU.NVIDIA:
{
if (processVideo)
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex},format=nv12,hwupload_cuda ";
else
process.StartInfo.Arguments += $"-filter_complex {scaleString}format=nv12,hwupload_cuda ";

process.StartInfo.Arguments += "-c:v h264_nvenc ";
break;
}
case GPU.None:
{
throw new Exception("ERR_HWACCEL_NOTSUPPORTED");
}
}
else
{
if (pgs)
process.StartInfo.Arguments += $"-filter_complex [0:v][0:s:{subtitleIndex}]overlay[v] -map [v] ";
else
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex} ";

process.StartInfo.Arguments += "-c:v libx264 ";
}

process.StartInfo.Arguments += $"-map 0:a:{audioIndex} ";
process.StartInfo.Arguments += $"-qp {quality} ";
}
else
{
if (resize)
if (processVideo)
{
process.StartInfo.Arguments += $"-vf 'scale={resw}:{resh}' ";
}
else
{
if (aac)
process.StartInfo.Arguments += "-c:v copy ";
if (pgs)
process.StartInfo.Arguments += $"-filter_complex [0:v][0:s:{subtitleIndex}]overlay[v] -map [v] ";
else
process.StartInfo.Arguments += "-c copy ";
process.StartInfo.Arguments += $"-filter_complex {scaleString}subtitles={escaped}:stream_index={subtitleIndex} ";
}

process.StartInfo.Arguments += "-c:v libx264 ";
}

if (processVideo)
process.StartInfo.Arguments += $"-map 0:a:{audioIndex} ";

process.StartInfo.Arguments += $"-qp {quality} ";

if (aac)
process.StartInfo.Arguments += "-c:a aac ";

Expand All @@ -447,7 +448,7 @@ public static void ActFile(string file, string output, bool processVideo,

process.StartInfo.Arguments += "-strict -2 ";
process.StartInfo.Arguments += $"'{output}/{shortName}{SupportedVideoFormats[format]}'";
// todo: fix FfmpegPath escaping

if (!IsWindows)
{
var args = process.StartInfo.Arguments;
Expand All @@ -459,7 +460,7 @@ public static void ActFile(string file, string output, bool processVideo,
else
{
var args = process.StartInfo.Arguments;
args = $"\"{FfmpegPath} {args}\"";
args = $"\"& '{FfmpegPath}' {args}\"";

process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = args;
Expand Down
1 change: 0 additions & 1 deletion HardSubberGUI/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private void ApplySubsControl_OnPropertyChanged(object? sender, AvaloniaProperty

SubtitleIndexControl.IsEnabled = (bool)ApplySubsControl.IsChecked!;
AudioIndexControl.IsEnabled = (bool)ApplySubsControl.IsChecked!;
QualityControl.IsEnabled = (bool)ApplySubsControl.IsChecked!;
}

private void InputControl_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
Expand Down

0 comments on commit a3c5295

Please sign in to comment.