Do not rotate MOV

monorepo
Varun Patil 2023-05-14 19:38:13 -07:00
parent 3ad8606d8d
commit c4ad66567f
1 changed files with 27 additions and 18 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 { 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 { if s.m.probe.CodecName == CODEC_H264 && s.quality == QUALITY_MAX {
// try to just send the original file // try to just send the original file
@ -191,7 +191,8 @@ func (s *Stream) ServeFullVideo(w http.ResponseWriter, r *http.Request) error {
// Output mov // Output mov
args = append(args, []string{ args = append(args, []string{
"-movflags", "frag_keyframe+empty_moov+faststart", "-f", "mov", "pipe:1", "-movflags", "frag_keyframe+empty_moov+faststart",
"-f", "mov", "pipe:1",
}...) }...)
coder := exec.Command(s.c.FFmpeg, args...) coder := exec.Command(s.c.FFmpeg, args...)
@ -350,7 +351,7 @@ func (s *Stream) restartAtChunk(w http.ResponseWriter, id int) {
} }
// Get arguments to ffmpeg // Get arguments to ffmpeg
func (s *Stream) transcodeArgs(startAt float64) []string { func (s *Stream) transcodeArgs(startAt float64, rotate bool) []string {
args := []string{ args := []string{
"-loglevel", "warning", "-loglevel", "warning",
} }
@ -375,10 +376,16 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
args = append(args, strings.Split(extra, " ")...) args = append(args, strings.Split(extra, " ")...)
} }
// Manual rotation: disable autorotate
if rotate {
args = append(args, []string{
"-noautorotate", // Rotate manually
}...)
}
// Input specs // Input specs
args = append(args, []string{ args = append(args, []string{
"-noautorotate", // Rotate manually "-i", s.m.path, // Input file
"-i", s.m.path, // Input file
"-copyts", // So the "-to" refers to the original TS "-copyts", // So the "-to" refers to the original TS
}...) }...)
@ -409,18 +416,20 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":")) filter := fmt.Sprintf("%s,%s=%s", format, scaler, strings.Join(scalerArgs, ":"))
// Add transpose filter if needed // Add transpose filter if needed
transposer := "transpose" if rotate {
if CV == ENCODER_VAAPI { transposer := "transpose"
transposer = "transpose_vaapi" if CV == ENCODER_VAAPI {
} else if CV == ENCODER_NVENC { transposer = "transpose_vaapi"
transposer = "transpose_npp" } else if CV == ENCODER_NVENC {
} transposer = "transpose_npp"
if s.m.probe.Rotation == -90 { }
filter = fmt.Sprintf("%s,%s=1", filter, transposer) if s.m.probe.Rotation == -90 {
} else if s.m.probe.Rotation == 90 { filter = fmt.Sprintf("%s,%s=1", filter, transposer)
filter = fmt.Sprintf("%s,%s=2", filter, transposer) } else if s.m.probe.Rotation == 90 {
} else if s.m.probe.Rotation == 180 || s.m.probe.Rotation == -180 { filter = fmt.Sprintf("%s,%s=2", filter, transposer)
filter = fmt.Sprintf("%s,%s=1,%s=1", filter, transposer, transposer) } else if s.m.probe.Rotation == 180 || s.m.probe.Rotation == -180 {
filter = fmt.Sprintf("%s,%s=1,%s=1", filter, transposer, transposer)
}
} }
args = append(args, []string{"-vf", filter}...) args = append(args, []string{"-vf", filter}...)
@ -485,7 +494,7 @@ func (s *Stream) transcode(startId int) {
} }
startAt := float64(startId * s.c.ChunkSize) startAt := float64(startId * s.c.ChunkSize)
args := s.transcodeArgs(startAt) args := s.transcodeArgs(startAt, true)
// Segmenting specs // Segmenting specs
args = append(args, []string{ args = append(args, []string{