Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS captions for iOS #5082

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@masaball masaball Feb 27, 2023

Choose a reason for hiding this comment

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

@caption = master_file.captions is unnessary for final implementation. The caption_manifest erb file does not acually make use of this but rather uses the captions_master_file_path. Shouldn't interfere with testing though.

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 %>"
Copy link
Contributor Author

@masaball masaball Feb 27, 2023

Choose a reason for hiding this comment

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

Final implementation could have a setting to specify a default caption language to avoid having to hardcode it as english. If this approach is implemented, would be good to eventually circle back and allow editors to define caption language, as well as provide an option to provide multiple caption files.

<% @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]
Comment on lines +50 to +51
Copy link
Contributor Author

@masaball masaball Feb 27, 2023

Choose a reason for hiding this comment

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

Not sure if necessary for final implementation. These are necessary when an HLS manifest with captions is requested by an external player such as Ramp, but depending on how iOS handles the requests it may not be through CORS. If we are able to provide captions to IIIF players via the IIIF manifest, then the captions being included in the HLS manifest may only be necessary for iOS.

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