add anullsrc audio input to webm converter

This commit is contained in:
eugene 2025-09-16 18:59:57 +03:00
parent ceb495ad1d
commit 3f85891111
3 changed files with 36 additions and 15 deletions

View File

@ -103,13 +103,14 @@ var (
}
PresetMP4 = ffmpeg_go.KwArgs{
"c:v": "libx264",
"preset": "ultrafast",
"f": "mp4",
"pix_fmt": "yuv420p",
"movflags": "frag_keyframe+empty_moov",
"preset": "ultrafast",
"tune": "zerolatency",
"c:a": "aac",
"shortest": "",
"movflags": "frag_keyframe+empty_moov",
"tune": "zerolatency",
"f": "mp4"}
}
)
func (t tgsConverterImpl) processVideo(ctx context.Context, anim rlottie.Lottie_Animation, out io.Writer, opts converter.TGSTransformOptions) error {
@ -171,6 +172,7 @@ func (t tgsConverterImpl) processVideo(ctx context.Context, anim rlottie.Lottie_
err := output.
WithInput(r).
WithOutput(out).
Silent(true).
Run()
if err != nil {
return err

View File

@ -15,6 +15,8 @@ var (
"movflags": "frag_keyframe+empty_moov",
"preset": "ultrafast",
"tune": "zerolatency",
"c:a": "aac",
"shortest": "",
}
PresetPNG = ffmpeg_go.KwArgs{

View File

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