diff options
Diffstat (limited to 'internal/media/ffmpeg.go')
-rw-r--r-- | internal/media/ffmpeg.go | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/internal/media/ffmpeg.go b/internal/media/ffmpeg.go index 0de5797ab..e26ec78d7 100644 --- a/internal/media/ffmpeg.go +++ b/internal/media/ffmpeg.go @@ -437,6 +437,42 @@ func (res *ffprobeResult) Process() (*result, error) { } } + // Check extra packet / frame information + // for provided orientation (not always set). + for _, pf := range res.PacketsAndFrames { + for _, d := range pf.SideDataList { + + // Ensure frame side + // data IS rotation data. + if d.Rotation == 0 { + continue + } + + // Ensure rotation not + // already been specified. + if r.rotation != 0 { + return nil, errors.New("multiple sets of rotation data") + } + + // Drop any decimal + // rotation value. + rot := int(d.Rotation) + + // Round rotation to multiple of 90. + // More granularity is not needed. + if q := rot % 90; q > 45 { + rot += (90 - q) + } else { + rot -= q + } + + // Drop any value above 360 + // or below -360, these are + // just repeat full turns. + r.rotation = (rot % 360) + } + } + // Preallocate streams to max possible lengths. r.audio = make([]audioStream, 0, len(res.Streams)) r.video = make([]videoStream, 0, len(res.Streams)) @@ -450,12 +486,19 @@ func (res *ffprobeResult) Process() (*result, error) { stream: stream{codec: s.CodecName}, }) case "video": - var framerate float32 + // Determine proper display dimensions, + // taking account of rotation data. + width, height := displayDimensions( + s.Width, + s.Height, + r.rotation, + ) // Parse stream framerate, bearing in // mind that some static container formats // (e.g. jpeg) still return a framerate, so // we also check for a non-1 timebase (dts). + var framerate float32 if str := s.RFrameRate; str != "" && s.DurationTS > 1 { var num, den uint32 @@ -478,49 +521,13 @@ func (res *ffprobeResult) Process() (*result, error) { // Append video stream data to result. r.video = append(r.video, videoStream{ stream: stream{codec: s.CodecName}, - width: s.Width, - height: s.Height, + width: width, + height: height, framerate: framerate, }) } } - // Check extra packet / frame information - // for provided orientation (not always set). - for _, pf := range res.PacketsAndFrames { - for _, d := range pf.SideDataList { - - // Ensure frame side - // data IS rotation data. - if d.Rotation == 0 { - continue - } - - // Ensure rotation not - // already been specified. - if r.rotation != 0 { - return nil, errors.New("multiple sets of rotation data") - } - - // Drop any decimal - // rotation value. - rot := int(d.Rotation) - - // Round rotation to multiple of 90. - // More granularity is not needed. - if q := rot % 90; q > 45 { - rot += (90 - q) - } else { - rot -= q - } - - // Drop any value above 360 - // or below -360, these are - // just repeat full turns. - r.rotation = (rot % 360) - } - } - return &r, nil } |