使用ffmpeg和phantomjs从网址制作电影 [英] Making a movie from the url using ffmpeg and phantomjs

查看:187
本文介绍了使用ffmpeg和phantomjs从网址制作电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im从URL中截取屏幕截图,使用setIntreval函数(现在25)使用幻影,然后将输出管道输出到ffmpeg(使用帧率-r 24)。
这是代码。 ffmpeg.js

  var page = require('webpage')。 
page.viewportSize = {width:1024,height:768};

page.open('http://ewoken.github.io/Leaflet.MovingMarker/',function(){
setInterval(function(){
page.render ('/ dev / stdout',{format:png});
},25);
});

然后我运行这个脚本。

  phantomjs ffmpeg.js | ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i  -  -c:v libx264 -pix_fmt yuv420p -movflags + faststart output.mp4 

喜欢在命令中获取10秒的视频与页面,但它的所有加速快速,最后一帧完全冻结。



你可以帮我一下吗,让我按照原样记录页面?像电影里有一个3000的延迟动画,它应该像电影里一样真实,就像平滑和实时一样。



谢谢你们。



Cheers,

解决方案

首先,您需要使用 - enable-x11grab 选项的ffmpeg,您需要编译它。



例如:
https://gist.github.com/holms/7009218
https://soledadpenades.com/2010/04/26/未知输入或输出格式-x11grab-ubuntu /

配置:

   -  prefix = / usr --enable-shared --enable-nonfree --enable-gpl --enable-libx264 --enable-version3 --enable-postproc --enable-pthreads --enable-libmp3lame --enable-libtheora --enable-libxvid --enable-x11grab --enable-libvorbis 

我们需要使用 SlimerJS ,它不是一个无头浏览器,但也可以脚本化:

  cd / root; \ 
wget http://download.slimerjs.org/releases/0.10.1/slimerjs-0.10.1.zip&& unzip slimerjs-0.10.1.zip&&& \
wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-x86_64/en-US/firefox-49.0.2.tar.bz2& &安培; \
tar -vxjf firefox-49.0.2.tar.bz2&&& \
ln -sf / root / firefox / firefox / usr / local / bin / -v&&& \
ln -sf /root/slimerjs-0.10.1/slimerjs / usr / local / bin / -v

对于slimerjs,我们需要安装以下 snap.js 脚本:

rm -f snap.js; nano snap.js; chmod + x snap.js;清除

  var page = require(' 
page.viewportSize = {width:1024,height:768};
page.open('http://ewoken.github.io/Leaflet.MovingMarker/',function(){
page.evaluate(function(){window.focus();});
// page.render('github.png');
// phantom.exit();
});

现在,我们需要安装 x虚拟帧缓冲区和一些用于firefox的库:

  aptitude update; aptitude install Xvfb libgtk-3-0 libasound2 libdbus-glib-1-2 -y 

现在我们需要添加新的虚拟显示1.1:

  pkill [X,x] vfb; pkill nw Xvfb:1-screen 1 1440x900x24> / dev / null 2>& 1& 

尝试运行 firefox 确保没有额外的库需要(如果输出中会出现一些错误,则是正常的):

  killall firefox; export DISPLAY =:1.1; firefox 

然后,我们可以使用脚本:



kill $ firefox; $ $ $ $ $ rm -f ouput2.mp4; \
睡眠5; export DISPLAY =:1.1;导出SLIMERJSLAUNCHER = / root / firefox / firefox; \
slimerjs snap.js& \
睡3 \
ffmpeg -f x11grab -framerate 60 -video_size 1024x768 -i:1.1 -vcodec libx264 -preset veryfast -b:v 10000k ouput2.mp4

我有这个视频:

https://drive.google.com/open?id=0B_tqnSHhFPBndDJ0Y1c5THBKWkk





注意:如果您使用的是32位Linux,则需要更换链接:

  https:// download- installer.cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-x86_64/en-US/firefox-49.0.2.tar.bz2 

使用以下内容:

  https://下载安装程序。 cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-i686/en-US/firefox-49.0.2.tar.bz2 


Im Taking screen shots from a url, using phantomjs using the setIntreval function (25 right now) and then piping the output to the ffmpeg (Using the frame rate -r 24). Here is the Code. ffmpeg.js

var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 768 };

page.open('http://ewoken.github.io/Leaflet.MovingMarker/', function () {
  setInterval(function() {
    page.render('/dev/stdout', { format: "png" });
  }, 25);
});

Then I run the script using this.

phantomjs ffmpeg.js | ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4

Like In the command Im getting the 10 sec video with the page, But Its all speeding up fast first and completely freezes with a last frame.

Can you guys help me, with a work around, enabling me to record the page , AS IS ? Like if there is a 3000 delay animation in the movie, It should appear like real in the movie, like smooth and in real time.

Thank you guys. Stuck on this for a long time now.

Cheers,

解决方案

First of all, you need to have ffmpeg with the --enable-x11grab option, you need to compile it.

# example:
https://gist.github.com/holms/7009218
https://soledadpenades.com/2010/04/26/unknown-input-or-output-format-x11grab-ubuntu/ 

configuration:

--prefix=/usr --enable-shared --enable-nonfree --enable-gpl --enable-libx264 --enable-version3 --enable-postproc --enable-pthreads --enable-libmp3lame --enable-libtheora --enable-libxvid --enable-x11grab --enable-libvorbis

We need to use SlimerJS, it's not a headless browser, but scriptable as well:

cd /root; \
wget http://download.slimerjs.org/releases/0.10.1/slimerjs-0.10.1.zip && unzip slimerjs-0.10.1.zip && \
wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-x86_64/en-US/firefox-49.0.2.tar.bz2 && \
tar -vxjf firefox-49.0.2.tar.bz2 && \
ln -sf /root/firefox/firefox /usr/local/bin/ -v && \
ln -sf /root/slimerjs-0.10.1/slimerjs /usr/local/bin/ -v

For slimerjs, we need to install the following snap.js script:
rm -f snap.js; nano snap.js; chmod +x snap.js; clear

var page = require('webpage').create();
page.viewportSize = {width: 1024,height: 768};
page.open('http://ewoken.github.io/Leaflet.MovingMarker/', function() {
page.evaluate(function () {window.focus();});
//  page.render('github.png');
//  phantom.exit();
});

Now, we need to install x virtual frame buffer and some libraries for firefox:

aptitude update; aptitude install Xvfb libgtk-3-0 libasound2 libdbus-glib-1-2 -y

Now we need to add new virtual display 1.1:

pkill [X,x]vfb; pkill nw; Xvfb :1 -screen 1 1440x900x24 >/dev/null 2>&1 &

Try to run firefox without any option, to make sure that no additional library needed (it's normal if there will be some errors in the output):

killall firefox; export DISPLAY=:1.1; firefox

Then, we can use the script:

killall firefox; rm -f ouput2.mp4; \
sleep 5; export DISPLAY=:1.1; export SLIMERJSLAUNCHER=/root/firefox/firefox; \
slimerjs snap.js & \
sleep 3; \
ffmpeg -f x11grab -framerate 60 -video_size 1024x768 -i :1.1 -vcodec libx264 -preset veryfast -b:v 10000k ouput2.mp4

I've got this video:
https://drive.google.com/open?id=0B_tqnSHhFPBndDJ0Y1c5THBKWkk


Note: if you are using 32-Bit Linux, you need to replace the link:

https://download-installer.cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-x86_64/en-US/firefox-49.0.2.tar.bz2

With the following:

https://download-installer.cdn.mozilla.net/pub/firefox/releases/49.0.2/linux-i686/en-US/firefox-49.0.2.tar.bz2

这篇关于使用ffmpeg和phantomjs从网址制作电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆