-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.tsx
143 lines (138 loc) · 3.33 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React from 'react'
import { graphql } from 'gatsby'
import './styles.css'
function Video({
video: {
videoH264,
videoH265,
videoVP9,
previewH264,
previewWebP,
previewGif,
videoSepia,
videoScreenshots,
},
...props
}) {
return (
<div {...props}>
<h3>Screenshots at 0s, 1s, 50% and 99%:</h3>
<div className="screenshots">
{videoScreenshots.map(({ publicURL }) => (
<div key="path">
<img src={publicURL} />
</div>
))}
</div>
<h3>
Animated preview via{` `}
<a href="https://css-tricks.com/fallbacks-videos-images/">
picture element
</a>
:
</h3>
<p>Fallbacks: h264, animated webP and Gifs</p>
<picture>
<source type="video/mp4" srcSet={previewH264.path} />
<source type="image/webp" srcSet={previewWebP.path} />
<img loading="lazy" src={previewGif.path} alt="" />
</picture>
<h3>Video as optimized h264 & h265 & VP9:</h3>
<video
playsInline
preload="auto"
poster={videoScreenshots[0].publicURL}
controls
>
<source src={videoH265.path} type="video/mp4; codecs=hevc" />
<source src={videoVP9.path} type="video/webm; codecs=vp9,opus" />
<source src={videoH264.path} type="video/mp4; codecs=avc1" />
</video>
<h3>Custom video converter:</h3>
<video
playsInline
preload="auto"
poster={videoScreenshots[0].publicURL}
controls
>
<source src={videoSepia.path} type="video/mp4; codecs=avc1" />
</video>
</div>
)
}
const Index = ({ data }) => {
return (
<main>
<h1>Using gatsby-transformer-video</h1>
<div className="grid">
<div>
<h2>Via gatsby-source-filesystem</h2>
<Video video={data.file} />
</div>
<div>
<h2>Via gatsby-source-contentful</h2>
<Video video={data.contentfulAsset} />
</div>
</div>
</main>
)
}
export default Index
export const query = graphql`
query HomePageQuery {
file(relativePath: { eq: "gatsby.mp4" }) {
id
videoH264 {
path
}
videoH265 {
path
}
videoVP9 {
path
}
videoSepia: videoProfile(profile: "sepia", maxWidth: 600) {
path
}
previewH264: videoH264(maxWidth: 600, fps: 4, duration: 2) {
path
}
previewWebP: videoWebP(maxWidth: 600, fps: 4, duration: 2) {
path
}
previewGif: videoGif(maxWidth: 600, fps: 4, duration: 2) {
path
}
videoScreenshots(timestamps: ["0", "1", "50%", "99%"]) {
publicURL
}
}
contentfulAsset(contentful_id: { eq: "6HqTq5U2PLoVO0Qo7Vy0Yk" }) {
id
videoH264 {
path
}
videoH265 {
path
}
videoVP9 {
path
}
videoSepia: videoProfile(profile: "sepia", maxWidth: 600) {
path
}
previewH264: videoH264(maxWidth: 600, fps: 4, duration: 2) {
path
}
previewWebP: videoWebP(maxWidth: 600, fps: 4, duration: 2) {
path
}
previewGif: videoGif(maxWidth: 600, fps: 4, duration: 2) {
path
}
videoScreenshots(timestamps: ["0", "1", "50%", "99%"]) {
publicURL
}
}
}
`