Adjust sound volume with CLI omxplayer - Raspberry Pi

I have a bash script that plays .mp3 files on my Raspberry Pi via omxplayer. But it can not control the sound volume on the local (headphone) using the GUI . Is there a command for the CLI that I can implement in a bash script? I searched quite a bit, but I can not find such a team.

code:

omxplayer Song_Title.mp3

Set audio for local (headphone) output:

sudo modprobe snd_bcm2835 sudo amixer cset numid=3 1

omxplayer -o local

Thanks!

+7
source share
5 answers

To provide more accurate information for playback through scripts, there are 3 ways to change the sound volume in the current version of omxplayer, and the values ​​are not so intuitive:

  • at command prompt, param --vol YYY , double millibels, default 0, range [-6000: 0]
  • via stdin interface, sending +/- to omxplayer will increase / decrease the volume for 300 dmbels
  • with DBUS interface, cmd 'set volume', value double:XXX , default 1, range [0: 1]

From xxx to yyy ratio: XXX = 10 ^ (YYY / 2000) ... according to omxplayer.cpp source code, the inverse formula is: YYY = 2000 * (log XXX) .

therefore, 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 the increase test, normal values ​​are <= 100%)

Running a bash script for dbus volume command:

 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) 

at startup it is equal to the volume parameter:

 omxplayer --vol -602 mediaFileName.mp4 

... both set the sound volume to 50%.

+16
source

I'm not sure how to adjust the volume using the command. But when using CLI omxplayer, just press - or + to increase or decrease the volume.

+9
source

You can set the initial volume by adding the --vol option:

omxplayer --vol N Sogn_title.mp3

Where N is a number representing millibytes. Valid values ​​for N are:

5000 (increase in volume)

-15000 (volume reduction)

+2
source

In Raspberry Pi 3, I was able to adjust the sound volume through alsamixer.

At the command prompt Type

alsamixer

you will see screen

Just use the up or down arrows to increase or decrease the volume. Press Esc. The volume is set.

+1
source

Omxplayer does not use alsa to output sound, but you can use the stdin interface

Volume up:

 echo -n "+" > /proc/$(pidof omxplayer.bin)/fd/0 

Turn down the sound:

 echo -n "-" > /proc/$(pidof omxplayer.bin)/fd/0 
0
source

Source: https://habr.com/ru/post/1233832/


All Articles