javascript - 如何截取youtube屏幕截图

标签 javascript php html youtube screenshot

<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>

如何添加 youtube 视频。无法在视频标签中播放 youtube 视频。嵌入标签正在播放 youtube 视频。如何通过将 youtube 视频放在嵌入标签内来截取屏幕截图。请帮助我

最佳答案

我可以用 ffmpeg 解决这个问题。

随便跑

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

在哪里

  • -i inputfile.avi - 输入文件
  • -r 1 - 每秒一帧
  • -t 1 - 多少秒应该转换为图像
  • -ss 00:00:03 - 从第几秒开始
  • image-%d.jpeg - 生成的文件名模板

在这里找到http://linuxers.org/tutorial/how-extract-images-video-using-ffmpeg

关于javascript - 如何截取youtube屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603618/

相关文章:

php - PSR-4:自动加载器( Composer )和扩展命名空间确保后备 php

javascript - 内容编辑器 Web 部件中的 iFrame

html - 在 Internet Explorer 中打印时输入元素中缺少值

javascript - 如何使用 javaScript 在运行时设置 HTML 属性值?

javascript - 使用 'validator' 进行“Ext Js”表单字段验证

javascript - 每个事件具有多个事件处理程序的 SignalR

javascript - 使用 Chai、Mocha、Express、johnny-five 和 node 编写测试时出现菜鸟错误

php - 如何确保所有sql查询运行没有错误?

php和mysql,如何找出某人在数据库中的位置

javascript - 使用Command + Z时如何关闭Safari打开上一页?