stream: add UseGopSize

monorepo
Varun Patil 2023-09-29 10:25:00 -07:00
parent ec9900e166
commit a7968c9279
2 changed files with 23 additions and 4 deletions

View File

@ -39,6 +39,9 @@ type Config struct {
NVENCTemporalAQ bool `json:"nvencTemporalAQ"` NVENCTemporalAQ bool `json:"nvencTemporalAQ"`
NVENCScale string `json:"nvencScale"` // cuda, npp NVENCScale string `json:"nvencScale"` // cuda, npp
// Use transpose for streaming // Use transpose workaround for streaming (VA-API)
UseTranspose bool `json:"useTranspose"` UseTranspose bool `json:"useTranspose"`
// Use GOP size workaround for streaming (NVENC)
UseGopSize bool `json:"useGopSize"`
} }

View File

@ -513,17 +513,33 @@ func (s *Stream) transcode(startId int) {
// Segmenting specs // Segmenting specs
args = append(args, []string{ args = append(args, []string{
"-start_number", fmt.Sprintf("%d", startId),
"-avoid_negative_ts", "disabled", "-avoid_negative_ts", "disabled",
"-f", "hls", "-f", "hls",
"-hls_flags", "split_by_time", "-hls_flags", "split_by_time",
"-hls_time", fmt.Sprintf("%d", s.c.ChunkSize), "-hls_time", fmt.Sprintf("%d", s.c.ChunkSize),
"-hls_segment_type", "mpegts", "-hls_segment_type", "mpegts",
"-hls_segment_filename", s.getTsPath(-1), "-hls_segment_filename", s.getTsPath(-1),
"-force_key_frames", fmt.Sprintf("expr:gte(t,n_forced*%d)", s.c.ChunkSize),
"-start_number", fmt.Sprintf("%d", startId),
"-",
}...) }...)
// Keyframe specs
if s.c.UseGopSize && s.m.probe.FrameRate > 0 {
// Fix GOP size
args = append(args, []string{
"-g", fmt.Sprintf("%d", s.c.ChunkSize*s.m.probe.FrameRate),
"-keyint_min", fmt.Sprintf("%d", s.c.ChunkSize*s.m.probe.FrameRate),
}...)
} else {
// Force keyframes every chunk
args = append(args, []string{
"-force_key_frames", fmt.Sprintf("expr:gte(t,n_forced*%d)", s.c.ChunkSize),
}...)
}
// Output to stdout
args = append(args, "-")
// Start the process
s.coder = exec.Command(s.c.FFmpeg, args...) s.coder = exec.Command(s.c.FFmpeg, args...)
log.Printf("%s-%s: %s", s.m.id, s.quality, strings.Join(s.coder.Args[:], " ")) log.Printf("%s-%s: %s", s.m.id, s.quality, strings.Join(s.coder.Args[:], " "))