Compare commits

..

No commits in common. "7717bf13a17ae357950ec80b7ba81764e9673ffe" and "ab3207d44199ed8202d3242c7d837a53eccec586" have entirely different histories.

5 changed files with 65 additions and 82 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,9 +4,8 @@ import (
"embed" "embed"
"os" "os"
"videoconcat/services"
"github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/application"
"videoconcat/services"
) )
//go:embed assets //go:embed assets
@ -55,9 +54,9 @@ func main() {
// 创建窗口 // 创建窗口
services.LogDebug("创建应用窗口...") services.LogDebug("创建应用窗口...")
window := app.Window.NewWithOptions(application.WebviewWindowOptions{ window := app.Window.NewWithOptions(application.WebviewWindowOptions{
Title: "视频拼接工具", Title: "视频拼接工具",
Width: 1100, Width: 1100,
Height: 800, Height: 800,
MinWidth: 800, MinWidth: 800,
MinHeight: 600, MinHeight: 600,
}) })

View File

@ -23,16 +23,16 @@ func NewExtractService() *ExtractService {
// ExtractFrameRequest 抽帧请求 // ExtractFrameRequest 抽帧请求
type ExtractFrameRequest struct { type ExtractFrameRequest struct {
FolderPath string `json:"folderPath"` FolderPath string `json:"folderPath"`
ExtractCount int `json:"extractCount"` // 每个视频生成的数量 ExtractCount int `json:"extractCount"` // 每个视频生成的数量
} }
// ExtractFrameResult 抽帧结果 // ExtractFrameResult 抽帧结果
type ExtractFrameResult struct { type ExtractFrameResult struct {
VideoPath string `json:"videoPath"` VideoPath string `json:"videoPath"`
OutputPath string `json:"outputPath"` OutputPath string `json:"outputPath"`
Success bool `json:"success"` Success bool `json:"success"`
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
} }
// ListVideos 列出文件夹中的视频文件 // ListVideos 列出文件夹中的视频文件
@ -213,37 +213,37 @@ func (s *ExtractService) ExtractFrames(ctx context.Context, req ExtractFrameRequ
// 检查文件是否已存在 // 检查文件是否已存在
if _, err := os.Stat(t.OutputPath); err == nil { if _, err := os.Stat(t.OutputPath); err == nil {
mu.Lock()
current++
result := ExtractFrameResult{
VideoPath: t.VideoPath,
OutputPath: t.OutputPath,
Success: true,
}
results = append(results, result)
mu.Unlock()
return
}
err := s.RemoveFrameRandom(ctx, t.VideoPath, t.OutputPath)
mu.Lock() mu.Lock()
current++ current++
var result ExtractFrameResult result := ExtractFrameResult{
if err != nil { VideoPath: t.VideoPath,
result = ExtractFrameResult{ OutputPath: t.OutputPath,
VideoPath: t.VideoPath, Success: true,
Success: false,
Error: err.Error(),
}
} else {
result = ExtractFrameResult{
VideoPath: t.VideoPath,
OutputPath: t.OutputPath,
Success: true,
}
} }
results = append(results, result) results = append(results, result)
mu.Unlock() mu.Unlock()
return
}
err := s.RemoveFrameRandom(ctx, t.VideoPath, t.OutputPath)
mu.Lock()
current++
var result ExtractFrameResult
if err != nil {
result = ExtractFrameResult{
VideoPath: t.VideoPath,
Success: false,
Error: err.Error(),
}
} else {
result = ExtractFrameResult{
VideoPath: t.VideoPath,
OutputPath: t.OutputPath,
Success: true,
}
}
results = append(results, result)
mu.Unlock()
}(task) }(task)
} }
@ -301,28 +301,29 @@ func (s *ExtractService) ModifyVideosMetadata(ctx context.Context, folderPath st
outputFileName := fmt.Sprintf("modify%d%s", randomNum, filepath.Base(videoPath)) outputFileName := fmt.Sprintf("modify%d%s", randomNum, filepath.Base(videoPath))
outputPath := filepath.Join(outputDir, outputFileName) outputPath := filepath.Join(outputDir, outputFileName)
err := s.ModifyByMetadata(ctx, videoPath, outputPath) err := s.ModifyByMetadata(ctx, videoPath, outputPath)
mu.Lock() mu.Lock()
current++ current++
var result ExtractFrameResult var result ExtractFrameResult
if err != nil { if err != nil {
result = ExtractFrameResult{ result = ExtractFrameResult{
VideoPath: videoPath, VideoPath: videoPath,
Success: false, Success: false,
Error: err.Error(), Error: err.Error(),
}
} else {
result = ExtractFrameResult{
VideoPath: videoPath,
OutputPath: outputPath,
Success: true,
}
} }
results = append(results, result) } else {
mu.Unlock() result = ExtractFrameResult{
VideoPath: videoPath,
OutputPath: outputPath,
Success: true,
}
}
results = append(results, result)
mu.Unlock()
}(video) }(video)
} }
wg.Wait() wg.Wait()
return results, nil return results, nil
} }

View File

@ -381,16 +381,16 @@ func (s *VideoService) JoinVideos(ctx context.Context, req VideoConcatRequest) (
} }
helper := GetFFmpegHelper() helper := GetFFmpegHelper()
if !helper.IsAvailable() { if !helper.IsAvailable() {
LogError("ffmpeg 不可用") LogError("ffmpeg 不可用")
result.Status = "拼接失败" result.Status = "拼接失败"
result.Progress = "失败" result.Progress = "失败"
mu.Lock() mu.Lock()
results = append(results, result) results = append(results, result)
mu.Unlock() mu.Unlock()
return return
} }
cmd := helper.Command(args...) cmd := helper.Command(args...)
cmd.Run() // 忽略错误,水印是可选的 cmd.Run() // 忽略错误,水印是可选的
} }
@ -438,3 +438,4 @@ func (s *VideoService) JoinVideos(ctx context.Context, req VideoConcatRequest) (
wg.Wait() wg.Wait()
return results, nil return results, nil
} }