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{ PresetMP4 = ffmpeg_go.KwArgs{
"c:v": "libx264", "c:v": "libx264",
"preset": "ultrafast", "f": "mp4",
"pix_fmt": "yuv420p", "pix_fmt": "yuv420p",
"movflags": "frag_keyframe+empty_moov",
"preset": "ultrafast",
"tune": "zerolatency",
"c:a": "aac", "c:a": "aac",
"shortest": "", "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 { 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. 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,6 +15,8 @@ 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,21 +31,39 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
return err return err
} }
stream := ffmpeg_go. inputVideo := ffmpeg_go.
Input("pipe:0", ffmpeg_go.KwArgs{ Input("pipe:0").
"f": "webm", Silent(true)
}).
Silent(true). var output *ffmpeg_go.Stream
Output("pipe:1", preset).
WithInput(rIn). switch opts.Format {
WithOutput(wOut) 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) && 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()
_ = stream.Run() _ = output.Run()
}() }()
zw := zip.NewWriter(out) zw := zip.NewWriter(out)
@ -77,8 +95,7 @@ func (ws webmConverter) Transform(ctx context.Context, in io.Reader, out io.Writ
return nil return nil
} }
defer wOut.Close() if err := output.WithInput(rIn).WithOutput(out).Run(); err != nil {
if err := stream.WithOutput(out).Run(); err != nil {
return err return err
} }