Skip to content

Commit

Permalink
release v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gsxhnd committed May 30, 2022
1 parent e6e24c7 commit bd8faca
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
"showLog": true,
"debugAdapter": "dlv-dap",
"program": "${workspaceRoot}/",
"args": ["video_subtitle", "--source_root_path=test", "--exec=false"],
"args": [
"video_subtitle",
"--source_root_path=test",
"--dest_path=test/result",
"--exec=false"
],
"output": "${workspaceRoot}/build/garage",
"trace": "verbose",
"cwd": "${workspaceRoot}"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Version 0.0.4

- FIX: 修改视频输出文件未知错误
- FEAT: 视频命令行功能参数添加
- FEAT: 视频命令行功能日志输出内容增加

## Version 0.0.3

- FEAT: 添加了视频处理的相关命令
Expand Down
26 changes: 15 additions & 11 deletions batch/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (
)

type VideoBatch struct {
SourceRootPath string
SourceVideoType string
SourceSubtitleType string
DestPath string
DestVideoType string
Advance string
Logger *zap.Logger
SourceRootPath string
SourceVideoType string
SourceSubtitleType string
SourceSubtitleNumber int
SourceSubtitleLanguage string
SourceSubtitleTitle string
DestPath string
DestVideoType string
Advance string
Logger *zap.Logger
}

func (vb *VideoBatch) GetVideos() ([]string, error) {
Expand Down Expand Up @@ -49,12 +52,13 @@ func (vb *VideoBatch) GetVideos() ([]string, error) {
}

func (vb *VideoBatch) GetSubtitleBatch(videos []string) []string {
t := `ffmpeg.exe -i "%v" -sub_charenc UTF-8 -i "%v" -metadata:s:s:0 language=chi -metadata:s:s:0 title="Chinese" -c copy %v "%v"`
t := `ffmpeg.exe -i "%v" -sub_charenc UTF-8 -i "%v" -metadata:s:s:%v language=%v -metadata:s:s:%v title="%v" -c copy %v "%v"`
var batch = []string{}
for _, v := range videos {
sourceVideo := filepath.Join(vb.SourceRootPath, v+vb.SourceVideoType)
sourceSubtitle := filepath.Join(vb.SourceRootPath, v+vb.SourceSubtitleType)
s := fmt.Sprintf(t, sourceVideo, sourceSubtitle, vb.Advance, vb.DestPath+v+vb.DestVideoType)
destVideo := filepath.Join(vb.DestPath, v+vb.DestVideoType)
s := fmt.Sprintf(t, sourceVideo, sourceSubtitle, vb.SourceSubtitleNumber, vb.SourceSubtitleLanguage, vb.SourceSubtitleNumber, vb.SourceSubtitleTitle, vb.Advance, destVideo)
batch = append(batch, s)
}
return batch
Expand All @@ -72,8 +76,8 @@ func (vb *VideoBatch) GetConvertBatch(videos []string) []string {
}

func (vb *VideoBatch) CreateDestDir() error {
destDir := path.Join(vb.SourceRootPath, vb.DestPath)
vb.Logger.Info("Start creating destination directory" + destDir)
destDir := path.Join(vb.DestPath)
vb.Logger.Info("Start creating destination directory: " + destDir)
time.Sleep(500 * time.Millisecond)
if fi, err := os.Stat(destDir); err != nil {
if os.IsNotExist(err) {
Expand Down
12 changes: 12 additions & 0 deletions cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ var (
Name: "source_subtitle_type",
Value: ".ass",
}
source_subtitle_number_flag = &cli.IntFlag{
Name: "source_subtitle_number_type",
Value: 0,
}
source_subtitle_language_flag = &cli.StringFlag{
Name: "source_subtitle_language",
Value: "chi",
}
source_subtitle_title_flag = &cli.StringFlag{
Name: "source_subtitle_title",
Value: "Chinese",
}
dest_path_flag = &cli.StringFlag{
Name: "dest_path",
Value: "./result/",
Expand Down
27 changes: 20 additions & 7 deletions cmd/video_subtitle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strconv"

"github.com/gsxhnd/garage/batch"
"github.com/gsxhnd/garage/utils"
Expand All @@ -18,6 +19,9 @@ var videoSubtitleCmd = &cli.Command{
source_root_path_flag,
source_video_type_flag,
source_subtitle_type_flag,
source_subtitle_number_flag,
source_subtitle_language_flag,
source_subtitle_title_flag,
dest_path_flag,
dest_video_type_flag,
advance_flag,
Expand All @@ -26,13 +30,16 @@ var videoSubtitleCmd = &cli.Command{
Action: func(c *cli.Context) error {
logger := utils.GetLogger()
var vb = &batch.VideoBatch{
SourceRootPath: c.String("source_root_path"),
SourceVideoType: c.String("source_video_type"),
SourceSubtitleType: c.String("source_subtitle_type"),
DestPath: c.String("dest_path"),
DestVideoType: c.String("dest_video_type"),
Advance: c.String("advance"),
Logger: logger,
SourceRootPath: c.String("source_root_path"),
SourceVideoType: c.String("source_video_type"),
SourceSubtitleType: c.String("source_subtitle_type"),
SourceSubtitleNumber: c.Int("source_subtitle_number"),
SourceSubtitleLanguage: c.String("source_subtitle_language"),
SourceSubtitleTitle: c.String("source_subtitle_title"),
DestPath: c.String("dest_path"),
DestVideoType: c.String("dest_video_type"),
Advance: c.String("advance"),
Logger: logger,
}
vl, err := vb.GetVideos()
if err != nil {
Expand All @@ -44,6 +51,12 @@ var videoSubtitleCmd = &cli.Command{
if err := vb.CreateDestDir(); err != nil {
return err
}
vb.Logger.Info("Source videos directory: " + vb.SourceRootPath)
vb.Logger.Info("Get matching video count: " + strconv.Itoa(len(vl)))
vb.Logger.Info("Target video's subtitle stream number: " + strconv.Itoa(vb.SourceSubtitleNumber))
vb.Logger.Info("Target video's subtitle language: " + vb.SourceSubtitleLanguage)
vb.Logger.Info("Target video's subtitle title: " + vb.SourceSubtitleTitle)
vb.Logger.Info("Dest video directory: " + vb.DestPath)

batch := vb.GetSubtitleBatch(vl)
if c.Bool("exec") {
Expand Down

0 comments on commit bd8faca

Please sign in to comment.