phantomjs屏幕截图和ffmpeg帧丢失
我在从phantomjs网站截图制作视频时遇到问题 phantomjs并没有在同一秒内对所有帧进行截图,甚至不是所有的秒,都有大量的丢失帧 结果是高速视频播放,视频效果有很多跳跃 test.js:phantomjs屏幕截图和ffmpeg帧丢失,ffmpeg,phantomjs,capture,Ffmpeg,Phantomjs,Capture,我在从phantomjs网站截图制作视频时遇到问题 phantomjs并没有在同一秒内对所有帧进行截图,甚至不是所有的秒,都有大量的丢失帧 结果是高速视频播放,视频效果有很多跳跃 test.js: var page = require('webpage').create(), address = 'http://raphaeljs.com/polar-clock.html', duration = 5, // duration of the video, in seconds
var page = require('webpage').create(),
address = 'http://raphaeljs.com/polar-clock.html',
duration = 5, // duration of the video, in seconds
framerate = 24, // number of frames per second. 24 is a good value.
counter = 0,
width = 1024,
height = 786;
frame = 10001;
page.viewportSize = { width: width, height: height };
page.open(address, function(status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.clipRect = { top: 0, left: 0, width: width, height: height };
window.setInterval(function () {
counter++;
page.render('newtest/image'+(frame++)+'.png', { format: 'png' });
if (counter > duration * framerate) {
phantom.exit();
}
}, 1/framerate);
}, 200);
}
});
fmpeg -start_number 10001 -i newtest/image%05d.png -c:v libx264 -r 24 -pix_fmt yuv420p out.mp4
这将创建120个图像,这是正确的计数,但当您逐个查看图像时,您将看到许多重复的相同内容和许多缺少的帧
ffmpeg:
var page = require('webpage').create(),
address = 'http://raphaeljs.com/polar-clock.html',
duration = 5, // duration of the video, in seconds
framerate = 24, // number of frames per second. 24 is a good value.
counter = 0,
width = 1024,
height = 786;
frame = 10001;
page.viewportSize = { width: width, height: height };
page.open(address, function(status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.clipRect = { top: 0, left: 0, width: width, height: height };
window.setInterval(function () {
counter++;
page.render('newtest/image'+(frame++)+'.png', { format: 'png' });
if (counter > duration * framerate) {
phantom.exit();
}
}, 1/framerate);
}, 200);
}
});
fmpeg -start_number 10001 -i newtest/image%05d.png -c:v libx264 -r 24 -pix_fmt yuv420p out.mp4
我知道这个脚本和ffmpeg命令并不完美,因为我在没有lucky的情况下做了数百次更改,并且我失去了对正确设置的理解
有人指导我修这个吗
谢谢大家有人知道吗?你找到解决办法了吗?这是我找到的最接近答案的东西