Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vset",
"productName": "VSET",
"version": "4.2.2",
"version": "4.3.6",
"description": "VSET",
"author": "NangInShell",
"main": "./out/main/index.js",
Expand Down
13 changes: 5 additions & 8 deletions src/main/getCorePath.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TaskConfig } from '@shared/type/taskConfig'
import path from 'node:path'
import { app } from 'electron'

Expand Down Expand Up @@ -30,7 +31,6 @@ export function getExecPath(): { vspipe: string, ffmpeg: string, ffprobe: string

/**
* 获取 VSET-core 中的额外超分模型文件夹路径
* @returns {string} 额外超分模型文件夹路径
*/
export function getExtraSRModelPath(): string {
return path.join(getCorePath(), 'vs-coreplugins', 'models', 'VSET_ExtraSrModel')
Expand All @@ -39,18 +39,15 @@ export function getExtraSRModelPath(): string {
/**
* 获取 VSET 生成的设置文件路径
* 暂时存放在 config_json.outputfolder 目录下
* @param config_json
*/
export function getGenSettingsPath(config_json): string {
return path.join(config_json.outputfolder, 'setting.json')
export function getGenSettingsPath(task_config: TaskConfig): string {
return path.join(task_config.outputFolder, 'setting.json')
}

/**
* 获取 VSET 生成的 vpy 文件路径
* 暂时存放在 config_json.outputfolder 目录下
* @param config_json
* @param base_name 生成的 vpy 文件名(不含扩展名)
*/
export function getGenVpyPath(config_json, base_name: string): string {
return path.join(config_json.outputfolder, `${base_name}.vpy`)
export function getGenVpyPath(task_config: TaskConfig, base_name: string): string {
return path.join(task_config.outputFolder, `${base_name}.vpy`)
}
14 changes: 6 additions & 8 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { writeFileSync } from 'node:fs'
import path from 'node:path'
import { electronApp, is, optimizer } from '@electron-toolkit/utils'
import { app, BrowserWindow, ipcMain, nativeImage, shell } from 'electron'
import appIcon from '../../resources/icon.png?asset'
import { killAllProcesses } from './childProcessManager'
import { getGenSettingsPath } from './getCorePath'
import { getCpuInfo, getGpuInfo } from './getSystemInfo'
import { openDirectory } from './openDirectory'
import { preview, previewFrame } from './previewOutput'
import { runCommand } from './runCommand'
import { PauseCommand, runCommand } from './runCommand'
import { writeSettingsJson } from './writeFile'

function createWindow(): BrowserWindow {
const mainWindow = new BrowserWindow({
Expand All @@ -19,7 +18,7 @@ function createWindow(): BrowserWindow {
show: false,
autoHideMenuBar: true,
icon: nativeImage.createFromPath(appIcon),
title: 'VSET 4.2.2',
title: 'VSET 4.3.6',
webPreferences: {
preload: path.join(__dirname, '../preload/index.js'),
sandbox: false,
Expand All @@ -29,16 +28,15 @@ function createWindow(): BrowserWindow {
// ipcMain
ipcMain.on('execute-command', runCommand)

ipcMain.on('pause', PauseCommand)

ipcMain.on('preview', preview)

ipcMain.on('preview-frame', previewFrame)

ipcMain.on('stop-all-processes', killAllProcesses)

ipcMain.on('generate-json', (_, data) => {
const filePath = getGenSettingsPath(data)
writeFileSync(filePath, JSON.stringify(data, null, 2))
})
ipcMain.on('generate-json', writeSettingsJson)

ipcMain.handle('open-folder-dialog', openDirectory)

Expand Down
2 changes: 1 addition & 1 deletion src/main/openDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { dialog } from 'electron'

/**
* @description Open a directory or file/multiple files
* @param _ Unused parameter, can be used for context in future
* @param _ IpcMainEvent
* @param p The properties of the dialog
*/
export async function openDirectory(_, p: Array<'openFile' | 'openDirectory' | 'multiSelections'>): Promise<Array<string>> {
Expand Down
25 changes: 13 additions & 12 deletions src/main/previewOutput.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import type { TaskConfig } from '@shared/type/taskConfig'
import type { IpcMainEvent } from 'electron'
import { Buffer } from 'node:buffer'
import { spawn } from 'node:child_process'
import { writeFileSync } from 'node:fs'
import path from 'node:path'
import iconv from 'iconv-lite'
import { addProcess, removeProcess } from './childProcessManager'
import { getExecPath, getGenVpyPath } from './getCorePath'
import { generate_vpy } from './runCommand'
import { writeVpyFile } from './writeFile'

export async function preview(event, config_json): Promise<void> {
export async function preview(event: IpcMainEvent, task_config: TaskConfig): Promise<void> {
const vspipePath = getExecPath().vspipe

const videos = config_json.fileList
if (videos?.length === 0) {
if (!task_config.fileList || task_config.fileList.length === 0) {
event.sender.send('ffmpeg-output', '错误: 没有提供用于预览的文件。\n')
event.sender.send('ffmpeg-finish')
return
}
const video = videos[0]

const baseName = path.basename(video, path.extname(video))
const vpyPath = getGenVpyPath(config_json, baseName)
const video = task_config.fileList[0] // 只预览第一个视频

// ========== 生成 vpy 文件 ==========
const vpyFile = generate_vpy(config_json, video)
writeFileSync(vpyPath, vpyFile)
// 生成唯一 vpy 路径
const baseName = path.basename(video, path.extname(video))
const vpyPath = getGenVpyPath(task_config, baseName)
await writeVpyFile(null, vpyPath, task_config.vpyContent, video)

let info: {
width: string
Expand Down Expand Up @@ -78,12 +79,12 @@ export async function preview(event, config_json): Promise<void> {
event.sender.send('ffmpeg-finish')
}

export async function previewFrame(event: any, vpyfile: string, currentFrame: number): Promise<void> {
export async function previewFrame(event: IpcMainEvent, vpy_path: string, current_frame: number): Promise<void> {
const vspipePath = getExecPath().vspipe
const ffmpegPath = getExecPath().ffmpeg

// 构造一行命令
const cmd = `"${vspipePath}" -c y4m --start ${currentFrame} --end ${currentFrame} "${vpyfile}" - | "${ffmpegPath}" -y -f yuv4mpegpipe -i - -frames:v 1 -vcodec png -f image2pipe -`
const cmd = `"${vspipePath}" -c y4m --start ${current_frame} --end ${current_frame} "${vpy_path}" - | "${ffmpegPath}" -y -f yuv4mpegpipe -i - -frames:v 1 -vcodec png -f image2pipe -`

const vspipePreviewProcess = spawn(cmd, { shell: true })
addProcess(vspipePreviewProcess)
Expand Down
Loading
Loading