[FFmpeg-user] fast video codec for screen casting

dE . de.techno at gmail.com
Thu Jan 5 13:49:51 CET 2012


On 01/05/12 17:06, Carl Eugen Hoyos wrote:
> dE .<de.techno<at>  gmail.com>  writes:
>
>>>>> ffmpeg -f x11grab -s 1280x800 -i :0.0 -f null -
>>>> 30 FPS
>>> I get approximately the same performance with -vcodec mpeg1video, isn't that
>>> also true for you?
>> No. I tend to think this's cause of bad ati drivers, X takes too much
>> CPU cause drivers are incapable of offloading load to the GPU.
> As said, I get (approximately) the same performance with -f null and -vcodec
> mpeg1video -threads 1, so I don't think this is likely
>
>> I've another PC with a Nvidia GPU and a single core processor. Using
>> x264, I get 24 FPS easily.
> I also think it is not unlikely that the GPU (and drivers) do play an important
> role. But that does not explain a large difference between -f null and using a
> "light" codec.

I was wondering that the main bottleneck should be the CPU -- since 
that's the most utilized. If some features of the drivers are missing 
(or it doesn't work well), software rendering has to take over which 
takes more CPU. Anyway, I'm also not sure if it's a GPU problem.

>
>>>> I also tried ffmpeg -f x11grab -s 1280x800 -i :0.0 -f null -qscale 2
>>>> -threads 1 -b 20000k -vcodec mpeg1video -an out.avi
>>> (-b makes no sense with -qscale)
>>> That is great.
>>>
>>> If you provide us with output / results (or say if the problem still exists
>>> with this command line), somebody may be able to help you.
>>>
>> The mailing list appears to have rejected my attachment (output video).
> Attachments are nearly always useless (they are at least much more often useless
> than useful so it makes sense not allow them).
> What I meant was that you neither provided complete, uncut console output (which
> contains all necessary information as you know) or at least told us the speed
> (fps) of above command.
>
> Carl Eugen

Using -f null I get full performance (upto 100 FPS) till I set -r 100 
for the input. Above 100 I only get 3 or 4 FPS. So everything is good 
with -f null.

I think I did post the output -

ffmpeg -f alsa -i default -f x11grab -s 1280x800 -i :0.0 -threads 1 
-qscale 2 -threads 1 -b 20000k -vcodec mpeg1video -ar 44100 -ac 2.0 
-acodec pcm_s16le out.avi
ffmpeg version , Copyright (c) 2000-2011 the FFmpeg developers
   built on Dec 29 2011 08:31:02 with gcc 4.4.5
   configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall 
-g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl 
--enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid 
--enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora 
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 
--enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter 
--enable-libdirac --disable-decoder=libdirac --enable-libschroedinger 
--disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg 
--enable-libvpx --enable-librtmp --extra-libs=-lgcrypt --disable-altivec 
--disable-armv5te --disable-armv6 --disable-vis
   libavutil    50. 43. 0 / 50. 43. 0
   libavcodec   52.123. 0 / 52.123. 0
   libavformat  52.111. 0 / 52.111. 0
   libavdevice  52.  5. 0 / 52.  5. 0
   libavfilter   1. 80. 0 /  1. 80. 0
   libswscale    0. 14. 1 /  0. 14. 1
   libpostproc  51.  2. 0 / 51.  2. 0
[alsa @ 0x19f92e0] capture with some ALSA plugins, especially dsnoop, 
may hang.
[alsa @ 0x19f92e0] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'default':
   Duration: N/A, start: 1325702385.056147, bitrate: N/A
     Stream #0.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[x11grab @ 0x1a1ada0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 
1280 height: 800
[x11grab @ 0x1a1ada0] shared memory extension found
[x11grab @ 0x1a1ada0] Estimating duration from bitrate, this may be 
inaccurate
Input #1, x11grab, from ':0.0':
   Duration: N/A, start: 1325702385.185941, bitrate: 982057 kb/s
     Stream #1.0: Video: rawvideo, bgra, 1280x800, 982057 kb/s, 29.97 
tbr, 1000k tbn, 29.97 tbc
File 'out.avi' already exists. Overwrite ? [y/N] y
Incompatible pixel format 'bgra' for codec 'mpeg1video', auto-selecting 
format 'yuv420p'
[buffer @ 0x1a1e940] w:1280 h:800 pixfmt:bgra tb:1/1000000 sar:0/1 
sws_param:
[buffersink @ 0x19f1f80] auto-inserting filter 'auto-inserted scaler 0' 
between the filter 'src' and the filter 'out'
[scale @ 0x19f2480] w:1280 h:800 fmt:bgra -> w:1280 h:800 fmt:yuv420p 
flags:0x4
Output #0, avi, to 'out.avi':
   Metadata:
     ISFT            : Lavf52.111.0
     Stream #0.0: Video: mpeg1video, yuv420p, 1280x800, q=2-31, 20000 
kb/s, 29.97 tbn, 29.97 tbc
     Stream #0.1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
Stream mapping:
   Stream #1.0 -> #0.0
   Stream #0.0 -> #0.1
Press [q] to stop, [?] for help
frame=    3 fps=  0 q=2.0 size=     786kB time=00:00:01.21 
bitrate=5319.6kbits/sframe=    9 fps=  7 q=2.0 size=     973kB 
time=00:00:02.16 bitrate=3682.1kbits/sframe=   16 fps=  9 q=2.0 size=    
1164kB time=00:00:02.72 bitrate=3503.4kbits/sframe=   24 fps= 10 q=2.0 
size=    1280kB time=00:00:03.27 bitrate=3197.6kbits/sframe=   31 fps= 
11 q=2.0 size=    1821kB time=00:00:03.83 bitrate=3889.2kbits/sframe=   
38 fps= 11 q=2.0 size=    1999kB time=00:00:04.31 
bitrate=3791.1kbits/sframe=   46 fps= 12 q=2.0 size=    2544kB 
time=00:00:04.76 bitrate=4373.6kbits/sframe=   53 fps= 12 q=2.0 size=    
2704kB time=00:00:05.32 bitrate=4162.6kbits/sframe=   61 fps= 12 q=2.0 
size=    3285kB time=00:00:05.87 bitrate=4577.0kbits/sframe=   68 fps= 
12 q=2.0 size=    3863kB time=00:00:06.43 bitrate=4917.1kbits/sframe=   
74 fps= 12 q=2.0 size=    4069kB time=00:00:06.99 
bitrate=4766.7kbits/sframe=   81 fps= 12 q=2.0 size=    4685kB 
time=00:00:07.54 bitrate=5083.7kbits/sframe=   89 fps= 13 q=2.0 size=    
4831kB time=00:00:07.92 bitrate=4995.9kbits/sframe=   97 fps= 13 q=2.0 
size=    5450kB time=00:00:08.47 bitrate=5264.8kbits/sframe=  103 fps= 
13 q=2.0 size=    6060kB time=00:00:09.03 bitrate=5493.5kbits/sframe=  
109 fps= 13 q=2.0 size=    6264kB time=00:00:09.59 
bitrate=5348.0kbits/s[mpeg1video @ 0x19f6300] warning, clipping 1 dct 
coefficients to -255..255
frame=  114 fps= 12 q=2.0 size=    7119kB time=00:00:10.15 
bitrate=5744.9kbits/sframe=  118 fps= 12 q=2.0 size=    7776kB 
time=00:00:10.62 bitrate=5992.4kbits/sframe=  123 fps= 12 q=2.0 size=    
8861kB time=00:00:11.08 bitrate=6551.0kbits/sframe=  131 fps= 12 q=2.0 
size=    9564kB time=00:00:11.63 bitrate=6732.1kbits/sframe=  138 fps= 
12 q=2.0 size=   10323kB time=00:00:12.19 bitrate=6934.6kbits/sframe=  
143 fps= 12 q=2.0 size=   10548kB time=00:00:12.75 
bitrate=6775.8kbits/sframe=  150 fps= 12 q=2.0 size=   11142kB 
time=00:00:13.30 bitrate=6857.6kbits/sframe=  155 fps= 12 q=2.0 size=   
11378kB time=00:00:13.68 bitrate=6812.9kbits/sframe=  159 fps= 12 q=2.0 
size=   12038kB time=00:00:14.23 bitrate=6926.1kbits/sframe=  165 fps= 
12 q=2.0 size=   13078kB time=00:00:14.79 bitrate=7241.2kbits/sframe=  
171 fps= 12 q=2.0 size=   14252kB time=00:00:15.26 
bitrate=7647.2kbits/sframe=  177 fps= 12 q=2.0 size=   14755kB 
time=00:00:15.72 bitrate=7687.2kbits/sframe=  181 fps= 12 q=2.0 size=   
15391kB time=00:00:16.28 bitrate=7744.1kbits/sframe=  188 fps= 12 q=2.0 
size=   16132kB time=00:00:16.83 bitrate=7847.9kbits/sframe=  195 fps= 
12 q=2.0 size=   17373kB time=00:00:17.39 bitrate=8180.9kbits/s    Last 
message repeated 2 times
frame=  201 fps= 12 q=2.0 Lsize=   19247kB time=00:00:17.95 
bitrate=8782.3kbits/s
video:14867kB audio:3093kB global headers:0kB muxing overhead 7.166209%

On Gentoo, I get 2 to 4 FPS -

ffmpeg -f alsa -i default -f x11grab -s 1280x800 -i :0.0 -qscale 2 
-threads 1 -b 20000k -vcodec mpeg1video -ar 44100 -ac 2.0 -acodec 
pcm_s16le out.avi
ffmpeg version N-35180-g31a1342, Copyright (c) 2000-2011 the FFmpeg 
developers
   built on Nov 26 2011 11:05:40 with gcc 4.5.3
   configuration: --prefix=/usr --libdir=/usr/lib64 
--shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared 
--cc=x86_64-pc-linux-gnu-gcc --disable-optimizations --disable-static 
--enable-gpl --enable-version3 --enable-postproc --enable-avfilter 
--disable-stripping --disable-debug --disable-doc --disable-network 
--disable-vaapi --disable-vdpau --enable-libmp3lame 
--enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libtheora 
--enable-libvorbis --enable-libx264 --enable-libxvid --enable-libaacplus 
--enable-nonfree --enable-openal --disable-indev=v4l 
--disable-indev=v4l2 --disable-indev=oss --disable-indev=jack 
--enable-x11grab --disable-outdev=oss --enable-libfreetype 
--enable-pthreads --enable-libopencore-amrwb --enable-libopencore-amrnb 
--enable-libgsm --enable-libdirac --enable-libschroedinger 
--enable-libspeex --enable-libvpx --enable-libopenjpeg --disable-altivec 
--disable-avx --disable-ssse3 --disable-vis --disable-neon 
--disable-iwmmxt --cpu=host --enable-hardcoded-tables
   libavutil    51. 29. 1 / 51. 29. 1
   libavcodec   53. 37. 1 / 53. 37. 1
   libavformat  53. 21. 0 / 53. 21. 0
   libavdevice  53.  4. 0 / 53.  4. 0
   libavfilter   2. 49. 1 /  2. 49. 1
   libswscale    2.  1. 0 /  2.  1. 0
   libpostproc  51.  2. 0 / 51.  2. 0
[alsa @ 0x1515430] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'default':
   Duration: N/A, start: 1325702995.554633, bitrate: N/A
     Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[x11grab @ 0x1550c10] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 
1280 height: 800
[x11grab @ 0x1550c10] shared memory extension found
[x11grab @ 0x1550c10] Estimating duration from bitrate, this may be 
inaccurate
Input #1, x11grab, from ':0.0':
   Duration: N/A, start: 1325702995.794243, bitrate: 982057 kb/s
     Stream #1:0: Video: rawvideo (BGRA / 0x41524742), bgra, 1280x800, 
982057 kb/s, 29.97 tbr, 1000k tbn, 29.97 tbc
Please use -b:a or -b:v, -b is ambiguous
Incompatible pixel format 'bgra' for codec 'mpeg1video', auto-selecting 
format 'yuv420p'
[buffer @ 0x1551580] w:1280 h:800 pixfmt:bgra tb:1/1000000 sar:0/1 
sws_param:
[buffersink @ 0x151b370] auto-inserting filter 'auto-inserted scale 0' 
between the filter 'src' and the filter 'out'
[scale @ 0x156ddb0] w:1280 h:800 fmt:bgra -> w:1280 h:800 fmt:yuv420p 
flags:0x4
Output #0, avi, to 'out.avi':
   Metadata:
     ISFT            : Lavf53.21.0
     Stream #0:0: Video: mpeg1video (mpg1 / 0x3167706D), yuv420p, 
1280x800, q=2-31, 20000 kb/s, 29.97 tbn, 29.97 tbc
     Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 
channels, s16, 1411 kb/s
Stream mapping:
   Stream #1:0 -> #0:0 (rawvideo -> mpeg1video)
   Stream #0:0 -> #0:1 (pcm_s16le -> pcm_s16le)
Press [q] to stop, [?] for help
[alsa @ 0x1515430] ALSA buffer xrun.
frame=   27 fps=  3 q=2.0 Lsize=    4924kB time=00:00:07.64 
bitrate=5272.6kbits/s
video:1495kB audio:1318kB global headers:0kB muxing overhead 75.069700%

After recompilation of ffmpeg -

ffmpeg version N-36445-gc4eec85, Copyright (c) 2000-2012 the FFmpeg 
developers
   built on Jan  5 2012 01:11:11 with gcc 4.5.3
   configuration: --prefix=/usr --libdir=/usr/lib64 
--shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared 
--cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ 
--ar=x86_64-pc-linux-gnu-ar --optflags='-march=native -O2 
-fomit-frame-pointer -floop-interchange -floop-strip-mine -floop-block 
-fgraphite-identity' --extra-cflags='-march=native -O2 
-fomit-frame-pointer -floop-interchange -floop-strip-mine -floop-block 
-fgraphite-identity' --extra-cxxflags='-march=native -O2 
-fomit-frame-pointer -floop-interchange -floop-strip-mine -floop-block 
-fgraphite-identity' --disable-static --enable-gpl --enable-version3 
--enable-postproc --enable-avfilter --disable-stripping --disable-debug 
--disable-doc --disable-network --disable-vaapi --disable-vdpau 
--enable-libmp3lame --enable-libvo-aacenc --enable-libvo-amrwbenc 
--enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid 
--enable-libaacplus --enable-nonfree --enable-openal --disable-indev=v4l 
--disable-indev=v4l2 --disable-indev=oss --disable-i  libavutil      51. 
34.100 / 51. 34.100
   libavcodec     53. 53.100 / 53. 53.100
   libavformat    53. 29.100 / 53. 29.100
   libavdevice    53.  4.100 / 53.  4.100
   libavfilter     2. 57.101 /  2. 57.101
   libswscale      2.  1.100 /  2.  1.100
   libswresample   0.  5.100 /  0.  5.100
   libpostproc    51.  2.100 / 51.  2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile 
options] outfile}...


I get ~20 FPS. Moving windows makes situation worst.

I did a few more experiments. I piped the output of ffmpeg (using 
rawvideo) to lzop (compressor for lzo -- a fast 
compression/decompression algo). Using compression level 6, I got 
performance better than mpeg1 or even x264 (27 FPS maximum). Moving 
windows did slow down the FPS, but it was better than other codecs. 
Compression level more than 6 resulted in dramatic performance loss, 
whereas values less than 6 also reduced performance by a little bit.
Reducing it further to -3 or -4 or lower results in high i/o which then 
reduces the FPS to a crawl.

Converting the raw video inside the LZO archive to any format increased 
the video speed -- so it was not of much use.

So CPU is definitely the bottleneck here and a lighter codec might be 
the answer, but apparently I didn't find any. Are there any ways to 
reduce compression of mpeg1video?


More information about the ffmpeg-user mailing list