Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Simple guide to grab desktop with FFMPEG

  1. #1
    Join Date
    Jul 2009
    Location
    CyberspacEastEngland
    Beans
    Hidden!
    Distro
    Ubuntu 13.10 Saucy Salamander

    Simple guide to grab desktop with FFMPEG

    How to grab desktop with FFMPEG



    1. just desktop no sound
    2. desktop with microphone sound
    3. webcam with sound
    4. desktop with onboard sound (music or video)


    1.
    ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq ./Desktop/mydesktop.mkv
    higher quality

    ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 30 -qscale 1 -i :0.0 ./Desktop/mydesktop.mkv

    2.
    ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1280x1024 -i :0.0 -acodec flac -vcodec libx264 -threads 0 ./Desktop/mydesktop.mkv

    make sure 1280x1024 matches your specs .... if not change to suit your settings


    3.
    ffmpeg -f alsa -ac 2 -i pulse -f video4linux2 -i /dev/video0 -vcodec libx264 -acodec flac -s 320x240 -r 30 -y ./Desktop/mywebcam.mkvi

    4.
    sudo apt-get install pavucontrol
    find pavucontrol in applications/sound and video

    click on recording/click on box/pick monitor of internal audio

    Nota Bene: you may need to run the code below in your terminal first to bring up the options on pavucontrol

    Then run as in 2.

    ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1280x1024 -i :0.0 -acodec flac -vcodec libx264 -threads 0 ./Desktop/mydesktop.mkv
    or .avi


    DO NOT forget to reset your pavucontrol at the end otherwise next time you try do microphone recording settings will be wrong
    Last edited by shantiq; June 17th, 2012 at 12:41 PM.
    Linux is Latin for off-the-beaten-track [◄►] ● Is there Voodoo in the machine?
    ShanArt ● Mark as SolvedXmms

  2. #2
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: VERY simple guide to grab desktop with FFMPEG

    Nice work
    No longer participating......

  3. #3
    Join Date
    Nov 2009
    Location
    Two Rivers
    Beans
    30
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VERY simple guide to grab desktop with FFMPEG

    Thank You !!

    Dropped it in a bash script :
    Code:
    #!/bin/bash
    dir="$HOME/Poker/Screens/Vids"
    size=$( xdpyinfo | grep 'dimensions:' | awk '{print $2}' )
    name=$( date +'%b.%d_%I:%M%#p' )
    video="$dir/$name.mkv"
    term="gnome-terminal --geometry 78x2+5-2 -t "recording" -x"
    $term ffmpeg -f x11grab -s $size -r 30 -qscale 1  -i :0.0 $video
    Tied it to a hotkey( Ctrl+PrtSc ) :
    - Main Menu->System->Preferences->Keyboard Shortcuts
    - add the full path -> (ie) "/home/me/bin/screencap.sh"
    And caught a memory :
    Attached Images Attached Images
    Last edited by rocuan; April 15th, 2011 at 10:34 AM.

  4. #4
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: VERY simple guide to grab desktop with FFMPEG

    More options for x11grab - positioning of the grab area if less than your screen.

    for example, if you want to capture 1024x768 from the middle of your 1920x1080 display

    x position = 1920-1024 = 896 then /2 = 448
    y position = 1080-768 = 312 then /2 = 156

    then your command would read (using 1. from shantiq's examples):
    ffmpeg -f x11grab -s 1024x768 -r 25 -i :0.0+448,156 -sameq ./Desktop/mydesktop.mkv
    No longer participating......

  5. #5
    Join Date
    Nov 2009
    Location
    Two Rivers
    Beans
    30
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VERY simple guide to grab desktop with FFMPEG

    Jose, I tried the modification you suggested
    Code:
    ffmpeg -f x11grab -s 1024x768 -r 25 -i :0.0+448,156 -sameq ./Desktop/mydesktop.mkv
    but it failed & threw this error
    FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: --extra-version=4:0.5.1-1ubuntu1.1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 1 / 52.20. 1
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    libavfilter 0. 4. 0 / 0. 4. 0
    libswscale 0. 7. 1 / 0. 7. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Mar 31 2011 18:53:20, gcc: 4.4.3
    [x11grab @ 0x9619a60]device: :0.0+448,156 -> display: :0.0 x: 448 y: 156 width: 1024 height: 768
    [x11grab @ 0x9619a60]shared memory extension found
    X Error of failed request: BadMatch (invalid parameter attributes)
    Major opcode of failed request: 145 (MIT-SHM)
    Minor opcode of failed request: 4 (X_ShmGetImage)
    Serial number of failed request: 11

  6. #6
    Join Date
    Sep 2006
    Beans
    3,470

    Re: VERY simple guide to grab desktop with FFMPEG

    Quote Originally Posted by Jose Catre-Vandis View Post
    More options for x11grab - positioning of the grab area if less than your screen.

    for example, if you want to capture 1024x768 from the middle of your 1920x1080 display

    x position = 1920-1024 = 896 then /2 = 448
    y position = 1080-768 = 312 then /2 = 156
    You can use xwininfo to figure out the coordinates for you by simply clicking on the window. More info about that (and much more):

    HOWTO: Proper Screencasting on Linux

    Quote Originally Posted by Jose Catre-Vandis View Post
    then your command would read (using 1. from shantiq's examples):
    Code:
    ffmpeg -f x11grab -s 1024x768 -r 25 -i :0.0+448,156 -sameq ./Desktop/mydesktop.mkv
    -sameq does not mean same quality. The documentation was misleading, but it has been changed in recent FFmpeg to "use same quantizer as source". It's generally recommended to use -qscale instead of -sameq, and "-qscale 2" is generally considered visually lossless for MPEG-1/2/4.

  7. #7
    Join Date
    Jul 2009
    Location
    CyberspacEastEngland
    Beans
    Hidden!
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: VERY simple guide to grab desktop with FFMPEG

    thnx for clarification Fake One


    Yes Verb3k knows his stuff


    This is the section you refer to no doubt

    FAQ:

    Q: How do I get the exact size and coordinates of a specific window I want to capture?
    A: Use a command called “xwininfo“. Basically, you run this command and then click on the window that you want to capture. It will then print the window information to the terminal. This command prints a lot of information, but what you need are the following lines:

    Absolute upper-left X:
    Absolute upper-left Y:
    Width:
    Height:

    If the command, for example, prints:

    Absolute upper-left X: 383
    Absolute upper-left Y: 184
    Width: 665
    Height: 486

    Then, you will adapt it to FFmpeg like this:

    Code:
    -s 664x486 -i :0.0+383,184
    Note that we used 664 instead of 665 for the width since ffmpeg only accepts resolutions divisible by 2.
    You can use the following command line combination with "xwininfo" to only print the information you’ll be needing:

    Code:
    xwininfo | grep -e Width -e Height -e Absolute

    Works like a dream! Great tool
    Linux is Latin for off-the-beaten-track [◄►] ● Is there Voodoo in the machine?
    ShanArt ● Mark as SolvedXmms

  8. #8
    Join Date
    Nov 2009
    Location
    Two Rivers
    Beans
    30
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VERY simple guide to grab desktop with FFMPEG

    Love the forums.
    Thanks everyone

  9. #9
    Join Date
    Jul 2009
    Location
    CyberspacEastEngland
    Beans
    Hidden!
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: VERY simple guide to grab desktop with FFMPEG

    also i find sometimes one wants to just grab desktop sound


    and this here really works well



    1.
    Install pavucontrol and sox ( pavucontrol for sound monitoring and sox for recording)



    Code:
    sudo apt-get install pavucontrol sox
    2. Play music or video on desktop

    3. open pavucontrol
    Code:
    pavucontrol
    or from applications/sound and video

    4.

    Run
    Code:
    rec nameyouwant.flac

    5. On pavucontrol click on recording then pick "Monitor of analogue internal audio stereo " see image

    6. Stop recording and start again now you have the correct sound monitoring

    7. At the end
    make sure to return pavucontrol to original setting of "internal analogue audio stereo"



    ===================================
    ===================================

    ps if you want other formats

    for lossless sound use flac above or for a thinner file ogg (112k)
    Code:
    rec nameyouwant.ogg
    you can override settings thus

    By default the encoding quality level is 3
    (which gives an encoded rate of approx. 112kbps), but this can
    be changed using the -C option (see above) with a number from -1
    to 10; fractional numbers (e.g. 3.6) are also allowed.

    example
    Code:
    rec   -c 9  nameyouwant.ogg




    OR if you want a 128k mp3 you can add this functionality to sox thus (thanx Andrew46)
    Code:
    sudo apt-get install sox libsox-fmt-all
    then run
    Code:
    rec nameyouwant.mp3

    And override this too

    MP3 compression parameters can be selected using SoX's -C option
    as follows (note that the current syntax is subject to change):

    The primary parameter to the LAME encoder is the bit rate. If
    the value of the -C value is a positive integer, it's taken as
    the bitrate in kbps (e.g. if you specify 128, it uses 128 kbps).
    Example
    Code:
    rec   -C 256 nameyouwant.mp3
    or
    Code:
    rec   -C 320  nameyouwant.mp3


    other formats info here formats like dat cdda ircam are available if you like really high-end formats

    Code:
    rec nameyouwant.dat
    gives you a really heavy file of extremely good quality
    Attached Images Attached Images
    Last edited by shantiq; July 16th, 2011 at 09:47 PM.
    Linux is Latin for off-the-beaten-track [◄►] ● Is there Voodoo in the machine?
    ShanArt ● Mark as SolvedXmms

  10. #10
    Join Date
    Nov 2008
    Location
    Portugal
    Beans
    117
    Distro
    Kubuntu 12.10 Quantal Quetzal

    Re: VERY simple guide to grab desktop with FFMPEG

    Thanks shantiq now I can record my desktop without problems

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •