Videos: Skip transcoding of HEVC / HVC1 if supported by the browser #440 #513 (#2379)

This commit is contained in:
Andre Carrera 2022-06-23 17:30:48 -06:00 committed by GitHub
parent 15b1f5728b
commit 95c03afe28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -39,8 +39,10 @@ import download from "common/download";
import * as src from "common/src";
export const CodecAvc1 = "avc1";
export const CodecHvc1 = "hvc1";
export const FormatMp4 = "mp4";
export const FormatAvc = "avc";
export const FormatHvc = "hvc";
export const FormatGif = "gif";
export const FormatJpeg = "jpg";
export const MediaImage = "image";
@ -474,6 +476,11 @@ export class Photo extends RestModel {
videoUrl() {
let file = this.videoFile();
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
if (file && file.Codec === CodecHvc1 && isSafari) {
return `${config.apiUri}/videos/${file.Hash}/${config.previewToken()}/${FormatHvc}`;
}
if (file) {
return `${config.apiUri}/videos/${file.Hash}/${config.previewToken()}/${FormatAvc}`;

View file

@ -11,6 +11,7 @@ import (
const (
ContentTypeAvc = `video/mp4; codecs="avc1"`
ContentTypeHvc = `video/mp4; codecs="hvc1"`
)
// AddCacheHeader adds a cache control header to the response.

View file

@ -84,7 +84,11 @@ func GetVideo(router *gin.RouterGroup) {
}
}
AddContentTypeHeader(c, ContentTypeAvc)
if video.Types[formatName] == video.HEVC {
AddContentTypeHeader(c, ContentTypeHvc)
} else {
AddContentTypeHeader(c, ContentTypeAvc)
}
if c.Query("download") != "" {
c.FileAttachment(fileName, f.DownloadName(DownloadName(c), 0))