From 52cef01dcac487fac5b350f82a984869721976f1 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 14 May 2023 18:38:50 -0700 Subject: [PATCH] manager: read rotation from side data --- manager.go | 40 ++++++++++++++++++++++------------------ stream.go | 6 +++--- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/manager.go b/manager.go index a3c3b29c..7eaf98c3 100644 --- a/manager.go +++ b/manager.go @@ -234,10 +234,8 @@ func (m *Manager) ffprobe() error { // Hide debug information "-v", "error", - // video - "-show_entries", "format=duration", - "-show_entries", "stream=duration,width,height,avg_frame_rate,codec_name,bit_rate", - "-show_entries", "stream_tags=rotate", + // Show everything + "-show_entries", "stream", "-select_streams", "v", // Video stream only, we're not interested in audio "-of", "json", @@ -259,22 +257,26 @@ func (m *Manager) ffprobe() error { out := struct { Streams []struct { - Width int `json:"width"` - Height int `json:"height"` - Duration string `json:"duration"` - FrameRate string `json:"avg_frame_rate"` - CodecName string `json:"codec_name"` - BitRate string `json:"bit_rate"` - Tags struct { - Rotate string `json:"rotate"` - } `json:"tags"` + Width int `json:"width"` + Height int `json:"height"` + Duration string `json:"duration"` + FrameRate string `json:"avg_frame_rate"` + CodecName string `json:"codec_name"` + BitRate string `json:"bit_rate"` + SideDataList []struct { + SideDataType string `json:"side_data_type"` + Rotation int `json:"rotation"` + } `json:"side_data_list"` } `json:"streams"` Format struct { Duration string `json:"duration"` } `json:"format"` }{} - if err := json.Unmarshal(stdout.Bytes(), &out); err != nil { + byts := stdout.Bytes() + log.Println(string(byts)) + + if err := json.Unmarshal(byts, &out); err != nil { return err } @@ -315,10 +317,12 @@ func (m *Manager) ffprobe() error { bitRate = 5000000 } - // Rotation is a string - rotation, err := strconv.Atoi(out.Streams[0].Tags.Rotate) - if err != nil { - rotation = 0 + // Get rotation from side data + rotation := 0 + for _, sideData := range out.Streams[0].SideDataList { + if sideData.SideDataType == "Display Matrix" { + rotation = sideData.Rotation + } } m.probe = &ProbeVideoData{ diff --git a/stream.go b/stream.go index 1228a547..f8b658c1 100644 --- a/stream.go +++ b/stream.go @@ -415,11 +415,11 @@ func (s *Stream) transcodeArgs(startAt float64) []string { } else if CV == ENCODER_NVENC { transposer = "transpose_npp" } - if s.m.probe.Rotation == 90 { + if s.m.probe.Rotation == -90 { filter = fmt.Sprintf("%s,%s=1", filter, transposer) - } else if s.m.probe.Rotation == 270 { + } else if s.m.probe.Rotation == 90 { filter = fmt.Sprintf("%s,%s=2", filter, transposer) - } else if 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) }