MPV command line video player

34 readers
1 users here now

https://github.com/mpv-player/mpv

founded 1 year ago
MODERATORS
1
 
 

cross-posted from: https://lemmy.world/post/21801277

https://gitlab.com/christosangel/genmon-mpv

This project is created for use with the xfce desktop environment, and the mpv media player.

With the use of the Generic Monitor panel plugin, it displays scrolling the name of the file or the stream playing with mpv.

If another instance of mpv starts playing, genmon-mpv will display the most recently opened title of file/stream.

As soon as an mpv instance displayed is closed, and another previous instance is still open, genmon-mpv will display the title of the still open file/stream.

This project is consisted of two scripts, one in bash, and one in lua. Any feedback is most welcome.

2
 
 

I get this when i try to run mpv in console:

D:/Programs/SMPlayer/mpv/mpv/mpv.conf:12: unparsable extra characters: 'add video-aspect +0.04'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:13: unparsable extra characters: 'add video-aspect -0.04'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:14: unparsable extra characters: 'add video-zoom .02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:15: unparsable extra characters: 'add video-zoom -.02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:16: unparsable extra characters: 'set video-zoom 0 ; set video-aspect 0'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:20: unparsable extra characters: '+KP8 add video-pan-y -.02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:21: unparsable extra characters: '+KP6 add video-pan-x .02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:22: unparsable extra characters: '+KP2 add video-pan-y .02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:23: unparsable extra characters: '+KP4 add video-pan-x -.02'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:24: unparsable extra characters: '+KP5 set video-pan-x 0 ; set video-pan-y 0'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:44: unparsable extra characters: 'volume=volume=-3.2dB'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:47: unparsable extra characters: 'lowshelf=gain=1.5:f=105:q=0.71'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:50: unparsable extra characters: 'equalizer=gain=-3.5:f=200:q=1.41'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:53: unparsable extra characters: 'highshelf=gain=5.5:f=2300:q=0.71'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:56: unparsable extra characters: 'equalizer=gain=-1.0:f=2400:q=3.0'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:59: unparsable extra characters: 'equalizer=gain=-2.4dB:f=3800:q=6.0'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf:62: unparsable extra characters: 'equalizer=gain=-8.0:f=5150:q=5.5'
D:/Programs/SMPlayer/mpv/mpv/mpv.conf: too many errors, stopping.
[file] Cannot open file 'audio-device=help': No such file or directory
Failed to open audio-device=help.
3
 
 

cross-posted from: https://lemmy.world/post/8393990

https://gitlab.com/christosangel/pyradion

Through the menus, the user can :

  • Select directly a station from the Favorites list (which is configurable).

  • Select a random station out of this list of Favorite stations.

  • Select a tag to pick a station from.

  • Select to pick a station from All Stations.

  • Select a random station out of this list of #tag stations.

  • ❌ Quit pyradion.


Recording

Recording a radio stream in pyradion can be done easily, just by hitting r or R.

record.png

The user will be notified through the status line of the recording taking place, and of the output file name.

Editing the pyradion.config file, the user will be able to define output audio file directory.

If the title is available by the stream, the file will take its name by it.

If title is Not Available, the file will take a date/time for name.

Output File Format

In order for recording to work for mpv, output file format must be the same with stream format.

Therefore stream format is recognised, and passed to the output file (e.g. mp3, ogg, aac).


This project shares more or less the same logic with a previous project in Bash:

https://gitlab.com/christosangel/radion

although with this Python script some more features are available.


4
 
 

Edit: I don't know why but specifying the filename of the script-opts file made it work even though the basenames are the same.

Change:

From:

-- Define a table with default options
local o = {
    memory_usage_percentage = 80,
    reserved_memory_gb = 6
}

-- Read the options from the script-opts file
options.read_options(o)

-- Print the read options for debugging purposes
msg.info("memory_usage_percentage: " .. o.memory_usage_percentage)
msg.info("reserved_memory_gb: " .. o.reserved_memory_gb)

To:

-- Define a table with default options
local opts = {
    memory_usage_percentage = 80,
    reserved_memory_gb = 6
}

-- Read the options from the script-opts file
(require 'mp.options').read_options(opts, "demuxer-max-bytes")

-- Print the read options for debugging purposes
msg.info("memory_usage_percentage: " .. opts.memory_usage_percentage)
msg.info("reserved_memory_gb: " .. opts.reserved_memory_gb)

Original post: I am making a lua script to adjust buffer size dynamically based on available ram. The script is working with the hardcoded values: memory_usage_percentage = 80, reserved_memory_gb = 6 but it is not reading the new values from my script-opts file. Do you see why?

cat /home/cmysmiaczxotoy/.config/mpv/script-opts/demuxer-max-bytes.conf

memory_usage_percentage=70
reserved_memory_gb=8

cat /home/cmysmiaczxotoy/.config/mpv/scripts/demuxer-max-bytes.lua (Now edited with fix)

-- Require the necessary modules
local mp = require 'mp'
local msg = require 'mp.msg'

-- Define a table with default options
local opts = {
    memory_usage_percentage = 80,
    reserved_memory_gb = 6
}

-- Read the options from the script-opts file
(require 'mp.options').read_options(opts, "demuxer-max-bytes")

-- Print the read options for debugging purposes
msg.info("memory_usage_percentage: " .. opts.memory_usage_percentage)
msg.info("reserved_memory_gb: " .. opts.reserved_memory_gb)

local function is_windows()
    return package.config:sub(1,1) == '\\'
end

local function set_memory_properties(free_mem_kib, total_mem_kib)
    -- Calculate the percentage of the total memory in KiB
    local allowed_mem_kib = total_mem_kib * (opts.memory_usage_percentage / 100)
    -- Convert reserved memory from GB to KiB
    local reserved_mem_kib = opts.reserved_memory_gb * 1024 * 1024
    -- Calculate the amount of memory to use, leaving the reserved memory free
    local mem_to_use_kib = allowed_mem_kib - (total_mem_kib - free_mem_kib - reserved_mem_kib)

    -- Apply various checks and calculations to mem_to_use_kib
    if mem_to_use_kib > free_mem_kib - reserved_mem_kib then
        mem_to_use_kib = free_mem_kib - reserved_mem_kib
    end
    if mem_to_use_kib < 0 then
        mem_to_use_kib = free_mem_kib - reserved_mem_kib
    end
    if mem_to_use_kib < 0 then
        mem_to_use_kib = 1024
    end

    -- Convert to bytes and round to nearest integer
    local mem_to_use_bytes = math.floor(mem_to_use_kib * 1024)

    -- Set demuxer-max-bytes to the calculated value
    mp.set_property("demuxer-max-bytes", tostring(mem_to_use_bytes))
    mp.msg.info("Set demuxer-max-bytes to: " .. mem_to_use_bytes .. " bytes")
    
    -- Set cache-related properties
    mp.set_property("cache", "yes")
    mp.set_property("cache-pause", "yes")
    mp.set_property("force-seekable", "yes")
    mp.set_property("demuxer-readahead-secs", "30")
end

-- Function to gather memory info on Windows
local function get_memory_info_windows()
    local ps_script = 'Get-CimInstance Win32_OperatingSystem | ' ..
                      'ForEach-Object { $_.FreePhysicalMemory, $_.TotalVisibleMemorySize }'
    local handle = io.popen('powershell -NoProfile -Command "' .. ps_script .. '"', 'r')
    local free_mem_kib = handle:read("*l")
    local total_mem_kib = handle:read("*l")
    handle:close()

    return tonumber(free_mem_kib), tonumber(total_mem_kib)
end

-- Function to gather memory info on Linux
local function get_memory_info_linux()
    local total_mem_kib = 0
    local free_mem_kib = 0
    local meminfo = io.open("/proc/meminfo", "r")
    if meminfo then
        for line in meminfo:lines() do
            local key, value = line:match("(%w+):%s+(%d+)")
            if key == "MemAvailable" then
                free_mem_kib = tonumber(value)
            elseif key == "MemTotal" then
                total_mem_kib = tonumber(value)
            end
        end
        meminfo:close()
    end

    return free_mem_kib, total_mem_kib
end

-- This hook runs at the start of file loading
mp.register_event("start-file", function()
    local free_mem_kib, total_mem_kib

    if is_windows() then
        free_mem_kib, total_mem_kib = get_memory_info_windows()
    else
        free_mem_kib, total_mem_kib = get_memory_info_linux()
    end

    if total_mem_kib > 0 then
        set_memory_properties(free_mem_kib, total_mem_kib)
    else
        mp.msg.error("Could not determine total memory.")
    end
end)
5
9
submitted 1 year ago* (last edited 1 year ago) by christos to c/mpv
 
 

cross-posted from: https://lemmy.world/post/7130971

cross-posted from: https://lemmy.world/post/7130937

radion is an internet radio CLI client, written in Bash.

https://gitlab.com/christosangel/radion

Radion can be costumized as far as the station selecting program is concerned. The user can choose between:

  • read

read

  • fzf

fzf

  • rofi

rofi

  • dmenu

dmenu


Update: Introduced new feature: costumizing prompt text for fzf dmenu and rofi.


Update: Recording functionality added, with the use of another (you guessed it) bash script

icy

Also options in read as Preferred selector are also case insensitive.

Any feedback is appreciated!

6
 
 

cross-posted from: https://lemmy.world/post/1594575

This script will get MPV watch history from files watch_later dir and display them in reverse order of watch. The list is numbered and a prompt for a number will play the desired file in MPV

Need line "write-filename-in-watch-later-config=yes" in mpv.conf Deps rg (ripgrep)

#!/usr/bin/env bash
# Return mpv watch history oldest to newest. 
# Need line "write-filename-in-watch-later-config=yes" in mpv.conf
# Deps rg

watch_later_dir="$HOME/.config/mpv/watch_later/"

SAVEIFS=$IFS
IFS=$'\n'

if [ ! -d "$watch_later_dir" ]; then
    echo "Specified dir doesn't exist: $watch_later_dir"
    echo "Set var watch_later_dir to your watch later dir"
    echo "also, mpv.conf should have line \"write-filename-in-watch-later-config=yes\""
    exit 1
fi

watch_later_files="$(find "$watch_later_dir" -type f -printf "%T@ %p\n" | sort | sed 's/^\([0-9]\+\.[0-9]\+\) //')"

file_count=$(find "$watch_later_dir" -type f | wc -l)

if [ "$file_count" -eq 0 ]; then
    echo "no files found in \"$watch_later_dir\""
    exit 1
fi

watch_later_files=($watch_later_files) 

filepaths_not_echoed="$(for (( i=0; i<${#watch_later_files[@]}; i++ ))
do
  cat "${watch_later_files[$i]}" | rg -o --color=never '(/|http).*'
done)"

filepaths_not_echoed=($filepaths_not_echoed) 

# Reverse the order of array
length=${#filepaths_not_echoed[@]}
for ((i=0; i<length/2; i++)); do
    temp="${filepaths_not_echoed[i]}"
    filepaths_not_echoed[i]="${filepaths_not_echoed[length-i-1]}"
    filepaths_not_echoed[length-i-1]="$temp"
done

filepaths="$(for (( i=0; i<${#watch_later_files[@]}; i++ ))
do
  echo -n "$(( $i - $file_count +1 )) " | sed 's/^-//' 
  cat "${watch_later_files[$i]}" | rg -o --color=never '/.*'
done)"

#echo "$filepaths" | perl -pe 's/^(\d+ ).*\//$1/g' | rg \
echo "$filepaths" | sed -E 's/^([0-9]+ ).*\//\1/g' | rg \
  --colors 'match:none' \
  --colors 'match:fg:0,200,0' \
  --colors 'match:bg:0,0,0' \
  --colors 'match:style:bold' \
  "[^0-9 ].*" 

IFS=$SAVEIFS

read -p "Enter number to play " selection

echo "${filepaths_not_echoed[$selection]}"

setsid >/dev/null 2>&1 </dev/null \
mpv "${filepaths_not_echoed[$selection]}" 2>&1 >/dev/null &