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

  1. Provide a FieldType and FieldWidget plugin to represent a WebVTT file.
  2. Support all of the attributes of the HTML <track> element. Authors should be able to set kind, 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).
  3. The field type config can allow site builders to limit the values of the kind attribute which a given MediaTrackItem can accept.
  4. 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

  1. Use a select element for the srclang in the FieldWidget plugin.
  2. Add some configuration options in the FieldType plugin, so that site builders can specify which values of the kind attribute to accept.
  3. Decide if validation is required/feasible for the <track default> attribute.
  4. Implement generateSpecimenValue. The patch has some pseudocode already.
  5. 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.

Issue fork drupal-3056714

Command icon 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:

Comments

andrewmacpherson created an issue. See original summary.

andrewmacpherson’s picture

Status: Active » Needs review
StatusFileSize
new13.28 KB

First draft of a patch. Still stuff TODO, already mentioned in issue summary.

andrewmacpherson’s picture

The 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 alt and title attributes.

Some screenshots with patch #2 applied.

  1. A Media Track field has been added to the Video media type. This is how it looks in the "manage fields" setting for the media type. The new "Media Track" field type is indicated:
    Screenshot of the manage fields page for  the video media type.
  2. The field widget settings aren't very remarkable. Here is "manage form display":
    Screenshot of the manage form display page for the video media type.
  3. An example of the widget itself. The media track field has been configured for unlimited values. One file has been uploaded already, and the extra properties for srclang, kind, label, and default are revealed. An "add a new file" input can be seen, but it's just a file input. The extra properties can't be specified until a track file is uploaded.
    Screenshot of the media track widget, on the edit form for a video media entity.

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.

andrewmacpherson’s picture

Issue summary: View changes

Tidying up the issue summary. Removed something which should be in the related issue instead.

andrewmacpherson’s picture

StatusFileSize
new1.21 KB

Here'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.vtt yourself. 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?

andrewmacpherson’s picture

Issue summary: View changes
jrockowitz’s picture

Here is more information about the <track> attributes.

Some initial thoughts on cleaning up to the UX (from the UX meeting)...

  • 'Kind' attribute could default to only supporting 'subtitles' and 'captions'
  • 'Default track' checkbox could be hidden and we use the first track as the default.
  • SRC Language could use a language select menu.
yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
StatusFileSize
new13.06 KB
new2.65 KB

Resolved some coding standard issues and removed unused use statements.

andrewmacpherson’s picture

Re: #7 -

'Default track' checkbox could be hidden and we use the first track as the default.

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 each kind of 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 use statements are likely to be needed when generateSampleValue() 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.

andrewmacpherson’s picture

Issue summary: View changes
Status: Needs review » Needs work

Updating 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 in Drupal\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:

The default attribute is a boolean attribute, which, if specified, indicates that the track is to be enabled if the user’s preferences do not indicate that another track would be more appropriate.

Each media element must have no more than one track element child whose kind attribute is in the Subtitles or Captions state and whose default attribute is specified.

Each media element must have no more than one track element child whose kind attribute is in the Descriptions state and whose default attribute is specified.

Each media element must have no more than one track element child whose kind attribute is in the Chapters state and whose default attribute is specified.

There is no limit on the number of track elements whose kind attribute is in the Metadata state and whose default attribute is specified.

jrglasgow’s picture

Status: Needs work » Needs review
StatusFileSize
new19.1 KB
new9.75 KB

I 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.

The last submitted patch, 12: 3056714-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andrewmacpherson’s picture

Thanks for working on this @jrglasgow.

There are probably use-cases for being able to set the srclang as 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 from LanguageManager::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.

jrglasgow’s picture

StatusFileSize
new20.74 KB
new7.66 KB

I 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.

jrglasgow’s picture

StatusFileSize
new20.67 KB
new379 bytes

In reviewing my last patch in #15 I saw a call to {{ dpm() }} in a twig template, so this corrects it

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

akoe’s picture

StatusFileSize
new20.67 KB

In patch from #16 the closing /> for the track element in the template file-video.html.twig is missing and therefore invalid markup is rendered by it.

Besides that patch works nice with Drupal 9.1.9

akoe’s picture

StatusFileSize
new20.67 KB

see #21 multiple template files are affected.

gauravvvv’s picture

StatusFileSize
new20.67 KB
new1.12 KB

Re-rolled patch #22, attached interdiff for same.

kapilv’s picture

StatusFileSize
new20.66 KB
new5.56 KB

Fixed Custom Commands Failed.

anybody’s picture

Great 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?

mgifford’s picture

Issue tags: +we4authors

Here's an example from teh We4Authors Cluster https://accessibilitycluster.com/main-results/video

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

eojthebrave made their first commit to this issue’s fork.

eojthebrave’s picture

Status: Needs review » Needs work

The 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.

eojthebrave’s picture

I 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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ajfernandez’s picture

StatusFileSize
new377.08 KB

Hi,

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!

ajfernandez’s picture

mgifford’s picture

Issue tags: +wcag122

I think we can tie this to WCAG SC 1.2.2.

jonathanshaw’s picture

Improvements 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

djanik’s picture

StatusFileSize
new20.16 KB

I 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.

jonathan_hunt’s picture

@djanik Thanks for the patch. FWIW it applies to Drupal 10.2.7.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jonathan_hunt’s picture

MR is 825 commits behind target branch. Attached is re-rolled patch for 11.3.3, also applies on 10.6.3

jonathan_hunt’s picture

StatusFileSize
new32.68 KB
jonathan_hunt’s picture

Patch at #44 lacks changes to FileMediaFormatterBase, so <track> element is not rendered. Also lacks twig changes from #40.