0

I am making a webpage to capture snapshot from a video and host it in a javascript photo viewer but facing difficulty in that. So, I am trying to save the snapshot in png format to a specific file location.

Please help me.

var videoId = 'video';
var scaleFactor = 2;
var snapshots = [];

/**
 * Captures a image frame from the provided video element.
 *
 * @param {Video} video HTML5 video element from where the image frame will be captured.
 * @param {Number} scaleFactor Factor to scale the canvas element that will be return. This is an optional parameter.
 *
 * @return {Canvas}
 */
function capture(video, scaleFactor) {
    if (scaleFactor == null) {
        scaleFactor = 1;
    }
    var w = video.videoWidth * scaleFactor;
    var h = video.videoHeight * scaleFactor;
    var canvas = document.createElement('canvas');
    canvas.width = w;
    canvas.height = h;
    var ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, w, h);
    return canvas;
}

/**
 * Invokes the <code>capture</code> function and attaches the canvas element to the DOM.
 */
function shoot() {
    var video = document.getElementById(videoId);
    var output = document.getElementById('output');
    var canvas = capture(video, scaleFactor);
    canvas.onclick = function() {
        window.open(this.toDataURL(image / jpg));
    };
    snapshots.unshift(canvas);
    output.innerHTML = '';
    for (var i = 0; i < 4; i++) {
        output.appendChild(snapshots[i]);
    }
}

(function() {
    var captureit = document.getElementById('cit');
    captureit.click();
})();
Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29
  • what is the axact problem u r facing? – Asutosh Aug 19 '20 at 08:07
  • 1
    Download to a specific location is not possible. This question has already been asked here: https://stackoverflow.com/questions/34870711/download-a-file-at-different-location-using-html5 – Yogendra Chauhan Aug 19 '20 at 08:11
  • Does this answer your question? [Download A File At Different Location Using HTML5](https://stackoverflow.com/questions/34870711/download-a-file-at-different-location-using-html5) – Icepickle Aug 19 '20 at 08:24

0 Answers0