Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
3f85891111 | |
|
|
ceb495ad1d |
|
|
@ -102,12 +102,14 @@ var (
|
|||
"deadline": "realtime",
|
||||
}
|
||||
PresetMP4 = ffmpeg_go.KwArgs{
|
||||
"vcodec": "libx264",
|
||||
"format": "mp4",
|
||||
"c:v": "libx264",
|
||||
"f": "mp4",
|
||||
"pix_fmt": "yuv420p",
|
||||
"movflags": "frag_keyframe+empty_moov",
|
||||
"preset": "ultrafast",
|
||||
"tune": "zerolatency",
|
||||
"c:a": "aac",
|
||||
"shortest": "",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -143,19 +145,35 @@ func (t tgsConverterImpl) processVideo(ctx context.Context, anim rlottie.Lottie_
|
|||
w.Close()
|
||||
}()
|
||||
|
||||
err := ffmpeg_go.
|
||||
Input("pipe:0", ffmpeg_go.KwArgs{
|
||||
inputVideo := ffmpeg_go.Input("pipe:0", ffmpeg_go.KwArgs{
|
||||
"format": "rawvideo",
|
||||
"pix_fmt": "bgra",
|
||||
"s": fmt.Sprintf("%dx%d", opts.ResizeWidth, opts.ResizeHeight),
|
||||
"r": frameRate,
|
||||
}).
|
||||
Silent(true).
|
||||
Output("pipe:1", preset).
|
||||
})
|
||||
|
||||
var output *ffmpeg_go.Stream
|
||||
|
||||
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).
|
||||
WithOutput(out).
|
||||
Silent(true).
|
||||
Run()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ var (
|
|||
"movflags": "frag_keyframe+empty_moov",
|
||||
"preset": "ultrafast",
|
||||
"tune": "zerolatency",
|
||||
"c:a": "aac",
|
||||
"shortest": "",
|
||||
}
|
||||
|
||||
PresetPNG = ffmpeg_go.KwArgs{
|
||||
|
|
|
|||
|
|
@ -31,21 +31,39 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
|
|||
return err
|
||||
}
|
||||
|
||||
stream := ffmpeg_go.
|
||||
Input("pipe:0", ffmpeg_go.KwArgs{
|
||||
"f": "webm",
|
||||
}).
|
||||
Silent(true).
|
||||
Output("pipe:1", preset).
|
||||
WithInput(rIn).
|
||||
WithOutput(wOut)
|
||||
inputVideo := ffmpeg_go.
|
||||
Input("pipe:0").
|
||||
Silent(true)
|
||||
|
||||
var output *ffmpeg_go.Stream
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
output = output.Silent(true).WithInput(rIn).WithOutput(wOut)
|
||||
|
||||
if (opts.Frame == converter.FrameAll || opts.Frame == converter.FrameRange) &&
|
||||
(opts.Format == converter.FormatWEBP || opts.Format == converter.FormatJPEG || opts.Format == converter.FormatPNG) {
|
||||
|
||||
output = output.Silent(true).WithInput(rIn).WithOutput(wOut)
|
||||
|
||||
go func() {
|
||||
defer wOut.Close()
|
||||
_ = stream.Run()
|
||||
_ = output.Run()
|
||||
}()
|
||||
|
||||
zw := zip.NewWriter(out)
|
||||
|
|
@ -77,8 +95,7 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
|
|||
return nil
|
||||
}
|
||||
|
||||
defer wOut.Close()
|
||||
if err := stream.WithOutput(out).Run(); err != nil {
|
||||
if err := output.WithInput(rIn).WithOutput(out).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue