Videos: Refactor File.UpdateVideoInfos() method #926 #3588 #3559

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-08-18 09:12:38 +02:00
parent 69f15924ab
commit c6bb28f60d
3 changed files with 29 additions and 21 deletions

View file

@ -446,21 +446,16 @@ func (m *File) Save() error {
return m.ResolvePrimary()
}
// UpdateVideoInfos updates related video infos based on this file.
// UpdateVideoInfos updates missing video metadata from the primary image.
// see https://github.com/photoprism/photoprism/pull/3588#issuecomment-1683429455
func (m *File) UpdateVideoInfos() error {
if m.PhotoID <= 0 {
return fmt.Errorf("file has invalid photo id")
}
// Update video dimensions, if necessary.
type Dimensions struct {
FileWidth int
FileHeight int
FileOrientation int
FileAspectRatio float32
}
dimensions := Dimensions{}
// Set the video dimensions from the primary image if it could not be determined from the video metadata.
// see https://github.com/photoprism/photoprism/blob/develop/internal/photoprism/index_mediafile.go
dimensions := FileDimensions{}
if err := deepcopier.Copy(&dimensions).From(m); err != nil {
return err
@ -468,16 +463,9 @@ func (m *File) UpdateVideoInfos() error {
return err
}
// Update video appearance, if necessary.
type Appearance struct {
FileMainColor string
FileColors string
FileLuminance string
FileDiff int
FileChroma int16
}
appearance := Appearance{}
// Set the video appearance from the primary file if it could not be detected e.g. from a JPEG sidecar file.
// see https://github.com/photoprism/photoprism/blob/develop/internal/photoprism/index_mediafile.go
appearance := FileAppearance{}
if err := deepcopier.Copy(&appearance).From(m); err != nil {
return err

View file

@ -0,0 +1,20 @@
package entity
// FileDimensions represents metadata related to the size and orientation of a file.
// see File.UpdateVideoInfos()
type FileDimensions struct {
FileWidth int
FileHeight int
FileOrientation int
FileAspectRatio float32
}
// FileAppearance represents file metadata related to colors, luminance and perception.
// see File.UpdateVideoInfos()
type FileAppearance struct {
FileMainColor string
FileColors string
FileLuminance string
FileDiff int
FileChroma int16
}

View file

@ -657,7 +657,7 @@ func (ind *Index) UserMediaFile(m *MediaFile, o IndexOptions, originalName, phot
file.FilePortrait = primaryFile.FilePortrait
}
// Set the appearance of the video from the primary file. In a future version, a still image extracted from the
// Set the video appearance from the primary file. In a future version, a still image extracted from the
// video could be used for this purpose if the primary image is not directly derived from the video file,
// e.g. in live photo stacks, see https://github.com/photoprism/photoprism/pull/3588#issuecomment-1683429455
if primaryFile.FileDiff > 0 {