repochecker/videos: Also check video ratio
This commit is contained in:
parent
38a4e21e28
commit
91b2daea2e
|
@ -25,6 +25,28 @@ type VideoInfo struct {
|
|||
} `json:"streams"`
|
||||
}
|
||||
|
||||
func gcd(a, b int) int {
|
||||
var bgcd func(a, b, res int) int
|
||||
|
||||
bgcd = func(a, b, res int) int {
|
||||
switch {
|
||||
case a == b:
|
||||
return res * a
|
||||
case a%2 == 0 && b%2 == 0:
|
||||
return bgcd(a/2, b/2, 2*res)
|
||||
case a%2 == 0:
|
||||
return bgcd(a/2, b, res)
|
||||
case b%2 == 0:
|
||||
return bgcd(a, b/2, res)
|
||||
case a > b:
|
||||
return bgcd(a-b, b, res)
|
||||
default:
|
||||
return bgcd(a, b-a, res)
|
||||
}
|
||||
}
|
||||
return bgcd(a, b, 1)
|
||||
}
|
||||
|
||||
func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
i, ok := sync.GlobalImporter.(sync.LocalImporter)
|
||||
if !ok {
|
||||
|
@ -66,6 +88,12 @@ func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (er
|
|||
errs = append(errs, fmt.Errorf("video track is too wide: %dx%d (maximum allowed: 1920x1080)", s.Width, s.Height))
|
||||
}
|
||||
|
||||
ratio := s.Width * 10 / s.Height
|
||||
if ratio < 13 || ratio > 19 && !exceptions.HasException(":size:strange_ratio") {
|
||||
m := gcd(s.Width, s.Height)
|
||||
errs = append(errs, fmt.Errorf("video track has a strange ratio: %d:%d. Is this really expected?", s.Width/m, s.Height/m))
|
||||
}
|
||||
|
||||
if s.CodecName != "h264" {
|
||||
errs = append(errs, fmt.Errorf("video codec has to be H264 (currently: %s)", s.CodecLongName))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue