How to record a specific window using ffmpeg?

前端 未结 6 808
说谎
说谎 2021-02-18 18:41

I use ffmpeg to record a window using this code:

ffmpeg.exe
-f dshow 
-y 
-i video=\"screen-capture-recorder\":audio=\"virtual-audio-capturer\":audio=\"Microphon         


        
6条回答
  •  感动是毒
    2021-02-18 19:03

    I was also looking for a solution online, but was not satisfied with the answers I found. I have now fiddled together this very simplistic solution for linux:

    ffmpeg -f x11grab -framerate 25 \
        $(xwininfo | gawk 'match($0, /-geometry ([0-9]+x[0-9]+).([0-9]+).([0-9]+)/, a)\
          { print "-video_size " a[1] " -i +" a[2] "," a[3] }') \
        $(date +%Y-%m-%d_%H-%M_%S).mp4
    
    • After executing this command the window can be selected with the mouse pointer

    • The target filename will take the form YYYY-mm-dd_hh_mm_ss.mp4 in the current directory.

    • The awk magic there just parses the window info. It is ugly and only works with gnu awk, but I have not found a better way yet to parse the window geometry into a custom format.

    The syntax to record a specific rectangle on screen is:

    -video_size [width]x[height] -i [x],[y]
    

    and should also work under windows and with dshow, I believe.

提交回复
热议问题