0

I am trying to get a video to play inside a video tag at the top left hand corner of my page, it loads ok, the resolution is good and it seems to be looping but it is lagging very much, definatly not achieving 60fps it is in mp4 format and the resolution on the original mp4 is 1920x1080 it is a hi resolution vj free loop called GlassVein, you can see it if you search on youtube. On right clicking properties it comes up with the following inforamtion;

Bitrate:127kbs Data rate:11270kbps Total bitrate:11398kbs Audio sample rate is: 44khz filetype is:VLC media file(.mp4) (but i do not want or need the audio)

& it also says 30fps, but I'm not sure i believe this as it runs smooth as butter on vlc media player no lagging, just smooth loop animation

I have searched on :https://trac.ffmpeg.org/wiki/Encode/AAC for encoding information but it is complete gobbldygook to me, I don't understand a word its saying

My code is so far as follows;

    <video src="GlassVeinColorful.mp4" autoplay="1" preload="auto"
      -movflags class="Vid" width="640" height="360" loop="1" viewport=""
      faststart mpeg4 -s 320x240 -r 1080 -b 128k>  
    </video>

Does anyone know why this is lagging so much, or what I could do about it. it is a quality animation and I don't really want to loose an of its resolution or crispness.. the -s section was originally set to 1920x1080 as this is what the original file is but i have changed it to try and render it quicker...

Any helpful sites, articles or answers would be great..

2020 Update

The Solution to this problem was to convert the Video to WebM, then use Javascript & a Html5 Canvas Element to render the Video to the page instead of using the video tag to embed the video.

Html

<section id="Theater">
        <video src="Imgs/Vid/PurpGlassVein.webm" type="video/webm"
               width="684" height="auto"
               muted loop autoplay>
               <source>
               <source>
               <source>
        </video>
        <canvas style="filter:opacity(0);"></canvas>
</section><!-- Closing Section for the Header -->

Css

video{
   display:none !important;
   visibility:hidden;
}

Javascript

    const Canv = document.querySelector("canvas");
    const Video = document.querySelector("video");
    const Ctx = Canv.getContext("2d");

    Video.addEventListener('play',()=>{
      function step() {
        Ctx.drawImage(Video, 0, 0, Canv.width, Canv.height)
        requestAnimationFrame(step)
      }
      requestAnimationFrame(step);
    })

    Canv.animate({
        filter: ['opacity(0) blur(5.28px)','opacity(1) blur(8.20px)']
    },{
        duration: 7288,
        fill: 'forwards',
        easing: 'ease-in',
        iterations: 1,
        delay: 728
    })

I've Also Used the Vanilla Javascript .animate() API to fade the element into the page when the page loads. But one Caveat is that both the Canvas and the off-screen Video Tag must match the original videos resolution otherwise it starts to lag again, however you can use Css to scale it down via transform:scale(0.5); which doesn't seem to effect performance at all.

runs smooth as butter, and doesn't loose any of the high resolution image. Added a slight blur 0.34px onto it aswell to smooth it even more.

Possibly could of still used ffmpeg to get a better[Smaller File Size] WebM Output file but thats something I'll have to look into at a later date.

Ryan Stone
  • 345
  • 4
  • 19

2 Answers2

0

Video over IP connections is going to be subject to network conditions and 60fps at that resolution is a quite high quality to try to maintain without any delay or buffering.

Most 'serious' video services, including YouTube. NetFlix etc provide multiple bit rate streams to allow for different network conditions, and different device capabilities.

The clients can switch between the streams through the video as they download the video chunk by chunk so can choose the best resolution possible for the current network conditions when they request a new chunk.

See here for an example: https://stackoverflow.com/a/42365034/334402

Mick
  • 24,231
  • 1
  • 54
  • 120
  • I'm a little bit confused about this answer as the video file is currently on my harddrive along with the html, css, php & javascript so i don't think My connection speed should have anything to do with it, Can you elaborate or provide reference/website or an article that would help me better understand I will google or youtube "Video over IP" to see if i can find anything – Ryan Stone May 03 '18 at 06:08
  • Ah, ok - I did not realise the video was on your local drive. The answer above is related to delivery of a high bandwidth video over IP networks, so may still be relevant if you get to that point. Can you share a link to your video or to some video which also has the same issue and I'll take a look. From this updated description it may be that the codec being used is not supported in HW on your platform, and the SW codec is simply finding it hard to have enough horsepower to keep up. – Mick May 03 '18 at 09:33
  • Thank you for your response, this will still be handy information for when I do set it up to go live. The link for the video is https://www.youtube.com/watch?v=cW7OfU865ZA & is Called GlassVein by Beeple it is a Vj loop, free to download. Am i right in geussing that "HW & SW" means Hardwear & Software. I have a pretty crudy laptop so that might be n issue aswell. Does FFmpeg actually work in browser? as I know its usually a cmd tool? – Ryan Stone May 03 '18 at 11:10
0

I recently went back to this project, and went back over the Code,

Found that Converting the Video to WebM & Using the html Canvas element to display the Vj loop has made the performance 10x better, I will Upload the code for writing the data to the canvas when I can find it, my projects folder is kinda messy and un organised.

The main Idea though is having an Offscreen canvas with display none, and then reading that data into another Canvas that is displayed on the screen. Seems to have fixed the issue that I was facing.

See the above edit[in the question] if you are facing any of the same issues or problems.

Ryan Stone
  • 345
  • 4
  • 19