如何把youtube截图 [英] How to take youtube screenshot
本文介绍了如何把youtube截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script src =jquery.js>< / script>
< source id ='mp4'src =http://media.w3.org/2010/05/sintel/trailer.mp4type ='video / mp4'/>
< source id ='webm'src =http://media.w3.org/2010/05/sintel/trailer.webmtype ='video / webm'/>
< source id ='ogv'src =http://media.w3.org/2010/05/sintel/trailer.ogvtype ='video / ogg'/>
< / video>
< br />
< input type =buttonid =capturevalue =Capture/>按播放,然后开始捕捉
< div id =screen>< / div>
< script>
var VideoSnapper = {
/ **
*将画面捕获为画布
* @param {HTMLElement}视频元素
* @param {Object} options =屏幕宽度,屏幕高度,查找时间
* @param {Function}在param中使用canvas元素处理函数
* /
captureAsCanvas:function(video,options,handle) {
//创建画布和调用句柄函数
var callback = function(){
//创建画布
var canvas = $('< canvas / >')。attr({
width:options.width,
height:options.height
})[0];
//获取上下文并在其上绘制屏幕
canvas.getContext('2d')。drawImage(video,0,0,options.width,options.height);
//如果我们有以前的位置,则返回视频
if(prevPos){
//解绑定查找事件 - 反循环
$(video).unbind('seeked') ;
//寻找视频到上一个位置
video.currentTime = prevPos;
}
//调用句柄函数(由于事件)
handle.call(this,canvas);
}
//如果我们有时间选项
if(options.time&&!isNaN(parseInt(options.time))){
//保存之前的(当前)视频位置
var prevPos = video.currentTime;
//寻找任何其他时间
video.currentTime = options.time;
//等待查询事件
$(video).bind('seeked',callback);
return;
}
//否则用视频上下文回调 - 仅用于与查找事件中的调用兼容
return callback.apply(video);
}
};
$ b $(函数(){
$('video')。bind('video_really_ready',function(){
var video = this;
$('input')。click(function(){
var canvases = $('canvas');
VideoSnapper.captureAsCanvas(video,{width:160,height:68,time: (Canvas.length == 4)
canvases.eq(0).remove() ();
})
});
});
});
< / script>
我如何添加youtube视频。无法在视频标签中播放YouTube视频。嵌入标签正在播放YouTube视频。如何通过将youtube视频嵌入到嵌入标记中进行截图。请帮助我
解决方案
我可以用 ffmpeg
来解决这个问题。 p>
只要运行
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
<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 video instead. Could not play youtube video in video tag. embed tag is working to play youtube video. How to take screenshot by placing youtube video inside embed tag. Please help me
解决方案
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 startimage-%d.jpeg
- resulting filename template
Found here http://linuxers.org/tutorial/how-extract-images-video-using-ffmpeg
这篇关于如何把youtube截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文