The FileVideoFormatter in core does not provide any thumbnail by default with local video uploads.

Luckily (?), most browsers like Chrome are smart enough to supply the first frame of the video as the thumbnail, but this is not something iOS Safari does.

The generated HTML for the current fieldformatter looks something like this:

<div class="field field--name-field-media-video-file field--type-file field--label-hidden field__item">
  <video controls="controls" width="1024" height="576">
      <source src="/sites/default/files/2019-05/somevideo.mp4" type="video/mp4">
  </video>
</div>

I found out that by adding preload="metadata" to the video tag and suffixing "#t=1" to the source files "src" attribute, it adds the wanted behavior to Safari iOS.

I've created a patch for adding this functionality. After adding the patch, video fields will look something like this:

<div class="field field--name-field-media-video-file field--type-file field--label-hidden field__item">
  <video controls="controls" width="1024" height="576" preload="metadata">
      <source src="/sites/default/files/2019-05/somevideo.mp4#t=1" type="video/mp4">
  </video>
</div>

Issue fork drupal-3079425

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

ras-ben created an issue. See original summary.

ras-ben’s picture

Version: 8.8.x-dev » 8.6.x-dev
StatusFileSize
new4.03 KB
ras-ben’s picture

StatusFileSize
new4.04 KB
ras-ben’s picture

Issue summary: View changes

The last submitted patch, 2: core_file_media_video_standard_thumbnail_2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3: core_file_media_video_standard_thumbnail_3.patch, failed testing. View results

ras-ben’s picture

Re-rolled against 8.7.7

arnested’s picture

Version: 8.6.x-dev » 8.7.x-dev
ras-ben’s picture

StatusFileSize
new3.96 KB

Sigh - i forgot a "use", so it would fail in certain cases..

samberry’s picture

I tried out the patch in #9 but found that the 1 second set for the 'thumbnail_second' variable was too late, as videos were starting from 1 second in. I have therefore modified the patch to remove the min of 1 to the thumbnail_second and set this by default to 0.01.

I feel like this may be a bit of a workaround though, and I'm not sure that this should be the final version.

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

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

samberry’s picture

Realised decimals won't work if its a number field - updated to textfield!

ras-ben’s picture

@samberry - why not just use decimal fieldtype?
I think using textfield would be wrong - and would probably open up to a security issue as we dont escape it or anything before adding it to the src :)

platinum1’s picture

@ras-ben I am dealing with this problem right now. Is development of your solution continuing?

ras-ben’s picture

@platinum1 Well, it's quite a while ago now since i looked at this
My own patch #7 solved my issue, but @samberry does have a valid point in his patches #10 and #12

Seeing as this is an issue against core, and it's a relative edgecase, I've never had the highest hopes that this would be merged any time soon.

But you are very welcome to build onto samberry's solution and deal with my latest comment.
I'll be happy to review it if you do - i dont expect it's a big fix :)

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

ras-ben’s picture

Status: Needs work » Needs review
StatusFileSize
new3.87 KB

Re-rolled against 9.2.

Status: Needs review » Needs work
samberry’s picture

So I've managed to include the step attribute which provides the ability to add a decimal value, I've also added thumbnail_second to the schema.

avpaderno’s picture

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

Drupal 8.9.x is now open only to security issues.

inaw’s picture

Status: Needs work » Needs review
StatusFileSize
new4.34 KB

I tested the patch #19 and had to change the field type in schema.yml to float, to be able to successfully save decimal numbers in the thumbnail_second.

thumbnail_second:
  type: float
  label: 'Thumbnail Second'

Otherwise, the patch seems to work fine with Drupal 9.2.x.

Status: Needs review » Needs work
rollins’s picture

I can confirm that #21 resolved bug
Thanks InaW!

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

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

_shy’s picture

Rerolled patch. Also added test fixes.

_shy’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

Keshav Patel made their first commit to this issue’s fork.

_shy’s picture

Updated patch to be able to apply it for the Drupal 10.3.1

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.