Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

HTML5 Video rotate

  • 18-12-2015 10:44am
    #1
    Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭


    Does anyone know if there is a HTML5 video control to rotate? I am building a library of video sources, muxing them and indexing them to be searching on a local webpage. However, some of the video is rotated 90 degrees (people not turning their mobile phones!).
    I am extracting the metadata from each video but some do not contain the rotation info. Because of this the video displays sideways (I can use css to auto rotate the ones that have the metadata). So, does anyone have a solution that adds user-selectable rotate controls?


Comments

  • Registered Users, Registered Users 2 Posts: 6,289 ✭✭✭Talisman


    You could build your own quite easily. Use the Font Awesome Video Player icons to style your controls.

    HTML player:
    <div id="player-container"
      <div id="video-player">
        <!-- video goes here -->
      </div>
      <div id="video-controls">
        <button class="play"><i class="fa fa-play"></i></button>
        <button class="rotate-left"><i class="fa fa-rotate-left"></i></button>
        <button class="rotate-right"><i class="fa fa-rotate-right"></i></button>
        <button class="reset">reset</button>
      </div>
    </div>
    

    Use some JavaScript to listen for events on the controls.
    (function() {
      var rotate = 0; // initial rotation
      var video = document.getElementById('video-player');
      var controls = document.getElementById('video-controls');
      if (controls) {
        controls.addEventListener('click', function(e){
          target = e.target;
          if (target.nodeName.toLowerCase() === 'button') {
            switch (target.className) {
              case 'play':
                if (video.paused) {
                  video.play();
                  target.innerHTML = '<i class="fa fa-pause"></i>';
                } else {
                  video.pause();
                  target.innerHTML = '<i class="fa fa-play"></i>';
                }
                break;
              case 'rotate-left' :
                rotate = rotate + 90;
                video.style['rotate']='rotate('+rotate+'deg)';
                // todo : resize video-player div
                break;
              case 'rotate-right' :
                rotate = rotate - 90;
                video.style['rotate'] = 'rotate('+rotate+'deg)';
                // todo : resize video-player div
                break;
              case 'reset' :
                rotate = 0;
                video.style['rotate'] = 'rotate('+rotate+'deg)';
                // todo : resize video-player div
                break;
            }
            e.preventDefault();
          }
        }, false);
      }
    })();
    

    Disclaimer: This code is untested but it should get you in the right area! You may need to add vendor specific style attributes for the rotation.

    You could tweak the code so that the rotation buttons only appear when you don't know the rotation of the video.


Advertisement