Clever Geek Handbook

How to take a screenshot of YouTube

<script src="jquery.js"></script>
<video id="video" controls preload="none" width="640" poster="http://media.w3.org/2010/05/sintel/poster.png" onloadedmetadata="$(this).trigger('video_really_ready')">
    <source id='mp4' src="http://media.w3.org/2010/05/sintel/trailer.mp4" type='video/mp4' />
    <source id='webm' src="http://media.w3.org/2010/05/sintel/trailer.webm" type='video/webm'/>
    <source id='ogv' src="http://media.w3.org/2010/05/sintel/trailer.ogv" type='video/ogg' />
</video>
<br />

<input type="button" id="capture" value="Capture" /> Press play, and then start capturing
<div id="screen"></div>
<script>
var VideoSnapper = {

    /**
     * Capture screen as canvas
     * @param {HTMLElement} video element 
     * @param {Object} options = width of screen, height of screen, time to seek
     * @param {Function} handle function with canvas element in param
     */
    captureAsCanvas: function(video, options, handle) {

        // Create canvas and call handle function
        var callback = function() {
            // Create canvas
            var canvas = $('<canvas />').attr({
                width: options.width,
                height: options.height
            })[0];
            // Get context and draw screen on it
            canvas.getContext('2d').drawImage(video, 0, 0, options.width, options.height);
            // Seek video back if we have previous position 
            if (prevPos) {
                // Unbind seeked event - against loop
                $(video).unbind('seeked');
                // Seek video to previous position
                video.currentTime = prevPos;
            }
            // Call handle function (because of event)
            handle.call(this, canvas);    
        }

        // If we have time in options 
        if (options.time && !isNaN(parseInt(options.time))) {
            // Save previous (current) video position
            var prevPos = video.currentTime;
            // Seek to any other time
            video.currentTime = options.time;
            // Wait for seeked event
            $(video).bind('seeked', callback);              
            return;
        }

        // Otherwise callback with video context - just for compatibility with calling in the seeked event
        return callback.apply(video);
    }
};

$(function() {

    $('video').bind('video_really_ready', function() {
        var video = this;
        $('input').click(function() {
            var canvases = $('canvas');
            VideoSnapper.captureAsCanvas(video, { width: 160, height: 68, time: 40 }, function(canvas) {
                $('#screen').append(canvas);                         
                if (canvases.length == 4) 
                    canvases.eq(0).remove();     
            })
        }); 
    });

});
</script>

      

How can I add YouTube videos. Unable to play YouTube videos in video tag. The embedded tag works for playing YouTube videos. How to take screenshot by placing youtube video inside embed tag. Please help me

+3
javascript html php youtube screenshot


user3392207 28 oct. '14 at 8:19
source to share


2 answers


I could solve this with ffmpeg

.

Just run

ffmpeg -i inputfile.avi  -r 1 -t 1 -ss  00:00:03 image-%d.jpeg

      



Where

  • -i inputfile.avi

    - input file
  • -r 1

    - one frame per second
  • -t 1

    - how many seconds should be converted to images
  • -ss 00:00:03

    - from what second to the beginning
  • image-%d.jpeg

    - final file name template

Found here http://linuxers.org/tutorial/how-extract-images-video-using-ffmpeg

0


antongorodezkiy 21 Sep 15 at 19:56
source to share


If you manually adjust the image, it might help you.

Try adding poster="placeholder.png" //photo you want

a video to your tag.



Example

<video width="470" height="255" poster="placeholder.png" controls>
   <source src="video.mp4" type="video/mp4">
   <source src="video.ogg" type="video/ogg">
   <source src="video.webm" type="video/webm">
   <object data="video.mp4" width="470" height="255">
   <embed src="video.swf" width="470" height="255">
   </object>
</video>

      

-1


TheSmile 28 oct. At 9:02 am
source to share






More articles:

    Removed postRemoved postRemoved postRemoved postRemoved postRemoved postRemoved postRemoved postRemoved postRemoved post

All Articles

Daily Blog | 2020

Green Geek Media (GGM)
1298 Despard Street
GA 30344 East Point, USA
404-763-3837