Compare commits
No commits in common. "master" and "v1.0.2" have entirely different histories.
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
converter "github.com/yazmeyaa/telegram_sticker_converter"
|
converter "github.com/yazmeyaa/telegram_sticker_converter"
|
||||||
"github.com/yazmeyaa/telegram_sticker_converter/tgs"
|
"github.com/yazmeyaa/telegram_sticker_converter/tgs"
|
||||||
|
|
@ -32,7 +31,7 @@ func main() {
|
||||||
inputType := inputParts[0]
|
inputType := inputParts[0]
|
||||||
var in *os.File
|
var in *os.File
|
||||||
if inputType == "file" {
|
if inputType == "file" {
|
||||||
input, err := os.Open(inputParts[1])
|
input, err := os.Open(*input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error opening file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error opening file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -83,13 +82,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
converter := tgs.NewConverter()
|
converter := tgs.NewConverter()
|
||||||
start := time.Now()
|
|
||||||
if err := converter.Transform(context.Background(), in, out, opts); err != nil {
|
if err := converter.Transform(context.Background(), in, out, opts); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "transform failed: %v\n", err)
|
fmt.Fprintf(os.Stderr, "transform failed: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
duration := time.Since(start)
|
|
||||||
fmt.Printf("Complete in %d ms\n", duration.Milliseconds())
|
|
||||||
|
|
||||||
fmt.Println("success:", *outPath)
|
fmt.Println("success:", *outPath)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -3,8 +3,8 @@ module github.com/yazmeyaa/telegram_sticker_converter
|
||||||
go 1.24.6
|
go 1.24.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/arugaz/go-rlottie v0.1.0
|
||||||
github.com/u2takey/ffmpeg-go v0.5.0
|
github.com/u2takey/ffmpeg-go v0.5.0
|
||||||
github.com/yazmeyaa/go-rlottie v1.0.3
|
|
||||||
golang.org/x/image v0.30.0
|
golang.org/x/image v0.30.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -1,3 +1,5 @@
|
||||||
|
github.com/arugaz/go-rlottie v0.1.0 h1:/rQaoBoSEG2T+PW56ANvpkgOHdYYtGZpvxzjI6touZ8=
|
||||||
|
github.com/arugaz/go-rlottie v0.1.0/go.mod h1:m50xy50q5U9ngFIBJja9m09vFhvfw6cxkRiqIxjKeWQ=
|
||||||
github.com/aws/aws-sdk-go v1.38.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
github.com/aws/aws-sdk-go v1.38.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
||||||
github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ=
|
github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ=
|
||||||
github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk=
|
github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk=
|
||||||
|
|
@ -37,8 +39,6 @@ github.com/u2takey/ffmpeg-go v0.5.0 h1:r7d86XuL7uLWJ5mzSeQ03uvjfIhiJYvsRAJFCW4uk
|
||||||
github.com/u2takey/ffmpeg-go v0.5.0/go.mod h1:ruZWkvC1FEiUNjmROowOAps3ZcWxEiOpFoHCvk97kGc=
|
github.com/u2takey/ffmpeg-go v0.5.0/go.mod h1:ruZWkvC1FEiUNjmROowOAps3ZcWxEiOpFoHCvk97kGc=
|
||||||
github.com/u2takey/go-utils v0.3.1 h1:TaQTgmEZZeDHQFYfd+AdUT1cT4QJgJn/XVPELhHw4ys=
|
github.com/u2takey/go-utils v0.3.1 h1:TaQTgmEZZeDHQFYfd+AdUT1cT4QJgJn/XVPELhHw4ys=
|
||||||
github.com/u2takey/go-utils v0.3.1/go.mod h1:6e+v5vEZ/6gu12w/DC2ixZdZtCrNokVxD0JUklcqdCs=
|
github.com/u2takey/go-utils v0.3.1/go.mod h1:6e+v5vEZ/6gu12w/DC2ixZdZtCrNokVxD0JUklcqdCs=
|
||||||
github.com/yazmeyaa/go-rlottie v1.0.3 h1:md1ptW6ZWEv9U6YpC/kg2QbQQoIhJcHik4U9+WAGNyc=
|
|
||||||
github.com/yazmeyaa/go-rlottie v1.0.3/go.mod h1:Ci2En07mkAOGiTMq5/js/AkTwH6q/ov/nA4lBkkUoB8=
|
|
||||||
gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
|
gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
|
|
||||||
1
tgs.go
1
tgs.go
|
|
@ -13,7 +13,6 @@ type TGSTransformOptions struct {
|
||||||
Qualtity int
|
Qualtity int
|
||||||
ResizeWidth int
|
ResizeWidth int
|
||||||
ResizeHeight int
|
ResizeHeight int
|
||||||
CacheKey string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TGSConverter interface {
|
type TGSConverter interface {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/arugaz/go-rlottie"
|
||||||
ffmpeg_go "github.com/u2takey/ffmpeg-go"
|
ffmpeg_go "github.com/u2takey/ffmpeg-go"
|
||||||
"github.com/yazmeyaa/go-rlottie"
|
|
||||||
converter "github.com/yazmeyaa/telegram_sticker_converter"
|
converter "github.com/yazmeyaa/telegram_sticker_converter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (t tgsConverterImpl) Transform(ctx context.Context, in io.Reader, out io.Wr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
anim := rlottie.LottieAnimationFromData(buf.String(), opts.CacheKey, "")
|
anim := rlottie.LottieAnimationFromData(buf.String(), "", "")
|
||||||
defer rlottie.LottieAnimationDestroy(anim)
|
defer rlottie.LottieAnimationDestroy(anim)
|
||||||
|
|
||||||
width, height := rlottie.LottieAnimationGetSize(anim)
|
width, height := rlottie.LottieAnimationGetSize(anim)
|
||||||
|
|
@ -102,14 +102,12 @@ var (
|
||||||
"deadline": "realtime",
|
"deadline": "realtime",
|
||||||
}
|
}
|
||||||
PresetMP4 = ffmpeg_go.KwArgs{
|
PresetMP4 = ffmpeg_go.KwArgs{
|
||||||
"c:v": "libx264",
|
"vcodec": "libx264",
|
||||||
"f": "mp4",
|
"format": "mp4",
|
||||||
"pix_fmt": "yuv420p",
|
"pix_fmt": "yuv420p",
|
||||||
"movflags": "frag_keyframe+empty_moov",
|
"movflags": "frag_keyframe+empty_moov",
|
||||||
"preset": "ultrafast",
|
"preset": "ultrafast",
|
||||||
"tune": "zerolatency",
|
"tune": "zerolatency",
|
||||||
"c:a": "aac",
|
|
||||||
"shortest": "",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -145,35 +143,19 @@ func (t tgsConverterImpl) processVideo(ctx context.Context, anim rlottie.Lottie_
|
||||||
w.Close()
|
w.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
inputVideo := ffmpeg_go.Input("pipe:0", ffmpeg_go.KwArgs{
|
err := ffmpeg_go.
|
||||||
|
Input("pipe:0", ffmpeg_go.KwArgs{
|
||||||
"format": "rawvideo",
|
"format": "rawvideo",
|
||||||
"pix_fmt": "bgra",
|
"pix_fmt": "bgra",
|
||||||
"s": fmt.Sprintf("%dx%d", opts.ResizeWidth, opts.ResizeHeight),
|
"s": fmt.Sprintf("%dx%d", opts.ResizeWidth, opts.ResizeHeight),
|
||||||
"r": frameRate,
|
"r": frameRate,
|
||||||
})
|
}).
|
||||||
|
Silent(true).
|
||||||
var output *ffmpeg_go.Stream
|
Output("pipe:1", preset).
|
||||||
|
|
||||||
switch opts.Format {
|
|
||||||
case converter.FormatMP4:
|
|
||||||
inputAudio := ffmpeg_go.Input("anullsrc=channel_layout=stereo:sample_rate=44100",
|
|
||||||
ffmpeg_go.KwArgs{"f": "lavfi"})
|
|
||||||
|
|
||||||
output = ffmpeg_go.Output(
|
|
||||||
[]*ffmpeg_go.Stream{inputVideo, inputAudio},
|
|
||||||
"pipe:1",
|
|
||||||
preset,
|
|
||||||
)
|
|
||||||
|
|
||||||
default:
|
|
||||||
output = inputVideo.Output("pipe:1", preset)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := output.
|
|
||||||
WithInput(r).
|
WithInput(r).
|
||||||
WithOutput(out).
|
WithOutput(out).
|
||||||
Silent(true).
|
|
||||||
Run()
|
Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ var (
|
||||||
"movflags": "frag_keyframe+empty_moov",
|
"movflags": "frag_keyframe+empty_moov",
|
||||||
"preset": "ultrafast",
|
"preset": "ultrafast",
|
||||||
"tune": "zerolatency",
|
"tune": "zerolatency",
|
||||||
"c:a": "aac",
|
|
||||||
"shortest": "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PresetPNG = ffmpeg_go.KwArgs{
|
PresetPNG = ffmpeg_go.KwArgs{
|
||||||
|
|
|
||||||
|
|
@ -31,39 +31,21 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
inputVideo := ffmpeg_go.
|
stream := ffmpeg_go.
|
||||||
Input("pipe:0").
|
Input("pipe:0", ffmpeg_go.KwArgs{
|
||||||
Silent(true)
|
"f": "webm",
|
||||||
|
}).
|
||||||
var output *ffmpeg_go.Stream
|
Silent(true).
|
||||||
|
Output("pipe:1", preset).
|
||||||
switch opts.Format {
|
WithInput(rIn).
|
||||||
case converter.FormatMP4:
|
WithOutput(wOut)
|
||||||
inputAudio := ffmpeg_go.Input(
|
|
||||||
"anullsrc=channel_layout=stereo:sample_rate=44100",
|
|
||||||
ffmpeg_go.KwArgs{"f": "lavfi"},
|
|
||||||
)
|
|
||||||
|
|
||||||
output = ffmpeg_go.Output(
|
|
||||||
[]*ffmpeg_go.Stream{inputVideo, inputAudio},
|
|
||||||
"pipe:1",
|
|
||||||
preset,
|
|
||||||
)
|
|
||||||
|
|
||||||
default:
|
|
||||||
output = inputVideo.Output("pipe:1", preset)
|
|
||||||
}
|
|
||||||
|
|
||||||
output = output.Silent(true).WithInput(rIn).WithOutput(wOut)
|
|
||||||
|
|
||||||
if (opts.Frame == converter.FrameAll || opts.Frame == converter.FrameRange) &&
|
if (opts.Frame == converter.FrameAll || opts.Frame == converter.FrameRange) &&
|
||||||
(opts.Format == converter.FormatWEBP || opts.Format == converter.FormatJPEG || opts.Format == converter.FormatPNG) {
|
(opts.Format == converter.FormatWEBP || opts.Format == converter.FormatJPEG || opts.Format == converter.FormatPNG) {
|
||||||
|
|
||||||
output = output.Silent(true).WithInput(rIn).WithOutput(wOut)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer wOut.Close()
|
defer wOut.Close()
|
||||||
_ = output.Run()
|
_ = stream.Run()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
zw := zip.NewWriter(out)
|
zw := zip.NewWriter(out)
|
||||||
|
|
@ -95,7 +77,8 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := output.WithInput(rIn).WithOutput(out).Run(); err != nil {
|
defer wOut.Close()
|
||||||
|
if err := stream.WithOutput(out).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue