What is this technique called using html5 video? [duplicate] - javascript

I'm creating a video player with HTML5 and Javascript and I'm wondering if anyone has solved the challenge of creating dynamic thumbnails.
Mimicking youtube video player where you hover over progress bar and a popup shows with a thumbnail. I know that youtube saves out an image and repositions the sprite in the thumbnail viewer frame based on position hovered over.
Is this viable to do with JS and canvas?
What I'm doing now is... hovering over my progress bar creates a copy of the video element. I then set the currentTime on the copied element. I then grab a snapshot using canvas. I'm not sure why, but the images seem to be blank.
Maybe someone has run into this problem?

YouTube have pre rendered thumbs that are stored in a single image in a grid with ten columns and how ever many rows are needed. The thum images I have seen are low quality jpg 800 pixels across giving thumbs 80 pixels by ?? (depending on aspect) When the user hovers the thumb closest to the that time is displayed.
Creating the thumbs at the client side will be problematic because video are not entirely random access. Seeking to a random location involves the video moving to the nearest previous keyframe and then decoding all frames till it gets to the frame you have requested. Depending on the format, encoding options, the spacing of key frames (if any rolling eyes), and if the seek location has been loaded, seeking to some location can be very slow. Getting a set of thumbs for a video can take a long time. The additional problem with the HTML5 video API is that it has only one playback channel, so while you are seeking for thumbs you can not watch the video.
You problem with blanks may be due to not waiting for the seek event.
Try
video.addEventListener("seeked",function(e){
// snap shot code here
});
But this does not always work I have found. So it pays to listen to all the appropriate events, and only seek when the video is ready. Here is a list of media events that will help.
As videos don't change your best bet is to create the thumbs on your server after the video has been uploaded. Low quality jpgs seem to be the go and will be loaded by the client much sooner than even a fraction of the video has been.

However, this can be achieved by using a combination of HTML5 canvas. You will have to do the following.
add an timeupdate event listener to the HTML5 video
at each 1 sec, grab the current time and create an element (span is this case) and bind the value of the current time in a special attribute of the newly created span
Append each created span element to your HTML5 progress element (I suppose you're using 'div' and not 'progress' element.
Add an mouseenter event listener to the created span.
Whenever the user hovers the progress bar, the mouse would eventually touches one of the span. Then, dynamically create a video element and set the src attribute with the main HTML5 video source. Then, set the currentTime to the value of the hovered span and snapshot it to an already canvas element.
There, you show the user the current frameRate.
Scripting is all about manipulations and gradually processes of putting pieces of codes to work.

Related

Dynamically Changing Video Source Causes Flicker

I have native video tag with source which dynamically changes by onEnded event which triggers a method that loads in the next video source in the tag for playback.
The main implementation is to make a playlist and keep inject the video sources until reached the end of the list.
** PROBLEM: As soon as the video source changes, it flickers for a few milliseconds and then plays the next video.
Have tried multiple approaches to solve including fixed width - height but didn't work.
Once approach was to render multiple players and turn them hide/show depending on which source is being play. This approach worked as expected but the drawback was that if I had 100 videos in the playlist, it would add 100 video nodes in the DOM.
I am sure that it is not a page re-render & there are no other props or state changes other than video source.
Have even tried implementing redux to handle it with global state but no luck!
Attached a video link showing the problem:
See Video
I'm impressed that it's as smooth as it's appearing. A lot of context is torn down and set up again when you change the src.
Once approach was to render multiple players and turn them hide/show depending on which source is being play. This approach worked as expected but the drawback was that if I had 100 videos in the playlist, it would add 100 video nodes in the DOM.
You don't need 100... you just need 2. Get your next player ready to transition to, while the first one is finishing. Once you've transitioned, destroy the first player and get the third ready.

Video with timed image overlay

I was wondering if anyone could help me with HTML5 video with image overlays that are timed. I want the images to display and disappear at certain times, which will make the video pause and resume on the click of a button. I want to know the best approach to this in regards using HTML5, javascript etc.
I am using the video tag in HTML5 with Dreamweaver CS6 at the moment and I have full screen video working, with an image overlaid using the z-index, but I can't get it to display and disappear at a certain time.
Any ideas?
probably you have to add some event listener to your video:
timeupdate , loadstart, ect to manage the visibility of your image in overlay

Vimeo default video size

I am trying to embed a number of different Vimeo players, which feature video content at different resolutions. I want the dimensions of each player be identical to that of it's respective video, so no letter boxing / black border appears around the edges. I'd have thought this would happen automatically, but every player I've embedded defaults to the same size, regardless of the dimensions of the video.
Does anybody know a way to either solve this simply, or pull the dimensions of the video itself so I could set the player's height dynamically?
I'm using the Iframe embed method.
Cheers
When working with different resolutions and browser sizes, best solution currently using JavaScript. Here's a jQuery plugin called FitVids that I would recommend.
How you would use it:
$(document).ready(function(){
// use div container that contains all your videos
$(document.body).fitVids();
});

HTML5 video background and transition

I am making a website for a friend of mine and he wants a really complicated one. Between the menupoints there are videos and the content is displayed on the last frame. So I thought I could use the videos (about 2 seconds long) as a background and fade the content in after two seconds. How should I go about this?
what I'd do is have the content as a hidden div. When you play the video attach an onended event to it and use that to hide the video element and reveal the content - that way they always stay in sync - for instance see something like this Add a div to replace Video after Video Plays Through

Controls overlay for video on iPhone/iPad

I am writing a webapp where I need to display a video and some (non standard) controls for it, which should appear in overlay. So create some divs and position them over the video, with a higher z-index.
Still, on iPhone and iPad, it appears those controls are not clickable. I register actions for the click event, but that is not fired at all when I tap on the controls. I understand I can have no control while the video is actually playing (it even goes fullscreen), but the problem is that the controls are unusable even when the video is stopped.
I have also tried to remove the controls attribute from the video, with no effect.
Is there a way to register click events for elements that are positioned over a video on iPhone/iPad?
I had the same problem and got it working by setting the CSS property of the HTML5 video element while
paused to -webkit-transform:scale(0.01);
playing to -webkit-transform:scale(1);
The problem is that the HTML5 video element on iOS seems to hijack the click events in the areas (of the elements layered on top) that are contained in the bounding box of the video element. If the bounding box is made smaller with scale(0.01) or the bounding box is pushed off the screen with translateX(-2560px), no element areas are directly above the video element and the click events will get fired.
One thing to try is to make the element with controls obstruct the whole video, not just a section of it - this will help you debug it in any case. Another approach is to use touch events instead of click events. These execute faster and are usually not over-ridden.
Sample code would be helpful.

Categories

Resources