你好,FFMPEG 可視化

你好,FFMPEG 可視化

給大家看看我現在的玩具:

image

它有哪些功能呢?如你所見,不止於此

1. 視頻錄製

image

暫時只能錄製視頻,音頻無法錄製
FFMPEG.exe 暫時只支持視頻,音頻錄製需要下載額外的工具

2. 視頻處理

image

支持簡單的分割,裁剪,以及壓縮
簡單實用

3. 視頻轉Gif

image

支持高清模式,生成文件會更大

下載與使用

1. 安裝WebView2 RunTime

Webview2 – Microsoft Edge Developer
image
點擊 下載,然後安裝

2. 下載TidyView

這是WebView2的封裝

👉百度網盤 TidyVew 密碼:Tidy
image

TidyView不提供任何功能,具體功能需要以App形式存在

3. 下載FFMPEG Visual

這是一個 TidyView 的App

👉百度網盤 FFMPEG Visual 密碼:Tidy
image

上述是 FFMPEG Visual 的目錄結構
其中 main.edge 便是入口程序

4. 打開FFMPEG Visual

右鍵 main.edge 👉 打開方式 👉 選擇其他應用
👉 更多應用 👉 在這台電腦上選擇其他應用 👉 找到TidyView.exe 👉 打開

下次打開,勾選 始終使用此應用打開.edge文件即可
image

5. 第一次使用

第一次使用時,程序會自動下載ffmpeg.exe
下載完成後,會進入主頁面
image

枯燥環節

下面便是技術環節了

1. 啥是main.edge?

其實就是一個腳本文件,TidyScript,👉TidyScript小組
有C#的語法,也有JavaScript的一些特徵
運行速度慢,但是靈活性高

log.clear();

var Url;
var JS;

void download(string url)
{
  var path=Environment["ScriptDir"]+"\\ffmpeg.zip";
  var downitem={};
  downitem.url=url;
  downitem.path=path;
  downitem.file="FFMPEG.exe";
  downitem.dest="用於視頻操作的核心程序";
  var params={};
  params.download=[];
  params.download.Add(downitem);
  Launch("Download/download.edge",params);
}

void OnLoad()
{
  EvalJS($"_tool_bar_ini({file.read(locate("plugins.json"))})");
}

void LoadPage(string Page)
{
  Launch("frame",Page);
}

if(file.exists(locate("ffmpeg.exe")))
{
  Url="main.html";
  JS="main.js";
}
else if(file.exists(locate("ffmpeg.zip")))
{
  Url="main.html";
  JS="main.js";
  zip.uncompress(locate("ffmpeg.zip"),Environment["ScriptDir"] as string);
  thread.sleep(1000);
  file.delete(locate("ffmpeg.zip"));
}
else
{
  Url="//shareyun.lanzous.com/iyuEeok4p6j";
  JS="main_download_ffmpeg.js";
}

2. 工作框架

從打包的角度,有兩個東西,一個是TidyView,另一個是TidyScript寫的腳本
往下面探一層,有四個東西:

  1. WebView2提供瀏覽器功能
  2. C#寫的dll提供本地化功能
  3. Html+JS提供頁面UI功能
  4. TidyScript寫的腳本提供業務功能

如果把WebView2作為基礎件,忽略掉,就是下面這個結構。

image

3. 工作流程

image
image

4. 交互方案

每個頁面都會注入基本JS

var edge = window.chrome.webview.hostObjects.edge;
var _id = (id) => { return document.getElementById(id); };
var _attr = (id, name) => { return document.getElementById(id).getAttribute(name) };
var call = (name, ...args) => { edge.CallApp(app_frame_path, name, ...args) };
var _frame = (frame_path) =>
{
    var paths = frame_path.split(".");
    var last = null;
    for (var i in paths) {
        if (last == null) {
            last = document.getElementById(paths[i]);
        }
        else {
            last = last.contentDocument.getElementById(paths[i]);
        }
    }
    return last;
};

假設一個TidyScript腳本如下

void Hello()
{
    EvalJS("console.log('hello world')");
}
void Hello(string Name)
{
    EvalJS($"console.log('hello world {Name}')");
}

JS中調用TidyScript中的函數就很簡單
直接在JS中這樣寫:call("Hello")
或者這樣寫:call("Hello","TidyScript")

那麼TidyScript如何調用JS呢?
其實上面的代碼已經告訴我們答案:EvalJS("console.log('hello world')")
其核心功能是WebView2提供的
ExecuteScriptAsync(string Script)

namespace Microsoft.Web.WebView2.WinForms
{
    public class WebView2 : Control, ISupportInitialize
    {
        public WebView2();
        //....
        public Uri Source { get; set; }
        public CoreWebView2 CoreWebView2 { get; }
        public CoreWebView2CreationProperties CreationProperties { get; set; }
        protected override CreateParams CreateParams { get; }
        //下面這個方法提供運行JS腳本功能
        public Task<string> ExecuteScriptAsync(string script);
        public void GoBack();
        //.....
    }
}

FFMPEG Visual 結構

image

最後

這個玩具很不錯,既能我自己玩,也能給大家玩。
但是它還是有點簡陋,下面會把它慢慢完善
下一個玩具呢?
暫時還不知道,確定好了,再說。