Skip to content

Commit

Permalink
Server: Use HLS on Safari.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Feb 26, 2024
1 parent 0df5d99 commit d70156a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ public HttpResponse onViewSpecificMedia(SoraHttpSession session) {
vCodec = VideoCodec.H264_HIGH;
aCodec = AudioCodec.AAC;
quality = VideoQuality.FHD;
} else if (userAgent.contains("Safari/")) {
container = ContainerFormat.HLS;
vCodec = VideoCodec.H264_HIGH;
aCodec = AudioCodec.AAC;
quality = VideoQuality.UHD;
} else {
container = ContainerFormat.MKV;
vCodec = VideoCodec.SOURCE;
Expand Down Expand Up @@ -529,11 +534,15 @@ public HttpResponse onWatchSpecificMedia(SoraHttpSession session) {
AudioCodec aCodec = AudioCodec.valueOf(session.getQueryParameters().get("aCodec"));
VideoQuality quality = VideoQuality.valueOf(session.getQueryParameters().get("quality"));

String videoUrl = String.format(
"/_internal/media/%s/stream?format=%s&videoCodec=%s&audioCodec=%s&quality=%s",
media.getId(), container, vCodec, aCodec, quality
);
// }
String videoUrl = container == ContainerFormat.HLS ? //
String.format(
"/_internal/media/%s/stream/hls/media.m3u8?format=%s&videoCodec=%s&audioCodec=%s&quality=%s",
media.getId(), container, vCodec, aCodec, quality
)
: String.format(
"/_internal/media/%s/stream?format=%s&videoCodec=%s&audioCodec=%s&quality=%s",
media.getId(), container, vCodec, aCodec, quality
);

return new HTMLBuilder()
.f("<a href=\"/media/%s\">Go back</a>", media.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class Transcoder {
if (desiredContainer == ContainerFormat.HLS) {
targetFile.mkdir(); // Make it a directory.
command.add("-vf", "fps=fps=" + HLS_RATE);
command.add("-hls_playlist_type", "event");
command.add("-hls_flags", "+append_list");
command.add(new File(targetFile, "media.m3u8").getCanonicalPath());
} else {
command.add("-f", desiredContainer.ff);
Expand Down

0 comments on commit d70156a

Please sign in to comment.