bash 使用 CLI omxplayer - Raspberry Pi 调整音频音量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33162820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adjust audio volume level with CLI omxplayer - Raspberry Pi
提问by Vandal
I have a bash script that plays .mp3 files on my Raspberry Pi via omxplayer. But can not control the local (earphone) audio volume with the GUI. Is there a command for the CLIthat I can implement in the bash script? I have searched quite a bit, but can not find such a command.
我有一个 bash 脚本,可以通过 omxplayer 在我的 Raspberry Pi 上播放 .mp3 文件。但不能用GUI控制本地(耳机)音频音量。是否有可以在 bash 脚本中实现的CLI命令?我已经搜索了很多,但找不到这样的命令。
Code:
代码:
omxplayer Song_Title.mp3
omxplayer Song_Title.mp3
Set audio for local (earphone) output:
为本地(耳机)输出设置音频:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1
omxplayer -o local
omxplayer -o local
Thanks!
谢谢!
回答by MetNP
to provide more precise information for playing through scripts, there are 3 ways to change sound volume in current version of omxplayer, and values are not so intuitive:
为了通过脚本提供更精确的播放信息,在当前版本的 omxplayer 中有 3 种更改音量的方法,并且值不是那么直观:
- on starting command line, param
--vol YYY
, double millibels, default 0, range [-6000:0] - by stdin interface, sending +/- to omxplayer will increase/decrease volume for 300 dmbels
- with DBUS interface, cmd 'set volume', value
double:XXX
, default 1, range [0:1]
- 在启动命令行,参数
--vol YYY
,双毫贝尔,默认 0,范围 [-6000:0] - 通过标准输入接口,向 omxplayer 发送 +/- 将增加/减少 300 dmbels 的音量
- 带 DBUS 接口,cmd '设置音量',值
double:XXX
,默认 1,范围 [0:1]
xxx to yyy relation is: XXX = 10 ^ (YYY / 2000)
... according to omxplayer.cppsource code, reverse formula would be: YYY = 2000 * (log XXX)
.
xxx 到 yyy 的关系是:XXX = 10 ^ (YYY / 2000)
...根据omxplayer.cpp源代码,反向公式为:YYY = 2000 * (log XXX)
。
so if we need:
所以如果我们需要:
- volume 1%, XXX=0.01 and YYY=-4000
(10^(-4000/2000)=10^-2=0.01
- volume 10%, XXX=0.1 and YYY=-2000
(10^(-2000/2000)=10^-1=0.1
- volume 50%, XXX=0.5 and YYY=-602
(10^(-602/2000))~=0.5
- volume 100%, XXX=1 and YYY=0
(10^(0/2000)=10^0=1)
- volume 150%, XXX=1.5 and YYY=352 ... (for boost test, normal values are <=100%)
- 体积 1%,XXX=0.01 和 YYY=-4000
(10^(-4000/2000)=10^-2=0.01
- 音量 10%,XXX=0.1 和 YYY=-2000
(10^(-2000/2000)=10^-1=0.1
- 音量 50%,XXX=0.5 和 YYY=-602
(10^(-602/2000))~=0.5
- 音量 100%,XXX=1 和 YYY=0
(10^(0/2000)=10^0=1)
- 音量 150%,XXX=1.5 和 YYY=352 ...(对于升压测试,正常值为 <=100%)
working bash script for dbus volume command:
dbus volume 命令的工作 bash 脚本:
export DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/omxplayerdbus.${USER:-root})
dbus-send --print-reply --session --reply-timeout=500 \
--dest=org.mpris.MediaPlayer2.omxplayer \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set \
string:"org.mpris.MediaPlayer2.Player" \
string:"Volume" double:0.5 # <-- XXX=0.5 (50% sound volume)
equals to volume parameter at startup:
等于启动时的音量参数:
omxplayer --vol -602 mediaFileName.mp4
... both sets sound volume to 50%.
...两者都将音量设置为 50%。
回答by LookAtMeh
I am not sure how to adjust the volume level with a command. But when using the omxplayer CLI, just press - or + to turn the volume up or down.
我不确定如何使用命令调整音量级别。但是在使用 omxplayer CLI 时,只需按 - 或 + 即可调高或调低音量。
回答by Roberto
You can set the initial volume by adding the option --vol
:
您可以通过添加选项来设置初始音量--vol
:
omxplayer --vol N Sogn_title.mp3
omxplayer --vol N Sogn_title.mp3
Where N
is a number indicating the millibels. Valid values for N are for example:
哪里N
是表示毫贝尔的数字。N 的有效值例如:
5000 (increase the volume)
5000(增加音量)
-15000 (decrease the volume)
-15000(减小音量)
回答by Sreeragh A R
回答by Giovanni Toraldo
Omxplayer doesn't use alsa for sound output, but it's possible to use stdin interface
Omxplayer 不使用 alsa 进行声音输出,但可以使用 stdin 接口
Volume up:
提高音量:
echo -n "+" > /proc/$(pidof omxplayer.bin)/fd/0
Volume down:
音量减小:
echo -n "-" > /proc/$(pidof omxplayer.bin)/fd/0