Making a movie from the url using ffmpeg and phant

2019-02-20 03:34发布

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,

1条回答
孤傲高冷的网名
2楼-- · 2019-02-20 04:02

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
查看更多
登录 后发表回答