Skip to content

Commit

Permalink
refactor: refactor stream chunks to 5 seconds
Browse files Browse the repository at this point in the history
closes #14
  • Loading branch information
trueChazza committed Apr 15, 2023
1 parent c496ca3 commit 342fae0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/exstream_web/controllers/playlist_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ defmodule ExstreamWeb.PlaylistController do
use ExstreamWeb, :controller

defp get_extinf(url, path, duration) do
steps = floor((Extaima.parse(duration) |> Extaima.seconds()) / 10)
steps = floor((Extaima.parse(duration) |> Extaima.seconds()) / 5)

Enum.map_join(1..steps, fn step ->
"#EXTINF:10,\n#{url}?path=#{path}&start=#{step * 10 - 10}&end=#{step * 10}\n"
"#EXTINF:5,\n#{url}?path=#{path}&start=#{step * 5 - 5}&end=#{step * 5}\n"
end)
end

def build(url, path, duration) do
"#EXTM3U\n" <>
"#EXT-X-PLAYLIST-TYPE:VOD\n" <>
"#EXT-X-TARGETDURATION:10\n" <>
"#EXT-X-TARGETDURATION:5\n" <>
"#EXT-X-VERSION:4\n" <>
"#EXT-X-MEDIA-SEQUENCE:0\n" <>
get_extinf(url, path, duration) <>
Expand Down
20 changes: 13 additions & 7 deletions test/fixtures/playlist.m3u8
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXT-X-TARGETDURATION:5
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=0&end=10
#EXTINF:10,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=10&end=20
#EXTINF:10,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=20&end=30
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=0&end=5
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=5&end=10
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=10&end=15
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=15&end=20
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=20&end=25
#EXTINF:5,
/some/url?path=dev/sample__1080__libx265__ac3__30s__video.mkv&start=25&end=30
#EXT-X-ENDLIST

0 comments on commit 342fae0

Please sign in to comment.