• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Screencasting with ffmpeg tutorial

teckk

Active Member

Thanks: 29
Messages: 148

#1
Screencasting with ffmpeg in FreeBSD.

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
% 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 fairly CPU intensive. You'll need a box with some horse power 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 horse power.

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 box uses /dev/dsp0.0 as it sound device. Use your own.

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.
 

graudeejs

Son of Beastie

Thanks: 686
Messages: 4,611

#2
No, that won't make screencast of Whole screen (my screen is much bigger)

But you can use this command $ xrandr --prop 2> /dev/null | awk '/\*/ {print $1}' and it will print your screen size :)

so you could use:
$ fmpeg -f oss -i /dev/dsp0.0 -f x11grab -r 24 -s `xrandr --prop 2> /dev/null | awk '/\*/ {print $1}'` -i :0.0 output.avi
 

teckk

Active Member

Thanks: 29
Messages: 148

#3
Thanks killa, that was just an example

You can also get your screen size with
% 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

If you have a mulitcore CPU then adding -threads=2 will help.

In fact there are 101 options with venerable ffmpeg
 

dllud

New Member


Messages: 1

#5
Thanks guys!

And here is my one-liner that prompts you to select a window and then captures only its area:

Code:
gm=$(xwininfo | grep 'geometry') && ffmpeg -video_size $(echo $gm | grep -Eo '[0-9]+x[0-9]+') -framerate 30 -f x11grab -i :0.0+$(echo $gm | grep -Eo '[0-9]+\+[0-9]+$' | sed s/+/,/),nomouse -c:v libx264 -qp 0 -preset ultrafast -profile:v high444 capture.mov
 
Top