の出力からpactl list sink-inputs
次のものを取得する必要があります。受信機入力VLC番号。それ以前は、VLC出力のみを含む部分を抽出してみました。私が考えるすべての方法には欠点があります。以下はサンプル出力です。
$ pactl list sink-inputs
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 453287 usec
Sink Latency: 19697 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.id = "org.VideoLAN.VLC"
application.version = "2.1.5"
application.icon_name = "vlc"
application.language = "pt_BR.UTF-8"
application.process.id = "19965"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
application.process.session_id = "948146522454ae6aa2bb8ed153f4bce4-1431635199.85146-1790309877"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "vlc"
window.x11.display = ":0.0"
module-stream-restore.id = "sink-input-by-media-role:video"
Sink Input #1378
Driver: protocol-native.c
Owner Module: 9
Client: 10378
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 989841 usec
Sink Latency: 19572 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer2"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.process.id = "20093"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "mplayer2"
application.language = "C"
window.x11.display = ":0.0"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
module-stream-restore.id = "sink-input-by-application-name:mplayer2"
両方とも、出力が終了するまでVLC部分だけでなくmplayer2部分もawk '/^Sink/,/VLC/'
取得します。sed -n '/^Sink/,/VLC/p'
$ pactl list sink-inputs | awk '/^Sink/,/VLC/'
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 437414 usec
Sink Latency: 19666 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
Sink Input #1379
Driver: protocol-native.c
Owner Module: 9
Client: 10381
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 980045 usec
Sink Latency: 19563 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer2"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.process.id = "20093"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "mplayer2"
application.language = "C"
window.x11.display = ":0.0"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
module-stream-restore.id = "sink-input-by-application-name:mplayer2"
grep -Poz '^Sink(?s).*?VLC'
動作しますが、VLC出力がmplayer2以降でなければならない場合は失敗します(VLCではなくmplayer2でテスト)。
$ pactl list sink-inputs | grep -Poz '^Sink(?s).*?mplayer'
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 441088 usec
Sink Latency: 18159 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.id = "org.VideoLAN.VLC"
application.version = "2.1.5"
application.icon_name = "vlc"
application.language = "pt_BR.UTF-8"
application.process.id = "19965"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
application.process.session_id = "948146522454ae6aa2bb8ed153f4bce4-1431635199.85146-1790309877"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "vlc"
window.x11.display = ":0.0"
module-stream-restore.id = "sink-input-by-media-role:video"
Sink Input #1380
Driver: protocol-native.c
Owner Module: 9
Client: 10396
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 989841 usec
Sink Latency: 18084 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer
希望の出力:
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 441088 usec
Sink Latency: 18159 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
答え1
そしてed
:
ed -s <<'IN'
r !pactl list sink-inputs
/VLC/+,$d
?Sink Input?,.p
q
IN
r
コマンド出力をテキストバッファに書き込み、最初の行のマッチ後d
のすべてのエントリを削除し、前の行VLC
からp
現在の行Sink Input
まで一致させます。
そしてsed
:
pactl list sink-inputs | sed -n 'H;/Sink Input/h;/VLC/{x;p;q}'
各行を前のバッファに追加しH
、行が一致した場合は前のバッファを上書きSink Input
しh
、行がVLCと一致するとx
予約されたスペースwを変更します。パターン空間、p
rins、q
uits。
答え2
私はPerlの短絡モードを使います:
pactl list sink-inputs | perl -00ne 'print if s/(.*?VLC.*?\n).*/$1/ms'
-00
入力レコード区切り文字を\n\n
段落「行」に設定します。その後、置換は最初の行より前のすべての項目と一致し、最初のVLC
改行前のすべての項目が一致し、$1
それ以降のすべての項目は削除されます(すべての項目がに置き換えられたため$1
)。最後に、交換が成功した「行」を印刷します。
答え3
これは実際には空行で区切られた複数行のレコードです。 Awkはこの種のデータ操作に適しています。
pactl list sink-inputs | awk -v RS="" '/VLC/'
最初の「VLC」が登場した後、レコードの下部を含まないことを非常にトリッキーに設定するには:
pactl list sink-inputs | awk -v RS="" -v FS="\n" '/VLC/{ for(i=1; i<=NF; i++) { print $i; if($i ~ /VLC/) exit}}'