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,9 +376,15 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
args = append(args, strings.Split(extra, " ")...) args = append(args, strings.Split(extra, " ")...)
} }
// Input specs // Manual rotation: disable autorotate
if rotate {
args = append(args, []string{ args = append(args, []string{
"-noautorotate", // Rotate manually "-noautorotate", // Rotate manually
}...)
}
// Input specs
args = append(args, []string{
"-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,6 +416,7 @@ 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
if rotate {
transposer := "transpose" transposer := "transpose"
if CV == ENCODER_VAAPI { if CV == ENCODER_VAAPI {
transposer = "transpose_vaapi" transposer = "transpose_vaapi"
@ -422,6 +430,7 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
} else if s.m.probe.Rotation == 180 || s.m.probe.Rotation == -180 { } else if s.m.probe.Rotation == 180 || s.m.probe.Rotation == -180 {
filter = fmt.Sprintf("%s,%s=1,%s=1", filter, transposer, transposer) filter = fmt.Sprintf("%s,%s=1,%s=1", filter, transposer, transposer)
} }
}
args = append(args, []string{"-vf", filter}...) args = append(args, []string{"-vf", filter}...)
args = append(args, []string{"-profile:v", "main"}...) args = append(args, []string{"-profile:v", "main"}...)
@ -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{