Skip to content

Commit d5ef7bf

Browse files
committed
Media: Refactor video content type constants photoprism#4770
Signed-off-by: Michael Mayer <[email protected]>
1 parent 6a89519 commit d5ef7bf

File tree

15 files changed

+78
-53
lines changed

15 files changed

+78
-53
lines changed

internal/api/abort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ func AbortVideo(c *gin.Context) {
128128

129129
func AbortVideoWithStatus(c *gin.Context, code int) {
130130
if c != nil {
131-
c.Data(code, header.ContentTypeMp4Avc720, brokenVideo)
131+
c.Data(code, header.ContentTypeMp4AvcMain, brokenVideo)
132132
}
133133
}

internal/api/video.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func GetVideo(router *gin.RouterGroup) {
153153

154154
if avcFile, avcErr := conv.ToAvc(mediaFile, get.Config().FFmpegEncoder(), false, false); avcFile != nil && avcErr == nil {
155155
videoFileName = avcFile.FileName()
156-
AddContentTypeHeader(c, header.ContentTypeMp4Avc)
156+
AddContentTypeHeader(c, header.ContentTypeMp4AvcHigh)
157157
} else {
158158
// Log error and default to 404.mp4
159159
log.Errorf("video: failed to transcode %s", clean.Log(f.FileName))

internal/api/video_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515

1616
func TestGetVideo(t *testing.T) {
1717
t.Run("ContentTypeAVC", func(t *testing.T) {
18-
assert.Equal(t, header.ContentTypeMp4Avc, clean.ContentType("video/mp4; codecs=\"avc1\""))
18+
assert.Equal(t, header.ContentTypeMp4AvcHigh, clean.ContentType("video/mp4; codecs=\"avc1\""))
1919
mimeType := fmt.Sprintf("video/mp4; codecs=\"%s\"", clean.Codec("avc1"))
20-
assert.Equal(t, header.ContentTypeMp4Avc, video.ContentType(mimeType, "mp4", "avc1"))
20+
assert.Equal(t, header.ContentTypeMp4AvcHigh, video.ContentType(mimeType, "mp4", "avc1"))
2121
})
2222

2323
t.Run("NoHash", func(t *testing.T) {

internal/entity/file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ func TestFile_ContentType(t *testing.T) {
886886
t.Run("Video", func(t *testing.T) {
887887
avc := FileFixtures.Get("Video.mp4")
888888
assert.Equal(t, true, avc.FileVideo)
889-
assert.Equal(t, header.ContentTypeMp4Avc, avc.ContentType())
889+
assert.Equal(t, header.ContentTypeMp4AvcHigh, avc.ContentType())
890890
hevc := FileFixtures.Get("Photo21.mp4")
891891
assert.Equal(t, true, hevc.FileVideo)
892892
assert.Equal(t, header.ContentTypeMp4Hevc, hevc.ContentType())

internal/entity/search/photos_results_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestPhoto_MediaInfo(t *testing.T) {
181181
{
182182
FileVideo: true,
183183
MediaType: media.Video.String(),
184-
FileMime: header.ContentTypeMp4Avc,
184+
FileMime: header.ContentTypeMp4AvcHigh,
185185
FileCodec: video.CodecAvc,
186186
FileHash: "53c89dcfa006c9e592dd9e6db4b31cd57be64b81",
187187
},
@@ -193,7 +193,7 @@ func TestPhoto_MediaInfo(t *testing.T) {
193193
mediaHash, mediaCodec, mediaMime := r.MediaInfo()
194194
assert.Equal(t, "53c89dcfa006c9e592dd9e6db4b31cd57be64b81", mediaHash)
195195
assert.Equal(t, video.CodecAvc, mediaCodec)
196-
assert.Equal(t, header.ContentTypeMp4Avc, mediaMime)
196+
assert.Equal(t, header.ContentTypeMp4AvcHigh, mediaMime)
197197
})
198198
t.Run("VideoCodecHVC", func(t *testing.T) {
199199
r := Photo{
@@ -216,7 +216,7 @@ func TestPhoto_MediaInfo(t *testing.T) {
216216
{
217217
FileVideo: true,
218218
MediaType: media.Video.String(),
219-
FileMime: header.ContentTypeMp4Avc,
219+
FileMime: header.ContentTypeMp4AvcHigh,
220220
FileCodec: "xyz",
221221
FileHash: "",
222222
},
@@ -231,7 +231,7 @@ func TestPhoto_MediaInfo(t *testing.T) {
231231
FileVideo: true,
232232
MediaType: media.Video.String(),
233233
FileCodec: video.CodecAvc,
234-
FileMime: header.ContentTypeMp4Avc,
234+
FileMime: header.ContentTypeMp4AvcHigh,
235235
FileHash: "ddb3f44eb500d7669cbe0a95e66d5a63f642487d",
236236
},
237237
},
@@ -259,7 +259,7 @@ func TestPhoto_MediaInfo(t *testing.T) {
259259
{
260260
FileVideo: true,
261261
MediaType: media.Video.String(),
262-
FileMime: header.ContentTypeMp4Avc,
262+
FileMime: header.ContentTypeMp4AvcHigh,
263263
FileHash: "",
264264
},
265265
},

pkg/clean/content_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ContentType(s string) string {
3737
return header.ContentTypeJpeg
3838
case "video/mp4; codecs=\"avc\"",
3939
"video/mp4; codecs=\"avc1\"":
40-
return header.ContentTypeMp4Avc // Advanced Video Coding (AVC), also known as H.264
40+
return header.ContentTypeMp4AvcHigh // Advanced Video Coding (AVC), also known as H.264
4141
case "video/mp4; codecs=\"hvc\"",
4242
"video/mp4; codecs=\"hvc1\"",
4343
"video/mp4; codecs=\"hevc\"":

pkg/media/http/header/content_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ func TestContent(t *testing.T) {
3030
assert.Equal(t, "image/png", ContentTypePng)
3131
assert.Equal(t, "image/jpeg", ContentTypeJpeg)
3232
assert.Equal(t, "image/svg+xml", ContentTypeSVG)
33-
assert.Equal(t, "video/mp4; codecs=\"avc1.640028\"", ContentTypeMp4Avc)
33+
assert.Equal(t, "video/mp4; codecs=\"avc1.640028\"", ContentTypeMp4AvcHigh)
3434
})
3535
}

pkg/media/http/header/content_types.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,36 @@ package header
77
- https://ott.dolby.com/codec_test/index.html
88
- https://dmnsgn.github.io/media-codecs/
99
- https://cconcolato.github.io/media-mime-support/
10+
- https://cconcolato.github.io/media-mime-support/mediacapabilities.html
1011
- https://thorium.rocks/misc/h265-tester.html
12+
- https://developers.google.com/cast/docs/media
13+
- https://privacycheck.sec.lrz.de/active/fp_cpt/fp_can_play_type.html
14+
- https://chromium.googlesource.com/chromium/src.git/+/62.0.3178.1/content/browser/media/media_canplaytype_browsertest.cc
1115
*/
1216

1317
// Standard ContentType identifiers for audio and video files.
1418
const (
15-
ContentTypeMov = "video/quicktime"
16-
ContentTypeMp4 = "video/mp4"
17-
ContentTypeMp4Avc720 = ContentTypeMp4 + "; codecs=\"avc1.640020\"" // MPEG-4 AVC, High Profile Level 3.2
18-
ContentTypeMp4Avc = ContentTypeMp4 + "; codecs=\"avc1.640028\"" // MPEG-4 AVC, High Profile Level 4.0
19-
ContentTypeMp4Hevc = ContentTypeMp4 + "; codecs=\"hvc1.2.4.L120.B0\"" // HEVC Mp4 Main10 Profile, Main Tier, Level 4.0
20-
ContentTypeMp4Hev1 = ContentTypeMp4 + "; codecs=\"hev1.2.4.L120.B0\"" // HEVC Bitstream, not supported on macOS
21-
ContentTypeMp4Vvc = ContentTypeMp4 + "; codecs=\"vvc1\"" // Versatile Video Coding (VVC), also known as H.266
22-
ContentTypeMp4Evc = ContentTypeMp4 + "; codecs=\"evc1\"" // MPEG-5 Essential Video Coding (EVC), also known as ISO/IEC 23094-1
23-
ContentTypeTheora = "video/ogg"
24-
ContentTypeWebm = "video/webm"
25-
ContentTypeWebmVp8 = "video/webm; codecs=\"vp8\""
26-
ContentTypeWebmVp9 = "video/webm; codecs=\"vp09.00.10.08\""
27-
ContentTypeWebmAv1 = "video/webm; codecs=\"av01.2.10M.10\""
19+
ContentTypeMp4 = "video/mp4"
20+
ContentTypeMp4AvcBaseline = ContentTypeMp4 + "; codecs=\"avc1.420028\"" // MPEG-4 AVC (H.264), Baseline Level 4.0
21+
ContentTypeMp4AvcMain = ContentTypeMp4 + "; codecs=\"avc1.4d0028\"" // MPEG-4 AVC (H.264), Main Level 4.0
22+
ContentTypeMp4AvcHigh = ContentTypeMp4 + "; codecs=\"avc1.640028\"" // MPEG-4 AVC (H.264), High Level 4.0
23+
ContentTypeMp4Avc3High = ContentTypeMp4 + "; codecs=\"avc3.640028\"" // MPEG-4 AVC Bitstream, High Profile, may not be supported on macOS
24+
ContentTypeMp4Hevc = ContentTypeMp4 + "; codecs=\"hvc1.1.6.L93.B0\"" // MPEG-4 HEVC (H.265), Main Profile
25+
ContentTypeMp4HevcHDR = ContentTypeMp4 + "; codecs=\"hev1.2.4.L153.B0\"" // MPEG-4 HEVC (H.265), Main 10 Profile
26+
ContentTypeMp4Hev1 = ContentTypeMp4 + "; codecs=\"hev1.1.6.L93.B0\"" // MPEG-4 HEVC Bitstream, Main Profile, not supported on macOS
27+
ContentTypeMp4Hev1HDR = ContentTypeMp4 + "; codecs=\"hev1.2.4.L153.B0\"" // MPEG-4 HEVC Bitstream, Main 10 Profile, not supported on macOS
28+
ContentTypeMp4Vvc = ContentTypeMp4 + "; codecs=\"vvc1\"" // Versatile Video Coding (VVC), also known as H.266
29+
ContentTypeMp4Evc = ContentTypeMp4 + "; codecs=\"evc1\"" // MPEG-5 Essential Video Coding (EVC), also known as ISO/IEC 23094-1
30+
ContentTypeMov = "video/quicktime"
31+
ContentTypeMovAvcMain = ContentTypeMov + "; codecs=\"avc1.4d0028\"" // Apple QuickTime AVC, Main Level 4.0
32+
ContentTypeMovAvcHigh = ContentTypeMov + "; codecs=\"avc1.640028\"" // Apple QuickTime AVC, High Level 4.0
33+
ContentTypeOgg = "video/ogg"
34+
ContentTypeOggVorbis = ContentTypeOgg + "; codecs=\"vorbis\""
35+
ContentTypeOggTheora = ContentTypeOgg + "; codecs=\"theora, vorbis\""
36+
ContentTypeWebm = "video/webm"
37+
ContentTypeWebmVp8 = ContentTypeWebm + "; codecs=\"vp8\""
38+
ContentTypeWebmVp9 = ContentTypeWebm + "; codecs=\"vp09.00.10.08\""
39+
ContentTypeWebmAv1 = ContentTypeWebm + "; codecs=\"av01.2.10M.10\""
2840
)
2941

3042
// Standard ContentType identifiers for images and vector graphics.
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package video
22

3-
// Profile represents a video codec profile name,
4-
// see https://en.wikipedia.org/wiki/Advanced_Video_Coding#Profiles.
5-
type Profile = string
6-
7-
const (
8-
ProfileBaseline Profile = "BaseLine"
9-
ProfileMain Profile = "Main"
10-
ProfileHigh Profile = "High"
11-
)
12-
13-
// Profiles contains common video codec profiles together with their ContentType ID,
14-
// maximum bitrate, resolution, and frame rate (if known).
15-
var Profiles = CodecProfiles{
3+
// AvcProfiles contains common MPEG-4 AVC profiles together with their ContentType ID,
4+
// maximum bitrate, resolution, and frame rate (if known):
5+
// - https://dmnsgn.github.io/media-codecs/#AVC
6+
// - https://en.wikipedia.org/wiki/Advanced_Video_Coding#Profiles
7+
// - https://ott.dolby.com/codec_test/index.html
8+
// - https://cconcolato.github.io/media-mime-support/
9+
// - https://w3c.github.io/media-capabilities/
10+
// - https://privacycheck.sec.lrz.de/active/fp_cpt/fp_can_play_type.html
11+
// - https://chromium.googlesource.com/chromium/src.git/+/62.0.3178.1/content/browser/media/media_canplaytype_browsertest.cc
12+
var AvcProfiles = CodecProfiles{
1613
{Codec: CodecAvc, Profile: ProfileBaseline, Level: 30, Bitrate: 10000, ID: "avc1.66.30"}, // iOS friendly
1714
{Codec: CodecAvc, Profile: ProfileBaseline, Level: 30, Bitrate: 10000, ID: "avc1.42001e"},
1815
{Codec: CodecAvc, Profile: ProfileBaseline, Level: 31, Bitrate: 14000, ID: "avc1.42001f"},

pkg/media/video/codec_profile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package video
22

3+
// Profile represents a video codec profile name,
4+
// see https://en.wikipedia.org/wiki/Advanced_Video_Coding#Profiles.
5+
type Profile = string
6+
7+
const (
8+
ProfileBaseline Profile = "Baseline"
9+
ProfileMain Profile = "Main"
10+
ProfileHigh Profile = "High"
11+
)
12+
13+
// CodecProfile represents a codec subtype with its standardized ID,
14+
// maximum bitrate, resolution, and frame rate (if known).
315
type CodecProfile struct {
416
Codec Codec
517
Profile string
@@ -11,4 +23,5 @@ type CodecProfile struct {
1123
ID string
1224
}
1325

26+
// CodecProfiles represents a set of codec subtypes.
1427
type CodecProfiles []CodecProfile

0 commit comments

Comments
 (0)