mirror of
https://github.com/fxkt-tech/liv
synced 2025-09-26 20:11:20 +08:00
feat: fsugar add ass_subtitle
This commit is contained in:
@@ -7,22 +7,49 @@ import (
|
||||
"github.com/fxkt-tech/liv/ffmpeg"
|
||||
"github.com/fxkt-tech/liv/ffmpeg/codec"
|
||||
"github.com/fxkt-tech/liv/ffmpeg/filter"
|
||||
"github.com/fxkt-tech/liv/ffmpeg/filter/fsugar"
|
||||
"github.com/fxkt-tech/liv/ffmpeg/input"
|
||||
"github.com/fxkt-tech/liv/ffmpeg/output"
|
||||
"github.com/fxkt-tech/liv/ffprobe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
infile = "in.mp4"
|
||||
|
||||
ffp, _ = ffprobe.New(
|
||||
ffprobe.WithDebug(true),
|
||||
).Input(infile).Extract(ctx)
|
||||
vs = ffp.GetFirstVideoStream()
|
||||
ow, oh = vs.Width, vs.Height
|
||||
|
||||
// inputs
|
||||
iMain = input.WithSimple("in.mp4")
|
||||
iMain = input.WithSimple(infile)
|
||||
|
||||
sw = int32(float32(ow) * 0.8)
|
||||
sh = int32(float32(oh) * 0.08)
|
||||
sx = int32(float32(ow) * 0.1)
|
||||
sy = int32(float32(oh) * 0.91)
|
||||
fontsize = sh
|
||||
marginv = sy
|
||||
|
||||
// filters
|
||||
fDelogo = filter.Crop("iw*0.8", "ih*0.08", "iw*0.1", "ih*0.91").Use(iMain.V())
|
||||
fDelogo = filter.Crop(sw, sh, sx, sy).Use(iMain.V())
|
||||
fGBlur = filter.GBlur(25).Use(fDelogo)
|
||||
fOverlay = filter.Overlay("W*0.1", "H*0.91").Use(iMain.V(), fGBlur)
|
||||
fSubtitles = filter.Subtitles("subtitle.srt", "", "MarginV=26,Alignment=6").Use(fOverlay)
|
||||
fOverlay = filter.Overlay(sx, sy).Use(iMain.V(), fGBlur)
|
||||
fSubtitles = filter.Subtitles("subtitle.srt", "",
|
||||
fsugar.NewAssSubtitle().
|
||||
SetPlayResX(ow).
|
||||
SetPlayResY(oh).
|
||||
SetFontSize(fontsize).
|
||||
SetMarginV(marginv).
|
||||
// SetFontName("阿里巴巴普惠体 3.0").
|
||||
SetFontName("报隶-简").
|
||||
SetAlignment(6).
|
||||
String(),
|
||||
).Use(fOverlay)
|
||||
|
||||
oOnly = output.New(
|
||||
output.Map(fSubtitles),
|
||||
@@ -36,6 +63,7 @@ func main() {
|
||||
err := ffmpeg.New(
|
||||
ffmpeg.WithDebug(true),
|
||||
ffmpeg.WithDry(true),
|
||||
ffmpeg.WithLogLevel("info"),
|
||||
).
|
||||
AddInput(iMain).
|
||||
AddFilter(fDelogo, fGBlur, fOverlay, fSubtitles).
|
||||
|
58
ffmpeg/filter/fsugar/subtitle.go
Normal file
58
ffmpeg/filter/fsugar/subtitle.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package fsugar
|
||||
|
||||
import "fmt"
|
||||
|
||||
type AssSubtitle struct {
|
||||
playResX int32
|
||||
playResY int32
|
||||
fontsize int32
|
||||
marginv int32
|
||||
fontname string
|
||||
alignment int32
|
||||
}
|
||||
|
||||
func NewAssSubtitle() *AssSubtitle {
|
||||
return &AssSubtitle{
|
||||
playResX: 1920,
|
||||
playResY: 1080,
|
||||
fontsize: 0,
|
||||
marginv: 10,
|
||||
fontname: "",
|
||||
alignment: 6,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetPlayResX(playResX int32) *AssSubtitle {
|
||||
s.playResX = playResX
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetPlayResY(playResY int32) *AssSubtitle {
|
||||
s.playResY = playResY
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetFontSize(fontsize int32) *AssSubtitle {
|
||||
s.fontsize = fontsize
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetMarginV(marginv int32) *AssSubtitle {
|
||||
s.marginv = marginv
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetFontName(fontname string) *AssSubtitle {
|
||||
s.fontname = fontname
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) SetAlignment(alignment int32) *AssSubtitle {
|
||||
s.alignment = alignment
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *AssSubtitle) String() string {
|
||||
return fmt.Sprintf("PlayResX=%d,PlayResY=%d,Fontsize=%d,MarginV=%d,Fontname=%s,Alignment=%d",
|
||||
s.playResX, s.playResY, s.fontsize, s.marginv, s.fontname, s.alignment)
|
||||
}
|
Reference in New Issue
Block a user