音视频分离支持多选

croire 2 years ago
parent 4c260854f3
commit 338d7d3c87

@ -37,5 +37,21 @@ namespace DownKyi.Utils
return showDialog == true ? dialog.FileName : ""; return showDialog == true ? dialog.FileName : "";
} }
/// <summary>
/// 选择多个视频dialog
/// </summary>
/// <returns></returns>
public static string[] SelectMultiVideoFile()
{
// 选择文件
var dialog = new Microsoft.Win32.OpenFileDialog
{
Filter = "mp4 (*.mp4)|*.mp4",
Multiselect = true
};
var showDialog = dialog.ShowDialog();
return showDialog == true ? dialog.FileNames : new string[0];
}
} }
} }

@ -18,11 +18,25 @@ namespace DownKyi.ViewModels.Toolbox
#region 页面属性申明 #region 页面属性申明
private string videoPath; private string videoPathsStr;
public string VideoPath public string VideoPathsStr
{ {
get { return videoPath; } get => videoPathsStr;
set { SetProperty(ref videoPath, value); } set
{
SetProperty(ref videoPathsStr, value);
}
}
private string[] videoPaths;
public string[] VideoPaths
{
get => videoPaths;
set
{
videoPaths = value;
VideoPathsStr = string.Join(Environment.NewLine, value);
}
} }
private string status; private string status;
@ -38,7 +52,7 @@ namespace DownKyi.ViewModels.Toolbox
{ {
#region 属性初始化 #region 属性初始化
VideoPath = string.Empty; VideoPaths = new string[0];
#endregion #endregion
} }
@ -60,7 +74,7 @@ namespace DownKyi.ViewModels.Toolbox
return; return;
} }
VideoPath = DialogUtils.SelectVideoFile(); VideoPaths = DialogUtils.SelectMultiVideoFile();
} }
// 提取音频事件 // 提取音频事件
@ -78,24 +92,27 @@ namespace DownKyi.ViewModels.Toolbox
return; return;
} }
if (VideoPath == "") if (VideoPaths.Length <= 0)
{ {
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo")); eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo"));
return; return;
} }
// 音频文件名
string audioFileName = VideoPath.Remove(VideoPath.Length - 4, 4) + ".aac";
Status = string.Empty; Status = string.Empty;
await Task.Run(() => await Task.Run(() =>
{ {
// 执行提取音频程序
isExtracting = true; isExtracting = true;
FFmpegHelper.ExtractAudio(VideoPath, audioFileName, new Action<string>((output) => foreach (var item in VideoPaths)
{ {
Status += output + "\n"; // 音频文件名
})); string audioFileName = item.Remove(item.Length - 4, 4) + ".aac";
// 执行提取音频程序
FFmpegHelper.ExtractAudio(item, audioFileName, new Action<string>((output) =>
{
Status += output + "\n";
}));
}
isExtracting = false; isExtracting = false;
}); });
} }
@ -115,30 +132,34 @@ namespace DownKyi.ViewModels.Toolbox
return; return;
} }
if (VideoPath == "") if (VideoPaths.Length <= 0)
{ {
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo")); eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipNoSeletedVideo"));
return; return;
} }
// 视频文件名
string videoFileName = VideoPath.Remove(VideoPath.Length - 4, 4) + "_onlyVideo.mp4";
Status = string.Empty; Status = string.Empty;
await Task.Run(() => await Task.Run(() =>
{ {
// 执行提取视频程序
isExtracting = true; isExtracting = true;
FFmpegHelper.ExtractVideo(VideoPath, videoFileName, new Action<string>((output) => foreach (var item in VideoPaths)
{ {
Status += output + "\n"; // 视频文件名
})); string videoFileName = item.Remove(item.Length - 4, 4) + "_onlyVideo.mp4";
// 执行提取视频程序
FFmpegHelper.ExtractVideo(item, videoFileName, new Action<string>((output) =>
{
Status += output + "\n";
}));
}
isExtracting = false; isExtracting = false;
}); });
} }
// Status改变事件 // Status改变事件
private DelegateCommand<object> statusCommand; private DelegateCommand<object> statusCommand;
public DelegateCommand<object> StatusCommand => statusCommand ?? (statusCommand = new DelegateCommand<object>(ExecuteStatusCommand)); public DelegateCommand<object> StatusCommand => statusCommand ?? (statusCommand = new DelegateCommand<object>(ExecuteStatusCommand));
/// <summary> /// <summary>

@ -9,7 +9,7 @@
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"> <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled">
<Grid Margin="50,0"> <Grid Margin="50,0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="150" /> <RowDefinition Height="200" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -28,11 +28,11 @@
<TextBlock VerticalAlignment="Center" Text="{DynamicResource VideoFilePath}" /> <TextBlock VerticalAlignment="Center" Text="{DynamicResource VideoFilePath}" />
<TextBox <TextBox
Width="300" Width="300"
Height="20" Height="50"
Margin="0,10,10,10" Margin="0,10,10,10"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
IsReadOnly="True" IsReadOnly="True"
Text="{Binding VideoPath, Mode=TwoWay}" /> Text="{Binding VideoPathsStr, Mode=TwoWay}" />
<Button <Button
Width="75" Width="75"

Loading…
Cancel
Save