add anullsrc to mp4 ffmpeg build (tgs)

This commit is contained in:
eugene 2025-09-16 18:42:19 +03:00
parent e668777431
commit ceb495ad1d
1 changed files with 31 additions and 15 deletions

View File

@ -102,13 +102,14 @@ var (
"deadline": "realtime", "deadline": "realtime",
} }
PresetMP4 = ffmpeg_go.KwArgs{ PresetMP4 = ffmpeg_go.KwArgs{
"vcodec": "libx264", "c:v": "libx264",
"format": "mp4",
"pix_fmt": "yuv420p",
"movflags": "frag_keyframe+empty_moov",
"preset": "ultrafast", "preset": "ultrafast",
"pix_fmt": "yuv420p",
"c:a": "aac",
"shortest": "",
"movflags": "frag_keyframe+empty_moov",
"tune": "zerolatency", "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 {
@ -143,19 +144,34 @@ func (t tgsConverterImpl) processVideo(ctx context.Context, anim rlottie.Lottie_
w.Close() w.Close()
}() }()
err := ffmpeg_go. inputVideo := ffmpeg_go.Input("pipe:0", ffmpeg_go.KwArgs{
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).
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). WithInput(r).
WithOutput(out). WithOutput(out).
Run() Run()
if err != nil { if err != nil {
return err return err
} }