Page 1 of 2 12 LastLast
Results 1 to 10 of 21

Thread: Simple guide to grab desktop with FFMPEG

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,029
    Distro
    Ubuntu 14.04 Trusty Tahr

    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
    what I like MOST about our Ubuntu community ... exchanging tips to make things better .... The World should take heed :]
    ShanArt

  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,689

    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
    Hippiesoldierstan
    Beans
    2,029
    Distro
    Ubuntu 14.04 Trusty Tahr

    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
    what I like MOST about our Ubuntu community ... exchanging tips to make things better .... The World should take heed :]
    ShanArt

  8. #8
    Join Date
    Sep 2006
    Beans
    3,689

    Re: VERY simple guide to grab desktop with FFMPEG

    Please include your ffmpeg command and the complete console output.

  9. #9
    Join Date
    Oct 2013
    Beans
    3

    Re: VERY simple guide to grab desktop with FFMPEG

    ffmpeg -f x11grab -s woxga -r 20 -i :0.0 -f mpegts udp://192.168.4.111:1234


    FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
    configuration: --prefix=/usr --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -fasm -std=c99 -fno-math-errno --enable-libdc1394 --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avfilter-lavf --enable-postproc --enable-swscale --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-optimizations --disable-stripping
    libavutil 49.10. 0 / 49.10. 0
    libavcodec 51.71. 0 / 51.71. 0
    libavformat 52.22. 1 / 52.22. 1
    libavdevice 52. 1. 0 / 52. 1. 0
    libavfilter 0. 1. 0 / 0. 1. 0
    libswscale 0. 6. 1 / 0. 6. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Feb 4 2009 19:41:05, gcc: 4.1.2 20071124 (Red Hat 4.1.2-42)
    [x11grab @ 0x191521b0]device: :0.0 -> display: :0.0 x: 0 y: 0 width: 2560 height: 1600
    [x11grab @ 0x191521b0]shared memory extension found
    Input #0, x11grab, from ':0.0':
    Duration: N/A, start: 1380813980.541533, bitrate: -2147483 kb/s
    Stream #0.0: Video: rawvideo, rgb32, 2560x1600, -2147483 kb/s, 20.00 tb(r)
    swScaler: Compile time max width is 2048 change VOF/VOFW and recompile
    Cannot get resampling context


    When I change the resolution, (example 1280x800 half of screen), I only get the upper right quadrant. I just want to know how I can resample the whole screen to a lower resolution.
    Last edited by Jay_Kemper; October 3rd, 2013 at 04:32 PM.

  10. #10
    Join Date
    Sep 2006
    Beans
    3,689

    Re: VERY simple guide to grab desktop with FFMPEG

    Quote Originally Posted by Jay_Kemper View Post
    Code:
    FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
    Wow, this is absolutely ancient. Where did you find this? What is your distro?

    There have been at least 41582 updates to ffmpeg since your graybeard version. Not to be blunt, but you're wasting your time (and mine) using this.

    Please use the code tag.

Page 1 of 2 12 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
  •