Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
januwA committed Sep 25, 2020
1 parent 2637f73 commit 71f51aa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
41 changes: 31 additions & 10 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using fpath = System.IO.Path;
using io = System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -28,19 +28,40 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
this.AllowDrop = true;
ffmpegExe = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe";
ffplayExe = AppDomain.CurrentDomain.BaseDirectory + "ffplay.exe";
// 1. 先在命令行PATH中找ffmpeg
// 2. 其次在程序执行目录中ffmpeg
// 3. 都没找到退出

if(System.IO.File.Exists(ffmpegExe) == false)
ffmpegExe = GetFullPath("ffmpeg.exe");
ffplayExe = GetFullPath("ffplay.exe");

if(ffmpegExe == null) ffmpegExe = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe";
if (ffplayExe == null) ffplayExe = AppDomain.CurrentDomain.BaseDirectory + "ffplay.exe";

if (System.IO.File.Exists(ffmpegExe) == false)
{
MessageBox.Show("未找到[ffmpeg.exe]", "文件未找到");
MessageBox.Show("未找到[ffmpeg.exe],工具将无法使用", "错误",MessageBoxButton.OK, MessageBoxImage.Error);
System.Windows.Application.Current.Shutdown();
}

if (System.IO.File.Exists(ffplayExe) == false)
{
MessageBox.Show("未找到[ffplay.exe]", "文件未找到");
MessageBox.Show("未找到[ffplay.exe],播放功能无法使用", "错误",MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private string GetFullPath(string fileName)
{
if (io.File.Exists(fileName))
return io.Path.GetFullPath(fileName);

var values = Environment.GetEnvironmentVariable("PATH");
foreach (var path in values.Split(io.Path.PathSeparator))
{
var fullPath = io.Path.Combine(path, fileName);
if (io.File.Exists(fullPath))
return fullPath;
}
return null;
}

private void Drop1(object sender, DragEventArgs e)
Expand Down Expand Up @@ -84,11 +105,11 @@ private void execute(string command)
/// <returns></returns>
private string getOutputFilepath(string extension = "")
{
extension = extension.Length != 0 ? extension : fpath.GetExtension(srcFilePath);
extension = extension.Length != 0 ? extension : io.Path.GetExtension(srcFilePath);
string time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds().ToString();

// xxx/xxx/[time]-oldname.extension
return fpath.GetDirectoryName(srcFilePath) + "\\[" + time + "]-" + fpath.GetFileNameWithoutExtension(srcFilePath) + extension;
return io.Path.GetDirectoryName(srcFilePath) + "\\[" + time + "]-" + io.Path.GetFileNameWithoutExtension(srcFilePath) + extension;
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 使用FFmpeg命令行处理视频的简单工具

- [ffmpeg官网](https://ffmpeg.org/)
- [下载ffmpeg](https://github.com/BtbN/FFmpeg-Builds/releases)可执行文件(lgpl.zip),然后将bin目录添加到PATH环境变量,或者将bin下面的exe拷贝到本软件的exe同级目录下
- 没有找到ffmpeg.exe将无法运行

![](./images/2020-09-24-22-49-01.png)

0 comments on commit 71f51aa

Please sign in to comment.