Skip to content

Commit

Permalink
Added Advanced Subtitle Support + Fixed Loading Job bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Mar 16, 2020
1 parent 2a24caa commit 1bac0cb
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 18 deletions.
73 changes: 72 additions & 1 deletion NotEnoughAV1Encodes/ConcatVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void Concat()
process.Start();
process.WaitForExit();

}else if (MainWindow.audioEncoding == true && MainWindow.subtitles == true)
}else if (MainWindow.audioEncoding == true && MainWindow.subtitles == true && MainWindow.subtitleStreamCopy == true && MainWindow.subtitleCustom == false)
{
//Concat the Videos with Audio and Subtitles
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Expand All @@ -81,6 +81,77 @@ public static void Concat()
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}else if (MainWindow.audioEncoding == true && MainWindow.subtitles == true && MainWindow.subtitleStreamCopy == false && MainWindow.subtitleCustom == true)
{
//Concat the Videos with Audio and Subtitles
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -f concat -safe 0 -i " + '\u0022' + MainWindow.chunksDir + "\\chunks.txt" + '\u0022' + " -c copy " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();


startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -i " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022' + " -i " + '\u0022' + MainWindow.workingTempDirectory + "\\AudioEncoded\\audio.mkv" + '\u0022' + " -i " + MainWindow.workingTempDirectory + "\\Subtitles\\subtitlecustom.mkv" + " -map 0:v -map 1:a -map 2:s -c copy " + '\u0022' + MainWindow.videoOutput + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
else if (MainWindow.audioEncoding == false && MainWindow.subtitles == true && MainWindow.subtitleStreamCopy == false && MainWindow.subtitleCustom == true)
{
//Concat the Videos with Audio and Subtitles
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -f concat -safe 0 -i " + '\u0022' + MainWindow.chunksDir + "\\chunks.txt" + '\u0022' + " -c copy " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();


startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -i " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022' + " -i " + MainWindow.workingTempDirectory + "\\Subtitles\\subtitlecustom.mkv" + " -map 0:v -map 1:s -c copy " + '\u0022' + MainWindow.videoOutput + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
else if (MainWindow.audioEncoding == false && MainWindow.subtitles == true && MainWindow.subtitleStreamCopy == true && MainWindow.subtitleCustom == false)
{
//Concat the Videos with Audio and Subtitles
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -f concat -safe 0 -i " + '\u0022' + MainWindow.chunksDir + "\\chunks.txt" + '\u0022' + " -c copy " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();


startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath;
//FFmpeg Arguments
startInfo.Arguments = "/C ffmpeg.exe -i " + '\u0022' + MainWindow.workingTempDirectory + "\\withoutaudio.mkv" + '\u0022' + " -i " + MainWindow.workingTempDirectory + "\\Subtitles\\subtitle.mkv" + " -map 0:v -map 1:s -c copy " + '\u0022' + MainWindow.videoOutput + '\u0022';
//Console.WriteLine(startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}

}
Expand Down
5 changes: 2 additions & 3 deletions NotEnoughAV1Encodes/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,12 @@
<TabItem Header="Subtitles" Background="#FF2C2C2C" Foreground="White" Style="{DynamicResource DarkTabItem}">
<Grid Background="#19191919">
<Label Content="Subtitles" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="White" Margin="10,10,0,0" FontWeight="Bold" />
<CheckBox x:Name="CheckBoxSubitleStreamCopy" Content="Stream Copy embedded Subtitles" HorizontalAlignment="Left" Margin="56,56,0,0" VerticalAlignment="Top" Foreground="White"/>
<CheckBox x:Name="CheckBoxCustomSubtitles" Content="Custom Subtitles" HorizontalAlignment="Left" Margin="56,95,0,0" VerticalAlignment="Top" Foreground="White"/>
<ListBox x:Name="ListBoxSubtitles" HorizontalAlignment="Left" Height="100" Margin="56,159,0,0" VerticalAlignment="Top" Width="756" Background="#99151515" Foreground="White"/>
<Button x:Name="ButtonAddCustomSubtitle" Content="Add Subtitle" HorizontalAlignment="Left" Margin="56,129,0,0" VerticalAlignment="Top" Width="83" Height="25" Foreground="White" Background="#FF2B2B2B" Click="ButtonAddCustomSubtitle_Click"/>
<Button x:Name="ButtonDeleteSubtitle" Content="Remove Subtitle" HorizontalAlignment="Left" Margin="709,129,0,0" VerticalAlignment="Top" Width="103" Height="25" Click="ButtonDeleteSubtitle_Click" Background="#FF2B2B2B" Foreground="White"/>
<CheckBox x:Name="CheckBoxEnableSubtitles" Content="Enable Subtitles" HorizontalAlignment="Left" Margin="92,16,0,0" VerticalAlignment="Top" Foreground="White"/>
<Label Content="Only Stream Copy embedded subtiles is avaiable for now. Further functions will be implemented later" HorizontalAlignment="Left" Margin="266,10,0,0" VerticalAlignment="Top" Foreground="#FFFF0404" Background="Black"/>
<RadioButton x:Name="RadioButtonStreamCopySubtitle" Content="Stream Copy embedded Subtitles" HorizontalAlignment="Left" Margin="56,60,0,0" VerticalAlignment="Top" Foreground="White" IsChecked="True"/>
<RadioButton x:Name="RadioButtonCustomSubtitles" Content="Custom Subtitles" HorizontalAlignment="Left" Margin="56,100,0,0" VerticalAlignment="Top" Foreground="White"/>
</Grid>
</TabItem>
<TabItem Header="Program Settings" Background="#FF2C2C2C" Foreground="White" Style="{DynamicResource DarkTabItem}">
Expand Down
23 changes: 20 additions & 3 deletions NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public partial class MainWindow : Window
//------------------------------------------------------||
//----- Subtitles --------------------------------------||
public static bool subtitleStreamCopy = false;
public static bool subtitleCustom = false;
public static bool subtitles = false;
public static string[] SubtitleChunks;
public static int subtitleAmount = 0;
//----- Shutdown ---------------------------------------||
public static bool shutDownAfterEncode = false;
//------------------------------------------------------||
Expand All @@ -88,9 +91,9 @@ public MainWindow()
{
InitializeComponent();
CheckFfprobe();
CheckForResumeFile();
LoadProfiles();
LoadProfileStartup();
CheckForResumeFile();
}

public async void AsyncClass()
Expand Down Expand Up @@ -372,6 +375,16 @@ public void SetParametersBeforeEncode()
if (CheckBoxEnableSubtitles.IsChecked == true)
{
subtitles = true;
if (RadioButtonStreamCopySubtitle.IsChecked == true)
{
subtitleStreamCopy = true;
SetSubtitleParameters();
}
if (RadioButtonCustomSubtitles.IsChecked == true)
{
subtitleCustom = true;
SetSubtitleParameters();
}
}
//----------------------------------------------------------------------------------------||
//Shutdown -------------------------------------------------------------------------------||
Expand Down Expand Up @@ -546,6 +559,11 @@ public void SetAudioParameters()
}
}

public void SetSubtitleParameters()
{
SubtitleChunks = ListBoxSubtitles.Items.OfType<string>().ToArray();
}

//-------------------------------------------------------------------------------------------------||

//----------------------------------------- Encoders ----------------------------------------------||
Expand Down Expand Up @@ -1072,6 +1090,7 @@ private void LoadProfiles()
}
catch { }
}

private void LoadProfileStartup()
{
try
Expand Down Expand Up @@ -1378,8 +1397,6 @@ private void ButtonAddCustomSubtitle_Click(object sender, RoutedEventArgs e)
{
//Open the OpenFileDialog to set the Subtitle Input
OpenFileDialog openVideoFileDialog = new OpenFileDialog();
openVideoFileDialog.Filter = "SubRip|*.srt|SubStation Alpha|*.ass|WebVTT|*.vtt";

Nullable<bool> result = openVideoFileDialog.ShowDialog();

if (result == true)
Expand Down
54 changes: 43 additions & 11 deletions NotEnoughAV1Encodes/Subtitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,49 @@ public static void EncSubtitles()
if (!Directory.Exists(Path.Combine(MainWindow.workingTempDirectory, "Subtitles")))
Directory.CreateDirectory(Path.Combine(MainWindow.workingTempDirectory, "Subtitles"));

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = true;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath + "\\";
startInfo.Arguments = "/C ffmpeg.exe -i " + '\u0022' + MainWindow.videoInput + '\u0022' + " -vn -an -dn -c copy " + '\u0022' + MainWindow.workingTempDirectory + "\\Subtitles\\subtitle.mkv" + '\u0022';
process.StartInfo = startInfo;
//Console.WriteLine(startInfo.Arguments);
process.Start();
process.WaitForExit();
if (MainWindow.subtitleStreamCopy == true)
{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = true;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath + "\\";
startInfo.Arguments = "/C ffmpeg.exe -i " + '\u0022' + MainWindow.videoInput + '\u0022' + " -vn -an -dn -c copy " + '\u0022' + MainWindow.workingTempDirectory + "\\Subtitles\\subtitle.mkv" + '\u0022';
process.StartInfo = startInfo;
//Console.WriteLine(startInfo.Arguments);
process.Start();
process.WaitForExit();
}

if (MainWindow.subtitleCustom == true)
{
string subtitleMapping = "";
string subtitleInput = "";
int subtitleAmount = 0;

foreach (var items in MainWindow.SubtitleChunks)
{
subtitleInput += " -i " + '\u0022' + items + '\u0022';
subtitleMapping += " -map "+subtitleAmount;
subtitleAmount += 1;
}

Console.WriteLine(subtitleMapping + subtitleInput);


Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = true;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = MainWindow.exeffmpegPath + "\\";
startInfo.Arguments = "/C ffmpeg.exe" + subtitleInput + " -vn -an -dn -c copy " + subtitleMapping + " " + '\u0022' + MainWindow.workingTempDirectory + "\\Subtitles\\subtitlecustom.mkv" + '\u0022';
process.StartInfo = startInfo;
Console.WriteLine(startInfo.Arguments);
process.Start();
process.WaitForExit();
}
}

}
Expand Down

0 comments on commit 1bac0cb

Please sign in to comment.