Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                main.grid-auto.gap.gap-block
  figure.figure-media
    figcaption.sr-only Spring
    video.media(controls poster='https://scriptura.github.io//medias/videos/Spring/Spring.jpg' style='aspect-ratio: 16/7')
      source(src='https://scriptura.github.io//medias/videos/Spring/Spring.mp4' type='video/mp4')
  div
    button.button Extract images
  output.output

              
            
!

CSS

              
                .button
  display: none
  &.active
    display: initial

              
            
!

JS

              
                'use strict'

// @see https://appcropolis.com/blog/using-html5-canvas-to-capture-frames-from-a-video/
// @see https://serversideup.net/capturing-an-image-from-an-html5-canvas-or-video-element/ +++

const media = document.querySelector('.media'),
      button = document.querySelector('.button'),
      output = document.querySelector('.output'),
      scale = 0.8,
      snapshots = []

/**
  * Captures a image frame from the provided video element.
  * @param {Video} video HTML5 video element from where the image frame will be captured.
  * @param {Number} scaleFactor Factor to scale the canvas element that will be return. This is an optional parameter.
  * @return {Canvas}
  */
const capture = (media, scale = 1) => {
  const w = media.videoWidth * scale,
        h = media.videoHeight * scale,
        canvas = document.createElement('canvas')
  canvas.width = w
  canvas.height = h
  const ctx = canvas.getContext('2d')
  ctx.drawImage(media, 0, 0, w, h)
  return canvas
}

const shoot = () => {
  const canvas = capture(media, scale)
  const img = document.createElement('img')
  document.body.appendChild(img)

  output.innerHTML = ''
  output.appendChild(canvas)

  //snapshots.unshift(canvas)
  //for (let i = 0; i < 4; i++) {
  //  output.appendChild(snapshots[i])
  //}

  img.crossOrigin = 'anonymous'
  canvas.onclick = () => {
    img.src = canvas.toDataURL('image/jpeg')
  }

}

media.addEventListener('play', () => button.classList.add('active'))

button.addEventListener('click', () => media.play = shoot()) // @note Pas de capture si poster en lieu et place de la vidéo.

              
            
!
999px

Console