Compare commits

..

No commits in common. "master" and "v1.0.3" have entirely different histories.

4 changed files with 24 additions and 62 deletions

1
tgs.go
View File

@ -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 {

View File

@ -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.
"format": "rawvideo", Input("pipe:0", ffmpeg_go.KwArgs{
"pix_fmt": "bgra", "format": "rawvideo",
"s": fmt.Sprintf("%dx%d", opts.ResizeWidth, opts.ResizeHeight), "pix_fmt": "bgra",
"r": frameRate, "s": fmt.Sprintf("%dx%d", opts.ResizeWidth, opts.ResizeHeight),
}) "r": frameRate,
}).
var output *ffmpeg_go.Stream Silent(true).
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
} }

View File

@ -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{

View File

@ -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
} }