Add UI controls for selecting lower quality video resolutions
This commit is contained in:
parent
ef8afabf3f
commit
58a6502c83
3 changed files with 93 additions and 4 deletions
80
app/app.go
80
app/app.go
|
@ -28,6 +28,15 @@ import (
|
|||
|
||||
//go:generate rice embed-go
|
||||
|
||||
var (
|
||||
SizeMap = map[string]string{
|
||||
"hd720": "720p",
|
||||
"hd480": "480p",
|
||||
"nhd": "360p",
|
||||
"film": "240p",
|
||||
}
|
||||
)
|
||||
|
||||
// App represents main application.
|
||||
type App struct {
|
||||
Config *Config
|
||||
|
@ -311,6 +320,41 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO: Make this a background job
|
||||
// Resize for lower quality options
|
||||
for size, suffix := range SizeMap {
|
||||
log.
|
||||
WithField("size", size).
|
||||
WithField("vf", filepath.Base(vf)).
|
||||
Info("resizing video for lower quality playback")
|
||||
sf := fmt.Sprintf(
|
||||
"%s#%s.mp4",
|
||||
strings.TrimSuffix(vf, filepath.Ext(vf)),
|
||||
suffix,
|
||||
)
|
||||
|
||||
if err := utils.RunCmd(
|
||||
a.Config.Transcoder.Timeout,
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i", vf,
|
||||
"-s", size,
|
||||
"-c:v", "libx264",
|
||||
"-c:a", "aac",
|
||||
"-crf", "18",
|
||||
"-strict", "-2",
|
||||
"-loglevel", "quiet",
|
||||
"-metadata", fmt.Sprintf("title=%s", title),
|
||||
"-metadata", fmt.Sprintf("comment=%s", description),
|
||||
sf,
|
||||
); err != nil {
|
||||
err := fmt.Errorf("error transcoding video: %w", err)
|
||||
log.Error(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "Video successfully uploaded!")
|
||||
} else {
|
||||
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||
|
@ -435,6 +479,42 @@ func (a *App) importHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Make this a background job
|
||||
// Resize for lower quality options
|
||||
for size, suffix := range SizeMap {
|
||||
log.
|
||||
WithField("size", size).
|
||||
WithField("vf", filepath.Base(vf)).
|
||||
Info("resizing video for lower quality playback")
|
||||
sf := fmt.Sprintf(
|
||||
"%s#%s.mp4",
|
||||
strings.TrimSuffix(vf, filepath.Ext(vf)),
|
||||
suffix,
|
||||
)
|
||||
|
||||
if err := utils.RunCmd(
|
||||
a.Config.Transcoder.Timeout,
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i", vf,
|
||||
"-s", size,
|
||||
"-c:v", "libx264",
|
||||
"-c:a", "aac",
|
||||
"-crf", "18",
|
||||
"-strict", "-2",
|
||||
"-loglevel", "quiet",
|
||||
"-metadata", fmt.Sprintf("title=%s", videoInfo.Title),
|
||||
"-metadata", fmt.Sprintf("comment=%s", videoInfo.Description),
|
||||
sf,
|
||||
); err != nil {
|
||||
err := fmt.Errorf("error transcoding video: %w", err)
|
||||
log.Error(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "Video successfully imported!")
|
||||
} else {
|
||||
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||
|
|
|
@ -123,9 +123,9 @@ func init() {
|
|||
}
|
||||
filee := &embedded.EmbeddedFile{
|
||||
Filename: "index.html",
|
||||
FileModTime: time.Unix(1585374250, 0),
|
||||
FileModTime: time.Unix(1585378864, 0),
|
||||
|
||||
Content: string("{{ define \"content\" }}\r\n{{ $playing := .Playing }}\r\n<div id=\"player\">\r\n {{ if $playing.ID }}\r\n <video id=\"video\" controls preload=\"metadata\" poster=\"/t/{{ $playing.ID}}\">\r\n <source src=\"/v/{{ $playing.ID }}.mp4?quality={{ $.Quality }}\" type=\"video/mp4\" />\r\n </video>\r\n <h1>{{ $playing.Title }}</h1>\r\n <h2>{{ $playing.Views }} views • {{ $playing.Modified }}<br />{{ $playing.Size | bytes }}</h2>\r\n <p>{{ $playing.Description }}</p>\r\n {{ else }}\r\n <video id=\"video\" controls></video>\r\n {{ end }}\r\n</div>\r\n<div id=\"playlist\">\r\n <div class=\"nav\">\r\n <ul>\r\n <li><a {{ if or (eq $.Sort \"timestamp\") (eq $.Sort \"\") }}class=\"active\"{{ end }} href=\"?sort=timestamp\">Recent</a></li>\r\n <li><a {{ if eq $.Sort \"views\" }}class=\"active\"{{ end }} href=\"?sort=views\">Views</a></li>\r\n </ul>\r\n </div>\r\n {{ range $m := .Playlist }}\r\n {{ if eq $m.ID $playing.ID }}\r\n <a href=\"/v/{{ $m.ID }}\" class=\"playing\">\r\n {{ else }}\r\n <a href=\"/v/{{ $m.ID }}\">\r\n {{ end }}\r\n <img src=\"/t/{{ $m.ID }}\">\r\n <div>\r\n <h1>{{ $m.Title }}</h1>\r\n <h2>{{ $m.Views }} views • {{ $m.Modified }}<br />{{ $m.Size | bytes }}</h2>\r\n </div>\r\n </a>\r\n {{ end }}\r\n</div>\r\n{{end}}\r\n"),
|
||||
Content: string("{{ define \"content\" }}\r\n{{ $playing := .Playing }}\r\n<div class=\"nav\">\r\n <ul>\r\n <li><a {{ if eq $.Quality \"\" }}class=\"active\"{{ end }} href=\"/v/{{ $playing.ID }}\">fullHD</a></li>\r\n <li><a {{ if eq $.Quality \"720p\" }}class=\"active\"{{ end }} href=\"/v/{{ $playing.ID }}?quality=720p\">720p</a></li>\r\n <li><a {{ if eq $.Quality \"480p\" }}class=\"active\"{{ end }} href=\"/v/{{ $playing.ID }}?quality=480p\">480p</a></li>\r\n <li><a {{ if eq $.Quality \"360p\" }}class=\"active\"{{ end }} href=\"/v/{{ $playing.ID }}?quality=360p\">360p</a></li>\r\n <li><a {{ if eq $.Quality \"240p\" }}class=\"active\"{{ end }} href=\"/v/{{ $playing.ID }}?quality=240p\">240p</a></li>\r\n </ul>\r\n</div>\r\n<div id=\"player\">\r\n {{ if $playing.ID }}\r\n <video id=\"video\" controls preload=\"metadata\" poster=\"/t/{{ $playing.ID}}\">\r\n <source src=\"/v/{{ $playing.ID }}.mp4?quality={{ $.Quality }}\" type=\"video/mp4\" />\r\n </video>\r\n <h1>{{ $playing.Title }}</h1>\r\n <h2>{{ $playing.Views }} views • {{ $playing.Modified }}<br />{{ $playing.Size | bytes }}</h2>\r\n <p>{{ $playing.Description }}</p>\r\n {{ else }}\r\n <video id=\"video\" controls></video>\r\n {{ end }}\r\n</div>\r\n<div id=\"playlist\">\r\n <div class=\"nav\">\r\n <ul>\r\n <li><a {{ if or (eq $.Sort \"timestamp\") (eq $.Sort \"\") }}class=\"active\"{{ end }} href=\"?sort=timestamp\">Recent</a></li>\r\n <li><a {{ if eq $.Sort \"views\" }}class=\"active\"{{ end }} href=\"?sort=views\">Views</a></li>\r\n </ul>\r\n </div>\r\n {{ range $m := .Playlist }}\r\n {{ if eq $m.ID $playing.ID }}\r\n <a href=\"/v/{{ $m.ID }}\" class=\"playing\">\r\n {{ else }}\r\n <a href=\"/v/{{ $m.ID }}\">\r\n {{ end }}\r\n <img src=\"/t/{{ $m.ID }}\">\r\n <div>\r\n <h1>{{ $m.Title }}</h1>\r\n <h2>{{ $m.Views }} views • {{ $m.Modified }}<br />{{ $m.Size | bytes }}</h2>\r\n </div>\r\n </a>\r\n {{ end }}\r\n</div>\r\n{{end}}\r\n"),
|
||||
}
|
||||
filef := &embedded.EmbeddedFile{
|
||||
Filename: "upload.html",
|
||||
|
@ -137,7 +137,7 @@ func init() {
|
|||
// define dirs
|
||||
dirb := &embedded.EmbeddedDir{
|
||||
Filename: "",
|
||||
DirModTime: time.Unix(1585374250, 0),
|
||||
DirModTime: time.Unix(1585378864, 0),
|
||||
ChildFiles: []*embedded.EmbeddedFile{
|
||||
filec, // "base.html"
|
||||
filed, // "import.html"
|
||||
|
@ -153,7 +153,7 @@ func init() {
|
|||
// register embeddedBox
|
||||
embedded.RegisterEmbeddedBox(`../templates`, &embedded.EmbeddedBox{
|
||||
Name: `../templates`,
|
||||
Time: time.Unix(1585374250, 0),
|
||||
Time: time.Unix(1585378864, 0),
|
||||
Dirs: map[string]*embedded.EmbeddedDir{
|
||||
"": dirb,
|
||||
},
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{{ define "content" }}
|
||||
{{ $playing := .Playing }}
|
||||
<div class="nav">
|
||||
<ul>
|
||||
<li><a {{ if eq $.Quality "" }}class="active"{{ end }} href="/v/{{ $playing.ID }}">fullHD</a></li>
|
||||
<li><a {{ if eq $.Quality "720p" }}class="active"{{ end }} href="/v/{{ $playing.ID }}?quality=720p">720p</a></li>
|
||||
<li><a {{ if eq $.Quality "480p" }}class="active"{{ end }} href="/v/{{ $playing.ID }}?quality=480p">480p</a></li>
|
||||
<li><a {{ if eq $.Quality "360p" }}class="active"{{ end }} href="/v/{{ $playing.ID }}?quality=360p">360p</a></li>
|
||||
<li><a {{ if eq $.Quality "240p" }}class="active"{{ end }} href="/v/{{ $playing.ID }}?quality=240p">240p</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="player">
|
||||
{{ if $playing.ID }}
|
||||
<video id="video" controls preload="metadata" poster="/t/{{ $playing.ID}}">
|
||||
|
|
Loading…
Reference in a new issue