Skip to content

Commit

Permalink
Support direct streaming of audio files. /fixes stashapp#1258
Browse files Browse the repository at this point in the history
  • Loading branch information
rezreal committed Oct 27, 2021
1 parent 372ea72 commit 169b797
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
18 changes: 18 additions & 0 deletions pkg/ffmpeg/ffprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const (
MimeMp4 string = "video/mp4"
MimeHLS string = "application/vnd.apple.mpegurl"
MimeMpegts string = "video/MP2T"
MimeAudioMpeg string = "audio/mpeg"
MimeAudioOgg string = "audio/ogg"
MimeAudioWav string = "audio/wav"
)

// only support H264 by default, since Safari does not support VP8/VP9
Expand Down Expand Up @@ -146,6 +149,21 @@ func IsValidAudioForContainer(audio AudioCodec, format Container) bool {

}

func IsAudioContainer(format Container) bool {
switch format {
case "mp3":
return true
case "flac":
return true
case "ogg":
return true
case "wav":
return true
}
return false

}

func IsValidForContainer(format Container, validContainers []Container) bool {
for _, fmt := range validContainers {
if fmt == format {
Expand Down
20 changes: 20 additions & 0 deletions pkg/manager/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ func GetSceneStreamPaths(scene *models.Scene, directStreamURL string, maxStreami
MimeType: &mimeMp4,
Label: &label,
})
} else if GetAudioMimeType(scene.Format.String) != "" {
label := "Direct audio stream"
mimetype := GetAudioMimeType(scene.Format.String)
ret = append(ret, &models.SceneStreamEndpoint{
URL: directStreamURL,
MimeType: &mimetype,
Label: &label,
})
}

// only add mkv stream endpoint if the scene container is an mkv already
Expand Down Expand Up @@ -363,3 +371,15 @@ func HasTranscode(scene *models.Scene, fileNamingAlgo models.HashAlgorithm) bool
ret, _ := utils.FileExists(transcodePath)
return ret
}

func GetAudioMimeType(format string) string {
switch format {
case "mp3":
return ffmpeg.MimeAudioMpeg
case "wav":
return ffmpeg.MimeAudioWav
case "ogg":
return ffmpeg.MimeAudioOgg
}
return ""
}
19 changes: 0 additions & 19 deletions ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,6 @@ export class ScenePlayerImpl extends React.Component<
}
});

//
this.player.on("meta", (metadata: any) => {
if (
metadata.metadataType === "media" &&
!metadata.width &&
!metadata.height
) {
// Occurs during preload when videos with supported audio/unsupported video are preloaded.
// Treat this as a decoding error and try the next source without playing.
// However on Safari we get an media event when m3u8 is loaded which needs to be ignored.
const currentFile = this.player.getPlaylistItem().file;
if (currentFile != null && !currentFile.includes("m3u8")) {
const state = this.player.getState();
const play = state === "buffering" || state === "playing";
this.handleError(play);
}
}
});

this.player.on("firstFrame", () => {
if (this.props.timestamp > 0) {
this.player.seek(this.props.timestamp);
Expand Down

1 comment on commit 169b797

@rezreal
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To actually add audio files to the library, the extensions need to be added to
"Settings" -> "Configurations" -> "Video Extensions"

Please sign in to comment.