Skip to content

Commit

Permalink
测试自动构建
Browse files Browse the repository at this point in the history
  • Loading branch information
zen committed May 26, 2024
1 parent 0c8ffd3 commit 7ccb519
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 19 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/xz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# .github/workflows/release.yml
name: xz_releaser

on:
pull_request:
push:
# run only against tags
tags:
- "xz*"
# branches: [ "master" ]

permissions:
contents: write
# packages: write
# issues: write

jobs:
dockerbuilder:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: go
run: go build -o conv main.go
- name: pwd
run: pwd
- name: build
run: docker build -t videos:latest ${{ github.workspace }}
- name: saveSpace
run: rm -rf /opt/hostedtoolcache
- name: export
run: docker save videos:latest | xz --threads=0 -9e --memlimit-compress=0 > ConvertVideos.tar.xz
- name: Upload
uses: actions/upload-artifact@v4
with:
name: images
path: ${{ github.workspace }}/ConvertVideos.tar.xz
compression-level: 9 # max compression
- name: release
run: |
time_var=$(date +"%Y%m%d-%H%M%S")
gh release create $time_var --generate-notes
gh release upload $time_var ${{ github.workspace }}/ConvertVideos.tar.xz
env:
GH_TOKEN: ${{ github.token }}
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN go env -w GOBIN=/root/go/bin
RUN mkdir -p /root/app
WORKDIR /root/app

COPY . .
RUN apk add ffmpeg mediainfo build-base
RUN apk add opencore-amr-dev libvorbis-dev mediainfo build-base xz wget ca-certificates dialog make cmake alpine-sdk gcc nasm yasm aom-dev libvpx-dev libwebp-dev x264-dev x265-dev dav1d-dev xvidcore-dev fdk-aac-dev opencore-amr-dev libvorbis-dev

RUN go build -o /usr/local/bin/conv main.go
RUN chmod +x /usr/local/bin/conv
WORKDIR /usr/local/bin

RUN wget https://ffmpeg.org/releases/ffmpeg-7.0.1.tar.xz
RUN tar xvf ffmpeg-7.0.1.tar.xz
WORKDIR /root/app/ffmpeg-7.0.1
RUN ./configure --prefix=/usr/local --enable-pthreads --enable-pic --arch=amd64 --enable-shared --enable-libaom --enable-gpl --enable-nonfree --enable-postproc --enable-avfilter --enable-pthreads --enable-libx264 --enable-libx265 --enable-libwebp --enable-libvpx --enable-libvorbis --enable-libfdk-aac --enable-libdav1d --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-ffplay
RUN make -j
RUN make install
CMD ["conv"]
# docker build -t videos:latest .
# docker run -dit --rm --name vp9 -e root=/data -e to=vp9 -e level=Debug -v /media/zen/swap/pikpak/telegram:/data videos:latest
12 changes: 3 additions & 9 deletions constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

var (
Root string = "/mnt/e/pikpak/hidden" // 工作目录 如果为空 默认/data
To string = "vp9" // 转换到的编码 如果为空 默认vp9
Level string = "Debug" //日志的输出等级
Root string = "/media/zen/ugreen/其他/Agent Red Girl/Animations" // 工作目录 如果为空 默认/data
//To string = "vp9" // 转换到的编码 如果为空 默认vp9
To string = "merge" // 转换到的编码 如果为空 默认vp9
Direction string = "ToRight"
CpuNums string
)
Expand Down Expand Up @@ -39,9 +39,3 @@ func GetTo() string {
func SetTo(s string) {
To = s
}
func GetLevel() string {
return Level
}
func SetLevel(s string) {
Level = s
}
27 changes: 20 additions & 7 deletions conv/merge.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
package conv

import (
"fmt"
"github.com/zhangyiming748/ConvertVideo/constant"
"github.com/zhangyiming748/ConvertVideo/mediainfo"
"github.com/zhangyiming748/ConvertVideo/util"
"github.com/zhangyiming748/FastMediaInfo"
"log"
"os"
"os/exec"
"path"
"strconv"
"strings"
)

/*
mkv添加ass
*/
func MkvWithAss(in mediainfo.BasicInfo) {
mi := FastMediaInfo.GetStandMediaInfo(in.FullPath)
FrameCount := mi.Video.FrameCount
var (
width, _ = strconv.Atoi(mi.Video.Width)
height, _ = strconv.Atoi(mi.Video.Height)
)
crf := FastMediaInfo.GetCRF("vp9", width, height)
if crf == "" {
crf = "31"
log.Printf("没有查询到crf,使用默认crf:%v\n", crf)
}
srt := strings.Replace(in.FullPath, in.PurgeExt, "srt", 1)
//ass := strings.Replace(file.FullPath, ".mp4", ".ass", 1)
if util.IsExist(srt) {
// output := strings.Replace(file, ".mp4", "_with_subtitle.mp4", 1)
ext := path.Ext(in.FullPath)
output := strings.Replace(in.FullPath, ext, "_with_subtitle.mkv", 1)
//cmd := exec.Command("ffmpeg", "-i", file.FullPath, "-f", "srt", "-i", srt, "-c:v", "libx265", "-c:a", "aac", "-ac", "1", "-tag:v", "hvc1", "-c:s", "mov_text", output)
// ffmpeg -i input.mkv -i input.ass -c copy -c:s ass output.mkv
cmd := exec.Command("ffmpeg", "-i", in.FullPath, "-i", srt, "-c:v", "libvpx-vp9", "-c:a", "libvorbis", "-ac", "1", "-c:s", "ass", output)
var cmd *exec.Cmd
cmd = exec.Command("ffmpeg", "-threads", constant.GetCpuNums(), "-i", in.FullPath, "-i", srt, "-c:v", "libvpx-vp9", "-crf", crf, "-c:a", "libvorbis", "-ac", "1", "-c:s", "ass", "-threads", constant.GetCpuNums(), output)
log.Printf("生成的命令: %s\n", cmd.String())
combinedOutput, err := cmd.CombinedOutput()
msg := fmt.Sprintf("当前正在处理的视频总帧数:%v", FrameCount)
err := util.ExecCommand(cmd, msg)
if err != nil {
log.Printf("命令执行失败: %s\n", err.Error())
return
} else {
log.Printf("命令成功执行: %s\n", string(combinedOutput))
log.Printf("命令成功执行: %s\n", cmd.String())
os.Remove(in.FullPath)
}
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
)

func main() {
Expand Down Expand Up @@ -69,7 +70,7 @@ func main() {
func setLog(level string) {
// 创建一个用于写入文件的Logger实例
fileLogger := &lumberjack.Logger{
Filename: "logs/mylog.log",
Filename: strings.Join([]string{constant.GetRoot(), "mylog.log"}, string(os.PathSeparator)),
MaxSize: 1, // MB
MaxBackups: 3,
MaxAge: 28, // days
Expand Down

0 comments on commit 7ccb519

Please sign in to comment.