Skip to content

Commit

Permalink
Merge pull request #5082 from avalonmediasystem/hls_subtitles
Browse files Browse the repository at this point in the history
HLS captions for iOS
  • Loading branch information
cjcolvar authored Feb 28, 2023
2 parents 82a9660 + 07a8480 commit 9e6b71e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/master_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ def hls_manifest
end
end

def caption_manifest
return head :unauthorized if cannot?(:read, @master_file)
@caption = @master_file.captions
end

def structure
authorize! :read, @master_file, message: "You do not have sufficient privileges"
render json: @master_file.structuralMetadata.as_json
Expand Down
10 changes: 10 additions & 0 deletions app/views/master_files/caption_manifest.m3u8.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% caption = captions_master_file_path %>

#EXTM3U
#EXT-X-TARGETDURATION:<%= @master_file.duration %>
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:<%= @master_file.duration %>
<%= caption %>
#EXT-X-ENDLIST
3 changes: 2 additions & 1 deletion app/views/master_files/hls_manifest.m3u8.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Unless required by applicable law or agreed to in writing, software distributed
--- END LICENSE_HEADER BLOCK ---
%>
#EXTM3U
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",LANGUAGE="en",NAME="English",AUTOSELECT=YES,URI="<%= caption_manifest_master_file_path %>"
<% @hls_streams.each do |hls| %>
#EXT-X-STREAM-INF:BANDWIDTH=<%= hls[:bitrate] %>
#EXT-X-STREAM-INF:BANDWIDTH=<%= hls[:bitrate] %>,SUBTITLES="subs"
<%= hls[:url] %>
<% end %>
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Application < Rails::Application
resource '/master_files/*/structure.json', headers: :any, methods: [:get, :post, :delete]
resource '/master_files/*/waveform.json', headers: :any, methods: [:get]
resource '/master_files/*/*.m3u8', headers: :any, credentials: true, methods: [:get, :head]
resource '/master_files/*/caption_manifest', headers: :any, methods: [:get]
resource '/master_files/*/captions', headers: :any, methods: [:get]
resource '/timelines/*/manifest.json', headers: :any, methods: [:get, :post]
end
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
get :captions
get :waveform
match ':quality.m3u8', to: 'master_files#hls_manifest', via: [:get], as: :hls_manifest
get 'caption_manifest'
get 'structure', to: 'master_files#structure', constraints: { format: 'json' }
post 'structure', to: 'master_files#set_structure', constraints: { format: 'json' }
delete 'structure', to: 'master_files#delete_structure', constraints: { format: 'json' }
Expand Down

0 comments on commit 9e6b71e

Please sign in to comment.