From 8975c781c5e308cf0b810814216c9bcfd2ae242c Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Thu, 12 Oct 2023 15:20:54 +0200 Subject: [PATCH] Live Photos: Default to MP4 for Google HVC1 Motion Photos Playback #3814 Signed-off-by: Michael Mayer --- pkg/video/info.go | 14 +++++--------- pkg/video/probe.go | 3 +-- pkg/video/probe_test.go | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/video/info.go b/pkg/video/info.go index 80e01e088..390ffd2b3 100644 --- a/pkg/video/info.go +++ b/pkg/video/info.go @@ -69,32 +69,28 @@ func (info Info) VideoBitrate() float64 { // VideoContentType composes the video content type from its mime type and codec. func (info Info) VideoContentType() string { if info.VideoMimeType == "" { - return "" + return ContentTypeDefault } return ContentType(info.VideoMimeType, info.VideoCodec) } -// VideoFileExt returns the appropriate video file extension based on the mime type, if any. +// VideoFileExt returns the appropriate video file extension based on the mime type and defaults to fs.ExtMP4 otherwise. func (info Info) VideoFileExt() string { switch info.VideoMimeType { - case fs.MimeTypeMP4: - return fs.ExtMP4 case fs.MimeTypeMOV: return fs.ExtMOV default: - return "" + return fs.ExtMP4 } } -// VideoFileType returns the video type based on the mime type, if any. +// VideoFileType returns the video type based on the mime type and defaults to fs.VideoMP4 otherwise. func (info Info) VideoFileType() fs.Type { switch info.VideoMimeType { - case fs.MimeTypeMP4: - return fs.VideoMP4 case fs.MimeTypeMOV: return fs.VideoMOV default: - return fs.TypeUnknown + return fs.VideoMP4 } } diff --git a/pkg/video/probe.go b/pkg/video/probe.go index 83c1c3ca0..f597325f3 100644 --- a/pkg/video/probe.go +++ b/pkg/video/probe.go @@ -94,6 +94,7 @@ func Probe(file io.ReadSeeker) (info Info, err error) { if CompatibleBrands.ContainsAny(video.CompatibleBrands) { info.Compatible = true info.VideoType = MP4 + info.VideoMimeType = fs.MimeTypeMP4 info.FPS = 30.0 // TODO: Detect actual frames per second! if info.VideoOffset > 0 { @@ -107,8 +108,6 @@ func Probe(file io.ReadSeeker) (info Info, err error) { // Check major brand. switch video.MajorBrand { - case ChunkMP41.Get(), ChunkMP42.Get(): - info.VideoMimeType = fs.MimeTypeMP4 case ChunkQT.Get(): info.VideoType = MOV info.VideoMimeType = fs.MimeTypeMOV diff --git a/pkg/video/probe_test.go b/pkg/video/probe_test.go index 2c28cd2a1..236761aa0 100644 --- a/pkg/video/probe_test.go +++ b/pkg/video/probe_test.go @@ -119,7 +119,7 @@ func TestProbeFile(t *testing.T) { assert.Equal(t, int64(-1), info.ThumbOffset) assert.Equal(t, media.Video, info.MediaType) assert.Equal(t, CodecUnknown, info.VideoCodec) - assert.Equal(t, "", info.VideoContentType()) + assert.Equal(t, ContentTypeDefault, info.VideoContentType()) assert.Equal(t, "", info.VideoMimeType) assert.Equal(t, "0s", info.Duration.String()) assert.Equal(t, 0, info.Tracks)