Adjust audio volume level with CLI omxplayer - Raspberry Pi
Asked Answered
J

5

15

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 CLI that I can implement in the bash script? I have searched quite a bit, but can not find such a command.

Code:

omxplayer Song_Title.mp3

Set audio for local (earphone) output:

sudo modprobe snd_bcm2835 sudo amixer cset numid=3 1

omxplayer -o local

Thanks!

Janik answered 16/10, 2015 at 4:54 Comment(0)
L
31

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:

  1. on starting command line, param --vol YYY, double millibels, default 0, range [-6000:0]
  2. by stdin interface, sending +/- to omxplayer will increase/decrease volume for 300 dmbels
  3. with DBUS interface, cmd 'set volume', value double:XXX, default 1, range [0:1]

xxx to yyy relation is: XXX = 10 ^ (YYY / 2000) ... according to omxplayer.cpp source code, reverse formula would be: 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%)

working 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)

equals to volume parameter at startup:

omxplayer --vol -602 mediaFileName.mp4

... both sets sound volume to 50%.

Licha answered 5/12, 2016 at 5:10 Comment(1)
very nice explanationLamination
J
12

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.

Juanjuana answered 17/10, 2015 at 7:45 Comment(1)
This worked for adjusting the volume level. Thank you!Janik
C
3

Omxplayer doesn't use alsa for sound output, but it's possible to use stdin interface

Volume up:

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

Volume down:

echo -n "-" > /proc/$(pidof omxplayer.bin)/fd/0
Cervical answered 5/2, 2019 at 13:52 Comment(0)
L
1

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

omxplayer --vol N Sogn_title.mp3

Where N is a number indicating the millibels. Valid values for N are for example:

5000 (increase the volume)

-15000 (decrease the volume)

Lappet answered 23/4, 2016 at 7:57 Comment(0)
L
1

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

In the command line type

alsamixer

you will see screen

Just use up or down arrow to increase or decrease volume. Press Esc. Volume is set.

Lesley answered 16/3, 2018 at 4:57 Comment(1)
you can ssh directly to alsamixer from a smartphone e.g. with ssh -t pi alsamixer (where pi is the entry you have in your ~/.ssh/config). You can also change the volume using vertical swipes on the touchscreen (tested in termux). You can also use the number keys, e.g. 7 to set 70% volume.Pazit

© 2022 - 2024 — McMap. All rights reserved.