Problem/Motivation
This task is part of the audio/video accessibility plan - #3002770: Provide authors with tools to manage transcripts and captions/subtitles for local video and audio.
We want to provide authors with the ability to upload WebVTT <track> files with subtitle, caption, and audio description, to supplement HTML <video> and <audio> elements.
Proposed resolution
- Provide a FieldType and FieldWidget plugin to represent a WebVTT file.
- Support all of the attributes of the HTML
<track>element. Authors should be able to setkind, label, src, srclang, default. Browsers currently only support captions and subtitles, but some JS player libraries support audio descriptions and chapters tracks too (notably AblePlayer). - The field type config can allow site builders to limit the values of the kind attribute which a given MediaTrackItem can accept.
- Rendering the track element is out of scope for this issue. FieldFormatter will be done in another task issue.
Challenges
Validation: the default attribute has a peculiar usage. It says which track is to be considered the default track to use, but this means the default track for each possible value of the kind attribute. For example, a <video> could have chapters, audio description, subtitles, and captions tracks, in 3 languages. There could be up to 4 default <track> elements in this case. Validating this could be tricky for the UI. Decide if validation is required/feasible for the <track default> attribute. We might just trust authors to use it correctly.
Remaining tasks
- Use a select element for the srclang in the FieldWidget plugin.
- Add some configuration options in the FieldType plugin, so that site builders can specify which values of the kind attribute to accept.
- Decide if validation is required/feasible for the
<track default>attribute. - Implement
generateSpecimenValue. The patch has some pseudocode already. - Tests.
User interface changes
Adds new FieldType and FieldWidget plugins to represent a HTML <track> element.
API changes
None.
Data model changes
Adds a new FieldType plugin to represent a HTML <track> element.
| Comment | File | Size | Author |
|---|---|---|---|
| #44 | 3056714-44-file-media-track.patch | 32.68 KB | jonathan_hunt |
| #40 | 3056714-22-tts-suport-for-media-video.patch | 20.16 KB | djanik |
| #25 | interdiff.txt | 5.56 KB | kapilv |
| #25 | 3056714-25.patch | 20.66 KB | kapilv |
| #24 | interdiff-3056714-22-24.txt | 1.12 KB | gauravvvv |
Issue fork drupal-3056714
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 9.5.x
compare
- 3056714-d
changes, plain diff MR !2443
- 3056714-provide-a-fieldtype
changes, plain diff MR !725
Comments
Comment #2
andrewmacpherson commentedFirst draft of a patch. Still stuff TODO, already mentioned in issue summary.
Comment #3
andrewmacpherson commentedThe approach I took in patch #2 was to add a new FieldType plugin, and a FieldWidget plugin, in the File module. These extend the existing FileItem and FileWidget classes, and provide the extra properties needed to support the HTML track element's attribute. This mostly follows the same approach as ImageItem and ImageWidget do for the
altandtitleattributes.Some screenshots with patch #2 applied.
The widget is functional, but takes up quite a lot of space because of having 5 sub-inputs. Maybe that can be made more elegant or compact with some styling in the admin theme.
Comment #4
andrewmacpherson commentedTidying up the issue summary. Removed something which should be in the related issue instead.
Comment #5
andrewmacpherson commentedHere's a specimen WebVTT file in case you need one to play with. It's the example from the WebVTT candidate recommendation at https://www.w3.org/TR/webvtt1/
You'll have to rename it to
test.vttyourself. The file upload here didn't permit the extension.Now, does that mean there are security implications that need to be covered in this feature?
Comment #6
andrewmacpherson commentedComment #7
jrockowitz commentedHere is more information about the <track> attributes.
Some initial thoughts on cleaning up to the UX (from the UX meeting)...
Comment #8
yogeshmpawarComment #9
yogeshmpawarResolved some coding standard issues and removed unused use statements.
Comment #10
andrewmacpherson commentedRe: #7 -
No, that's not how the default attribute works. It's permissible (and likely, even) that there would be more than one
<track>with the default attribute. That's because there can be a default track for eachkindof track.If we just treat the first Drupal field delta as the only default track, then it won't be possible to have a default captions track and a default chapters track.
In the specific case where the field only accepts subtitle and captions for the
kind, then the idea of making the first track the default may hold up. But as soon as the field accepts other kinds like chapters and audio descriptions, that assumption is no longer valid.The default attribute is the most difficult part of this entire FieldType, IMO.
Re: #9 - thanks yogeshmpawar. Note that some of those unused
usestatements are likely to be needed whengenerateSampleValue()is implemented (it's currently pseudo-code), so that's why I left them there. No worries though, it'll be easy enough to find them again in the earlier patch.Comment #11
andrewmacpherson commentedUpdating the proposed resolution and tasks in the issue summary, based on some feedback from the usability meeting where I demonstrated the work-in-progress.
For the language select, we can use
Drupal\Core\Language\LanguageManager::getStandardLanguageList(), like the first step of the Drupal installer does inDrupal\Core\Installer\Form\SelectLanguageForm.Re. #7:
The MDN article disagrees says that the default attribute "may only be used on one track element per media element". However, this disagrees with what the HTML5.2 recommendation which says multiple tracks can have the default attribute:
Comment #12
jrglasgow commentedI have done some work on this, in this patch I have added the select field for the language of the track using
\Drupal::languageManager()->getLanguages()which returns a list of the currently installed language. I have done some whitespace cleanup and got the tracks showing up inside the video tags editing a a few of the twig templates.Comment #14
andrewmacpherson commentedThanks for working on this @jrglasgow.
There are probably use-cases for being able to set the
srclangas any language. For example, videos in a learning management system for a college which teaches language courses, or a manga fandom site with community-provided subtitles. So I was thinking of offering the whole list of languages fromLanguageManager::getStandardLanguagesList(). That would be a very long list though, and many sites will only want the installed languages. So we could make a configuration setting for the field so site builders could choose which list to offer.I'll review the whole patch as soon as I can. Interdiffs want a .txt suffix, not a .patch suffix - so the test bots will ignore them.
Comment #15
jrglasgow commentedI added the ability in the field edit form to select whether the editor will see all languages or just those languages that are currently installed. The default is to only have the option of languages that are installed.
Comment #16
jrglasgow commentedIn reviewing my last patch in #15 I saw a call to {{ dpm() }} in a twig template, so this corrects it
Comment #21
akoe commentedIn patch from #16 the closing
/>for the track element in the templatefile-video.html.twigis missing and therefore invalid markup is rendered by it.Besides that patch works nice with Drupal 9.1.9
Comment #22
akoe commentedsee #21 multiple template files are affected.
Comment #24
gauravvvv commentedRe-rolled patch #22, attached interdiff for same.
Comment #25
kapilv commentedFixed Custom Commands Failed.
Comment #26
anybodyGreat work and very interesting issue here. Did someone find an issue where this is put into a Media type (Drupal Core Video Upload Media type) context? As video_embed_field is discontinued, I see a lot of space here?
That might also be interesting to provide a good / expected UX for Video Uploads by default from core including the webvtt option?
Currently, it seems there's nothing else than oEmbed / Video Plaforms?
Comment #27
mgiffordHere's an example from teh We4Authors Cluster https://accessibilitycluster.com/main-results/video
Comment #31
eojthebraveThe patch in #25, and starting back in #16 adds some logic here for displaying the
element inside a tag. However, there's another issue for dealing with the output of the collected track files already. That issue is #3057144: Update audio and video file field formatters to include track elements. Which has a more robust approach in that it makes the association between a track file and a file field containing and audio or video file configurable. This would allow for better handling of situations like an entity type with a field for uploading audio files, and another for uploading video files, and being able to know which one of the two the track file belongs to.
So I think to proceed here we should remove the logic for output the track files as part of the video tag and instead focus on just the field type, and field widget parts.
Comment #33
eojthebraveI started a new MR because I was having trouble figuring out how to get the previous one to apply against the 9.5.x branch. And this just seemed easier. Sorry if that was a mistake or creates other issues.
In this new MR I added to the code from #25 with the parts related to displaying the fields content with a field formatter removed. Since that's being handled in this other issue #3057144: Update audio and video file field formatters to include track elements.
In an attempt to address feedback from #7 I made it possible to configure which 'kind' values are available for a field instance. And set the default to subtitles and captions only.
I also added some configuration schema for the new field. And tests for both the field item and field widget classes. Hopefully this helps move things in the right direction.
Comment #35
ajfernandez commentedHi,
I have applied patch #16 on a drupal core 8.9.20 and it is applied correctly. Then I have created a field of type Media track, but when I try to upload a file of type .vtt in that field, the file is not uploaded and the following error is displayed in the drupal error log:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity:file:undefined" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: [...] in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).Which of these patches should I apply for drupal core 8.9.20?
Thanks in advance!
Comment #36
ajfernandez commentedComment #37
mgiffordI think we can tie this to WCAG SC 1.2.2.
Comment #38
jonathanshawImprovements in deep learning have led to the advent of automatic speech recognition tools like OpenAI's whisper that have dramatically improved speect-to-text capability. Therefore I'm doubtful that this issue is correct to expect uploaded webvtt files to be the most common use case in the future. The webvtt data may well be coming from a cloud API call of some kind, not an upload in the UI, and therefore a text field may be better than a file field.
Comment #40
djanik commentedI removed the patches for deprecated themes from patchfile in order to use it with drupal 10.1. so stable9 is the only core theme that gets patched.
As long as there is no better option it still does it's duty in drupal 10.
Comment #41
jonathan_hunt commented@djanik Thanks for the patch. FWIW it applies to Drupal 10.2.7.
Comment #43
jonathan_hunt commentedMR is 825 commits behind target branch. Attached is re-rolled patch for 11.3.3, also applies on 10.6.3
Comment #44
jonathan_hunt commentedComment #45
jonathan_hunt commentedPatch at #44 lacks changes to FileMediaFormatterBase, so
<track>element is not rendered. Also lacks twig changes from #40.