manager: read rotation from side data

monorepo
Varun Patil 2023-05-14 18:38:50 -07:00
parent dd637f9b1f
commit 52cef01dca
2 changed files with 25 additions and 21 deletions

View File

@ -234,10 +234,8 @@ func (m *Manager) ffprobe() error {
// Hide debug information // Hide debug information
"-v", "error", "-v", "error",
// video // Show everything
"-show_entries", "format=duration", "-show_entries", "stream",
"-show_entries", "stream=duration,width,height,avg_frame_rate,codec_name,bit_rate",
"-show_entries", "stream_tags=rotate",
"-select_streams", "v", // Video stream only, we're not interested in audio "-select_streams", "v", // Video stream only, we're not interested in audio
"-of", "json", "-of", "json",
@ -259,22 +257,26 @@ func (m *Manager) ffprobe() error {
out := struct { out := struct {
Streams []struct { Streams []struct {
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
Duration string `json:"duration"` Duration string `json:"duration"`
FrameRate string `json:"avg_frame_rate"` FrameRate string `json:"avg_frame_rate"`
CodecName string `json:"codec_name"` CodecName string `json:"codec_name"`
BitRate string `json:"bit_rate"` BitRate string `json:"bit_rate"`
Tags struct { SideDataList []struct {
Rotate string `json:"rotate"` SideDataType string `json:"side_data_type"`
} `json:"tags"` Rotation int `json:"rotation"`
} `json:"side_data_list"`
} `json:"streams"` } `json:"streams"`
Format struct { Format struct {
Duration string `json:"duration"` Duration string `json:"duration"`
} `json:"format"` } `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 return err
} }
@ -315,10 +317,12 @@ func (m *Manager) ffprobe() error {
bitRate = 5000000 bitRate = 5000000
} }
// Rotation is a string // Get rotation from side data
rotation, err := strconv.Atoi(out.Streams[0].Tags.Rotate) rotation := 0
if err != nil { for _, sideData := range out.Streams[0].SideDataList {
rotation = 0 if sideData.SideDataType == "Display Matrix" {
rotation = sideData.Rotation
}
} }
m.probe = &ProbeVideoData{ m.probe = &ProbeVideoData{

View File

@ -415,11 +415,11 @@ func (s *Stream) transcodeArgs(startAt float64) []string {
} else if CV == ENCODER_NVENC { } else if CV == ENCODER_NVENC {
transposer = "transpose_npp" transposer = "transpose_npp"
} }
if s.m.probe.Rotation == 90 { if s.m.probe.Rotation == -90 {
filter = fmt.Sprintf("%s,%s=1", filter, transposer) 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) 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) filter = fmt.Sprintf("%s,%s=1,%s=1", filter, transposer, transposer)
} }