Optimized way of implementing Hero background Video

Does any of you have some experiencing with optimizing a video, which is played, in loop and with autoplay, the background of a website's hero? It is currently quite large (around 10MB), which is clearly too much for a user to download, but it still needs to be of fairly good quality Thank you in advance! 😊
269 Replies
Jochem
Jochem15mo ago
might be useful to share stuff like resolution, which formats you've tried, how long the video is, fps of the video
LOKKEE
LOKKEEOP15mo ago
Sorry, sure: Resolution: 720 × 1280 FPS: 30 Duration: 29s File-size: 10.6MB Format: MP4 (WEBM lead to a 3x increase of file-size; it seems like it does not always reduce file-size) I thought someone may already had to deal with a situation like this before. I am mainly looking for an idea / impulse or direction I can head into, to solve this Thanks for the guiding
ἔρως
ἔρως15mo ago
what's the video codec? did you made sure the video doesn't have a sound channel? what's the video's contents? maybe it can be re-implemented in css have you considered also not using a video, but just static images?
LOKKEE
LOKKEEOP15mo ago
Oh yea, sorry, I forgot. The codec is: H.264; Colour-profile: HD (1-1-1) That's the first thing I checked, it's always unnecessary files-size, since the video is muted anyways that's my usual solution, however, in this case, a video is neccessary and images don't work either
ἔρως
ἔρως15mo ago
well, you can try to reduce the video resolution, and apply some blur to it, depending on the contents of the video if it is something like buildings and stuff, it won't matter much
LOKKEE
LOKKEEOP15mo ago
it actually is a showreel of a room's interior :-/ I mean technically there could be a placeholder image of the first frame which is shown until the video finished downloading? but still, forcing the user to download a 10MB video is still quite harsh
ἔρως
ἔρως15mo ago
well, i don't have a lot of other ideas, besides hosting it on youtube or something, when the visitor clicks to play that's something you can already do you can show the first non-black frame on a poster
LOKKEE
LOKKEEOP15mo ago
I am just not too sure whether it is fine to have a 10MB file automatically download upon site visit
ἔρως
ἔρως15mo ago
: The Video Embed element - HTML: HyperText Markup Language | MDN
The HTML element embeds a media player which supports video playback into the document. You can use for audio content as well, but the element may provide a more appropriate user experience.
ἔρως
ἔρως15mo ago
check the example: it has a poster if i were you, i wouldn't auto-download it, but only play it when the visitor presses a play button somewhere
LOKKEE
LOKKEEOP15mo ago
Yes, I have to see. Thank you for your input. Codec etc. seems fine for a website though? I see, that's already an improvement I guess. Thanks!
ἔρως
ἔρως15mo ago
it's the most compatible option anyways by the way, did you made that file yourself?
Choo♚𝕂𝕚𝕟𝕘
If you are able to transcode it, use a streaming video format like MPEG-DASH. Streaming formats do not need to download the whole video before it starts playing, so the size does not impact loading time of the page.
ἔρως
ἔρως15mo ago
oh, yeah, mpeg-dash seems like a really good idea
LOKKEE
LOKKEEOP15mo ago
No, it's actually an Instagram story Ohh, how does it look compatibility-wise though?
Choo♚𝕂𝕚𝕟𝕘
None of the browsers have native support, but all of them except Opera Mini can play it if you have the appropriate library. This is the most common one: https://github.com/Dash-Industry-Forum/dash.js
GitHub
GitHub - Dash-Industry-Forum/dash.js: A reference client implementa...
A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers. - GitHub - Dash-Industry-Forum/dash.js: A reference client implementation for the playback of ...
ἔρως
ἔρως15mo ago
i recommend you to contact the owner of the video and request the original file, so you can re-encode it yourself
Choo♚𝕂𝕚𝕟𝕘
And also verify that you have legal permission to use it.
ἔρως
ἔρως15mo ago
^ that is extremely important and get it in writting, not just a phone call
LOKKEE
LOKKEEOP15mo ago
Thank you for the advocacy, but I am not that naive ;) I am building the site for a client and they just really want a showreel of their location on the page I do have the original file, but it is just a video taken with an iPhone
ἔρως
ἔρως15mo ago
that's way better than nothing you can try to re-encode it into h265 as well,
LOKKEE
LOKKEEOP15mo ago
I don't know if converting the codec to dash and thus introducing more javascript is a good idea though
ἔρως
ἔρως15mo ago
h264, h265 and vp9 are your best options then
LOKKEE
LOKKEEOP15mo ago
does h265 take up less space?
ἔρως
ἔρως15mo ago
yes
LOKKEE
LOKKEEOP15mo ago
I see, thank you!
ἔρως
ἔρως15mo ago
usually
LOKKEE
LOKKEEOP15mo ago
maybe lowering the framerate could work as well I take all the small wins I can get
ἔρως
ἔρως15mo ago
no, lower bitrate is better you can go for the magical 23.97 fps too both at the same time should be okay
Gashy
Gashy15mo ago
Cloudflare has a video streaming option, I'm not 100% if it's free or not, but weve used it for clients at work and it works rapidly
ἔρως
ἔρως15mo ago
that could be an option too
LOKKEE
LOKKEEOP15mo ago
the question is how I can change the codec. does it even make a difference whether I have the original or not? I think I cannot just edit the codec of an iPhone video
ἔρως
ἔρως15mo ago
yes, a lot
Gashy
Gashy15mo ago
You could also look into creating a mobile version of the video to be served on smaller devices
LOKKEE
LOKKEEOP15mo ago
I guess I'll give it a look the 10MB version is actually the Instagram Reel format, so exactly that of a phone 😂
ἔρως
ἔρως15mo ago
you can use something that does it for you, like cloudflare video or youtube or other video hosting service or you can use a tool like handbrake or ffmpeg
LOKKEE
LOKKEEOP15mo ago
Yes, HandBrake is best, that's what I was about to use
ἔρως
ἔρως15mo ago
i wouldnt say "best" but it's an option
LOKKEE
LOKKEEOP15mo ago
I guess if I use the original, instead of the Instagram version, I have the raw version without Instagram's modifications and shenanigans? Is that what you're aiming at?
ἔρως
ἔρως15mo ago
no, you just have lower quality loss, and you can lower the bitrate for the same perceived quality
LOKKEE
LOKKEEOP15mo ago
No description
LOKKEE
LOKKEEOP15mo ago
I see, thanks. Glad I can learn a thing or two, regarding videos
Gashy
Gashy15mo ago
Theres a CLI program that is a lot better than handbrake, managed to turn 150MB+ videos into like 2 - 5MB
LOKKEE
LOKKEEOP15mo ago
do you or did you work in a field where you had to work with videos a lot or how do you know all this? 😅 just curious
ἔρως
ἔρως15mo ago
handbrake is easier to use im just a web developer
LOKKEE
LOKKEEOP15mo ago
performance or output size wise?
Gashy
Gashy15mo ago
Both
LOKKEE
LOKKEEOP15mo ago
well, I bet there are a lot of web developers who never even touched a video before
ἔρως
ἔρως15mo ago
good, they shouldn't it's horrible to do it yourself
Gashy
Gashy15mo ago
Its called ffmpeg
LOKKEE
LOKKEEOP15mo ago
may you be so kind to give me the name? 👀 nvm, haha
ἔρως
ἔρως15mo ago
yeah, ffmpeg is amazing, but it's almost an art form to use it effectively
LOKKEE
LOKKEEOP15mo ago
ffmpeg -i input.mp4 output.avi this is already worth installing it
Gashy
Gashy15mo ago
Yeah, it will vary on what is in the video itself - a lot of high motion usually equates in a larger size as you lose a lot of info at lower file sizes I used that ffmpeg for this client on the hero section https://vanfitsolutions.co.uk/
LOKKEE
LOKKEEOP15mo ago
I don't have the slightest clue what VideoToolBox means, to be honest
ἔρως
ἔρως15mo ago
honestly: me neither i think it's the first time i hear that name it's the name of the encoder i would pick h264 (x264)
LOKKEE
LOKKEEOP15mo ago
and then see whether h265 (x265) performs better file-size-wise I guess Thanks
ἔρως
ἔρως15mo ago
you're welcome
LOKKEE
LOKKEEOP15mo ago
could constant framerate vs peak framerate (VFR) make a difference as well?
ἔρως
ἔρως15mo ago
i don't know how it works, so, just try both if it feels weird of something, just don't use that
LOKKEE
LOKKEEOP15mo ago
the size actually went up by 50% I feel like HandBrake is always just increasing file size, when it comes to this video
ἔρως
ἔρως15mo ago
probably you have some setting enabled or something or the resolution is wrong or you're re-encoding the video
LOKKEE
LOKKEEOP15mo ago
if I just drop the video in and instantly run it, without changing settings, it doubles
ἔρως
ἔρως15mo ago
yeah, that's not how it works
LOKKEE
LOKKEEOP15mo ago
I know, but how do I like reset the settings to the existing data of the video, so I can only change the ones I actually want to change 😅
ἔρως
ἔρως15mo ago
well, that's a good question what's the resolution of your video?
LOKKEE
LOKKEEOP15mo ago
720 × 1280
ἔρως
ἔρως15mo ago
that's the original video?
LOKKEE
LOKKEEOP15mo ago
Yep
ἔρως
ἔρως15mo ago
do you have vlc?
LOKKEE
LOKKEEOP15mo ago
I don't, since I am mac, but I can quickly download it, if it helps :)
ἔρως
ἔρως15mo ago
doesn't help a ton, but gives a lot of information did you remove the audio track, in handbrake?
Jochem
Jochem15mo ago
just as a head's up, h265 doesn't have very good browser support
LOKKEE
LOKKEEOP15mo ago
Yes, of course What about h264 though? Currently only tried that one
Jochem
Jochem15mo ago
https://caniuse.com/hevc h264 is pretty much 100%
ἔρως
ἔρως15mo ago
it doesn't, but it's good to include it as an alternative same as the horrible vp9
LOKKEE
LOKKEEOP15mo ago
just saw, thank you
ἔρως
ἔρως15mo ago
h264 also has really good hardware support, which is really great
LOKKEE
LOKKEEOP15mo ago
I'll give it a shot then
ἔρως
ἔρως15mo ago
the idea of using vlc is to check the file encoding information im sure there's better ways, but that is a simple way of getting it
LOKKEE
LOKKEEOP15mo ago
and then compare the handbrake generated with the original one I guess? I get it
ἔρως
ἔρως15mo ago
not just that, but there could be some extra information in it
LOKKEE
LOKKEEOP15mo ago
Thank y'all very much for your support and patience on this! It's nothing that can be taken for granted 😄
ἔρως
ἔρως15mo ago
it isnt but in the end, the easiest is to host it somewhere else those platforms deal with this work for you
LOKKEE
LOKKEEOP15mo ago
is this some sort of option you can open in vlc?
ἔρως
ἔρως15mo ago
the menu on top should have an option called "media" > "codec information" or something like that
LOKKEE
LOKKEEOP15mo ago
ahh it's called "media information", it's under 'window' for mac
LOKKEE
LOKKEEOP15mo ago
No description
ἔρως
ἔρως15mo ago
that should be it so, try to keep the same fps don't go for 30fps, or 60fps
LOKKEE
LOKKEEOP15mo ago
and that's the HandBrake-modified one
No description
ἔρως
ἔρως15mo ago
the buffer dimentions are different 🤔
LOKKEE
LOKKEEOP15mo ago
Framerate does not match though
No description
LOKKEE
LOKKEEOP15mo ago
yea, they are wrong. it's so weird
ἔρως
ἔρως15mo ago
they are i get it! the framerate isn't constant try setting an average bitrate of about 4500 and enable 2 pass encoding (which probably takes a while and will look bad, but maybe you squeeze some space)
LOKKEE
LOKKEEOP15mo ago
isn't this it?
No description
ἔρως
ἔρως15mo ago
it is
LOKKEE
LOKKEEOP15mo ago
so I genuinely should have changed it can you even do these sort of things in HandBrake? Oh nvm found it Turbo first pass? Do we go all turbo 🐭
ἔρως
ἔρως15mo ago
im telling you the equivalent of "flip all the knobs and see if it works"
LOKKEE
LOKKEEOP15mo ago
gotcha boss buffer dimensions are still wrong and file size is still larger than of the original
LOKKEE
LOKKEEOP15mo ago
No description
LOKKEE
LOKKEEOP15mo ago
huh
ἔρως
ἔρως15mo ago
interesting ... i usually use it and have great results specially the discord presets, to shrink down the videos to share in here
LOKKEE
LOKKEEOP15mo ago
Hmm, this is so weird I'll just use discord for my video compression from now on, all problems solved 👀 would you mind trying the same on your machine once? just to eliminate possible problem sources
ἔρως
ἔρως15mo ago
don't think that discord re-compresses videos, but wouldn't be surprised if it did i can try
LOKKEE
LOKKEEOP15mo ago
I'll be sure to give it a look thank you ❤️
ἔρως
ἔρως15mo ago
well, i can reduce it quite a fair bit
ἔρως
ἔρως15mo ago
No description
No description
No description
No description
No description
No description
ἔρως
ἔρως15mo ago
copy these settings, and you can generate a 5.24mb version that's a bit artifacty in the first few seconds
ἔρως
ἔρως15mo ago
this is what i got, from the downloaded video
LOKKEE
LOKKEEOP15mo ago
how do you have so much better results? I am confused
ἔρως
ἔρως15mo ago
if you don't mind losing fine details, then you can just go crazy and use 1000kbps instead
LOKKEE
LOKKEEOP15mo ago
I don't mind
ἔρως
ἔρως15mo ago
i started with the 1080p 30fps preset
LOKKEE
LOKKEEOP15mo ago
It should just convey the mood
ἔρως
ἔρως15mo ago
if you do that
ἔρως
ἔρως15mo ago
this is what i got
ἔρως
ἔρως15mo ago
you probably can go even lower
LOKKEE
LOKKEEOP15mo ago
General > Fast 1080p30? me too
ἔρως
ἔρως15mo ago
yup, that's it
LOKKEE
LOKKEEOP15mo ago
is the last version you've sent using this already? that's what I've been using as well, huh?
ἔρως
ἔρως15mo ago
yes, the 3.50mb version
ἔρως
ἔρως15mo ago
i made this one with 800kbps, but it looks pretty bad
LOKKEE
LOKKEEOP15mo ago
I guess this is really the best we can do?
ἔρως
ἔρως15mo ago
not really im trying something
LOKKEE
LOKKEEOP15mo ago
That's what I wanted to hear! 😄 You are a charm!
ἔρως
ἔρως15mo ago
but honestly, i don't think i can do a lot better without looking awful
ἔρως
ἔρως15mo ago
ἔρως
ἔρως15mo ago
looks better than this one here but i can't do a lot better that one is 1000kbps
ἔρως
ἔρως15mo ago
these are the settings ive used
No description
LOKKEE
LOKKEEOP15mo ago
this one is actually 1.2MB bigger than the previous one
ἔρως
ἔρως15mo ago
yes, but looks much better and isn't pixelated it isn't perfect, but eh
LOKKEE
LOKKEEOP15mo ago
I see, I guess I'll see which one works better for me Thank you so much for your help! You really helped me out a lot here. I wish you a lovely evening and I'll be sure to let you know how it worked out and how the finished product looks Fox gang btw 🦊
ἔρως
ἔρως15mo ago
thank you lol i tried to exporting as h265, but couldn't get better results
LOKKEE
LOKKEEOP15mo ago
oh, could you try webm once please? for me it somehow trippled file size using HandBrake last time I had to compress a video for the web it lowered file size, I thought it was more optimized. does seem like it is very much depending on the use-case
ἔρως
ἔρως15mo ago
hardware encoding and decoding for it isn't that good
ἔρως
ἔρως15mo ago
i used the settings you see there, and there was no space savings but kinda looks like the 5mb version ive sent
LOKKEE
LOKKEEOP15mo ago
Thank you! Would you prioritize the WEBM source over the MP4 one, if WEBM is supported by the browser?
ἔρως
ἔρως15mo ago
yes, i would, since it SEEMS to look better for the same file size
LOKKEE
LOKKEEOP15mo ago
Thank you! You really helped me :) Be sure to let me know if you ever need help on anything, not, video-related, and I am your man ;)
ἔρως
ἔρως15mo ago
thank you, i will remember that
Gashy
Gashy15mo ago
Just a heads up you can serve multiple sources and the browser will pick the one it has support for - I think it goes in inheritance order so place the WEBM first and then MP4, MOV, etc afterwards
<video>
<source src="..." type="video/webm" />
<source src="..." type="video/mp4" />
</video>
<video>
<source src="..." type="video/webm" />
<source src="..." type="video/mp4" />
</video>
LOKKEE
LOKKEEOP15mo ago
Yea, that’s exactly what I did. Thanks for the heads up though :) Is there a way to defer the loading of the video / load it async? At the moment, all other images and logos are taking a long while to load, as they only start loading once the video finished doing so, which is quite a while
Gashy
Gashy15mo ago
Im not 100% sure about lazy loading - but we usually add a preload attribute to it, which might help your situation. Also any images you have on the page that are not in immediate view you can add a loading="lazy" attribute which will make it so the images only start loading when they come in/close to view
ἔρως
ἔρως15mo ago
what i would do is to, for example, take the first frame from the video and show it with a play button, on something. then, swap that with a player with controls disabled, and just let it load
LOKKEE
LOKKEEOP15mo ago
what preload attribute value do you think of in this case? that would be the optimal way of going about this for sure
ἔρως
ἔρως15mo ago
and it doesnt load the video unless it is needed
LOKKEE
LOKKEEOP15mo ago
yea ._. This is not possible without the use of js right?
ἔρως
ἔρως15mo ago
no, because as soon as you put a video element, it start loading, if it has autoplay enabled
ἔρως
ἔρως15mo ago
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
ἔρως
ἔρως15mo ago
i was wrong you can do it with pure css you can also set it to only preload metadata with preload="metadata" the idea is simple:
<div>
<input type="checkbox">
<video preload="metadata"></video>
<label><img></label>
</div>
<div>
<input type="checkbox">
<video preload="metadata"></video>
<label><img></label>
</div>
input[type="checkbox"], video {
display: none;
}

input[type="checkbox"]:checked ~ video {
display: block;
}
input[type="checkbox"]:checked ~ label {
display: none;
}
input[type="checkbox"], video {
display: none;
}

input[type="checkbox"]:checked ~ video {
display: block;
}
input[type="checkbox"]:checked ~ label {
display: none;
}
checkbox unchecked: - shows the label pointing to the video - shows the image with the play button checkbox checked: - shows the video - hides the label and image the problem is that the video won't autoplay
LOKKEE
LOKKEEOP15mo ago
so you'd have to hit play twice? otherwise you could just select the video through js and call the play function on button click right?
ἔρως
ἔρως15mo ago
basically, yes
LOKKEE
LOKKEEOP15mo ago
I think I even prefer the actual image tag over the poster; it gives more control over how you implement the placeholder image
ἔρως
ἔρως15mo ago
it does, but the poster attribute has a huge advantage instead of showing just a black background, it shows the image OH MY i had an epiphany instead of having that weird html, you can put the background image under the video you can set some styles for the video player with the preloading of metadata and stuff, it shouldnt use too much bandwidth, and hides the spinner this way, you could have it work with just 1 tap
LOKKEE
LOKKEEOP15mo ago
I see but then I wouldn't need the overlayed image, would I?
ἔρως
ἔρως15mo ago
on top? no. under it? probably not, if you massage it right
LOKKEE
LOKKEEOP15mo ago
massage? ^^ so no custom play button?
ἔρως
ἔρως15mo ago
you probably wont need, but test it
LOKKEE
LOKKEEOP15mo ago
@epic2937 Somehow the video just disappears / turns invisible and does not start when you start it on a mobile device. Have you ever had this happen? Can it be that mobile browsers just don't load videos of a certain size?
ἔρως
ἔρως15mo ago
no, that is incredibly weird if you have an android phone, that is super easy to debug
LOKKEE
LOKKEEOP15mo ago
I think so too ^^
ἔρως
ἔρως15mo ago
do you have an android phone?
LOKKEE
LOKKEEOP15mo ago
if you have an iPhone and MacBook you can link them through Safari as well or Xcode works as well I guess as you might have already guessed, I don't have an android phone ;)
ἔρως
ἔρως15mo ago
well, i cant afford that type of stuff so, it may be a safari problem instead of a mobile page problem
LOKKEE
LOKKEEOP15mo ago
could it be because of the encoding type?
ἔρως
ἔρως15mo ago
webkit isnt as up-to-date as chrome
LOKKEE
LOKKEEOP15mo ago
it doesn't work in any mobile browser, already tested them all I know
ἔρως
ἔρως15mo ago
if you linked the mp4 and webm, no
LOKKEE
LOKKEEOP15mo ago
Checked the Network Tab in DevTools
No description
LOKKEE
LOKKEEOP15mo ago
Seems like it fails to properly load the video on mobile devices the mp4
ἔρως
ἔρως15mo ago
the server doesnt support byte ranges
LOKKEE
LOKKEEOP15mo ago
oh, so it couldn't display the video anyways?
ἔρως
ἔρως15mo ago
it cant load it at all
LOKKEE
LOKKEEOP15mo ago
there are no error messages or something similar
ἔρως
ἔρως15mo ago
there shouldnt be
LOKKEE
LOKKEEOP15mo ago
idk what I should debug at this point well where did the video go
ἔρως
ἔρως15mo ago
just to confirm, extend the file list in the screenshot you sent
LOKKEE
LOKKEEOP15mo ago
you mean the entire list of Network transfers?
LOKKEE
LOKKEEOP15mo ago
No description
LOKKEE
LOKKEEOP15mo ago
Sources
No description
LOKKEE
LOKKEEOP15mo ago
good to know btw, thanks for that :)
ἔρως
ἔρως15mo ago
nice, so what was it?
LOKKEE
LOKKEEOP15mo ago
what was what? :0
ἔρως
ἔρως15mo ago
the problem
LOKKEE
LOKKEEOP15mo ago
idk, it is not fixed yet small misunderstanding I assume
ἔρως
ἔρως15mo ago
i meant the name column
LOKKEE
LOKKEEOP15mo ago
ohh, now I finally understand you tired me
ἔρως
ἔρως15mo ago
its fine
LOKKEE
LOKKEEOP15mo ago
Byte Range 0-1
No description
ἔρως
ἔρως15mo ago
thats the metadata
LOKKEE
LOKKEEOP15mo ago
Ohh
ἔρως
ἔρως15mo ago
sounds like a browser bug
LOKKEE
LOKKEEOP15mo ago
so the actual, "full" video never downloads?
ἔρως
ἔρως15mo ago
the way that the preload="metadata" works is that it tries to request just enough to get stuff like length of the video and others but not the video itself
LOKKEE
LOKKEEOP15mo ago
but it would have to be a bug which is shared by all browsers then also this same bug occured before I added preload="metadata"
ἔρως
ἔρως15mo ago
then it is a bug in your code
LOKKEE
LOKKEEOP15mo ago
there is not much code to begin with though you are sure it is not an issue with the video file itself?
ἔρως
ἔρως15mo ago
mp4 doesnt have transparency, and i used the h264 encoder
LOKKEE
LOKKEEOP15mo ago
'use client';

import cafejohannaShowreelPosterImage from '@/assets/images/cafejohanna-showreel-poster.webp';
import Icons from '@/components/ui/icons';
import { cn } from '@/lib/utils';
import { ElementRef, useRef, useState } from 'react';

function HeroSection() {
const videoRef = useRef<ElementRef<'video'>>(null);
const [isVideoPlaying, setIsVideoPlaying] = useState(false);

return (
<section className="relative">
<h1 className="sr-only">Café Johanna</h1>
<video
ref={videoRef}
preload="metadata"
muted
loop
playsInline
poster={cafejohannaShowreelPosterImage.src}
className="h-screen w-full bg-primary object-cover"
>
<source
src="/videos/cafejohanna-showreel.webm"
type="video/webm"
/>
<source
src="/videos/cafejohanna-showreel.mp4"
type="video/mp4"
/>
<p>Showreel of Café Johanna</p>
</video>
<label
aria-hidden={isVideoPlaying}
className="absolute inset-0 flex items-center justify-center"
>
<button
type="button"
onClick={() => {
if (!videoRef.current || isVideoPlaying) return;
videoRef.current.play();
setIsVideoPlaying(true);
}}
className={cn(
'group transition-opacity duration-500',
isVideoPlaying && 'pointer-events-none opacity-0',
)}
>
<div
className={cn(
'rounded-full border-3 border-black bg-neutrals-50/40 p-4 shadow-lg backdrop-blur-md lg:p-6',
!isVideoPlaying &&
'transition-transform duration-500 ease-[cubic-bezier(0.68,-0.6,0.32,1.6)] hover:scale-[1.15] group-focus-visible:scale-[1.15]',
)}
>
<Icons.Play className="h-7 w-7 lg:h-9 lg:w-9" />
</div>
</button>
</label>
</section>
);
}

export default HeroSection;
'use client';

import cafejohannaShowreelPosterImage from '@/assets/images/cafejohanna-showreel-poster.webp';
import Icons from '@/components/ui/icons';
import { cn } from '@/lib/utils';
import { ElementRef, useRef, useState } from 'react';

function HeroSection() {
const videoRef = useRef<ElementRef<'video'>>(null);
const [isVideoPlaying, setIsVideoPlaying] = useState(false);

return (
<section className="relative">
<h1 className="sr-only">Café Johanna</h1>
<video
ref={videoRef}
preload="metadata"
muted
loop
playsInline
poster={cafejohannaShowreelPosterImage.src}
className="h-screen w-full bg-primary object-cover"
>
<source
src="/videos/cafejohanna-showreel.webm"
type="video/webm"
/>
<source
src="/videos/cafejohanna-showreel.mp4"
type="video/mp4"
/>
<p>Showreel of Café Johanna</p>
</video>
<label
aria-hidden={isVideoPlaying}
className="absolute inset-0 flex items-center justify-center"
>
<button
type="button"
onClick={() => {
if (!videoRef.current || isVideoPlaying) return;
videoRef.current.play();
setIsVideoPlaying(true);
}}
className={cn(
'group transition-opacity duration-500',
isVideoPlaying && 'pointer-events-none opacity-0',
)}
>
<div
className={cn(
'rounded-full border-3 border-black bg-neutrals-50/40 p-4 shadow-lg backdrop-blur-md lg:p-6',
!isVideoPlaying &&
'transition-transform duration-500 ease-[cubic-bezier(0.68,-0.6,0.32,1.6)] hover:scale-[1.15] group-focus-visible:scale-[1.15]',
)}
>
<Icons.Play className="h-7 w-7 lg:h-9 lg:w-9" />
</div>
</button>
</label>
</section>
);
}

export default HeroSection;
ἔρως
ἔρως15mo ago
so, no, it should t you can try to load it in the browser yourself just the video, on a new tab
LOKKEE
LOKKEEOP15mo ago
the bug already existed without the custom button functionality with just autoplay
ἔρως
ἔρως15mo ago
i will check that code later, but try what i said
LOKKEE
LOKKEEOP15mo ago
with just the following:
<video
autoplay
muted
loop
playsInline
className="h-screen w-full bg-primary object-cover"
>
<source
src="/videos/cafejohanna-showreel.webm"
type="video/webm"
/>
<source
src="/videos/cafejohanna-showreel.mp4"
type="video/mp4"
/>
<p>Showreel of Café Johanna</p>
</video>
<video
autoplay
muted
loop
playsInline
className="h-screen w-full bg-primary object-cover"
>
<source
src="/videos/cafejohanna-showreel.webm"
type="video/webm"
/>
<source
src="/videos/cafejohanna-showreel.mp4"
type="video/mp4"
/>
<p>Showreel of Café Johanna</p>
</video>
that's what I already did, and there is shows a couldn't load screen as well
LOKKEE
LOKKEEOP15mo ago
No description
ἔρως
ἔρως15mo ago
and the webm?
LOKKEE
LOKKEEOP15mo ago
it only offers me to download it also both sources were greyed-out in the DevTools, whereas they are not on the computer
ἔρως
ἔρως15mo ago
weird very very very weird
LOKKEE
LOKKEEOP15mo ago
exactly.. hmm
LOKKEE
LOKKEEOP15mo ago
I mean the website is currently online at https://cafejohanna.vercel.app so feel free to test it on your android phone as well
Café Johanna
less stresso
[PH]
LOKKEE
LOKKEEOP15mo ago
I am not too sure what to test and where to look right now though
ἔρως
ἔρως15mo ago
No description
ἔρως
ἔρως15mo ago
its working for me
Gashy
Gashy15mo ago
Working on mine too
ἔρως
ἔρως15mo ago
what doesn't work is the video stopping
vince
vince15mo ago
What's not working for you? I recently was dealing with video optimization issues on Safari, so I may be able to help
LOKKEE
LOKKEEOP15mo ago
The video shouldn’t stop, ever; there is no pausing functionality as of now Huh? So it seems to be an iOS issue, tested Firefox and safari so far. I think both are WebKit browsers on iOS right? As soon as I play the video on either iOS Safari or iOS Firefox it just disappears / goes invisible without playing; seems like it doesn’t properly load the source? On all other browsers and devices it works like a charm however
vince
vince15mo ago
Did you try just using the mp4 source without the webm to see if that works? Safari doesn't support autoplay with webm
LOKKEE
LOKKEEOP15mo ago
There is no autoplay involved though This is outdated code
LOKKEE
LOKKEEOP15mo ago
Sorry for the confusion ^^ It doesn’t work on iOS chrome either, just tested it So it only works on Android and Computers Really seems to be an iOS issue then?
vince
vince15mo ago
Nw, I'm not sure honestly but yea it sounds like an iOS thing
LOKKEE
LOKKEEOP15mo ago
Not sure how I can debug this I think I am going to test if a different, not custom, video works, while also removing the webm source; so we can be sure whether the video or the code is the issue @vince Do you maybe have a video you used for a similar use-case on a website yet, which worked on iOS browsers?
vince
vince15mo ago
I have an autoplay video on my website https://www.vincewebdesigns.com/ They're all autoplay
LOKKEE
LOKKEEOP15mo ago
how do you autoplay 5.3MB videos on mobile? multiple
vince
vince15mo ago
I lazy load the videos and use the poster attr to show an image while it loads
LOKKEE
LOKKEEOP15mo ago
oh yea, mine is the largest contentful paint and above the fold, so that's why it doesn't work in my case I'ma try your video now
vince
vince15mo ago
lmk
LOKKEE
LOKKEEOP15mo ago
your video worked @epic2937 this means that the video is causing the issue somehow the video has some information iOS browsers / devices cannot read? I am so confused right now
ἔρως
ἔρως15mo ago
the video should work fine, since ive simply re-encoded it with h264 but from "should" to actually working...
LOKKEE
LOKKEEOP15mo ago
haha, I'ma test the original vs the compressed version of the video, to be 100% sure :)
ἔρως
ἔρως15mo ago
try it
LOKKEE
LOKKEEOP15mo ago
the uncompressed version of the video works :0 hmm
ἔρως
ἔρως15mo ago
i think i might know what it is i removed all metadata, and webkit is trying to load it
LOKKEE
LOKKEEOP15mo ago
so what are you proposing? restore the metadata but keep the same bitrate and compression? @epic2937 are you able to apply the exact same settings as you did to the most compressed mp4 and webm, but keep the metadata? my output videos still seem to be way bigger than yours, even after replicating your settings 1:1. Would help me out a ton 🙂 But no stress, it can wait
ἔρως
ἔρως15mo ago
i can in 3 hours but you need to send the video again, i dont know where it is but, this time, send it in a compressed file
LOKKEE
LOKKEEOP15mo ago
alright, thank you! :) oh yea, sure. here you go what do you mean with "in a compressed file"?
ἔρως
ἔρως15mo ago
zip folder just in case discors is doing some fuckery
LOKKEE
LOKKEEOP15mo ago
oh yea
ἔρως
ἔρως15mo ago
can you test this?
LOKKEE
LOKKEEOP15mo ago
I can and I will (: it works! wooohoo!! could you make me a webm with metadata included as well then? <3 so happy this finally worked out
ἔρως
ἔρως15mo ago
give me a few minutes
LOKKEE
LOKKEEOP15mo ago
sure, take your time
ἔρως
ἔρως15mo ago
7zip put them together, and im too lazy to split them wait don't touch that
LOKKEE
LOKKEEOP15mo ago
lmao
ἔρως
ἔρως15mo ago
the file came out all fucked
ἔρως
ἔρως15mo ago
i had to re-do it twice because i messed the settings
LOKKEE
LOKKEEOP15mo ago
but this one looks like the previous webm I suppose? oh gosh, that sounds horrible. thanks for all the effort :))
ἔρως
ἔρως15mo ago
you're welcome
LOKKEE
LOKKEEOP14mo ago
Hello @ἔρως, I hate to ask this again, but would you mind to throw those two videos into HandBrake with the same configuration again? There was much back and forth. Would be much appreciated! No pressure though. Please let me know if I can help you out with anything as well 😃
ἔρως
ἔρως14mo ago
this is the best i can do with the 2nd video
ἔρως
ἔρως14mo ago
it's too grainy, and handbrake makes a shitty flickery mess with it
ἔρως
ἔρως14mo ago
same, but webm
ἔρως
ἔρως14mo ago
this was pure hell... the top-right corner was always moving, so, these are pretty big
LOKKEE
LOKKEEOP14mo ago
the top-right corner? 👀 Oh gosh, this sounds horrible. I hope I haven't caused you too much hassle Thank you very much! They all look almost the same as the original 😄
ἔρως
ἔρως14mo ago
they could look better, but considering it is for a phone, i think it is perfect yes, at 1500kbps and below with the fast preset, the top-right corner was being "stuck" and flickered in weird ways i had to pick the 2nd slowest preset, which makes the re-encoding go from a few seconds to almost 15 minutes
LOKKEE
LOKKEEOP14mo ago
the landscape one is for the desktop view though sounds like a nightmare lol
ἔρως
ἔρως14mo ago
well, it still looks ok-ish... for desktop, just use the original
LOKKEE
LOKKEEOP14mo ago
isn't it way too big for basically any device? I mean we are talkin' 30MB..
ἔρως
ἔρως14mo ago
for a desktop, not really more often than not it is in an unlimited connection i can try to squeeze some more quality, if you want, but the video is too grainy
LOKKEE
LOKKEEOP14mo ago
the video is autoplayed and lazily loaded, but that should not really matter right?
ἔρως
ἔρως14mo ago
it does
LOKKEE
LOKKEEOP14mo ago
so 30MB is indeed bad then? I mean I don't really care how fast the video loads, as long as the poster is shown and the rest of the site isn't affected by it
ἔρως
ἔρως14mo ago
well, it depends honestly, for a desktop, i think that quality is more imporant
LOKKEE
LOKKEEOP14mo ago
but you think it's technically fine to autoplay a 30MB video on desktop?
ἔρως
ἔρως14mo ago
you download way bigger files from youtube i will try to get it to half the size, or less
LOKKEE
LOKKEEOP14mo ago
I try to get a less grainy video. I'll get back to you in a day or so. I think that will just make this whole thing easier. Thank you once again :) they are not autoplay, to be fair, though
ἔρως
ἔρως14mo ago
take your time just try to get better light also, try playing with the iso settings on the phone, and see which one looks better
Want results from more Discord servers?
Add your server