LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Screencasting with ffmpeg tutorial (https://www.linuxquestions.org/questions/linux-desktop-74/screencasting-with-ffmpeg-tutorial-880858/)

teckk 05-15-2011 12:36 PM

Screencasting with ffmpeg tutorial
 
Screencasting with ffmpeg in FreeBSD and Linux. Use your own OS syntax.

Example: If you want the whole desktop, at 24fps, with sound, to output.avi
Code:

ffmpeg -f oss -i /dev/dsp0.0 -f x11grab -r 24 -s 1024x768 -i :0.0 output.avi
Example: If you want the desktop with raw audio, x264 video at 30 fps to output.avi
Code:

ffmpeg -f oss -i /dev/dsp0.0 -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s32le -vcodec libx264 -vpre lossless_ultrafast output.avi
Example If you want a screen area captured with 128k mp3 audio, and 1000k 30 fps mpeg4 video to output.avi, qscale n will be more or less CPU intensive with resulting better or worse video
Code:

ffmpeg -f oss -i /dev/dsp0.0 -f x11grab -r 30 -s 410x230 -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -b 1000k -qscale 10 output.avi
If you want to find the size and offset of a particular window to capture
Code:

xwininfo
Then enter that info after the :0.0 in format +30,25

Example: A video window in a web browser captured at 30 fps, raw audio, x264 vid, to ouput.mkv
Code:

ffmpeg -f oss -i /dev/dsp0.0 -f x11grab -r 30 -s 416x234 -i :0.0+35,86 -acodec pcm_s32le -vcodec libx264 -vpre lossless_ultrafast output.mkv
You'll need to have ffmpeg compiled with libmp3lame, libx264, mpeg4 or whatever it is that you are wanting to use, faac, faad, matroska......

The capturing of video is faily CPU intensive. You'll need a box with some hoursepower if you want to capture videos of any major size.

It also depends on how active the screen is that you are capturing. You can capture an xterm full screen as you type with audio from your mic without stressing the CPU much. (Turn up your mixers record input).
Capturing a flash video as it plays will require more horsepower.

For example: I tried it on a older P4 2Ghz. box with onboard AGP video, and trying to capture videos much past a resolution of around 600x350 would peg the CPU 100% and result in ffmpeg dropping to 8-10 fps capture rate. the videos captured would still play but were quite jerky and missing video as you would imagine.

Oh, and this FreeBSD box uses oss and /dev/dsp0.0 as its sound device. Use your own device and sound system. If you have a multi core box then -threads will help things up too. Linux may use pulse or just alsa, and /dev/dsp0
Code:

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 2 output.mkv
The less you encode while capturing the better. You can re-encode the video later after you have it.

Hopefully this is of some use to someone.

teckk 05-15-2011 05:35 PM

You can also get your screen size with
Code:

xwininfo | grep -e Width -e Height -e Absolute
Then click on a window or the desktop.

You can also hide the mouse cursor
Add +nomouse after :0.0 to look like this: :0.0+nomouse

Someone suggests
Code:

xrandr --prop 2> /dev/null | awk '/\*/ {print $1}'
For screen size


All times are GMT -5. The time now is 06:53 PM.