How to save the frames of video on Local Disk?

Viewed 110

I am extracting frames from video , it is extracting and displaying all the frames on canvas means on the web browser . I am trying to save that frame on disk using local-storage .set Item but not working , Kindly Help , I want to save that frames on my Local disk . How to do this , My code is shown below :

<!DOCTYPE html>
<html>
<body>

<video width="400" controls>
    <source src="180419_Boxing_17_13.mp4" type="video/mp4">
    Your browser does not support HTML5 video.
</video>

<p>These are the frames' images generated by getVideoImage():</p>
<ol id="olFrames"></ol>

<script type="text/JavaScript">
    function getVideoImage(path, secs, callback) {
        var me = this, video = document.createElement('video');
        video.onloadedmetadata = function() {
            if ('function' === typeof secs) {
                secs = secs(this.duration);
            }
            this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
        };
        video.onseeked = function(e) {
            var canvas = document.createElement('canvas');
            canvas.height = video.videoHeight;
            canvas.width = video.videoWidth;
            var ctx = canvas.getContext('2d');
            ctx.drawImage(video, 0, 0, 500, 500);
            var img = new Image();
            img.src = canvas.toDataURL();
            callback.call(me, img, this.currentTime, e);

            var data = ctx.getImageData(x, y, img.width, img.height).data;
            localStorage.setItem('image', data);

        };
        video.onerror = function(e) {
            callback.call(me, undefined, undefined, e);
        };
        video.src = path;
    }

    function showImageAt(secs) {
        var duration;
        getVideoImage(
            '180419_Boxing_17_13.mp4',
            function(totalTime) {
                duration = totalTime;
                return secs;
            },
            function(img, secs, event) {
                if (event.type == 'seeked') {
                    var li = document.createElement('li');
                    li.innerHTML += '<b>Frame at second ' + secs + ':</b><br />';
                    li.appendChild(img);
                    document.getElementById('olFrames').appendChild(li);
                    if (duration >= ++secs) {
                         showImageAt(secs);
                    };
                }
            }
        );
    }
    showImageAt(0);
</script>
</body>
</html>
0 Answers
Related