- 課題:GStreamer の
ximagesrc xid=
に渡すウィンドウ ID を自動で取得したい(艦これを起動している Google Chrome のウィンドウ ID だけが欲しい) - 問題:ウィンドウ ID がころころ変わる
- 問題:Ubuntu 16.04 の
gst-launch-1.0 ximagesrc xname=
が何故か効かない
とりあえず xwininfo
でウィンドウの名前を調べる。
$ xwininfo xwininfo: Please select the window about which you would like information by clicking the mouse in that window. xwininfo: Window id: 0x740005c "艦隊これくしょん -艦これ- - オンラインゲーム - DMM GAMES" Absolute upper-left X: 0 Absolute upper-left Y: 65 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 1366 Height: 703 Depth: 24 Visual: 0x20 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x22 (installed) Bit Gravity State: NorthWestGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +0+65 -1050+65 -1050-912 +0-912 -geometry 1366x703+0+36
とりあえずこれでいま艦これを起動している Google Chrome のウィンドウ ID は 0x740005c
であることがわかった。しかしこれは毎回ころころ変わってしまうので使い物にならない。
ウィンドウ名は変わることがないので 艦隊これくしょん -艦これ- - オンラインゲーム - DMM GAMES
を使うことにする。
X 環境ではウィンドウは親がウィンドウマネージャなので子がある(ウィンドウの枠などが無いところ)。さっき調べたウィンドウ名から子を調べる。
$ xwininfo -name "艦隊これくしょん -艦これ- - オンラインゲーム - DMM GAMES" -children xwininfo: Window id: 0x740005c "艦隊これくしょん -艦これ- - オンラインゲーム - DMM GAMES" Root window id: 0xc1 (the root window) (has no name) Parent window id: 0x2b31f74 (has no name) 1 child: 0x7600077 (has no name): () 1366x703+0+0 +0+65
これで子の ID が 0x7600077
であることがわかった。あとはこれを適当に取り出せばよい。
xwininfo -name "艦隊これくしょん -艦これ- - オンラインゲーム - DMM GAMES" -children | grep -A1 "1 child:" | awk 'NR == 2 { print $1 }'
ここまでわかれば FLASH プレイヤーの表示位置もほぼ固定なので座標も指定できる。
x=276 y=77; gst-launch-1.0 -v ximagesrc show-pointer=false startx=$x starty=$y endx=$((x+800-1)) endy=$((y+480-1)) xid="`xwininfo -name "艦隊これくしょん -艦これ- - オン ラインゲーム - DMM GAMES" -children | grep -A1 "1 child:" | awk 'NR == 2 { print $1 }'`" ! video/x-raw, framerate=30/1 ! videoconvert ! video/x-raw, format=I420 ! vaapih264enc init-qp=22 dct8x8=true cabac=true max-bframes=2 ! h264parse ! flvmux ! filesink location=game.flv