Add seeking for live transcodes via video.js

This commit is contained in:
WithoutPants
2019-07-29 13:42:00 +10:00
parent 4f016ab3c9
commit 8ed3c5f71d
6 changed files with 336 additions and 22 deletions

View File

@@ -1,17 +1,18 @@
package api
import (
"io"
"context"
"io"
"net/http"
"strconv"
"strings"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"github.com/stashapp/stash/pkg/ffmpeg"
"net/http"
"strconv"
"strings"
)
type sceneRoutes struct{}
@@ -41,7 +42,7 @@ func (rs sceneRoutes) Routes() chi.Router {
func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
scene := r.Context().Value(sceneKey).(*models.Scene)
// detect if not a streamable file and try to transcode it instead
filepath := manager.GetInstance().Paths.Scene.GetStreamPath(scene.Path, scene.Checksum)
@@ -58,10 +59,14 @@ func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
logger.Errorf("[stream] error reading video file: %s", err.Error())
return
}
// start stream based on query param, if provided
r.ParseForm()
startTime := r.Form.Get("start")
encoder := ffmpeg.NewEncoder(manager.GetInstance().FFMPEGPath)
stream, process, err := encoder.StreamTranscode(*videoFile)
stream, process, err := encoder.StreamTranscode(*videoFile, startTime)
if err != nil {
logger.Errorf("[stream] error transcoding video file: %s", err.Error())
return

View File

@@ -26,8 +26,14 @@ func (e *Encoder) Transcode(probeResult VideoFile, options TranscodeOptions) {
_, _ = e.run(probeResult, args)
}
func (e *Encoder) StreamTranscode(probeResult VideoFile) (io.ReadCloser, *os.Process, error) {
args := []string{
func (e *Encoder) StreamTranscode(probeResult VideoFile, startTime string) (io.ReadCloser, *os.Process, error) {
args := []string{}
if startTime != "" {
args = append(args, "-ss", startTime)
}
args = append(args,
"-i", probeResult.Path,
"-c:v", "libvpx-vp9",
"-vf", "scale=iw:-2",
@@ -37,6 +43,7 @@ func (e *Encoder) StreamTranscode(probeResult VideoFile) (io.ReadCloser, *os.Pro
"-b:v", "0",
"-f", "webm",
"pipe:",
}
)
return e.stream(probeResult, args)
}