[PLUG] avconv -f x11grab tool question

King Beowulf kingbeowulf at gmail.com
Fri Mar 22 08:11:57 UTC 2013


On 03/21/2013 05:21 PM, website reader wrote:
> I am attempting to create mpg or avi movies directly from a window
> on my Ubuntu 12.04 LTS system.  The display monitor is a
> 1920x1080p digital unit and the output from geomview of the
> rotating spherical polygon and unit sphere look 3d when viewing the
> monitor.
> 
> However when I use "avconv -f x11grab -b 500k -s vga -r 30 -i 
> :0,0+738,98 out.mpg" to capture this window, the video capture ends
> up with poor quality, and has distracting jerky green rectangular 
> blotches flashing in the movie.  The video itself has poor
> definition, like viewing through frosted glass and slightly out of
> focus.
> 
> If we know exactly where the frame buffer is, for the window
> (which xwininfo does provide) why cannot we get the exact video
> memory capture of this window??
> 
> What can I do to improve the video quality?  It seems peculiar
> that using a digital display that such a poor quality mpg resulted.
> Is the video codec the problem?  It wants to use the yuv420p video
> codec, not the bgra.
> 
> I also rename the output file to out.mkv and that has improved the 
> quality of the video capture, but it still is out of focus and
> moire effects are visible.  Searching the avconv documentation
> about yuv420p doesn't turn up much.
> 
> Thanks for your suggestions.
> 
> Randall _______________________________________________ PLUG
> mailing list PLUG at lists.pdxlinux.org 
> http://lists.pdxlinux.org/mailman/listinfo/plug
> 
Quality of the capture is governed by your CPU speed and settings.
Your best bet is to capture raw video and then convert to the
appropriate format.  avconv tries to guess based on output file
extension (see -codecs and -formats). The container format will also
define the codec as well as default options.  For the mpeg1video codec
yuv420p is the default color space pixel format. BGR is for the raw
video stream.

As I am not in the libav camp, I use ffmpeg (IMHO, it is better;
avconv will have similar options).  Replicating your settings also
provides a poor quality, pixelated movie:

$ ffmpeg -f x11grab -b:v 500k -bufsize 500k -s vga -r 30 -i :0.0+10,50
screenGrab.mpg

ffmpeg output:
[x11grab @ 0x12a4920] device: :0.0+10,50 -> display: :0.0 x: 10 y: 50
width: 640 height: 480
[x11grab @ 0x12a4920] shared memory extension found
[x11grab @ 0x12a4920] Estimating duration from bitrate, this may be
inaccurate
Input #0, x11grab, from ':0.0+10,50':
  Duration: N/A, start: 1363935879.837044, bitrate: 294912 kb/s
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480,
294912 kb/s, 30 tbr, 1000k tbn, 30 tbc
w:640 h:480 pixfmt:bgr0 tb:1/1000000 sar:0/1 sws_param:flags=2
[buffersink @ 0x12b6ea0] No opaque field provided
[format @ 0x12b7740] auto-inserting filter 'auto-inserted scaler 0'
between the filter 'src' and the filter 'format'
[scale @ 0x1288400] w:640 h:480 fmt:bgr0 sar:0/1 -> w:640 h:480
fmt:yuv420p sar:0/1 flags:0x4
[mpeg @ 0x12b2e80] VBV buffer size not set, muxing may fail
Output #0, mpeg, to 'screenGrab.mpg':
  Metadata:
    encoder         : Lavf54.6.100
    Stream #0:0: Video: mpeg1video, yuv420p, 640x480, q=2-31, 200
kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg1video)
Press [q] to stop, [?] for help
frame=  720 fps= 36 q=31.0 Lsize=    1136kB time=00:00:23.96 bitrate=
388.3kbits/s dup=135 drop=55

Letting ffmpeg decide for your codec (note you often can't force your
bitrate depending on codec) and tweaking qscale results in much
improved video:

$ ffmpeg -f x11grab -s vga -r 30 -i :0.0+10,50 -q:v 5 screenGrab.mpg

[x11grab @ 0x2096920] device: :0.0+10,50 -> display: :0.0 x: 10 y: 50
width: 640 height: 480
[x11grab @ 0x2096920] shared memory extension found
[x11grab @ 0x2096920] Estimating duration from bitrate, this may be
inaccurate
Input #0, x11grab, from ':0.0+10,50':
  Duration: N/A, start: 1363936466.818580, bitrate: 294912 kb/s
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480,
294912 kb/s, 30 tbr, 1000k tbn, 30 tbc
[buffer @ 0x20a8b60] w:640 h:480 pixfmt:bgr0 tb:1/1000000 sar:0/1
sws_param:flags=2
[buffersink @ 0x20a90a0] No opaque field provided
[format @ 0x20a98c0] auto-inserting filter 'auto-inserted scaler 0'
between the filter 'src' and the filter 'format'
[scale @ 0x20aa040] w:640 h:480 fmt:bgr0 sar:0/1 -> w:640 h:480
fmt:yuv420p sar:0/1 flags:0x4
[mpeg @ 0x20a4e40] VBV buffer size not set, muxing may fail
Output #0, mpeg, to 'screenGrab.mpg':
  Metadata:
    encoder         : Lavf54.6.100
    Stream #0:0: Video: mpeg1video, yuv420p, 640x480, q=2-31, 200
kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg1video)
Press [q] to stop, [?] for help
frame=  687 fps= 30 q=5.0 Lsize=    3748kB time=00:00:22.86
bitrate=1342.7kbits/s dup=13 drop=2

For lossless high quality (can transcode later and you will need h.264
support compiled in), try

$ ffmpeg -f x11grab -b:v 500 -s vga -r 30 -i :0.0+10,50 -q:v 5 -vcodec
libx264 -crf 0 -preset ultrafast -pix_fmt yuv420p screenGrab.mkv

References
1.
http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20grab%20the%20desktop%20%28screen%29%20with%20FFmpeg
2. http://ffmpeg.org/trac/ffmpeg/wiki/StreamingGuide
3. http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide

Enjoy,
Ed







More information about the PLUG mailing list