Fix invalid rotation with CPU

monorepo
Varun Patil 2023-07-21 19:02:31 -07:00
parent 92413eaa29
commit ff9c27a74e
1 changed files with 10 additions and 6 deletions

View File

@ -181,7 +181,7 @@ func (s *Stream) ServeChunk(w http.ResponseWriter, id int) error {
}
func (s *Stream) ServeFullVideo(w http.ResponseWriter, r *http.Request) error {
args := s.transcodeArgs(0)
args := s.transcodeArgs(0, false)
if s.m.probe.CodecName == CODEC_H264 && s.quality == QUALITY_MAX {
// try to just send the original file
@ -351,7 +351,7 @@ func (s *Stream) restartAtChunk(w http.ResponseWriter, id int) {
}
// Get arguments to ffmpeg
func (s *Stream) transcodeArgs(startAt float64) []string {
func (s *Stream) transcodeArgs(startAt float64, isHls bool) []string {
args := []string{
"-loglevel", "warning",
}
@ -376,6 +376,9 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
args = append(args, strings.Split(extra, " ")...)
}
// Disable autorotation
args = append(args, []string{"-noautorotate"}...)
// Input specs
args = append(args, []string{
"-i", s.m.path, // Input file
@ -409,11 +412,12 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":"))
// Rotation is a mess: https://trac.ffmpeg.org/ticket/8329
// 1/ autorotate=1 is needed, otherwise the sidecar metadata gets copied to the output
// 2/ But autorotation doesn't seem to work with HW (at least not with VAAPI)
// 1/ -noautorotate copies the sidecar metadata to the output
// 2/ autorotation doesn't seem to work with HW anyway (at least not with VAAPI)
// 3/ autorotation doesn't work with HLS streams
// So keep autorotation enabled, but manually rotate for HW anyway.
// Also, the sidecar metadata only exists for MOV/MP4, so it's not a problem for TS.
if CV == ENCODER_VAAPI || CV == ENCODER_NVENC {
if isHls {
transposer := "transpose"
if CV == ENCODER_VAAPI {
transposer = "transpose_vaapi"
@ -491,7 +495,7 @@ func (s *Stream) transcode(startId int) {
}
startAt := float64(startId * s.c.ChunkSize)
args := s.transcodeArgs(startAt)
args := s.transcodeArgs(startAt, true)
// Segmenting specs
args = append(args, []string{