Cant set negative gain value with ffmpeg equalizer filter
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.
Pyradion, internet radio TUI client, with recording functionality, written in Python
My MPV lua script isn't reading my script-opts file. Why?
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)
Radion, an internet radio CLI client, written in Bash.
Script: Get MPV watch history from watch_later dir. Numbered selector to pick file to play
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 &